From 6efbaef42e97caece985444a7595b8115d887890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20COMPASTI=C3=89?= Date: Wed, 9 Dec 2020 02:17:50 +0100 Subject: [PATCH 1/5] Initial version EMS deployment --- .../org/activeeon/morphemic/PAGateway.java | 22 ++++ .../application/deployment/PAFactory.java | 32 ++++++ .../morphemic/model/EmsDeploymentRequest.java | 100 ++++++++++++++++++ .../resources/emsdeploy_mainscript.groovy | 93 ++++++++++++++++ src/main/resources/emsdeploy_postscript.sh | 2 + src/main/resources/emsdeploy_prescript.sh | 9 ++ 6 files changed, 258 insertions(+) create mode 100644 src/main/java/org/activeeon/morphemic/model/EmsDeploymentRequest.java create mode 100644 src/main/resources/emsdeploy_mainscript.groovy create mode 100644 src/main/resources/emsdeploy_postscript.sh create mode 100644 src/main/resources/emsdeploy_prescript.sh diff --git a/src/main/java/org/activeeon/morphemic/PAGateway.java b/src/main/java/org/activeeon/morphemic/PAGateway.java index 8863ac09..35355980 100644 --- a/src/main/java/org/activeeon/morphemic/PAGateway.java +++ b/src/main/java/org/activeeon/morphemic/PAGateway.java @@ -242,6 +242,18 @@ public class PAGateway { schedulerGateway.submit(fXmlFile, variables); } + /** + * Add an EMS deployment to a defined job + * @param authorizationBearer The authorization bearer used by upperware's components to authenticate with each other. Needed by the EMS. + * @param jobId A constructed job identifier + * @return return 0 if the deployment task is properly added. + */ + public int createEmsDeployment(String authorizationBearer, String jobId) { + Validate.notNull(authorizationBearer,"The provided authorization bearer cannot be empty"); + // TODO + return 0; + } + /** * Add nodes to the tasks of a defined job * @param nodes An array of nodes information in JSONObject format @@ -451,6 +463,16 @@ public class PAGateway { return deployNodeTask; } + // TODO To be integrated + private ScriptTask createEmsDeploymentTask(Task task, EmsDeploymentRequest emsDeploymentRequest, String taskNameSuffix, String nodeToken) { + LOGGER.debug("Preparing EMS deployment task"); + ScriptTask emsDeploymentTask = PAFactory.createComplexScriptTaskFromFiles("emsDeployment" + taskNameSuffix,"emsdeploy_mainscript.groovy","groovy","emsdeploy_prescript.sh","bash","emsdeploy_postscript.sh","bash"); + Map variablesMap = emsDeploymentRequest.getWorkflowMap(); + variablesMap.put("token", new TaskVariable("token",nodeToken)); + emsDeploymentTask.setVariables(variablesMap); + return emsDeploymentTask; + } + /** * Translate a Morphemic task skeleton into a list of ProActive tasks * @param task A Morphemic task skeleton diff --git a/src/main/java/org/activeeon/morphemic/application/deployment/PAFactory.java b/src/main/java/org/activeeon/morphemic/application/deployment/PAFactory.java index 2055783c..ae68d810 100644 --- a/src/main/java/org/activeeon/morphemic/application/deployment/PAFactory.java +++ b/src/main/java/org/activeeon/morphemic/application/deployment/PAFactory.java @@ -149,6 +149,38 @@ public class PAFactory { return scriptTask; } + /** + * Create a script task + * @param taskName The name of the task + * @param scriptFileName The script implementation file name + * @param scriptLanguage The script language + * @param preScriptFileName The pre-script implementation file name + * @param preScriptLanguage The pre-script language + * @param postScriptFileName The post-script implementation file name + * @param postScriptLanguage The post-script language + * @return A ProActive ScriptTask instance + */ + public static ScriptTask createComplexScriptTaskFromFiles(String taskName, String scriptFileName, String scriptLanguage, String preScriptFileName, String preScriptLanguage, String postScriptFileName, String postScriptLanguage ) { + ScriptTask scriptTask = new ScriptTask(); + scriptTask.setName(taskName); + TaskScript taskScript = null; + TaskScript taskPreScript = null; + TaskScript taskPostScript = null; + LOGGER.debug("Creating a script task from the files : scriptFileName=" + scriptFileName + " preScriptFileName=" + preScriptFileName + " postScriptFileName=" + postScriptFileName); + try { + taskScript = new TaskScript(createSimpleScriptFromFIle(scriptFileName, scriptLanguage)); + taskPreScript = new TaskScript(createSimpleScriptFromFIle(preScriptFileName, preScriptLanguage)); + taskPostScript = new TaskScript(createSimpleScriptFromFIle(postScriptFileName, postScriptLanguage)); + } catch (InvalidScriptException ie) { + LOGGER.error("ERROR: Task " + taskName + " script not created due to an InvalidScriptException: " + ie.toString()); + } + LOGGER.debug("Bash script task created."); + scriptTask.setScript(taskScript); + scriptTask.setScript(taskPreScript); + scriptTask.setScript(taskPostScript); + return scriptTask; + } + /** * Create a Groovy node selection script * @param scriptFileName The script implementation file name diff --git a/src/main/java/org/activeeon/morphemic/model/EmsDeploymentRequest.java b/src/main/java/org/activeeon/morphemic/model/EmsDeploymentRequest.java new file mode 100644 index 00000000..cc255eef --- /dev/null +++ b/src/main/java/org/activeeon/morphemic/model/EmsDeploymentRequest.java @@ -0,0 +1,100 @@ +package org.activeeon.morphemic.model; + +import org.ow2.proactive.scheduler.common.task.TaskVariable; + +import java.net.InetAddress; +import java.util.HashMap; +import java.util.Map; + +public class EmsDeploymentRequest { + + public enum TargetType { + vm("IAAS"), + container("PAAS"), + edge("EDGE"), + baremetal("BYON"), + faas("FAAS"); + + TargetType(String adapterVal) { + this.adapterVal = adapterVal; + } + + String adapterVal; + + } + + public enum TargetProvider { + // Amazon Web Service Elastic Compute Cloud + AWSEC2("aws-ec2"), + // Azure VM + AZUREVM("azure"), + // Google CLoud Engine + GCE("gce"), + // OpenStack NOVA + OPENSTACKNOVA("openstack"), + // BYON, to be used for on-premise baremetal & Edge + BYON("byon"); + + TargetProvider(String upperwareVal) { + this.upperwareValue = upperwareVal; + } + + String upperwareValue; + } + + private String authorizationBearer; + + private InetAddress baguetteIp; + + private int baguette_port; + + private OperatingSystemFamily targetOs; + + private TargetType targetType; + + private String targetName; + + private TargetProvider targetProvider; + + private String location; + + private boolean isUsingHttps; + + private String id; + + + public EmsDeploymentRequest(String authorizationBearer, InetAddress baguetteIp, int baguette_port, OperatingSystemFamily targetOs, + String 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.valueOf(targetType); + this.targetName = targetName; + this.targetProvider = targetProvider; + this.location = location; + this.isUsingHttps = isUsingHttps; + this.id = id; + } + + /** + * Provide the variable Array to be used in the EMS deployment workflow, structured to be ysed with the submit PA API + * @return The structured map. + */ + public Map getWorkflowMap() { + Map result = new HashMap<>(); + result.put("authorization_bearer", new TaskVariable("authorization_bearer",this.authorizationBearer,"",false)); + result.put("baguette_ip", new TaskVariable("baguette_ip",baguetteIp.toString(),"",false)); + result.put("baguette_port",new TaskVariable("baguette_port",String.valueOf(baguette_port),"",false)); + result.put("target_operating_system",new TaskVariable("target_operating_system",targetOs.name(),"",false)); + result.put("target_type", new TaskVariable("target_type",targetType.name(),"",false)); + result.put("target_name",new TaskVariable("target_name",targetName,"",false)); + result.put("target_provider",new TaskVariable("target_provider",targetProvider.name(),"",false)); + result.put("location", new TaskVariable("location",location,"",false)); + result.put("using_https", new TaskVariable("using_https",isUsingHttps + "","PA:Boolean",false)); + result.put("id",new TaskVariable("id",id,"",false)); + return result; + } + +} diff --git a/src/main/resources/emsdeploy_mainscript.groovy b/src/main/resources/emsdeploy_mainscript.groovy new file mode 100644 index 00000000..f294e5da --- /dev/null +++ b/src/main/resources/emsdeploy_mainscript.groovy @@ -0,0 +1,93 @@ +// Calculing privatekey fingerprint +println "== Baguette request preparation" +println "-- Getting parameters" +def password = credentials.containsKey('target_password') ? credentials.get('target_password') : "" +File privateKeyFile = new File("/tmp/ems-keypair") +File ipFile = new File("/tmp/ip.txt") +if (!privateKeyFile.exists()) { + println "ERR: PrivateKey file doesn't exist. Exiting" + return 255 +} +if (!ipFile.exists()) { + println "ERR: Public ip file doesn't exist. Exiting" + return 255 +} +def privateKey = privateKeyFile.text +def ip = ipFile.text + +def fingerprint = '' // TODO: + +println "-- Validating parameters" +// Chacking parameters values +def baguetteBearer = variables.get('authorization_bearer'); +def baguetteIp = variables.get('baguette_ip'); +def baguettePort = variables.get('baguette_port'); +def usingHttps = variables.get("using_https").toBoolean() +def emsUrl = String.format("%s://%s:%s/baguette/registerNode", usingHttps ? "https" : "http",baguetteIp,baguettePort) +def os = variables.get("target_operating_system") +//def ip = variables.get("target_ip") +def port = 22 //variables.get("target_port") +def username = "whoami".execute().text[0..-2] // We capture the output of whoami command & remove the \n char +def type = variables.get("target_type") +def name = variables.get("target_name") +def provider = variables.get("target_provider") +def location = variables.get("location") +def id = variables.get("id") + +// Request preparation +def isInputValid = true; +isInputValid &= (baguetteBearer != null); +isInputValid &= (baguetteIp != null); +isInputValid &= (baguettePort != null); +isInputValid &= (emsUrl != null); +isInputValid &= (os != null); +isInputValid &= (ip != null); +isInputValid &= (port != null); +isInputValid &= (username != null); +isInputValid &= (type != null); +isInputValid &= (name != null); +isInputValid &= (provider != null); + +if (!isInputValid) { + println "ERR: One or many provided parameters are invalid." + return 255; +} + +println "-- payload preparation" +def requestPayload = [:] +requestPayload.operatingSystem = os; +requestPayload.address = ip; +requestPayload.ssh = [:]; +requestPayload.ssh.port = port; +requestPayload.ssh.username = username; +requestPayload.type = type; +requestPayload.name = name; +requestPayload.provider = provider; +requestPayload.timestamp = new Date().getTime(); +requestPayload.location = location; +requestPayload.id = id; + +//if (password != "") { +// println "INFO: Using provided password" +requestPayload.ssh.password = password; +//} +requestPayload.ssh.key = privateKey; +requestPayload.ssh.fingerprint = fingerprint; + +def requestContent = groovy.json.JsonOutput.toJson(requestPayload); +println requestContent +// Request execution +println "== Requesting baguette server for EMS deployment" +def emsConnection = new URL(emsUrl).openConnection(); +emsConnection.setRequestMethod("POST") +emsConnection.setDoOutput(true) +emsConnection.setRequestProperty("Content-Type", "application/json") +emsConnection.setRequestProperty("Authorization", "Bearer " + baguetteBearer) +emsConnection.getOutputStream().write(requestContent.getBytes("UTF-8")); +def responseCode = emsConnection.getResponseCode(); +def responseContent = emsConnection.getInputStream().getText(); + +// Feedback analysis +println "== Obtaining result:" +println ">> Result: Code=" + responseCode + " Content=" + responseContent +result = '{"Code"="' + responseCode + '","Content"="' + responseContent + '"}' \ No newline at end of file diff --git a/src/main/resources/emsdeploy_postscript.sh b/src/main/resources/emsdeploy_postscript.sh new file mode 100644 index 00000000..eeec924b --- /dev/null +++ b/src/main/resources/emsdeploy_postscript.sh @@ -0,0 +1,2 @@ +echo "== Removing generated keypair" +rm -f /tmp/ems-keypair /tmp/ems-keypair.pup /tmp/ip.txt \ No newline at end of file diff --git a/src/main/resources/emsdeploy_prescript.sh b/src/main/resources/emsdeploy_prescript.sh new file mode 100644 index 00000000..2d3e6438 --- /dev/null +++ b/src/main/resources/emsdeploy_prescript.sh @@ -0,0 +1,9 @@ +echo "== Configuring infrastructure resource" +echo "-- Generating EMS-Specific keypair" +ssh-keygen -t rsa -m pkcs8 -f /tmp/ems-keypair +echo "-- Getting the public IP address of the infrastructure" +curl -o /tmp/ip.txt ifconfig.me +echo Found IP: +cat /tmp/ip.txt +echo "-- Adding generated public key" +cat /tmp/ems-keypair.pub >> ~/.ssh/authorized_keys \ No newline at end of file -- GitLab From 6ba087aa012da5eed140b30f344eee3f2902cdbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20COMPASTI=C3=89?= Date: Thu, 10 Dec 2020 01:10:27 +0100 Subject: [PATCH 2/5] Persistence of EmsDeploymentRequest --- .../org/activeeon/morphemic/PAGateway.java | 55 +++++++++++++++++-- .../activeeon/morphemic/model/Deployment.java | 3 + .../morphemic/model/EmsDeploymentRequest.java | 30 ++++++++-- 3 files changed, 76 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/activeeon/morphemic/PAGateway.java b/src/main/java/org/activeeon/morphemic/PAGateway.java index 35355980..6d532a10 100644 --- a/src/main/java/org/activeeon/morphemic/PAGateway.java +++ b/src/main/java/org/activeeon/morphemic/PAGateway.java @@ -32,7 +32,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.security.KeyException; import java.util.*; -import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicInteger; public class PAGateway { @@ -248,10 +248,52 @@ public class PAGateway { * @param jobId A constructed job identifier * @return return 0 if the deployment task is properly added. */ - public int createEmsDeployment(String authorizationBearer, String jobId) { + public int addEmsDeployment(JSONArray nodes, String jobId, String authorizationBearer) { Validate.notNull(authorizationBearer,"The provided authorization bearer cannot be empty"); - // TODO - return 0; + em.getTransaction().begin(); + + AtomicInteger failedDeployementIdentification = new AtomicInteger(); + // TODO Info to fetch from a config file and from nodeCandidate, when the feature will be available + String baguetteIp = "ems"; + int baguettePort = 22; + String operatingSystem = "UBUNTU"; + String targetType = "IAAS"; + boolean isUsingHttps = true; + + // For supplied node ... + nodes.forEach(object -> { + JSONObject node = (JSONObject) object; + Task task = em.find(Job.class, jobId).findTask(node.optString("taskName")); + PACloud cloud = em.find(PACloud.class, node.optJSONObject("nodeCandidateInformation").optString("cloudID")); + // ... we find the deployment containing the designed node + Optional optDeployment = task.getDeployments().stream() + .filter(d -> d.getLocationName().equals(node.optJSONObject("nodeCandidateInformation").optString("locationName"))) + .filter(d -> d.getImageProviderId().equals(node.optJSONObject("nodeCandidateInformation").optString("imageProviderId"))) + .filter(d -> d.getImageProviderId().equals(node.optJSONObject("nodeCandidateInformation").optString("hardwareProviderId"))) + .filter(d -> d.getHardwareProviderId().equals(node.optJSONObject("nodeCandidateInformation").optString("hardwareProviderId"))) + .filter(d -> d.getPaCloud().equals(cloud)) + .findAny(); + + if (optDeployment.isPresent()) { + // If we have found a deployment affecting the described node ... + Deployment deployment = optDeployment.get(); + EmsDeploymentRequest req = new EmsDeploymentRequest(authorizationBearer, baguetteIp, baguettePort, OperatingSystemFamily.fromValue(operatingSystem), targetType, deployment.getNodeName(), EmsDeploymentRequest.TargetProvider.valueOf(cloud.getCloudProviderName()), deployment.getLocationName(), isUsingHttps, deployment.getNodeName()); + deployment.setEmsDeployment(req); + em.persist(deployment); + em.persist(cloud); + em.persist(task); + } else { + // Other, we notify the error + LOGGER.error(String.format("Unable to deploy EMS: Node [%s] is not recognized",node)); + failedDeployementIdentification.getAndIncrement(); + } + + }); + + em.getTransaction().commit(); + + LOGGER.info("EMS deployment definition finished."); + return failedDeployementIdentification.get(); } /** @@ -463,8 +505,7 @@ public class PAGateway { return deployNodeTask; } - // TODO To be integrated - private ScriptTask createEmsDeploymentTask(Task task, EmsDeploymentRequest emsDeploymentRequest, String taskNameSuffix, String nodeToken) { + private ScriptTask createEmsDeploymentTask(EmsDeploymentRequest emsDeploymentRequest, String taskNameSuffix, String nodeToken) { LOGGER.debug("Preparing EMS deployment task"); ScriptTask emsDeploymentTask = PAFactory.createComplexScriptTaskFromFiles("emsDeployment" + taskNameSuffix,"emsdeploy_mainscript.groovy","groovy","emsdeploy_prescript.sh","bash","emsdeploy_postscript.sh","bash"); Map variablesMap = emsDeploymentRequest.getWorkflowMap(); @@ -491,6 +532,8 @@ public class PAGateway { String token = task.getTaskId() + tasksTokens.size(); String suffix = "_" + tasksTokens.size(); scriptTasks.add(createInfraTask(task, deployment, suffix, token)); + // If the infrastructure comes with the deployment of the EMS, we set it up. + Optional.ofNullable(deployment.getEmsDeployment()).ifPresent(emsDeploymentRequest -> scriptTasks.add(createEmsDeploymentTask(emsDeploymentRequest,suffix,token))); LOGGER.debug("Token added: " + token); tasksTokens.add(token); }); diff --git a/src/main/java/org/activeeon/morphemic/model/Deployment.java b/src/main/java/org/activeeon/morphemic/model/Deployment.java index cae65332..31e1eec2 100644 --- a/src/main/java/org/activeeon/morphemic/model/Deployment.java +++ b/src/main/java/org/activeeon/morphemic/model/Deployment.java @@ -29,6 +29,9 @@ public class Deployment implements Serializable { @Column(name = "HARDWARE_PROVIDER_ID") private String hardwareProviderId; + @OneToOne(fetch = FetchType.EAGER) + private EmsDeploymentRequest emsDeployment; + @ManyToOne(fetch = FetchType.EAGER) private PACloud paCloud; diff --git a/src/main/java/org/activeeon/morphemic/model/EmsDeploymentRequest.java b/src/main/java/org/activeeon/morphemic/model/EmsDeploymentRequest.java index cc255eef..4c7fc4ce 100644 --- a/src/main/java/org/activeeon/morphemic/model/EmsDeploymentRequest.java +++ b/src/main/java/org/activeeon/morphemic/model/EmsDeploymentRequest.java @@ -2,11 +2,15 @@ package org.activeeon.morphemic.model; import org.ow2.proactive.scheduler.common.task.TaskVariable; +import javax.persistence.*; +import java.io.Serializable; import java.net.InetAddress; import java.util.HashMap; import java.util.Map; -public class EmsDeploymentRequest { +@Entity +@Table(name = "EMSDEPLOYMENTREQUEST") +public class EmsDeploymentRequest implements Serializable { public enum TargetType { vm("IAAS"), @@ -42,28 +46,42 @@ public class EmsDeploymentRequest { String upperwareValue; } + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private String id; + + @Column(name = "AUTHORIZATIONBEARER") private String authorizationBearer; - private InetAddress baguetteIp; + @Column(name = "BAGUETTEIP") + private String baguetteIp; + @Column(name = "BAGUETTEPORT") private int baguette_port; + @Column(name = "TARGETOS") private OperatingSystemFamily targetOs; + @Column(name = "TARGETTYPE") private TargetType targetType; + @Column(name = "TARGETNAME") private String targetName; + @Column(name = "TARGETPROVIDER") private TargetProvider targetProvider; + @Column(name = "LOCATION") private String location; + @Column(name = "ISUSINGHTTP") private boolean isUsingHttps; - private String id; + @Column(name = "NODEID") + private String nodeId; - public EmsDeploymentRequest(String authorizationBearer, InetAddress baguetteIp, int baguette_port, OperatingSystemFamily targetOs, + public EmsDeploymentRequest(String authorizationBearer, String baguetteIp, int baguette_port, OperatingSystemFamily targetOs, String targetType, String targetName, TargetProvider targetProvider, String location, boolean isUsingHttps, String id) { this.authorizationBearer = authorizationBearer; @@ -75,7 +93,7 @@ public class EmsDeploymentRequest { this.targetProvider = targetProvider; this.location = location; this.isUsingHttps = isUsingHttps; - this.id = id; + this.nodeId = id; } /** @@ -93,7 +111,7 @@ public class EmsDeploymentRequest { result.put("target_provider",new TaskVariable("target_provider",targetProvider.name(),"",false)); result.put("location", new TaskVariable("location",location,"",false)); result.put("using_https", new TaskVariable("using_https",isUsingHttps + "","PA:Boolean",false)); - result.put("id",new TaskVariable("id",id,"",false)); + result.put("id",new TaskVariable("id", nodeId,"",false)); return result; } -- GitLab From d705d43fcf55e637722178bcb6ea2df2422154fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20COMPASTI=C3=89?= Date: Thu, 10 Dec 2020 14:11:11 +0100 Subject: [PATCH 3/5] Applying reviewer's comments --- .../org/activeeon/morphemic/PAGateway.java | 37 ++++--------------- .../application/deployment/PAFactory.java | 4 +- .../activeeon/morphemic/model/Deployment.java | 5 +-- 3 files changed, 11 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/activeeon/morphemic/PAGateway.java b/src/main/java/org/activeeon/morphemic/PAGateway.java index 6d532a10..6e2e8e73 100644 --- a/src/main/java/org/activeeon/morphemic/PAGateway.java +++ b/src/main/java/org/activeeon/morphemic/PAGateway.java @@ -248,7 +248,7 @@ public class PAGateway { * @param jobId A constructed job identifier * @return return 0 if the deployment task is properly added. */ - public int addEmsDeployment(JSONArray nodes, String jobId, String authorizationBearer) { + public int addEmsDeployment(List nodeNames, String jobId, String authorizationBearer) { Validate.notNull(authorizationBearer,"The provided authorization bearer cannot be empty"); em.getTransaction().begin(); @@ -261,33 +261,12 @@ public class PAGateway { boolean isUsingHttps = true; // For supplied node ... - nodes.forEach(object -> { - JSONObject node = (JSONObject) object; - Task task = em.find(Job.class, jobId).findTask(node.optString("taskName")); - PACloud cloud = em.find(PACloud.class, node.optJSONObject("nodeCandidateInformation").optString("cloudID")); - // ... we find the deployment containing the designed node - Optional optDeployment = task.getDeployments().stream() - .filter(d -> d.getLocationName().equals(node.optJSONObject("nodeCandidateInformation").optString("locationName"))) - .filter(d -> d.getImageProviderId().equals(node.optJSONObject("nodeCandidateInformation").optString("imageProviderId"))) - .filter(d -> d.getImageProviderId().equals(node.optJSONObject("nodeCandidateInformation").optString("hardwareProviderId"))) - .filter(d -> d.getHardwareProviderId().equals(node.optJSONObject("nodeCandidateInformation").optString("hardwareProviderId"))) - .filter(d -> d.getPaCloud().equals(cloud)) - .findAny(); - - if (optDeployment.isPresent()) { - // If we have found a deployment affecting the described node ... - Deployment deployment = optDeployment.get(); - EmsDeploymentRequest req = new EmsDeploymentRequest(authorizationBearer, baguetteIp, baguettePort, OperatingSystemFamily.fromValue(operatingSystem), targetType, deployment.getNodeName(), EmsDeploymentRequest.TargetProvider.valueOf(cloud.getCloudProviderName()), deployment.getLocationName(), isUsingHttps, deployment.getNodeName()); - deployment.setEmsDeployment(req); - em.persist(deployment); - em.persist(cloud); - em.persist(task); - } else { - // Other, we notify the error - LOGGER.error(String.format("Unable to deploy EMS: Node [%s] is not recognized",node)); - failedDeployementIdentification.getAndIncrement(); - } - + nodeNames.forEach(object -> { + Deployment deployment = em.find(Deployment.class,nodeNames); + PACloud cloud = deployment.getPaCloud(); + EmsDeploymentRequest req = new EmsDeploymentRequest(authorizationBearer, baguetteIp, baguettePort, OperatingSystemFamily.fromValue(operatingSystem), targetType, deployment.getNodeName(), EmsDeploymentRequest.TargetProvider.valueOf(cloud.getCloudProviderName()), deployment.getLocationName(), isUsingHttps, deployment.getNodeName()); + deployment.setEmsDeployment(req); + em.persist(deployment); }); em.getTransaction().commit(); @@ -509,7 +488,7 @@ public class PAGateway { LOGGER.debug("Preparing EMS deployment task"); ScriptTask emsDeploymentTask = PAFactory.createComplexScriptTaskFromFiles("emsDeployment" + taskNameSuffix,"emsdeploy_mainscript.groovy","groovy","emsdeploy_prescript.sh","bash","emsdeploy_postscript.sh","bash"); Map variablesMap = emsDeploymentRequest.getWorkflowMap(); - variablesMap.put("token", new TaskVariable("token",nodeToken)); + emsDeploymentTask.addGenericInformation("token", nodeToken); emsDeploymentTask.setVariables(variablesMap); return emsDeploymentTask; } diff --git a/src/main/java/org/activeeon/morphemic/application/deployment/PAFactory.java b/src/main/java/org/activeeon/morphemic/application/deployment/PAFactory.java index ae68d810..48b5b693 100644 --- a/src/main/java/org/activeeon/morphemic/application/deployment/PAFactory.java +++ b/src/main/java/org/activeeon/morphemic/application/deployment/PAFactory.java @@ -176,8 +176,8 @@ public class PAFactory { } LOGGER.debug("Bash script task created."); scriptTask.setScript(taskScript); - scriptTask.setScript(taskPreScript); - scriptTask.setScript(taskPostScript); + scriptTask.setPreScript(taskPreScript); + scriptTask.setPostScript(taskPostScript); return scriptTask; } diff --git a/src/main/java/org/activeeon/morphemic/model/Deployment.java b/src/main/java/org/activeeon/morphemic/model/Deployment.java index 31e1eec2..0a1938dc 100644 --- a/src/main/java/org/activeeon/morphemic/model/Deployment.java +++ b/src/main/java/org/activeeon/morphemic/model/Deployment.java @@ -12,11 +12,9 @@ import java.io.Serializable; @Entity @Table(name = "DEPLOYMENT") public class Deployment implements Serializable { + @Id @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "DEPLOYMENT_ID") - private int deploymentId; - @Column(name = "NODE_NAME") private String nodeName; @@ -38,7 +36,6 @@ public class Deployment implements Serializable { @Override public String toString() { return "Deployment{" + - "deploymentId=" + deploymentId + ", nodeName='" + nodeName + '\'' + ", locationName='" + locationName + '\'' + ", imageProviderId='" + imageProviderId + '\'' + -- GitLab From f60d3571eb7dee848f38bb22fcad6b07f6e294fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20COMPASTI=C3=89?= Date: Thu, 10 Dec 2020 14:13:57 +0100 Subject: [PATCH 4/5] Removing unneeded input in EMS deployment interface --- src/main/java/org/activeeon/morphemic/PAGateway.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/activeeon/morphemic/PAGateway.java b/src/main/java/org/activeeon/morphemic/PAGateway.java index 6e2e8e73..90ddfd33 100644 --- a/src/main/java/org/activeeon/morphemic/PAGateway.java +++ b/src/main/java/org/activeeon/morphemic/PAGateway.java @@ -245,10 +245,9 @@ public class PAGateway { /** * Add an EMS deployment to a defined job * @param authorizationBearer The authorization bearer used by upperware's components to authenticate with each other. Needed by the EMS. - * @param jobId A constructed job identifier * @return return 0 if the deployment task is properly added. */ - public int addEmsDeployment(List nodeNames, String jobId, String authorizationBearer) { + public int addEmsDeployment(List nodeNames, String authorizationBearer) { Validate.notNull(authorizationBearer,"The provided authorization bearer cannot be empty"); em.getTransaction().begin(); -- GitLab From f95ca407c2859bf3aa09cd776683f807d0f030f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20COMPASTI=C3=89?= Date: Thu, 10 Dec 2020 15:02:42 +0100 Subject: [PATCH 5/5] Bugfix --- src/main/java/org/activeeon/morphemic/PAGateway.java | 6 +++--- src/main/java/org/activeeon/morphemic/model/Deployment.java | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/activeeon/morphemic/PAGateway.java b/src/main/java/org/activeeon/morphemic/PAGateway.java index 90ddfd33..6420185d 100644 --- a/src/main/java/org/activeeon/morphemic/PAGateway.java +++ b/src/main/java/org/activeeon/morphemic/PAGateway.java @@ -260,8 +260,8 @@ public class PAGateway { boolean isUsingHttps = true; // For supplied node ... - nodeNames.forEach(object -> { - Deployment deployment = em.find(Deployment.class,nodeNames); + nodeNames.forEach(node -> { + Deployment deployment = em.find(Deployment.class,node); PACloud cloud = deployment.getPaCloud(); EmsDeploymentRequest req = new EmsDeploymentRequest(authorizationBearer, baguetteIp, baguettePort, OperatingSystemFamily.fromValue(operatingSystem), targetType, deployment.getNodeName(), EmsDeploymentRequest.TargetProvider.valueOf(cloud.getCloudProviderName()), deployment.getLocationName(), isUsingHttps, deployment.getNodeName()); deployment.setEmsDeployment(req); @@ -487,7 +487,7 @@ public class PAGateway { LOGGER.debug("Preparing EMS deployment task"); ScriptTask emsDeploymentTask = PAFactory.createComplexScriptTaskFromFiles("emsDeployment" + taskNameSuffix,"emsdeploy_mainscript.groovy","groovy","emsdeploy_prescript.sh","bash","emsdeploy_postscript.sh","bash"); Map variablesMap = emsDeploymentRequest.getWorkflowMap(); - emsDeploymentTask.addGenericInformation("token", nodeToken); + emsDeploymentTask.addGenericInformation("NODE_ACCESS_TOKEN", nodeToken); emsDeploymentTask.setVariables(variablesMap); return emsDeploymentTask; } diff --git a/src/main/java/org/activeeon/morphemic/model/Deployment.java b/src/main/java/org/activeeon/morphemic/model/Deployment.java index 0a1938dc..783735cb 100644 --- a/src/main/java/org/activeeon/morphemic/model/Deployment.java +++ b/src/main/java/org/activeeon/morphemic/model/Deployment.java @@ -14,7 +14,6 @@ import java.io.Serializable; public class Deployment implements Serializable { @Id - @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "NODE_NAME") private String nodeName; -- GitLab