diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/nc/NodeCandidateUtils.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/nc/NodeCandidateUtils.java index 65ce8ee..1664349 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/nc/NodeCandidateUtils.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/nc/NodeCandidateUtils.java @@ -183,6 +183,10 @@ private static boolean satisfyAttributeRequirement(AttributeRequirement attribut .compare(nodeCandidate.getCloud().getCloudType().name(), attributeRequirement.getValue()); } + if (attributeRequirement.getRequirementAttribute().equals("id")) { + return attributeRequirement.getRequirementOperator().compare(nodeCandidate.getCloud().getId(), + attributeRequirement.getValue()); + } } if (attributeRequirement.getRequirementClass().toLowerCase(Locale.ROOT).equals("environment")) { if (attributeRequirement.getRequirementAttribute().equals("runtime")) { diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/ClusterService.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/ClusterService.java index 09a5809..8b7815b 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/ClusterService.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/ClusterService.java @@ -274,15 +274,19 @@ public Cluster scaleInCluster(String sessionId, String clusterName, List throw new NotConnectedException(); } LOGGER.info("scaleDownCluster endpoint is called for the cluster: " + clusterName); - Cluster toScaleCluster = getCluster(sessionId, clusterName); + Cluster toScaleCluster = ClusterUtils.getClusterByName(clusterName, repositoryService.listCluster()); repositoryService.deleteCluster(toScaleCluster); repositoryService.flush(); + String masterNodeToken = ""; + if (toScaleCluster != null) { + masterNodeToken = toScaleCluster.getMasterNode() + "_" + clusterName; + } List clusterNodes = toScaleCluster.getNodes(); for (String nodeName : nodesToDelete) { ClusterNodeDefinition node = getNodeFromCluster(toScaleCluster, nodeName); if (node != null && !node.getName().equals(toScaleCluster.getMasterNode())) { try { - if (deleteNode(sessionId, clusterName, node) != -1L) { + if (deleteNode(sessionId, clusterName, node, masterNodeToken, true) != -1L) { clusterNodes = deleteNodeFromCluster(clusterNodes, nodeName); } } catch (NotConnectedException e) { @@ -326,7 +330,8 @@ public Long labelNodes(String sessionId, String clusterName, List newN jobService.addCleanChannelsTaskWithDependencies(paJob, job); paJob.setMaxNumberOfExecution(2); - paJob.setProjectName("Morphemic"); + paJob.setProjectName("NebulOuS"); long submittedJobId = schedulerGateway.submit(paJob).longValue(); job.setSubmittedJobId(submittedJobId); @@ -374,7 +374,7 @@ private void submitScalingInJob(Job job, String scaledTaskName) { jobService.addCleanChannelsTaskWithDependencies(paJob, job); paJob.setMaxNumberOfExecution(2); - paJob.setProjectName("Morphemic"); + paJob.setProjectName("NebulOuS"); long submittedJobId = schedulerGateway.submit(paJob).longValue(); job.setSubmittedJobId(submittedJobId); diff --git a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/TaskBuilder.java b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/TaskBuilder.java index 1abe0a0..243aa56 100644 --- a/sal-service/src/main/java/org/ow2/proactive/sal/service/service/TaskBuilder.java +++ b/sal-service/src/main/java/org/ow2/proactive/sal/service/service/TaskBuilder.java @@ -40,14 +40,14 @@ import org.ow2.proactive.sal.service.util.Utils; import org.ow2.proactive.scheduler.common.task.ScriptTask; import org.ow2.proactive.scheduler.common.task.TaskVariable; -import org.ow2.proactive.scripting.InvalidScriptException; -import org.ow2.proactive.scripting.SelectionScript; +import org.ow2.proactive.scripting.*; import org.springframework.stereotype.Service; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Strings; import lombok.extern.log4j.Log4j2; +import net.bytebuddy.dynamic.scaffold.TypeInitializer; @Log4j2 @@ -98,6 +98,8 @@ public class TaskBuilder { private static final String WAIT_FOR_LOCK_SCRIPT = "wait_for_lock_script.sh"; + private static final String DRIAN_NODE_SCRIPT = "drain_node_script.sh"; + private static final String WAIT_FOR_MASTER_SCRIPT = "wait_for_master.groovy"; private static final String SET_TOKEN_SCRIPT = "set_token.groovy"; @@ -892,10 +894,19 @@ private ScriptTask createSetTokenTask(String masterNodeToken) { } public ScriptTask createDeleteNodeTask(String nodeUrl) { - ScriptTask setTokenTask = PAFactory.createGroovyScriptTaskFromFile("Delete-Node", DELETE_NODE_SCRIPT); + ScriptTask deleteNodeTask = PAFactory.createGroovyScriptTaskFromFile("Delete-Node", DELETE_NODE_SCRIPT); Map variablesMap = new HashMap<>(); variablesMap.put("nodeURL", new TaskVariable("nodeURL", nodeUrl)); - setTokenTask.setVariables(variablesMap); - return setTokenTask; + deleteNodeTask.setVariables(variablesMap); + return deleteNodeTask; + } + + public ScriptTask createDrainNodeTask(String nodeName, String masterNodeToken) { + ScriptTask drainNodeTask = PAFactory.createBashScriptTaskFromFile("Drain-Node", DRIAN_NODE_SCRIPT); + Map variablesMap = new HashMap<>(); + variablesMap.put("nodeName", new TaskVariable("nodeName", nodeName)); + drainNodeTask.setVariables(variablesMap); + drainNodeTask.addGenericInformation("NODE_ACCESS_TOKEN", masterNodeToken); + return drainNodeTask; } } diff --git a/sal-service/src/main/resources/Define_NS_AWS.xml b/sal-service/src/main/resources/Define_NS_AWS.xml index 02dfbd1..8f927a4 100644 --- a/sal-service/src/main/resources/Define_NS_AWS.xml +++ b/sal-service/src/main/resources/Define_NS_AWS.xml @@ -1,7 +1,7 @@ + xmlns="urn:proactive:jobdescriptor:3.13" xsi:schemaLocation="urn:proactive:jobdescriptor:3.13 http://www.activeeon.com/public_content/schemas/proactive/jobdescriptor/3.13/schedulerjob.xsd" name="Define_NS_AWS" projectName="NebulOuS" priority="normal" onTaskError="continueJobExecution" maxNumberOfExecution="2" > diff --git a/sal-service/src/main/resources/Define_NS_AWS_AutoScale.xml b/sal-service/src/main/resources/Define_NS_AWS_AutoScale.xml index f16bc78..6c8cdf4 100644 --- a/sal-service/src/main/resources/Define_NS_AWS_AutoScale.xml +++ b/sal-service/src/main/resources/Define_NS_AWS_AutoScale.xml @@ -1,7 +1,7 @@ + xmlns="urn:proactive:jobdescriptor:3.13" xsi:schemaLocation="urn:proactive:jobdescriptor:3.13 http://www.activeeon.com/public_content/schemas/proactive/jobdescriptor/3.13/schedulerjob.xsd" name="Define_NS_AWS_AS" projectName="NebulOuS" priority="normal" onTaskError="continueJobExecution" maxNumberOfExecution="2" > diff --git a/sal-service/src/main/resources/Define_NS_OS.xml b/sal-service/src/main/resources/Define_NS_OS.xml index de15efd..01c6687 100644 --- a/sal-service/src/main/resources/Define_NS_OS.xml +++ b/sal-service/src/main/resources/Define_NS_OS.xml @@ -1,7 +1,7 @@ + xmlns="urn:proactive:jobdescriptor:3.13" xsi:schemaLocation="urn:proactive:jobdescriptor:3.13 http://www.activeeon.com/public_content/schemas/proactive/jobdescriptor/3.13/schedulerjob.xsd" name="Define_NS_OS" projectName="NebulOuS" priority="normal" onTaskError="continueJobExecution" maxNumberOfExecution="2" > diff --git a/sal-service/src/main/resources/drain_node_script.sh b/sal-service/src/main/resources/drain_node_script.sh new file mode 100644 index 0000000..82ec6ff --- /dev/null +++ b/sal-service/src/main/resources/drain_node_script.sh @@ -0,0 +1,2 @@ +sudo -H -u ubuntu bash -c "kubectl drain $variables_nodeName --ignore-daemonsets" +sudo -H -u ubuntu bash -c "kubectl delete node $variables_nodeName"