Commit 27d34c3b authored by Maxime COMPASTIÉ's avatar Maxime COMPASTIÉ
Browse files

Feature scaling

parent e36efe9a
......@@ -15,6 +15,7 @@ import org.json.JSONObject;
import org.ow2.proactive.resourcemanager.exception.RMException;
import org.ow2.proactive.scheduler.common.exception.NotConnectedException;
import org.ow2.proactive.scheduler.common.exception.UserException;
import org.ow2.proactive.scheduler.common.job.JobId;
import org.ow2.proactive.scheduler.common.job.JobResult;
import org.ow2.proactive.scheduler.common.job.JobState;
import org.ow2.proactive.scheduler.common.job.TaskFlowJob;
......@@ -37,6 +38,7 @@ import java.net.URL;
import java.security.KeyException;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
public class PAGateway {
......@@ -592,6 +594,113 @@ public class PAGateway {
return emsDeploymentTask;
}
/**
* Register a set of node as an operation for scale up
* @param nodeNames Name of the nodes to be created and provisioned
* @param jobId The name of the Job to be allocated
* @param taskName the name of the task whose node are to be allocated
* @return 0 if the operation went successful, 1 if the scaling failed because no job/task was node found, 2 if the scaling failed because no deployment to clone are available.
*/
public int addScaleOutTask(List<String> nodeNames, String jobId, String taskName) {
Validate.notEmpty(nodeNames,"The provided nodes list should not be empty");
Validate.notNull(jobId,"The provided jobId should not be null.");
em.getTransaction().begin();
// Let's find the jobId to retrieve the task
Optional<Job> optJob = Optional.ofNullable(em.find(Job.class,jobId));
if (!optJob.isPresent()) {
LOGGER.error(String.format("Job [%s] not found", jobId));
return 1;
}
// Let's find the task:
Optional<Task> optTask = Optional.ofNullable(em.find(Task.class,optJob.get().findTask(taskName)));
if (!optTask.isPresent()) {
LOGGER.error(String.format("Task [%s] not found", taskName));
return 1;
}
// Let's retrieve the deployment to clone
Optional<Deployment> optDeployment = Optional.ofNullable(optTask.get().getDeployments().get(0));
if (!optDeployment.isPresent()) {
LOGGER.error(String.format("No previous deployment found in task [%s] ",taskName));
return 2;
}
// Let's clone the deployment/node as needed.
Deployment oldDeployment = optDeployment.get();
nodeNames.stream().map(nodeName -> {
Deployment newDeployment = new Deployment();
newDeployment.setPaCloud(oldDeployment.getPaCloud());
newDeployment.setNodeName(nodeName);
newDeployment.setLocationName(oldDeployment.getLocationName());
newDeployment.setIsDeployed(false);
newDeployment.setImageProviderId(oldDeployment.getImageProviderId());
newDeployment.setHardwareProviderId(oldDeployment.getHardwareProviderId());
EmsDeploymentRequest newEmsDeploymentReq = oldDeployment.getEmsDeployment().clone(nodeName);
newDeployment.setEmsDeployment(newEmsDeploymentReq);
return newDeployment;
}).forEach( deployment -> {
optTask.get().addDeployment(deployment);
em.persist(deployment.getEmsDeployment());
em.persist(deployment);
em.persist(optTask.get());
});
em.getTransaction().commit();
return 0;
}
/**
* Unregister a set of node as a scale-down operation
* @param nodeNames A list of node to be removed
* @param jobId The name of the job to scale down the nodes
* @param taskName the name of the task whose nodes are to be removed
* @return 0 if the operation went successful, 2 if the operation avorted to prevent last node to be removed.
*/
public int addScaleInTask(List<String> nodeNames, String jobId, String taskName) {
Validate.notEmpty(nodeNames,"The provided nodes list should not be empty");
Validate.notNull(jobId,"The provided jobId should not be null.");
em.getTransaction().begin();
// Let's find the jobId to retrieve the task
Optional<Job> optJob = Optional.ofNullable(em.find(Job.class,jobId));
if (!optJob.isPresent()) {
LOGGER.error(String.format("Job [%s] not found", jobId));
return 1;
}
// Let's find the task:
Optional<Task> optTask = Optional.ofNullable(em.find(Task.class,optJob.get().findTask(taskName)));
if (!optTask.isPresent()) {
LOGGER.error(String.format("Task [%s] not found", taskName));
return 1;
}
// Validating there will still be at least on task in the task
if (optTask.get().getDeployments().size() - nodeNames.size() < 1) {
LOGGER.error("I stop the scale-in: the task will loose its last deployment");
return 2;
}
// For supplied node, I retrieve their deployment
List<Deployment> deployments = nodeNames.stream().map(node -> em.find(Deployment.class,node)).filter(deployment -> (deployment != null)).collect(Collectors.toList());
// For deployed node, I flag their removal
List<String> nodesToBeRemoved = deployments.stream().filter(deployment -> deployment.getIsDeployed()).map(Deployment::getNodeName).collect(Collectors.toList());
// For every node, I remove the deployment entree
deployments.forEach(
deployment -> {
em.remove(deployment);
em.persist(deployment);
}
);
// I commit the removal of deployed node
removeNodes(nodesToBeRemoved,false);
em.getTransaction().commit();
return 0;
}
/**
* Translate a Morphemic task skeleton into a list of ProActive tasks
* @param task A Morphemic task skeleton
......
......@@ -83,6 +83,21 @@ public class EmsDeploymentRequest implements Serializable {
private String nodeId;
private EmsDeploymentRequest(String authorizationBearer, String baguetteIp, int baguette_port, OperatingSystemFamily targetOs,
TargetType targetType, String targetName,
TargetProvider targetProvider, String location, boolean isUsingHttps, String id) {
this.authorizationBearer = authorizationBearer;
this.baguetteIp = baguetteIp;
this.baguette_port = baguette_port;
this.targetOs = targetOs;
this.targetType = targetType;
this.targetName = targetName;
this.targetProvider = targetProvider;
this.location = location;
this.isUsingHttps = isUsingHttps;
this.nodeId = id;
}
public EmsDeploymentRequest(String authorizationBearer, String baguetteIp, int baguette_port, OperatingSystemFamily targetOs,
String targetType, String targetName,
TargetProvider targetProvider, String location, boolean isUsingHttps, String id) {
......@@ -117,4 +132,8 @@ public class EmsDeploymentRequest implements Serializable {
return result;
}
public EmsDeploymentRequest clone(String nodeId) {
EmsDeploymentRequest req = new EmsDeploymentRequest(authorizationBearer,baguetteIp,baguette_port,targetOs,targetType,targetName,targetProvider,location,isUsingHttps,nodeId);
return req;
}
}
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