Skip to content

Commit

Permalink
Fix missing OS family and arch with Azure (#107)
Browse files Browse the repository at this point in the history
* Fix missing OS family and arch with Azure

* Add constants in NodeCandidateUtils.java

* Add constants in NodeCandidateUtils.java
  • Loading branch information
mbenguig authored Nov 5, 2024
1 parent b5066e1 commit 79cc9fe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public enum OperatingSystemFamily {

CLOUD_LINUX("CLOUD_LINUX"),

WINDOWS("WINDOWS");
WINDOWS("WINDOWS"),

LINUX("LINUX");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
@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 +232,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 +264,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 @@ -279,15 +287,17 @@ private Image createImage(JSONObject nodeCandidateJSON, JSONObject imageJSON, PA
image.setProviderId(StringUtils.substringAfterLast(imageJSON.optString("id"), "/"));
OperatingSystem os = new OperatingSystem();
JSONObject osJSON = imageJSON.optJSONObject("operatingSystem");
os.setOperatingSystemFamily(OperatingSystemFamily.fromValue(osJSON.optString("family")));
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"))) {
arch = osJSON.optString("arch");
}
os.setOperatingSystemArchitecture(OperatingSystemArchitecture.fromValue(arch));
os.setOperatingSystemVersion(osJSON.optBigDecimal("version", BigDecimal.valueOf(0)));
Expand Down Expand Up @@ -374,21 +384,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 79cc9fe

Please sign in to comment.