Commit 15225d02 authored by Mohamed Khalil Labidi's avatar Mohamed Khalil Labidi
Browse files

Fix BYON node candidate and cloud creation

parent 3c27d182
......@@ -8,7 +8,7 @@ import org.activeeon.morphemic.infrastructure.deployment.PAConnectorIaasGateway;
import org.activeeon.morphemic.infrastructure.deployment.PAResourceManagerGateway;
import org.activeeon.morphemic.model.*;
import org.activeeon.morphemic.service.*;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.Validate;
import org.json.JSONArray;
import org.json.JSONObject;
......@@ -344,7 +344,8 @@ public class PAGateway {
List<NodeCandidate> allNodeCandidates = EntityManagerHelper.createQuery("SELECT nc FROM NodeCandidate nc",
NodeCandidate.class).getResultList();
allNodeCandidates.forEach(nodeCandidate -> {
if (JCloudsInstancesUtils.isHandledHardwareInstanceType(nodeCandidate.getCloud().getApi().getProviderName(),
if (nodeCandidate.isByonNodeCandidate() ||
JCloudsInstancesUtils.isHandledHardwareInstanceType(nodeCandidate.getCloud().getApi().getProviderName(),
nodeCandidate.getHardware().getName())) {
if (NodeCandidateUtils.verifyAllFilters(requirements, nodeCandidate)) {
filteredNodeCandidates.add(nodeCandidate);
......@@ -627,9 +628,11 @@ public class PAGateway {
Validate.notNull(byonNodeDefinition, "The received Byon node definition is empty. Nothing to be registered.");
Validate.notNull(jobId, "The received jobId is empty. Nothing to be registered.");
Job job = EntityManagerHelper.find(Job.class, jobId);
// assert job is not null
assert job != null;
LOGGER.info("Registering a new BYON definition related to job " + jobId + " ...");
NodeCandidate byonNC = ByonUtils.createByonNodeCandidate(byonNodeDefinition, jobId);
EntityManagerHelper.begin();
NodeCandidate byonNC = createByonNodeCandidate(byonNodeDefinition, jobId);
ByonNode newByonNode = new ByonNode();
newByonNode.setName(byonNodeDefinition.getName());
newByonNode.setLoginCredential(byonNodeDefinition.getLoginCredential());
......@@ -640,6 +643,7 @@ public class PAGateway {
EntityManagerHelper.persist(newByonNode);
EntityManagerHelper.commit();
LOGGER.info("BYON node registered.");
return newByonNode;
/* TODO:
......@@ -649,74 +653,6 @@ public class PAGateway {
}
/**
* Create a dummy object of class Cloud to be used for the node candidates
* @return the created byonCloud object
*/
private Cloud createByonCloud() {
EntityManagerHelper.begin();
//Check if the Byon cloud already exists
List<Cloud> clouds =EntityManagerHelper.createQuery("SELECT cloud FROM Cloud cloud", Cloud.class).getResultList();;
for(Cloud cloud : clouds ) {
if(cloud.getCloudType()==CloudType.BYON && cloud.getOwner().equals("BYON") && cloud.getId().equals("byon")) {
// Halt, the Byon Cloud already exist
return cloud;}
}
//else, Byon cloud will be created
Cloud byonCloud = new Cloud();
byonCloud.setCloudType(CloudType.BYON);
byonCloud.setOwner("BYON");
byonCloud.setId("byon");
//Add the Byon cloud to the database
EntityManagerHelper.persist(byonCloud);
EntityManagerHelper.commit();
return byonCloud;
/* TODO :
* Check if we have to add other variables to the new cloud
*/
}
/**
* @param byonDef an Object of class ByonDefinition that contains all the nodes Definition
* @return an object of class NodeCandidate
*/
public NodeCandidate createByonNodeCandidate( ByonDefinition byonDef, String jobId) {
//create a dummy cloud
Cloud byoncloud = createByonCloud();
//set the image
Image image = new Image();
image.setOperatingSystem(byonDef.getNodeProperties().getOperatingSystem());
//image.setId("Byon_Image_"+jobId);
//set the hardware
Hardware hardware = new Hardware();
hardware.setCores(byonDef.getNodeProperties().getNumberOfCores());
hardware.setDisk((double) byonDef.getNodeProperties().getDisk());
hardware.setRam(byonDef.getNodeProperties().getMemory());
//hardware.setId("ByonHardware_"+jobId);
//set the location
Location location = new Location();
location.setGeoLocation(byonDef.getNodeProperties().getGeoLocation());
//location.setId("Byon_Location_"+jobId);
//define a dummy NC
NodeCandidate byonNC = new NodeCandidate();
//byonNC.setId("Byon_NC_"+jobId);
byonNC.setNodeCandidateType(NodeCandidate.NodeCandidateTypeEnum.BYON);
byonNC.setJobIdForBYON(jobId);
byonNC.setPrice(0.0);
byonNC.setMemoryPrice(0.0);
byonNC.setPricePerInvocation(0.0);
byonNC.setCloud(byoncloud);
byonNC.setImage(image);
byonNC.setHardware(hardware);
byonNC.setLocation(location);
return byonNC;
}
/**
* Return the List of registered BYON nodes
......
......@@ -288,6 +288,13 @@ public class NodeCandidate implements Serializable {
this.environment = environment;
}
/**
* Check if a node candidate is of BYON type
* @return true if yes, false if not
*/
public boolean isByonNodeCandidate() {
return nodeCandidateType.value.equals("BYON");
}
@Override
public boolean equals(java.lang.Object o) {
......
package org.activeeon.morphemic.service;
import lombok.extern.slf4j.Slf4j;
import org.activeeon.morphemic.model.*;
import org.apache.commons.lang3.RandomStringUtils;
import java.util.Optional;
@Slf4j
public class ByonUtils {
private ByonUtils() {}
/**
* @param byonDef an Object of class ByonDefinition that contains all the nodes Definition
* @return an object of class NodeCandidate
*/
public static NodeCandidate createByonNodeCandidate(ByonDefinition byonDef, String jobId) {
LOGGER.debug("Creating the BYON node candidate ...");
//create a dummy cloud
Cloud byonCloud = ByonUtils.getOrCreateDummyByonCloud();
EntityManagerHelper.begin();
//set the image
Image image = new Image();
image.setId("byon-image-" + RandomStringUtils.randomAlphanumeric(16));
image.setOperatingSystem(byonDef.getNodeProperties().getOperatingSystem());
//set the hardware
Hardware hardware = new Hardware();
hardware.setId("byon-hardware-" + RandomStringUtils.randomAlphanumeric(16));
hardware.setCores(byonDef.getNodeProperties().getNumberOfCores());
hardware.setDisk((double) byonDef.getNodeProperties().getDisk());
hardware.setRam(byonDef.getNodeProperties().getMemory());
//set the location
Location location = new Location();
location.setId("byon-location-" + RandomStringUtils.randomAlphanumeric(16));
location.setGeoLocation(byonDef.getNodeProperties().getGeoLocation());
//define a dummy NC
NodeCandidate byonNC = new NodeCandidate();
byonNC.setNodeCandidateType(NodeCandidate.NodeCandidateTypeEnum.BYON);
byonNC.setJobIdForBYON(jobId);
byonNC.setPrice(0.0);
byonNC.setMemoryPrice(0.0);
byonNC.setPricePerInvocation(0.0);
byonNC.setCloud(byonCloud);
byonNC.setImage(image);
byonNC.setHardware(hardware);
byonNC.setLocation(location);
EntityManagerHelper.persist(byonNC);
EntityManagerHelper.commit();
LOGGER.info("BYON node candidate created.");
return byonNC;
}
/**
* Create a dummy object of class Cloud to be used for the node candidates
* @return the created byonCloud object
*/
public static Cloud getOrCreateDummyByonCloud() {
LOGGER.debug("Searching for the dummy BYON cloud ...");
EntityManagerHelper.begin();
//Check if the Byon cloud already exists
Optional<Cloud> optCloud = Optional.ofNullable(EntityManagerHelper.find(Cloud.class, "byon"));
if (optCloud.isPresent()) {
LOGGER.info("Dummy BYON cloud found!");
return optCloud.get();
}
LOGGER.debug("Creating the dummy BYON cloud ...");
//else, Byon cloud will be created
Cloud byonCloud = new Cloud();
byonCloud.setCloudType(CloudType.BYON);
byonCloud.setOwner("BYON");
byonCloud.setId("byon");
//Add the Byon cloud to the database
EntityManagerHelper.persist(byonCloud);
EntityManagerHelper.commit();
LOGGER.info("Dummy BYON cloud created.");
return byonCloud;
/* TODO :
* Check if we have to add other variables to the new cloud
*/
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment