Commit 4f9ad381 authored by Mohamed Khalil Labidi's avatar Mohamed Khalil Labidi
Browse files

Add stopJob and stopJobs endpoint to SAL

parent 774673a3
......@@ -901,7 +901,70 @@ public class PAGateway {
* @param jobIDs List of job IDs to stop
*/
public void stopJobs(List<String> jobIDs) {
//TODO
jobIDs.forEach(this::stopJob);
}
/**
* Stop the deployed job
* @param jobId A deployed job identifier
* @return The submitted stopping job id
*/
public long stopJob(String jobId) {
LOGGER.info("Stopping job " + jobId);
Optional<Job> optJob = Optional.ofNullable(EntityManagerHelper.find(Job.class, jobId));
if (!optJob.isPresent()) {
LOGGER.error(String.format("Job [%s] not found", jobId));
return 0L;
}
Job job = optJob.get();
EntityManagerHelper.begin();
job.getTasks().forEach(task -> {
List<String> iaasNodesToBeRemoved = task.getDeployments().stream()
.filter(deployment -> NodeType.IAAS.equals(deployment.getDeploymentType()))
.filter(Deployment::getIsDeployed)
.map(Deployment::getNodeName)
.collect(Collectors.toList());
List<String> byonNodesToBeRemoved = task.getDeployments().stream()
.filter(deployment -> NodeType.BYON.equals(deployment.getDeploymentType()))
.filter(Deployment::getIsDeployed)
.map(Deployment::getNodeName)
.collect(Collectors.toList());
task.getDeployments().forEach(deployment -> {
switch (deployment.getDeploymentType()) {
case IAAS:
deployment.getTask().removeDeployment(deployment);
EntityManagerHelper.persist(deployment.getTask());
deployment.getPaCloud().removeDeployment(deployment);
EntityManagerHelper.persist(deployment.getPaCloud());
EntityManagerHelper.remove(deployment);
break;
case BYON:
deployment.getTask().removeDeployment(deployment);
EntityManagerHelper.persist(deployment.getTask());
EntityManagerHelper.remove(deployment);
break;
}
});
removeNodes(iaasNodesToBeRemoved,true);
////////////////////////////////////////////////
// Is that correct ???
// Should we just delete the token set on the node ???
removeNodes(byonNodesToBeRemoved, true);
// To verify the behavior needed in upperware.
// If we don't remove BYON nodes we should stop the component in it with a script.
////////////////////////////////////////////////
});
EntityManagerHelper.commit();
// This is kept for future improvement.
// It is in case we want to return the submitted stopping job's ID
return 0L;
}
private void updateNodeCandidatesAsync(List<String> newCloudIds) {
......@@ -1768,16 +1831,6 @@ public class PAGateway {
return(submittedJobId);
}
/**
* Stop the deployed job
* @param jobId A deployed job identifier
* @return The submitted stopping job id
*/
public long stopJob(String jobId) {
//TODO: Submit stopping scripts for all apps
return 0L;
}
/**
* Get a ProActive job state
* @param jobId A job ID
......
Markdown is supported
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