7
7
import org .zstack .core .cloudbus .MessageSafe ;
8
8
import org .zstack .core .componentloader .PluginRegistry ;
9
9
import org .zstack .core .db .DatabaseFacade ;
10
+ import org .zstack .core .db .SQL ;
10
11
import org .zstack .core .db .SimpleQuery ;
11
12
import org .zstack .core .db .SimpleQuery .Op ;
12
13
import org .zstack .core .db .UpdateQuery ;
@@ -130,7 +131,9 @@ private void handle(APIUpdateEipMsg msg) {
130
131
131
132
@ Transactional (readOnly = true )
132
133
private List <VmNicInventory > getAttachableVmNicForEip (String eipUuid , String vipUuid ) {
133
- String zoneUuid = null ;
134
+ String zoneUuid ;
135
+ String providerType ;
136
+
134
137
if (eipUuid != null ) {
135
138
String sql = "select l3.zoneUuid, vip.uuid" +
136
139
" from L3NetworkVO l3, VipVO vip, EipVO eip" +
@@ -142,6 +145,10 @@ private List<VmNicInventory> getAttachableVmNicForEip(String eipUuid, String vip
142
145
Tuple t = q .getSingleResult ();
143
146
zoneUuid = t .get (0 , String .class );
144
147
vipUuid = t .get (1 , String .class );
148
+
149
+ providerType = SQL .New ("select v.serviceProvider from VipVO v, EipVO e where e.vipUuid = v.uuid" +
150
+ " and e.uuid = :euuid" ).param ("euuid" , eipUuid ).find ();
151
+
145
152
} else {
146
153
String sql = "select l3.zoneUuid" +
147
154
" from L3NetworkVO l3, VipVO vip" +
@@ -150,28 +157,53 @@ private List<VmNicInventory> getAttachableVmNicForEip(String eipUuid, String vip
150
157
TypedQuery <String > q = dbf .getEntityManager ().createQuery (sql , String .class );
151
158
q .setParameter ("vipUuid" , vipUuid );
152
159
zoneUuid = q .getSingleResult ();
160
+
161
+ providerType = SQL .New ("select v.serviceProvider from VipVO v where v.uuid = :uuid" )
162
+ .param ("uuid" , vipUuid ).find ();
153
163
}
154
164
165
+ List <String > l3Uuids ;
166
+
167
+ if (providerType != null ) {
168
+ // the eip is created on the backend
169
+ l3Uuids = SQL .New ("select l3.uuid" +
170
+ " from L3NetworkVO l3, VipVO vip, NetworkServiceL3NetworkRefVO ref, NetworkServiceProviderVO np" +
171
+ " where l3.system = :system" +
172
+ " and l3.uuid != vip.l3NetworkUuid" +
173
+ " and l3.uuid = ref.l3NetworkUuid" +
174
+ " and ref.networkServiceType = :nsType" +
175
+ " and l3.zoneUuid = :zoneUuid" +
176
+ " and vip.uuid = :vipUuid" +
177
+ " and np.uuid = ref.networkServiceProviderUuid" +
178
+ " and np.type = :npType" )
179
+ .param ("system" , false )
180
+ .param ("zoneUuid" , zoneUuid )
181
+ .param ("nsType" , EipConstant .EIP_NETWORK_SERVICE_TYPE )
182
+ .param ("npType" , providerType )
183
+ .param ("vipUuid" , vipUuid )
184
+ .list ();
185
+ } else {
186
+ // the eip is not created on the backend
187
+ l3Uuids = SQL .New ("select l3.uuid" +
188
+ " from L3NetworkVO l3, VipVO vip, NetworkServiceL3NetworkRefVO ref" +
189
+ " where l3.system = :system" +
190
+ " and l3.uuid != vip.l3NetworkUuid" +
191
+ " and l3.uuid = ref.l3NetworkUuid" +
192
+ " and ref.networkServiceType = :nsType" +
193
+ " and l3.zoneUuid = :zoneUuid" +
194
+ " and vip.uuid = :vipUuid" )
195
+ .param ("system" , false )
196
+ .param ("zoneUuid" , zoneUuid )
197
+ .param ("nsType" , EipConstant .EIP_NETWORK_SERVICE_TYPE )
198
+ .param ("vipUuid" , vipUuid )
199
+ .list ();
200
+ }
155
201
156
- String sql = "select l3.uuid" +
157
- " from L3NetworkVO l3, VipVO vip, NetworkServiceL3NetworkRefVO ref" +
158
- " where l3.system = :system" +
159
- " and l3.uuid != vip.l3NetworkUuid" +
160
- " and l3.uuid = ref.l3NetworkUuid" +
161
- " and ref.networkServiceType = :nsType" +
162
- " and l3.zoneUuid = :zoneUuid" +
163
- " and vip.uuid = :vipUuid" ;
164
- TypedQuery <String > l3q = dbf .getEntityManager ().createQuery (sql , String .class );
165
- l3q .setParameter ("vipUuid" , vipUuid );
166
- l3q .setParameter ("system" , false );
167
- l3q .setParameter ("zoneUuid" , zoneUuid );
168
- l3q .setParameter ("nsType" , EipConstant .EIP_NETWORK_SERVICE_TYPE );
169
- List <String > l3Uuids = l3q .getResultList ();
170
202
if (l3Uuids .isEmpty ()) {
171
- return new ArrayList <VmNicInventory >();
203
+ return new ArrayList <>();
172
204
}
173
205
174
- sql = "select nic" +
206
+ String sql = "select nic" +
175
207
" from VmNicVO nic, VmInstanceVO vm" +
176
208
" where nic.l3NetworkUuid in (:l3Uuids)" +
177
209
" and nic.vmInstanceUuid = vm.uuid" +
0 commit comments