You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b28749f
Browse filesBrowse the repository at this point in the historyBrowse files
Murali Reddy
authored and
Murali Reddy
committed
upgrade external devices support from 2.2.14 to network offering framework
PreparedStatementfetchF5NspStmt = conn.prepareStatement("SELECT id from `cloud`.`physical_network_service_providers` where physical_network_id=" + physicalNetworkId
709
+
+ " and provider_name = 'F5BigIp'");
710
+
ResultSetrsF5NSP = fetchF5NspStmt.executeQuery();
711
+
booleanhasF5Nsp = rsF5NSP.next();
712
+
fetchF5NspStmt.close();
713
+
714
+
if (!hasF5Nsp) {
715
+
f5DevicesStmt = conn.prepareStatement("SELECT id FROM host WHERE data_center_id=? AND type = 'ExternalLoadBalancer' AND removed IS NULL");
716
+
f5DevicesStmt.setLong(1, zoneId);
717
+
f5DevicesResult = f5DevicesStmt.executeQuery();
718
+
719
+
while (f5DevicesResult.next()) {
720
+
longf5HostId = f5DevicesResult.getLong(1);;
721
+
// add F5BigIP provider and provider instance to physical network
PreparedStatementfetchSRXNspStmt = conn.prepareStatement("SELECT id from `cloud`.`physical_network_service_providers` where physical_network_id=" + physicalNetworkId
pstmt = conn.prepareStatement("select id from `cloud`.`data_center` where lb_provider='F5BigIp' or firewall_provider='JuniperSRX' or gateway_provider='JuniperSRX'");
900
+
rs = pstmt.executeQuery();
901
+
while (rs.next()) {
902
+
zoneIds.add(rs.getLong(1));
903
+
}
904
+
} catch (SQLExceptione) {
905
+
thrownewCloudRuntimeException("Unable to create network to LB & firewalla device mapping for networks that use them", e);
906
+
}
907
+
908
+
if (zoneIds.size() == 0) {
909
+
return; // no zones using F5 and SRX devices so return
910
+
}
911
+
912
+
// find the default network offering created for external devices during upgrade from 2.2.14
913
+
try {
914
+
pstmt = conn.prepareStatement("select id from `cloud`.`network_offerings` where unique_name='Isolated with external providers' ");
915
+
rs = pstmt.executeQuery();
916
+
if (rs.first()) {
917
+
networkOfferingId = rs.getLong(1);
918
+
} else {
919
+
thrownewCloudRuntimeException("Cannot upgrade as there is no 'Isolated with external providers' network offering crearted .");
920
+
}
921
+
} catch (SQLExceptione) {
922
+
thrownewCloudRuntimeException("Unable to create network to LB & firewalla device mapping for networks that use them", e);
923
+
}
924
+
925
+
for (LongzoneId : zoneIds) {
926
+
try {
927
+
// find the F5 device id in the zone
928
+
pstmt = conn.prepareStatement("SELECT id FROM host WHERE data_center_id=? AND type = 'ExternalLoadBalancer' AND removed IS NULL");
929
+
pstmt.setLong(1, zoneId);
930
+
rs = pstmt.executeQuery();
931
+
if (rs.first()) {
932
+
f5HostId = rs.getLong(1);
933
+
} else {
934
+
thrownewCloudRuntimeException("Cannot upgrade as there is no F5 load balancer device found in data center " + zoneId);
935
+
}
936
+
pstmt = conn.prepareStatement("SELECT id FROM external_load_balancer_devices WHERE host_id=?");
937
+
pstmt.setLong(1, f5HostId);
938
+
rs = pstmt.executeQuery();
939
+
if (rs.first()) {
940
+
f5DeviceId = rs.getLong(1);
941
+
} else {
942
+
thrownewCloudRuntimeException("Cannot upgrade as there is no F5 load balancer device with host ID " + f5HostId + " found in external_load_balancer_device");
943
+
}
944
+
945
+
// find the SRX device id in the zone
946
+
pstmt = conn.prepareStatement("SELECT id FROM host WHERE data_center_id=? AND type = 'ExternalFirewall' AND removed IS NULL");
947
+
pstmt.setLong(1, zoneId);
948
+
rs = pstmt.executeQuery();
949
+
if (rs.first()) {
950
+
srxHostId = rs.getLong(1);
951
+
} else {
952
+
thrownewCloudRuntimeException("Cannot upgrade as there is no SRX firewall device found in data center " + zoneId);
953
+
}
954
+
pstmt = conn.prepareStatement("SELECT id FROM external_firewall_devices WHERE host_id=?");
955
+
pstmt.setLong(1, srxHostId);
956
+
rs = pstmt.executeQuery();
957
+
if (rs.first()) {
958
+
srxDevivceId = rs.getLong(1);
959
+
} else {
960
+
thrownewCloudRuntimeException("Cannot upgrade as there is no SRX firewall device found with host ID " + srxHostId + " found in external_firewall_devices");
961
+
}
962
+
963
+
// check if network any uses F5 or SRX devices in the zone
964
+
pstmt = conn.prepareStatement("select id from `cloud`.`networks` where guest_type='Virtual' and data_center_id=? and network_offering_id=? and removed IS NULL");
965
+
pstmt.setLong(1, zoneId);
966
+
pstmt.setLong(2, networkOfferingId);
967
+
rs = pstmt.executeQuery();
968
+
while (rs.next()) {
969
+
// get the network Id
970
+
networkId = rs.getLong(1);
971
+
972
+
// add mapping for the network in network_external_lb_device_map
pstmt = conn.prepareStatement("update `cloud`.`host_details` set name=? where host_id=? AND name=?");
1010
+
pstmt.setString(1, lowerCaseName);
1011
+
pstmt.setLong(2, hostId);
1012
+
pstmt.setString(3, camlCaseName);
1013
+
pstmt.executeUpdate();
1014
+
}
1015
+
s_logger.debug("Successfully updated host details for F5 and SRX devices");
1016
+
} catch (SQLExceptione) {
1017
+
thrownewCloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e);
1018
+
} finally {
1019
+
try {
1020
+
if (rs != null) {
1021
+
rs.close();
1022
+
}
1023
+
if (pstmt != null) {
1024
+
pstmt.close();
1025
+
}
1026
+
} catch (SQLExceptione) {
1027
+
}
1028
+
}
1029
+
s_logger.info("Successfully upgraded networks using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map");
0 commit comments