Commit 9eda6b26 authored by Ali Fahs's avatar Ali Fahs
Browse files

adding the undeploy and remove NS function

parent cd014c46
Pipeline #15139 passed with stage
in 1 minute and 7 seconds
......@@ -690,6 +690,9 @@ public class PAGateway {
ByonNode byonNode = EntityManagerHelper.find(ByonNode.class, byonNodeId);
Task task = EntityManagerHelper.find(Task.class, componentId);
assert byonNode!=null : "The BYON ID passed in the mapping does not exist in the database";
assert task!=null : "The componentId passed in the mapping does not exist in the database";
Deployment newDeployment = new Deployment();
newDeployment.setNodeName(byonNode.getName());
newDeployment.setDeploymentType(NodeType.BYON);
......@@ -697,8 +700,9 @@ public class PAGateway {
List<ByonNode> byonNodeList = new LinkedList<>();
byonNodeList.add(byonNode);
defineByonNodeSource(byonNodeList, "BYON_NS_"+jobId);
LOGGER.info("BYON node source defined.");
LOGGER.info("BYON node Added: " + byonNode.getName() + " Ip: " + byonNode.getIpAddresses().get(0).getValue() );
defineByonNodeSource(byonNodeList, "BYON_NS_"+byonNode.getId());
LOGGER.info("BYON node source BYON_NS_"+ byonNode.getId() + " is defined");
newDeployment.setTask(task);
newDeployment.setNumber(task.getNextDeploymentID());
......@@ -712,13 +716,10 @@ public class PAGateway {
EntityManagerHelper.commit();
LOGGER.info("BYON nodes added properly.");
return 0;
/*TODO:
* Create node sources per JobID
* */
}
/**
* Undeploy clouds
* @param cloudIDs List of cloud IDs to remove
......@@ -817,19 +818,59 @@ public class PAGateway {
EntityManagerHelper.begin();
ByonNode byonNode = EntityManagerHelper.find(ByonNode.class, byonId);
if (byonNode == null) {
LOGGER.error("The passed BYON ID is not Found in the database");
return false;
}
else {
System.out.println("Deleting the node: " + byonNode.getId());
if(!undeployByonNs(byonNode, false, true)) {
LOGGER.warn("The BYON node source undeploy finished with errors");
}
LOGGER.info("Deleting the BYON node " + byonNode.getId() +" from the database" );
EntityManagerHelper.remove(byonNode);
EntityManagerHelper.commit();
return true;
}
return true;
/*TODO:
* add logging info when deleting
* change the hardcoding for preempt and remove variables
* */
}
/**
* Undeploy or remove the node source of a BYON node
* @param byonNode an object of class ByonNode to be undeployed or removed.
* @param preempt If true undeploy or remove node source immediately without waiting for nodes to be freed
* @param remove If true completely remove the node source, if false only undeply the node source
* @return true if the resourceManagerGateway return no errors, false otherwise
*/
private Boolean undeployByonNs(ByonNode byonNode, Boolean preempt, Boolean remove) {
assert byonNode!= null : "A null value was passed for byonNode, A node source must have a BYON ID";
String nodeSourceName = "BYON_NS_" + byonNode.getId();
if (remove) {
try {
LOGGER.info("Removing BYON node source " + nodeSourceName + " from the ProActive server");
resourceManagerGateway.removeNodeSource(nodeSourceName, preempt);
} catch (NotConnectedException | PermissionRestException e) {
LOGGER.error(Arrays.toString(e.getStackTrace()));
return false;
}
}
else {
try {
LOGGER.info("Undeploying BYON node source " + nodeSourceName + " from the ProActive server");
resourceManagerGateway.undeployNodeSource(nodeSourceName, preempt);
} catch (NotConnectedException | PermissionRestException e) {
LOGGER.error(Arrays.toString(e.getStackTrace()));
return false;
}
}
LOGGER.info("BYON node source was removed with no errors");
return true;
/*TODO:
* Check if the nodes source is present before calling the resourceManagerGateway
*/
}
/**
* Stop jobs
* @param jobIDs List of job IDs to stop
......
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