From c0538e46c598e3eab8203623394721d433ea2dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Benguigui?= Date: Tue, 5 Nov 2024 15:00:43 +0100 Subject: [PATCH] Add constants in NodeCandidateUtils.java --- .../sal/service/nc/NodeCandidateUtils.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/nc/NodeCandidateUtils.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/nc/NodeCandidateUtils.java index b1139ef..7de733c 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/nc/NodeCandidateUtils.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/nc/NodeCandidateUtils.java @@ -38,6 +38,11 @@ @Component public class NodeCandidateUtils { + public static final String AWS_EC2 = "aws-ec2"; + public static final String AZURE = "azure"; + public static final String GCE = "gce"; + public static final String OPENSTACK = "openstack"; + @Autowired private PAConnectorIaasGateway connectorIaasGateway; @@ -224,7 +229,7 @@ private Hardware createHardware(JSONObject nodeCandidateJSON, PACloud paCloud) { hardware.setRam(Long.valueOf(minRam)); hardware.setFpga(hardwareJSON.optString("type")); - if ("aws-ec2".equals(nodeCandidateJSON.optString("cloud"))) { + if (AWS_EC2.equals(nodeCandidateJSON.optString("cloud"))) { hardware.setDisk((double) 8); } else { hardware.setDisk((double) 0); @@ -256,13 +261,13 @@ private Location createLocation(JSONObject nodeCandidateJSON, PACloud paCloud) { private GeoLocation createGeoLocation(String cloud, String region) { switch (cloud) { - case "aws-ec2": + case AWS_EC2: return new GeoLocation(geoLocationUtils.findGeoLocation("AWS", region)); - case "azure": + case AZURE: return new GeoLocation(geoLocationUtils.findGeoLocation("Azure", region)); - case "gce": + case GCE: return new GeoLocation(geoLocationUtils.findGeoLocation("GCE", region)); - case "openstack": + case OPENSTACK: return new GeoLocation(geoLocationUtils.findGeoLocation("OVH", region)); } LOGGER.warn("Cloud provider name no handled for Geo Location."); @@ -282,13 +287,13 @@ private Image createImage(JSONObject nodeCandidateJSON, JSONObject imageJSON, PA os.setOperatingSystemFamily(OperatingSystemFamily.fromValue(osJSON.optString("family").toUpperCase())); String arch = ""; - if ("aws-ec2".equals(nodeCandidateJSON.optString("cloud"))) { + if (AWS_EC2.equals(nodeCandidateJSON.optString("cloud"))) { if (nodeCandidateJSON.optJSONObject("hw").optString("type").startsWith("a")) { arch = osJSON.optBoolean("is64Bit") ? "ARM64" : "ARM"; } else { arch = osJSON.optBoolean("is64Bit") ? "AMD64" : "i386"; } - } else if ("azure".equals(nodeCandidateJSON.optString("cloud"))) { + } else if (AZURE.equals(nodeCandidateJSON.optString("cloud"))) { arch = osJSON.optString("arch"); } os.setOperatingSystemArchitecture(OperatingSystemArchitecture.fromValue(arch)); @@ -376,13 +381,13 @@ public void saveNodeCandidates(List newCloudIds) { os = os.substring(0, 1).toUpperCase() + os.substring(1); String pair = os + ":" + region; switch (paCloud.getCloudProviderName()) { - case "aws-ec2": + case AWS_EC2: imageReq = "Linux"; break; - case "openstack": + case OPENSTACK: imageReq = os; break; - case "azure": + case AZURE: imageReq = os; break; default: @@ -390,7 +395,7 @@ public void saveNodeCandidates(List newCloudIds) { " is not handled yet."); } - if (paCloud.getCloudProviderName().equals("openstack")) { + if (paCloud.getCloudProviderName().equals(OPENSTACK)) { entries.add(pair); } populateNodeCandidatesFromCache(paCloud, region, imageReq, image);