Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting gpu, fpga and cpuFrequency for cloud #114

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
50 changes: 48 additions & 2 deletions sal-common/src/main/java/org/ow2/proactive/sal/model/Hardware.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -33,6 +35,36 @@
@Table(name = "HARDWARE")
public class Hardware implements Serializable {

// FPGA mappings for cloud providers
private static final Map<CloudProviderType, Map<String, Integer>> CLOUD_FPGA_MAPPINGS;
static {
Map<CloudProviderType, Map<String, Integer>> tempMappings = new HashMap<>();

// AWS mappings
Map<String, Integer> 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<String, Integer> 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<String, Integer> 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";
Expand Down Expand Up @@ -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":
Expand All @@ -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<String, Integer> cloudMapping = CLOUD_FPGA_MAPPINGS.get(cloudProvider);
if (cloudMapping != null) {
this.fpga = cloudMapping.getOrDefault(machineType, 0);
} else {
throw new IllegalArgumentException("Unsupported cloud provider: " + cloudProvider);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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='" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -111,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":
Expand All @@ -168,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(),
Expand Down Expand Up @@ -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);
Expand All @@ -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:
Expand All @@ -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) {
image.setId(imageJSON.optString("id"));
arch = osJSON.optString("arch");
}
Expand Down Expand Up @@ -399,7 +393,7 @@ public void saveNodeCandidates(List<String> newCloudIds) {
" is not handled yet.");
}

if (paCloud.getCloudProviderName().equals(OPENSTACK)) {
if (paCloud.getCloudProviderName().equals(CloudProviderType.OPENSTACK)) {
entries.add(pair);
}
populateNodeCandidatesFromCache(paCloud, region, imageReq, image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public Boolean addByonNodes(String sessionId, Map<String, String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public Boolean addEdgeNodes(String sessionId, Map<String, String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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("clientId", cloud.getCredentials().getUserName());
variables.put("secret", cloud.getCredentials().getPrivateKey());
Expand Down
Loading
Loading