From c5298f6a7d37008d89cbaf8369bcc5c99444840f Mon Sep 17 00:00:00 2001 From: ankicabarisic Date: Thu, 28 Nov 2024 18:12:02 +0100 Subject: [PATCH 1/3] introducing CloudProviderType and setting fpga values for cloud providers --- .../proactive/sal/model/CloudDefinition.java | 2 +- .../sal/model/CloudProviderType.java | 48 ++++++++++++++++++ .../org/ow2/proactive/sal/model/Hardware.java | 50 ++++++++++++++++++- .../org/ow2/proactive/sal/model/PACloud.java | 7 +-- .../sal/service/nc/NodeCandidateUtils.java | 32 +++++------- .../sal/service/service/ByonService.java | 2 +- .../sal/service/service/EdgeService.java | 2 +- .../service/service/MonitoringService.java | 3 +- .../sal/service/service/NodeService.java | 8 +-- .../sal/service/service/TaskBuilder.java | 8 +-- .../PAConnectorIaasGateway.java | 6 +-- 11 files changed, 129 insertions(+), 39 deletions(-) create mode 100644 sal-common/src/main/java/org/ow2/proactive/sal/model/CloudProviderType.java diff --git a/sal-common/src/main/java/org/ow2/proactive/sal/model/CloudDefinition.java b/sal-common/src/main/java/org/ow2/proactive/sal/model/CloudDefinition.java index 6ffcfde..eacbc36 100644 --- a/sal-common/src/main/java/org/ow2/proactive/sal/model/CloudDefinition.java +++ b/sal-common/src/main/java/org/ow2/proactive/sal/model/CloudDefinition.java @@ -28,7 +28,7 @@ public class CloudDefinition implements Serializable { private String cloudId = null; @JsonProperty("cloudProviderName") - private String cloudProviderName = null; + private CloudProviderType cloudProviderName = null; @JsonProperty("cloudType") private CloudType cloudType = null; diff --git a/sal-common/src/main/java/org/ow2/proactive/sal/model/CloudProviderType.java b/sal-common/src/main/java/org/ow2/proactive/sal/model/CloudProviderType.java new file mode 100644 index 0000000..dc07eab --- /dev/null +++ b/sal-common/src/main/java/org/ow2/proactive/sal/model/CloudProviderType.java @@ -0,0 +1,48 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ +package org.ow2.proactive.sal.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + + +/** + * Types of cloud providers + */ +public enum CloudProviderType { + + AWS_EC2("aws-ec2"), + AZURE("azure"), + GCE("gce"), + OPENSTACK("openstack"), + + EDGE("EDGE"), + BYON("BYON"), + + OTHER("other"); // For any unknown or future providers + + private final String value; + + CloudProviderType(String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CloudProviderType fromValue(String text) { + for (CloudProviderType type : CloudProviderType.values()) { + if (type.value.equalsIgnoreCase(text)) { + return type; + } + } + return OTHER; // Return a default type if the input is invalid + } +} diff --git a/sal-common/src/main/java/org/ow2/proactive/sal/model/Hardware.java b/sal-common/src/main/java/org/ow2/proactive/sal/model/Hardware.java index c280c6b..820b732 100644 --- a/sal-common/src/main/java/org/ow2/proactive/sal/model/Hardware.java +++ b/sal-common/src/main/java/org/ow2/proactive/sal/model/Hardware.java @@ -6,7 +6,9 @@ package org.ow2.proactive.sal.model; import java.io.Serializable; -import java.util.Objects; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import javax.persistence.*; @@ -33,6 +35,36 @@ @Table(name = "HARDWARE") public class Hardware implements Serializable { + // FPGA mappings for cloud providers + private static final Map> CLOUD_FPGA_MAPPINGS; + static { + Map> tempMappings = new HashMap<>(); + + // AWS mappings + Map awsMappings = new HashMap<>(); + awsMappings.put("f1.2xlarge", 1); + awsMappings.put("f1.4xlarge", 2); + awsMappings.put("f1.16xlarge", 8); + tempMappings.put(CloudProviderType.AWS_EC2, Collections.unmodifiableMap(awsMappings)); + + // GCE mappings + Map gceMappings = new HashMap<>(); + gceMappings.put("n1-standard-1", 0); + gceMappings.put("n1-standard-2", 0); + gceMappings.put("a2-highgpu-1g", 1); + gceMappings.put("a2-highgpu-8g", 8); + tempMappings.put(CloudProviderType.GCE, Collections.unmodifiableMap(gceMappings)); + + // Azure mappings + Map azureMappings = new HashMap<>(); + azureMappings.put("Standard_NC6", 0); + azureMappings.put("Standard_ND6s", 1); + azureMappings.put("Standard_ND24s", 4); + tempMappings.put(CloudProviderType.AZURE, Collections.unmodifiableMap(azureMappings)); + + CLOUD_FPGA_MAPPINGS = Collections.unmodifiableMap(tempMappings); + } + public static final String JSON_ID = "id"; public static final String JSON_NAME = "name"; @@ -110,7 +142,7 @@ public class Hardware implements Serializable { /** * Sets the FPGA field based on machine type. * @param machineType the machine type - */ + public void setCloudFpga(String machineType) { switch (machineType) { case "f1.2xlarge": @@ -125,6 +157,20 @@ public void setCloudFpga(String machineType) { default: this.fpga = 0; } + }*/ + + /** + * Sets the FPGA field based on the cloud provider and machine type. + * @param cloudProvider The type of the cloud provider (as a CloudProviderType enum). + * @param machineType The machine type to map. + */ + public void setCloudFpga(CloudProviderType cloudProvider, String machineType) { + Map cloudMapping = CLOUD_FPGA_MAPPINGS.get(cloudProvider); + if (cloudMapping != null) { + this.fpga = cloudMapping.getOrDefault(machineType, 0); + } else { + throw new IllegalArgumentException("Unsupported cloud provider: " + cloudProvider); + } } /** diff --git a/sal-common/src/main/java/org/ow2/proactive/sal/model/PACloud.java b/sal-common/src/main/java/org/ow2/proactive/sal/model/PACloud.java index 7c5e0ef..d3644b1 100644 --- a/sal-common/src/main/java/org/ow2/proactive/sal/model/PACloud.java +++ b/sal-common/src/main/java/org/ow2/proactive/sal/model/PACloud.java @@ -36,7 +36,8 @@ public class PACloud implements Serializable { private String nodeSourceNamePrefix; @Column(name = "CLOUD_PROVIDER_NAME") - private String cloudProviderName; + @Enumerated(EnumType.STRING) + private CloudProviderType cloudProviderName; @Column(name = "CLOUD_TYPE") @Enumerated(EnumType.STRING) @@ -151,8 +152,8 @@ public String toString() { .collect(Collectors.toList()) .toString(); return "PACloud{" + "cloudId='" + cloudId + '\'' + ", nodeSourceNamePrefix='" + nodeSourceNamePrefix + '\'' + - ", cloudProviderName='" + cloudProviderName + '\'' + ", cloudType='" + cloudType.toString() + '\'' + - ", subnet='" + subnet + '\'' + ", securityGroup='" + securityGroup + '\'' + ", sshCredentials='" + + ", cloudProviderName='" + cloudProviderName.toString() + '\'' + ", cloudType='" + cloudType.toString() + + '\'' + ", subnet='" + subnet + '\'' + ", securityGroup='" + securityGroup + '\'' + ", sshCredentials='" + Optional.ofNullable(sshCredentials).map(SSHCredentials::toString).orElse(null) + '\'' + ", endpoint='" + endpoint + '\'' + ", scopePrefix='" + scopePrefix + '\'' + ", scopeValue='" + scopeValue + '\'' + ", identityVersion='" + identityVersion + '\'' + ", dummyInfrastructureName='" + 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 5f790f3..85793c0 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,14 +38,6 @@ @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; @@ -225,18 +217,19 @@ private Hardware createHardware(JSONObject nodeCandidateJSON, PACloud paCloud) { hardware.setName(hardwareJSON.optString("type")); hardware.setProviderId(hardwareJSON.optString("type")); hardware.setCores(Math.round(Float.parseFloat(hardwareJSON.optString("minCores")))); + String minRam = hardwareJSON.optString("minRam"); if (minRam.endsWith(".0")) { minRam = minRam.replace(".0", ""); } hardware.setRam(Long.valueOf(minRam)); - hardware.setCloudFpga(hardwareJSON.optString("type")); - if (AWS_EC2.equals(nodeCandidateJSON.optString("cloud"))) { - hardware.setDisk((double) 8); - } else { - hardware.setDisk((double) 0); - } + //for now is better to not assign values for the disk as they are not dynamically obtained: hardware.setDisk((double) 0); + //we used value 8 for AWS as it is a defuault but can be modified: hardware.setDisk((double) 8); + + hardware.setCloudFpga(CloudProviderType.fromValue(nodeCandidateJSON.optString("cloud")), + hardwareJSON.optString("type")); + hardware.setLocation(createLocation(nodeCandidateJSON, paCloud)); repositoryService.saveHardware(hardware); @@ -262,8 +255,8 @@ private Location createLocation(JSONObject nodeCandidateJSON, PACloud paCloud) { return location; } - private GeoLocation createGeoLocation(String cloud, String region) { - switch (cloud) { + private GeoLocation createGeoLocation(CloudProviderType cloudProvider, String region) { + switch (cloudProvider) { case AWS_EC2: return new GeoLocation(geoLocationUtils.findGeoLocation("AWS", region)); case AZURE: @@ -290,13 +283,14 @@ 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"))) { + CloudProviderType cloudProvider = CloudProviderType.fromValue(nodeCandidateJSON.optString("cloud")); + if (cloudProvider == CloudProviderType.AWS_EC2) { 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 (cloudProvider == CloudProviderType.AZURE) { arch = osJSON.optString("arch"); } os.setOperatingSystemArchitecture(OperatingSystemArchitecture.fromValue(arch)); @@ -398,7 +392,7 @@ public void saveNodeCandidates(List newCloudIds) { " is not handled yet."); } - if (paCloud.getCloudProviderName().equals(OPENSTACK)) { + if (paCloud.getCloudProviderName().equals(CloudProviderType.OPENSTACK)) { entries.add(pair); } populateNodeCandidatesFromCache(paCloud, region, imageReq, image); diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/ByonService.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/ByonService.java index c61f4a3..fa0919f 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/ByonService.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/ByonService.java @@ -173,7 +173,7 @@ public Boolean addByonNodes(String sessionId, Map byonIdPerCompo cloud.setCloudId(nodeSourceName); cloud.setNodeSourceNamePrefix(nodeSourceName); cloud.setCloudType(CloudType.BYON); - cloud.setCloudProviderName("BYON"); + cloud.setCloudProviderName(CloudProviderType.BYON); cloud.setSshCredentials(sshCred); cloud.addDeployment(newDeployment); newDeployment.setPaCloud(cloud); diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/EdgeService.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/EdgeService.java index c24cc5c..6b6fee2 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/EdgeService.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/EdgeService.java @@ -172,7 +172,7 @@ public Boolean addEdgeNodes(String sessionId, Map edgeIdPerCompo cloud.setCloudId(nodeSourceName); cloud.setNodeSourceNamePrefix(nodeSourceName); cloud.setCloudType(CloudType.EDGE); - cloud.setCloudProviderName("EDGE"); + cloud.setCloudProviderName(CloudProviderType.EDGE); cloud.setSshCredentials(sshCred); cloud.addDeployment(newDeployment); newDeployment.setPaCloud(cloud); diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/MonitoringService.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/MonitoringService.java index 0547c9e..8e6d906 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/MonitoringService.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/MonitoringService.java @@ -92,7 +92,8 @@ public Deployment addEmsDeploymentForNode(Deployment deployment, String authoriz deployment.getDeploymentType().getName(), deployment.getNode().getNodeCandidate(), deployment.getNodeName(), - EmsDeploymentRequest.TargetProvider.fromValue(cloud.getCloudProviderName()), + EmsDeploymentRequest.TargetProvider.fromValue(cloud.getCloudProviderName() + .toString()), deployment.getTask() .getPortsToOpen() .stream() diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/NodeService.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/NodeService.java index 1c62385..1ce029e 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/NodeService.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/NodeService.java @@ -193,7 +193,7 @@ private void defineNSWithDeploymentInfo(String nodeSourceName, PACloud cloud, De .getHardware() .getProviderId())) { switch (cloud.getCloudProviderName()) { - case "aws-ec2": + case AWS_EC2: filename = File.separator + "Define_NS_AWS_AutoScale.xml"; variables.put("aws_username", cloud.getCredentials().getUserName()); variables.put("aws_secret", cloud.getCredentials().getPrivateKey()); @@ -213,13 +213,13 @@ private void defineNSWithDeploymentInfo(String nodeSourceName, PACloud cloud, De deployment.getNode().getNodeCandidate().getLocation().getName() + File.separator + deployment.getNode().getNodeCandidate().getImage().getProviderId()); switch (cloud.getCloudProviderName()) { - case "aws-ec2": + case AWS_EC2: filename = File.separator + "Define_NS_AWS.xml"; variables.put("aws_username", cloud.getCredentials().getUserName()); variables.put("aws_secret", cloud.getCredentials().getPrivateKey()); variables.put("subnet", Optional.ofNullable(cloud.getSubnet()).orElse("")); break; - case "openstack": + case OPENSTACK: filename = File.separator + "Define_NS_OS.xml"; variables.put("os_endpoint", cloud.getEndpoint()); variables.put("os_scopePrefix", cloud.getScopePrefix()); @@ -231,7 +231,7 @@ private void defineNSWithDeploymentInfo(String nodeSourceName, PACloud cloud, De variables.put("os_region", deployment.getNode().getNodeCandidate().getLocation().getName()); variables.put("os_networkId", cloud.getDefaultNetwork()); break; - case "azure": + case AZURE: filename = File.separator + "Define_NS_Azure.xml"; variables.put("azure_username", cloud.getCredentials().getUserName()); variables.put("azure_secret", cloud.getCredentials().getPrivateKey()); diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/TaskBuilder.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/TaskBuilder.java index 55e860c..2ec2b31 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/TaskBuilder.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/TaskBuilder.java @@ -249,7 +249,7 @@ private String createIAASNodeConfigJson(Task task, Deployment deployment) { ObjectMapper mapper = new ObjectMapper(); String imageId; switch (deployment.getPaCloud().getCloudProviderName()) { - case "aws-ec2": + case AWS_EC2: if (WhiteListedInstanceTypesUtils.isHandledHardwareInstanceType(deployment.getNode() .getNodeCandidate() .getHardware() @@ -260,7 +260,7 @@ private String createIAASNodeConfigJson(Task task, Deployment deployment) { deployment.getNode().getNodeCandidate().getImage().getProviderId(); } break; - case "openstack": + case OPENSTACK: imageId = deployment.getNode().getNodeCandidate().getImage().getProviderId(); break; default: @@ -355,9 +355,9 @@ private ScriptTask createInfraIAASTaskForOS(Task task, Deployment deployment, St private ScriptTask createInfraIAASTask(Task task, Deployment deployment, String taskNameSuffix, String nodeToken) { switch (deployment.getPaCloud().getCloudProviderName()) { - case "aws-ec2": + case AWS_EC2: return createInfraIAASTaskForAWS(task, deployment, taskNameSuffix, nodeToken); - case "openstack": + case OPENSTACK: return createInfraIAASTaskForOS(task, deployment, taskNameSuffix, nodeToken); default: return new ScriptTask(); diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/infrastructure/PAConnectorIaasGateway.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/infrastructure/PAConnectorIaasGateway.java index c7efaf4..78b2c29 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/infrastructure/PAConnectorIaasGateway.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/infrastructure/PAConnectorIaasGateway.java @@ -128,13 +128,13 @@ public void defineInfrastructure(String infrastructureName, PACloud cloud, Strin String jsonOutputString; switch (cloud.getCloudProviderName()) { - case "aws-ec2": + case AWS_EC2: jsonOutputString = "{\"id\": \"" + infrastructureName + "\"," + "\"type\": \"" + cloud.getCloudProviderName() + "\"," + "\"credentials\": {\"username\": \"" + cloud.getCredentials().getUserName() + "\", \"password\": \"" + cloud.getCredentials().getPrivateKey() + "\"}}"; break; - case "openstack": + case OPENSTACK: jsonOutputString = "{\"id\": \"" + infrastructureName + "\"," + "\"type\": \"openstack-nova\", \"endpoint\": \"" + cloud.getEndpoint() + "\", \"scope\":{\"prefix\": \"" + cloud.getScopePrefix() + "\", \"value\":\"" + @@ -144,7 +144,7 @@ public void defineInfrastructure(String infrastructureName, PACloud cloud, Strin cloud.getCredentials().getPrivateKey() + "\", \"domain\": \"" + cloud.getCredentials().getDomain() + "\"}, \"region\": \"" + region + "\"}"; break; - case "azure": + case AZURE: jsonOutputString = "{\"id\": \"" + infrastructureName + "\"," + "\"type\": \"" + cloud.getCloudProviderName() + "\"," + "\"credentials\": {\"username\": \"" + cloud.getCredentials().getUserName() + "\", \"password\": \"" + From 056ebddefa1518822dc6bd3eb79662677d4aada4 Mon Sep 17 00:00:00 2001 From: ankicabarisic Date: Wed, 4 Dec 2024 15:45:48 +0100 Subject: [PATCH 2/3] reuse the constants from node candidate model --- .../sal/service/nc/NodeCandidateUtils.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 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 85793c0..9efcb29 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 @@ -103,47 +103,47 @@ private static boolean satisfyAttributeRequirement(AttributeRequirement attribut attributeRequirement.toString(), nodeCandidate.getId()); // THIS LOG IS ADDED FOR TESTING,TO BE IMPROVED LATER - if (attributeRequirement.getRequirementClass().equals("hardware")) { + if (attributeRequirement.getRequirementClass().equals(NodeCandidate.JSON_HARDWARE)) { switch (attributeRequirement.getRequirementAttribute()) { - case "ram": + case Hardware.JSON_RAM: return attributeRequirement.getRequirementOperator() .compare(nodeCandidate.getHardware().getRam(), Long.valueOf(attributeRequirement.getValue())); - case "cores": + case Hardware.JSON_CORES: return attributeRequirement.getRequirementOperator() .compare(nodeCandidate.getHardware().getCores(), Integer.valueOf(attributeRequirement.getValue())); - case "disk": + case Hardware.JSON_DISK: return attributeRequirement.getRequirementOperator() .compare(nodeCandidate.getHardware().getDisk(), Double.valueOf(attributeRequirement.getValue())); - case "fpga": + case Hardware.JSON_FPGA: return attributeRequirement.getRequirementOperator() .compare(nodeCandidate.getHardware().getFpga(), Integer.valueOf(attributeRequirement.getValue())); - case "name": + case Hardware.JSON_NAME: return attributeRequirement.getRequirementOperator().compare(nodeCandidate.getHardware().getName(), attributeRequirement.getValue()); } } - if (attributeRequirement.getRequirementClass().equals("location")) { + if (attributeRequirement.getRequirementClass().equals(NodeCandidate.JSON_LOCATION)) { // if (attributeRequirement.getRequirementAttribute().equals("geoLocation.country")) { switch (attributeRequirement.getRequirementAttribute()) { case "geoLocation.country": return attributeRequirement.getRequirementOperator() .compare(nodeCandidate.getLocation().getGeoLocation().getCountry(), attributeRequirement.getValue()); - case "name": + case Location.JSON_NAME: return attributeRequirement.getRequirementOperator().compare(nodeCandidate.getLocation().getName(), attributeRequirement.getValue()); } } - if (attributeRequirement.getRequirementClass().equals("image")) { + if (attributeRequirement.getRequirementClass().equals(NodeCandidate.JSON_IMAGE)) { switch (attributeRequirement.getRequirementAttribute()) { - case "name": + case Image.JSON_NAME: return attributeRequirement.getRequirementOperator().compare(nodeCandidate.getImage().getName(), attributeRequirement.getValue()); - case "id": + case Image.JSON_ID: return attributeRequirement.getRequirementOperator().compare(nodeCandidate.getImage().getId(), attributeRequirement.getValue()); case "operatingSystem.family": @@ -160,7 +160,7 @@ private static boolean satisfyAttributeRequirement(AttributeRequirement attribut attributeRequirement.getValue()); } } - if (attributeRequirement.getRequirementClass().toLowerCase(Locale.ROOT).equals("cloud")) { + if (attributeRequirement.getRequirementClass().toLowerCase(Locale.ROOT).equals(NodeCandidate.JSON_CLOUD)) { if (attributeRequirement.getRequirementAttribute().equals("type")) { return attributeRequirement.getRequirementOperator() .compare(nodeCandidate.getCloud().getCloudType().name(), From f903b3218ba1b7bfe31c540dc3ed416483592771 Mon Sep 17 00:00:00 2001 From: ankicabarisic Date: Thu, 5 Dec 2024 09:13:46 +0100 Subject: [PATCH 3/3] spotless apply --- .../sal/service/nc/NodeCandidateUtils.java | 136 +++++++++--------- 1 file changed, 68 insertions(+), 68 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 efa1578..e0df469 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 @@ -58,17 +58,17 @@ private void initStaticAttributes() { public void initNodeCandidateUtils() { geoLocationUtils = new GeoLocationUtils(); nodeCandidatesCache = CacheBuilder.newBuilder() - .maximumSize(100) - .expireAfterWrite(60, TimeUnit.MINUTES) - .build(new CacheLoader, JSONArray>() { - @Override - public JSONArray load(Quartet key) { - return getAllPagedNodeCandidates(key.getValue0(), - key.getValue1(), - key.getValue2(), - key.getValue3()); - } - }); + .maximumSize(100) + .expireAfterWrite(60, TimeUnit.MINUTES) + .build(new CacheLoader, JSONArray>() { + @Override + public JSONArray load(Quartet key) { + return getAllPagedNodeCandidates(key.getValue0(), + key.getValue1(), + key.getValue2(), + key.getValue3()); + } + }); } public static boolean verifyAllFilters(List requirements, NodeCandidate nodeCandidate) { @@ -97,33 +97,33 @@ public static boolean verifyAllFilters(List requirements, NodeCandi } private static boolean satisfyAttributeRequirement(AttributeRequirement attributeRequirement, - NodeCandidate nodeCandidate) { + NodeCandidate nodeCandidate) { // THIS LOG IS ADDED FOR TESTING,TO BE IMPROVED LATER LOGGER.info("Checking the attribute requirement: \n {} \n for node candidate \"{}\" ", - attributeRequirement.toString(), - nodeCandidate.getId()); + attributeRequirement.toString(), + nodeCandidate.getId()); // THIS LOG IS ADDED FOR TESTING,TO BE IMPROVED LATER if (attributeRequirement.getRequirementClass().equals(NodeCandidate.JSON_HARDWARE)) { switch (attributeRequirement.getRequirementAttribute()) { case Hardware.JSON_RAM: return attributeRequirement.getRequirementOperator() - .compare(nodeCandidate.getHardware().getRam(), - Long.valueOf(attributeRequirement.getValue())); + .compare(nodeCandidate.getHardware().getRam(), + Long.valueOf(attributeRequirement.getValue())); case Hardware.JSON_CORES: return attributeRequirement.getRequirementOperator() - .compare(nodeCandidate.getHardware().getCores(), - Integer.valueOf(attributeRequirement.getValue())); + .compare(nodeCandidate.getHardware().getCores(), + Integer.valueOf(attributeRequirement.getValue())); case Hardware.JSON_DISK: return attributeRequirement.getRequirementOperator() - .compare(nodeCandidate.getHardware().getDisk(), - Double.valueOf(attributeRequirement.getValue())); + .compare(nodeCandidate.getHardware().getDisk(), + Double.valueOf(attributeRequirement.getValue())); case Hardware.JSON_FPGA: return attributeRequirement.getRequirementOperator() - .compare(nodeCandidate.getHardware().getFpga(), - Integer.valueOf(attributeRequirement.getValue())); + .compare(nodeCandidate.getHardware().getFpga(), + Integer.valueOf(attributeRequirement.getValue())); case Hardware.JSON_NAME: return attributeRequirement.getRequirementOperator().compare(nodeCandidate.getHardware().getName(), - attributeRequirement.getValue()); + attributeRequirement.getValue()); } } if (attributeRequirement.getRequirementClass().equals(NodeCandidate.JSON_LOCATION)) { @@ -131,59 +131,59 @@ private static boolean satisfyAttributeRequirement(AttributeRequirement attribut switch (attributeRequirement.getRequirementAttribute()) { case "geoLocation.country": return attributeRequirement.getRequirementOperator() - .compare(nodeCandidate.getLocation().getGeoLocation().getCountry(), - attributeRequirement.getValue()); + .compare(nodeCandidate.getLocation().getGeoLocation().getCountry(), + attributeRequirement.getValue()); case Location.JSON_NAME: return attributeRequirement.getRequirementOperator().compare(nodeCandidate.getLocation().getName(), - attributeRequirement.getValue()); + attributeRequirement.getValue()); } } if (attributeRequirement.getRequirementClass().equals(NodeCandidate.JSON_IMAGE)) { switch (attributeRequirement.getRequirementAttribute()) { case Image.JSON_NAME: return attributeRequirement.getRequirementOperator().compare(nodeCandidate.getImage().getName(), - attributeRequirement.getValue()); + attributeRequirement.getValue()); case Image.JSON_ID: return attributeRequirement.getRequirementOperator().compare(nodeCandidate.getImage().getId(), - attributeRequirement.getValue()); + attributeRequirement.getValue()); case "operatingSystem.family": return attributeRequirement.getRequirementOperator().compare(nodeCandidate.getImage() - .getOperatingSystem() - .getOperatingSystemFamily() - .name(), - attributeRequirement.getValue()); + .getOperatingSystem() + .getOperatingSystemFamily() + .name(), + attributeRequirement.getValue()); case "operatingSystem.version": return attributeRequirement.getRequirementOperator().compare(nodeCandidate.getImage() - .getOperatingSystem() - .getOperatingSystemVersion() - .toString(), - attributeRequirement.getValue()); + .getOperatingSystem() + .getOperatingSystemVersion() + .toString(), + attributeRequirement.getValue()); } } if (attributeRequirement.getRequirementClass().toLowerCase(Locale.ROOT).equals(NodeCandidate.JSON_CLOUD)) { if (attributeRequirement.getRequirementAttribute().equals("type")) { return attributeRequirement.getRequirementOperator() - .compare(nodeCandidate.getCloud().getCloudType().name(), - attributeRequirement.getValue()); + .compare(nodeCandidate.getCloud().getCloudType().name(), + attributeRequirement.getValue()); } if (attributeRequirement.getRequirementAttribute().equals("id")) { return attributeRequirement.getRequirementOperator().compare(nodeCandidate.getCloud().getId(), - attributeRequirement.getValue()); + attributeRequirement.getValue()); } } if (attributeRequirement.getRequirementClass().toLowerCase(Locale.ROOT).equals("environment")) { if (attributeRequirement.getRequirementAttribute().equals("runtime")) { return attributeRequirement.getRequirementOperator() - .compare(nodeCandidate.getEnvironment().getRuntime().name(), - attributeRequirement.getValue()); + .compare(nodeCandidate.getEnvironment().getRuntime().name(), + attributeRequirement.getValue()); } } if (attributeRequirement.getRequirementClass().toLowerCase(Locale.ROOT).equals("name")) { if (attributeRequirement.getRequirementAttribute().equals("placementName")) { if (nodeCandidate.getNodeCandidateType() == NodeCandidate.NodeCandidateTypeEnum.BYON || - nodeCandidate.getNodeCandidateType() == NodeCandidate.NodeCandidateTypeEnum.EDGE) { + nodeCandidate.getNodeCandidateType() == NodeCandidate.NodeCandidateTypeEnum.EDGE) { return attributeRequirement.getRequirementOperator().compare(nodeCandidate.getHardware().getName(), - attributeRequirement.getValue()); + attributeRequirement.getValue()); } } } @@ -198,9 +198,9 @@ private static boolean satisfyNodeTypeRequirement(NodeTypeRequirement requiremen return true; } else { // THIS LOG IS ADDED FOR TESTING,TO BE IMPROVED LATER LOGGER.info("the nodeType in the requirement \"{}\" is mismatched with the node candidate \"{}\" nodeType \"{}\"", - nodeType.getLiteral(), - nodeCandidate.getId(), - nodeCandidate.getNodeCandidateType().name()); + nodeType.getLiteral(), + nodeCandidate.getId(), + nodeCandidate.getNodeCandidateType().name()); return false; } })); @@ -209,7 +209,7 @@ private static boolean satisfyNodeTypeRequirement(NodeTypeRequirement requiremen private Hardware createHardware(JSONObject nodeCandidateJSON, PACloud paCloud) { JSONObject hardwareJSON = nodeCandidateJSON.optJSONObject("hw"); String hardwareId = paCloud.getCloudId() + "/" + nodeCandidateJSON.optString("region") + "/" + - hardwareJSON.optString("type"); + hardwareJSON.optString("type"); Hardware hardware = repositoryService.getHardware(hardwareId); if (hardware == null) { hardware = new Hardware(); @@ -228,7 +228,7 @@ private Hardware createHardware(JSONObject nodeCandidateJSON, PACloud paCloud) { //we used value 8 for AWS as it is a defuault but can be modified: hardware.setDisk((double) 8); hardware.setCloudFpga(CloudProviderType.fromValue(nodeCandidateJSON.optString("cloud")), - hardwareJSON.optString("type")); + hardwareJSON.optString("type")); hardware.setLocation(createLocation(nodeCandidateJSON, paCloud)); @@ -357,15 +357,15 @@ public void saveNodeCandidates(List newCloudIds) { JSONArray images = connectorIaasGateway.getImages(paCloud.getDummyInfrastructureName()); if (images == null) { LOGGER.warn(String.format("No available images were found for the cloud [%s]. Please check your configuration.", - paCloud.getCloudId())); + paCloud.getCloudId())); return; } LOGGER.info("Returned images: {}", images); List consolidatedImages = images.toList() - .parallelStream() - .map(NodeCandidateUtils::convertObjectToJson) - .filter(record -> !blacklistedRegions.contains(record.get("location"))) - .collect(Collectors.toList()); + .parallelStream() + .map(NodeCandidateUtils::convertObjectToJson) + .filter(record -> !blacklistedRegions.contains(record.get("location"))) + .collect(Collectors.toList()); LOGGER.info("Consolidated images: {}", consolidatedImages); //TODO: (Optimization) An images per region map structure could be the best here. @@ -390,7 +390,7 @@ public void saveNodeCandidates(List newCloudIds) { break; default: throw new IllegalArgumentException("The infrastructure " + paCloud.getCloudProviderName() + - " is not handled yet."); + " is not handled yet."); } if (paCloud.getCloudProviderName().equals(CloudProviderType.OPENSTACK)) { @@ -423,16 +423,16 @@ private void populateNodeCandidatesFromCache(PACloud paCloud, String region, Str private JSONArray getAllPagedNodeCandidates(PACloud paCloud, String region, String imageReq, String token) { JSONObject nodeCandidates = connectorIaasGateway.getNodeCandidates(paCloud.getDummyInfrastructureName(), - region, - imageReq, - token); + region, + imageReq, + token); try { if (!nodeCandidates.optString("nextToken").isEmpty()) { return (joinJSONArrays(nodeCandidates.optJSONArray("nodeCandidates"), - nodeCandidatesCache.get(Quartet.with(paCloud, - region, - imageReq, - nodeCandidates.optString("nextToken"))))); + nodeCandidatesCache.get(Quartet.with(paCloud, + region, + imageReq, + nodeCandidates.optString("nextToken"))))); } } catch (ExecutionException ee) { LOGGER.error("Could not get node candidates from cache: ", ee); @@ -443,18 +443,18 @@ private JSONArray getAllPagedNodeCandidates(PACloud paCloud, String region, Stri private JSONArray joinJSONArrays(JSONArray... jsonArrays) { JSONArray resultJSONArray = new JSONArray(); Arrays.stream(jsonArrays) - .forEach(jsonArray -> IntStream.range(0, jsonArray.length()) - .mapToObj(jsonArray::get) - .forEach(resultJSONArray::put)); + .forEach(jsonArray -> IntStream.range(0, jsonArray.length()) + .mapToObj(jsonArray::get) + .forEach(resultJSONArray::put)); return resultJSONArray; } public long cleanNodeCandidates(List newCloudIds) { List nodeCandidatesToBeRemoved = repositoryService.listNodeCandidates() - .stream() - .filter(nodeCandidate -> newCloudIds.contains(nodeCandidate.getCloud() - .getId())) - .collect(Collectors.toList()); + .stream() + .filter(nodeCandidate -> newCloudIds.contains(nodeCandidate.getCloud() + .getId())) + .collect(Collectors.toList()); try { LOGGER.info("Deleting nodes associated with the clouds {}", newCloudIds); // TODO: try finding a way to delete the nodes in batch rather than one by one