Skip to content

Commit

Permalink
Add constants in NodeCandidateUtils.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mbenguig committed Nov 5, 2024
1 parent ae30ec2 commit c0538e4
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.");
Expand All @@ -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));
Expand Down Expand Up @@ -376,21 +381,21 @@ public void saveNodeCandidates(List<String> 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:
throw new IllegalArgumentException("The infrastructure " + paCloud.getCloudProviderName() +
" is not handled yet.");
}

if (paCloud.getCloudProviderName().equals("openstack")) {
if (paCloud.getCloudProviderName().equals(OPENSTACK)) {
entries.add(pair);
}
populateNodeCandidatesFromCache(paCloud, region, imageReq, image);
Expand Down

0 comments on commit c0538e4

Please sign in to comment.