From 72fd046c83a4b2c19c075e97b9d7a5829caafdc1 Mon Sep 17 00:00:00 2001 From: marounkoussaifi Date: Tue, 12 Jul 2022 14:58:20 +0200 Subject: [PATCH 1/5] Add the WF Analyser to SAL --- scheduling-abstraction-layer/pom.xml | 5 + .../workflow.analyser/WfAnalyser.java | 243 ++++++++++++++++++ 2 files changed, 248 insertions(+) create mode 100644 scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow.analyser/WfAnalyser.java diff --git a/scheduling-abstraction-layer/pom.xml b/scheduling-abstraction-layer/pom.xml index ee70e446..b00ebcc0 100644 --- a/scheduling-abstraction-layer/pom.xml +++ b/scheduling-abstraction-layer/pom.xml @@ -79,6 +79,11 @@ 5.4.22.Final compile + + org.jdom + jdom2 + 2.0.6.1 + org.mariadb.jdbc mariadb-java-client diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow.analyser/WfAnalyser.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow.analyser/WfAnalyser.java new file mode 100644 index 00000000..a75edbf0 --- /dev/null +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow.analyser/WfAnalyser.java @@ -0,0 +1,243 @@ +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.JDOMException; +import org.jdom2.input.SAXBuilder; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +public class WfAnalyser { + + Element camelModelRoot; + + // Environment Variable Name for the camel xmi model path = CAMEL_XMI_DIR, e.g. CAMEL_XMI_DIR = "/users/user1/Documens/camel.xmi" + private final static String propertiesFileEnvironmentVariableName = "CAMEL_XMI_DIR"; + + public WfAnalyser() throws IOException, JDOMException { + SAXBuilder builder = new SAXBuilder(); + String path = System.getenv(propertiesFileEnvironmentVariableName); + File xmiFile = new File(path); + Document document = builder.build(xmiFile); + this.camelModelRoot = document.getRootElement(); + } + + public WfAnalyser(String path) throws IOException, JDOMException { + SAXBuilder builder = new SAXBuilder(); + File xmiFile = new File(path); + Document document = builder.build(xmiFile); + this.camelModelRoot = document.getRootElement(); + } + + public JSONObject getJsonGrouping() throws IOException, JDOMException { + JSONObject result = new JSONObject(); + JSONArray applicationComponents = new JSONArray(); + + // Get application name + Element applicationElement = camelModelRoot.getChild("application"); + result.put("Application_name", applicationElement.getAttributeValue("name")); + + // Get number of components + List components = camelModelRoot.getChild("deploymentModels").getChildren("softwareComponents"); + result.put("Number_of_components", components.size()); + + // App Requirements + result.put("General_requirements", getAppRequirements(components.size())); + + // Get components metadata: name, requirements, long_lived, ... + for(Element component: components){ + JSONObject componentMetaData = new JSONObject(); + + // Get component name + componentMetaData.put("name", component.getAttributeValue("name")); + + // Get component long_lived value if it exists + componentMetaData.put("Long_lived", component.getAttributeValue("longLived")); + + // Get resource requirements + String resourceReqValue = component.getAttributeValue("requirementSet"); + int reqIndex = Integer.parseInt(resourceReqValue.split("@requirementSets.")[1]); + JSONArray resourceRequirements = getResourceReq(reqIndex); + componentMetaData.put("Resources", resourceRequirements); + + // Get component variants + componentMetaData.put("Variants", getVariants(component)); + + applicationComponents.put(componentMetaData); + } + result.put("Application_components", applicationComponents); + result.put("Application_graph", getWorkflowArchitecture()); + return result; + } + + public String generateDotGraph() { + StringBuilder dotGraphSyntax = new StringBuilder(); + + // Write the dot file header + dotGraphSyntax.append("digraph g {\n"); + + // Add components to the do graph + List components = camelModelRoot.getChild("deploymentModels").getChildren("softwareComponents"); + for(Element component: components) { + dotGraphSyntax.append(component.getAttributeValue("name")).append("[fontcolor=black, color=orange];\n"); + } + // Add required communication + for(Element component: components) { + List requiredCommunications = component.getChildren("requiredCommunications"); + for(Element requiredCommunication: requiredCommunications) { + dotGraphSyntax.append(findRequiredComp(components, requiredCommunication.getAttributeValue("portNumber"))) + .append("->") + .append(component.getAttributeValue("name")) + .append(" [fillcolor=grey, fontcolor=blue, color=grey, fontsize=6]").append(";"); + dotGraphSyntax.append("\n"); + } + } + // Write the dot file end character + dotGraphSyntax.append("}\n"); + return dotGraphSyntax.toString(); + } + + private String findRequiredComp(List components, String portNumber) { + for(Element component: components) { + if(component.getChildren("providedCommunications").stream().anyMatch(provComm -> provComm.getAttributeValue("portNumber").equals(portNumber))) { + return component.getAttributeValue("name"); + } + } + return ""; + } + + private String findProvidedComp(List components, String portNumber) { + for(Element component: components) { + if(component.getChildren("requiredCommunications").stream().anyMatch(provComm -> provComm.getAttributeValue("portNumber").equals(portNumber))) { + return component.getAttributeValue("name"); + } + } + return ""; + } + + private JSONArray getResourceReq(int reqIndex) { + JSONArray resourceRequirement = new JSONArray(); + Element requirementModels = camelModelRoot.getChild("requirementModels"); + // Get component Req by index + Element compRequirement = requirementModels.getChildren("requirements").get(reqIndex); + // Get component req features + List subFeatures = compRequirement.getChildren("subFeatures"); + // Get list of attributes per component feature + for(Element feature: subFeatures) { + JSONObject requirement = new JSONObject(); + String reqName = feature.getAttributeValue("annotations"); + // Get list of attributes per requirement element + List attributes = feature.getChildren("attributes"); + JSONArray listOfRequirements = new JSONArray(); + for(Element attribute: attributes) { + // Get attribute name + String attributeName = attribute.getAttributeValue("name"); + // Get attribute value + String value = attribute.getChild("value").getAttributeValue("value"); + JSONObject attributeValue = new JSONObject(); + // Create json object with attribute name and value + attributeValue.put(attributeName, value); + // Add the attribute object to the list + listOfRequirements.put(attributeValue); + } + requirement.put(reqName, listOfRequirements); + resourceRequirement.put(requirement); + } + return resourceRequirement; + } + + private JSONArray getVariants(Element component) { + JSONArray variants = new JSONArray(); + List attributes = component.getChildren("attributes"); + for(Element element: attributes) { + String value = element.getChild("value").getAttributeValue("value"); + if(value.contains("VM") || value.contains("DOCKER") || value.contains("SERVERLESS") || value.contains("HPC")) { + variants.put(value); + } + } + return variants; + } + + private JSONArray getAppRequirements(int startIndex) { + JSONArray appRequirements = new JSONArray(); + Element requirementModels = camelModelRoot.getChild("requirementModels"); + // Get component Req + List compRequirements = requirementModels.getChildren("requirements"); + for(int i=startIndex; i images = requirement.getChildren("images"); + JSONArray imagesValue = new JSONArray(); + for(Element image: images) { + imagesValue.put(image.getValue()); + } + + if(imagesValue.length()>0) { + instancesRequirementObject.put("Images for: " + reqName, imagesValue); + } + + if(!instancesReq.isEmpty()) { + instancesRequirementObject.put(reqName, instancesReq); + } + + //instancesRequirementObject.get() + + if(!instancesRequirementObject.isEmpty()) { + appRequirements.put(instancesRequirementObject); + } + } + return appRequirements; + } + + private JSONArray getWorkflowArchitecture() { + JSONArray results = new JSONArray(); + List components = camelModelRoot.getChild("deploymentModels").getChildren("softwareComponents"); + for(Element component: components) { + JSONArray cnx = new JSONArray(); + List requiredCommunications = component.getChildren("requiredCommunications"); + List providedCommunications = component.getChildren("providedCommunications"); + for(Element requiredCommunication: requiredCommunications) { + String connectionName = findRequiredComp(components, requiredCommunication.getAttributeValue("portNumber")); + if(!connectionName.isEmpty()) { + cnx.put(connectionName); + } + } + for(Element providedCommunication: providedCommunications) { + String connectionName = findProvidedComp(components, providedCommunication.getAttributeValue("portNumber")); + if(!connectionName.isEmpty()) { + cnx.put(connectionName); + } + } + JSONObject compConnections = new JSONObject(); + compConnections.put(component.getAttributeValue("name"), cnx); + results.put(compConnections); + } + return results; + } +} \ No newline at end of file -- GitLab From e3b8b710760eedd1ce10917151954b397d6210f8 Mon Sep 17 00:00:00 2001 From: mklkun Date: Tue, 12 Jul 2022 15:41:46 +0200 Subject: [PATCH 2/5] Fix package name and some tipos --- .../analyser}/WfAnalyser.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) rename scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/{workflow.analyser => workflow/analyser}/WfAnalyser.java (96%) diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow.analyser/WfAnalyser.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java similarity index 96% rename from scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow.analyser/WfAnalyser.java rename to scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java index a75edbf0..2e217f64 100644 --- a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow.analyser/WfAnalyser.java +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java @@ -1,3 +1,5 @@ +package org.activeeon.morphemic.workflow.analyser; + import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.JDOMException; @@ -13,12 +15,12 @@ public class WfAnalyser { Element camelModelRoot; - // Environment Variable Name for the camel xmi model path = CAMEL_XMI_DIR, e.g. CAMEL_XMI_DIR = "/users/user1/Documens/camel.xmi" - private final static String propertiesFileEnvironmentVariableName = "CAMEL_XMI_DIR"; + // Environment Variable Name for the camel xmi model path = CAMEL_XMI_DIR, e.g. CAMEL_XMI_DIR = "/users/user1/Documents/camel.xmi" + private static final String PROPERTIES_FILE_ENVIRONMENT_VARIABLE_NAME = "CAMEL_XMI_DIR"; public WfAnalyser() throws IOException, JDOMException { SAXBuilder builder = new SAXBuilder(); - String path = System.getenv(propertiesFileEnvironmentVariableName); + String path = System.getenv(PROPERTIES_FILE_ENVIRONMENT_VARIABLE_NAME); File xmiFile = new File(path); Document document = builder.build(xmiFile); this.camelModelRoot = document.getRootElement(); @@ -31,7 +33,7 @@ public class WfAnalyser { this.camelModelRoot = document.getRootElement(); } - public JSONObject getJsonGrouping() throws IOException, JDOMException { + public JSONObject getJsonGrouping() { JSONObject result = new JSONObject(); JSONArray applicationComponents = new JSONArray(); -- GitLab From 1359e2c2d186a17962be85be6c9d63f9d38aa636 Mon Sep 17 00:00:00 2001 From: mklkun Date: Tue, 19 Jul 2022 15:29:01 +0200 Subject: [PATCH 3/5] Code refactoring --- .../workflow/analyser/WfAnalyser.java | 159 ++---------------- .../analyser/WfAnalyserCamelUtils.java | 130 ++++++++++++++ .../analyser/WfAnalyserXmiElementUtils.java | 43 +++++ 3 files changed, 184 insertions(+), 148 deletions(-) create mode 100644 scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserCamelUtils.java create mode 100644 scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserXmiElementUtils.java diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java index 2e217f64..8fcb13d1 100644 --- a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java @@ -13,17 +13,20 @@ import java.util.List; public class WfAnalyser { - Element camelModelRoot; - // Environment Variable Name for the camel xmi model path = CAMEL_XMI_DIR, e.g. CAMEL_XMI_DIR = "/users/user1/Documents/camel.xmi" private static final String PROPERTIES_FILE_ENVIRONMENT_VARIABLE_NAME = "CAMEL_XMI_DIR"; + Element camelModelRoot; + + WfAnalyserCamelUtils wfAnalyserCamelUtils; + public WfAnalyser() throws IOException, JDOMException { SAXBuilder builder = new SAXBuilder(); String path = System.getenv(PROPERTIES_FILE_ENVIRONMENT_VARIABLE_NAME); File xmiFile = new File(path); Document document = builder.build(xmiFile); this.camelModelRoot = document.getRootElement(); + wfAnalyserCamelUtils = new WfAnalyserCamelUtils(this.camelModelRoot); } public WfAnalyser(String path) throws IOException, JDOMException { @@ -31,6 +34,7 @@ public class WfAnalyser { File xmiFile = new File(path); Document document = builder.build(xmiFile); this.camelModelRoot = document.getRootElement(); + wfAnalyserCamelUtils = new WfAnalyserCamelUtils(this.camelModelRoot); } public JSONObject getJsonGrouping() { @@ -46,7 +50,7 @@ public class WfAnalyser { result.put("Number_of_components", components.size()); // App Requirements - result.put("General_requirements", getAppRequirements(components.size())); + result.put("General_requirements", wfAnalyserCamelUtils.getAppRequirements(components.size())); // Get components metadata: name, requirements, long_lived, ... for(Element component: components){ @@ -61,16 +65,16 @@ public class WfAnalyser { // Get resource requirements String resourceReqValue = component.getAttributeValue("requirementSet"); int reqIndex = Integer.parseInt(resourceReqValue.split("@requirementSets.")[1]); - JSONArray resourceRequirements = getResourceReq(reqIndex); + JSONArray resourceRequirements = wfAnalyserCamelUtils.getResourceRequirements(reqIndex); componentMetaData.put("Resources", resourceRequirements); // Get component variants - componentMetaData.put("Variants", getVariants(component)); + componentMetaData.put("Variants", WfAnalyserXmiElementUtils.getVariants(component)); applicationComponents.put(componentMetaData); } result.put("Application_components", applicationComponents); - result.put("Application_graph", getWorkflowArchitecture()); + result.put("Application_graph", wfAnalyserCamelUtils.getWorkflowArchitecture()); return result; } @@ -89,7 +93,7 @@ public class WfAnalyser { for(Element component: components) { List requiredCommunications = component.getChildren("requiredCommunications"); for(Element requiredCommunication: requiredCommunications) { - dotGraphSyntax.append(findRequiredComp(components, requiredCommunication.getAttributeValue("portNumber"))) + dotGraphSyntax.append(WfAnalyserXmiElementUtils.findRequiredComponent(components, requiredCommunication.getAttributeValue("portNumber"))) .append("->") .append(component.getAttributeValue("name")) .append(" [fillcolor=grey, fontcolor=blue, color=grey, fontsize=6]").append(";"); @@ -101,145 +105,4 @@ public class WfAnalyser { return dotGraphSyntax.toString(); } - private String findRequiredComp(List components, String portNumber) { - for(Element component: components) { - if(component.getChildren("providedCommunications").stream().anyMatch(provComm -> provComm.getAttributeValue("portNumber").equals(portNumber))) { - return component.getAttributeValue("name"); - } - } - return ""; - } - - private String findProvidedComp(List components, String portNumber) { - for(Element component: components) { - if(component.getChildren("requiredCommunications").stream().anyMatch(provComm -> provComm.getAttributeValue("portNumber").equals(portNumber))) { - return component.getAttributeValue("name"); - } - } - return ""; - } - - private JSONArray getResourceReq(int reqIndex) { - JSONArray resourceRequirement = new JSONArray(); - Element requirementModels = camelModelRoot.getChild("requirementModels"); - // Get component Req by index - Element compRequirement = requirementModels.getChildren("requirements").get(reqIndex); - // Get component req features - List subFeatures = compRequirement.getChildren("subFeatures"); - // Get list of attributes per component feature - for(Element feature: subFeatures) { - JSONObject requirement = new JSONObject(); - String reqName = feature.getAttributeValue("annotations"); - // Get list of attributes per requirement element - List attributes = feature.getChildren("attributes"); - JSONArray listOfRequirements = new JSONArray(); - for(Element attribute: attributes) { - // Get attribute name - String attributeName = attribute.getAttributeValue("name"); - // Get attribute value - String value = attribute.getChild("value").getAttributeValue("value"); - JSONObject attributeValue = new JSONObject(); - // Create json object with attribute name and value - attributeValue.put(attributeName, value); - // Add the attribute object to the list - listOfRequirements.put(attributeValue); - } - requirement.put(reqName, listOfRequirements); - resourceRequirement.put(requirement); - } - return resourceRequirement; - } - - private JSONArray getVariants(Element component) { - JSONArray variants = new JSONArray(); - List attributes = component.getChildren("attributes"); - for(Element element: attributes) { - String value = element.getChild("value").getAttributeValue("value"); - if(value.contains("VM") || value.contains("DOCKER") || value.contains("SERVERLESS") || value.contains("HPC")) { - variants.put(value); - } - } - return variants; - } - - private JSONArray getAppRequirements(int startIndex) { - JSONArray appRequirements = new JSONArray(); - Element requirementModels = camelModelRoot.getChild("requirementModels"); - // Get component Req - List compRequirements = requirementModels.getChildren("requirements"); - for(int i=startIndex; i images = requirement.getChildren("images"); - JSONArray imagesValue = new JSONArray(); - for(Element image: images) { - imagesValue.put(image.getValue()); - } - - if(imagesValue.length()>0) { - instancesRequirementObject.put("Images for: " + reqName, imagesValue); - } - - if(!instancesReq.isEmpty()) { - instancesRequirementObject.put(reqName, instancesReq); - } - - //instancesRequirementObject.get() - - if(!instancesRequirementObject.isEmpty()) { - appRequirements.put(instancesRequirementObject); - } - } - return appRequirements; - } - - private JSONArray getWorkflowArchitecture() { - JSONArray results = new JSONArray(); - List components = camelModelRoot.getChild("deploymentModels").getChildren("softwareComponents"); - for(Element component: components) { - JSONArray cnx = new JSONArray(); - List requiredCommunications = component.getChildren("requiredCommunications"); - List providedCommunications = component.getChildren("providedCommunications"); - for(Element requiredCommunication: requiredCommunications) { - String connectionName = findRequiredComp(components, requiredCommunication.getAttributeValue("portNumber")); - if(!connectionName.isEmpty()) { - cnx.put(connectionName); - } - } - for(Element providedCommunication: providedCommunications) { - String connectionName = findProvidedComp(components, providedCommunication.getAttributeValue("portNumber")); - if(!connectionName.isEmpty()) { - cnx.put(connectionName); - } - } - JSONObject compConnections = new JSONObject(); - compConnections.put(component.getAttributeValue("name"), cnx); - results.put(compConnections); - } - return results; - } } \ No newline at end of file diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserCamelUtils.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserCamelUtils.java new file mode 100644 index 00000000..2c92cfac --- /dev/null +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserCamelUtils.java @@ -0,0 +1,130 @@ +package org.activeeon.morphemic.workflow.analyser; + +import lombok.AllArgsConstructor; +import org.jdom2.Element; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.List; + +@AllArgsConstructor +public class WfAnalyserCamelUtils { + + Element camelModelRoot; + + public JSONArray getResourceRequirements(int reqIndex) { + JSONArray resourceRequirement = new JSONArray(); + Element requirementModels = camelModelRoot.getChild("requirementModels"); + // Get component Req by index + Element compRequirement = requirementModels.getChildren("requirements").get(reqIndex); + // Get component req features + List subFeatures = compRequirement.getChildren("subFeatures"); + // Get list of attributes per component feature + for(Element feature: subFeatures) { + JSONObject requirement = new JSONObject(); + String reqName = feature.getAttributeValue("annotations"); + // Get list of attributes per requirement element + List attributes = feature.getChildren("attributes"); + JSONArray listOfRequirements = new JSONArray(); + for(Element attribute: attributes) { + // Get attribute name + String attributeName = attribute.getAttributeValue("name"); + // Get attribute value + String value = attribute.getChild("value").getAttributeValue("value"); + JSONObject attributeValue = new JSONObject(); + // Create json object with attribute name and value + attributeValue.put(attributeName, value); + // Add the attribute object to the list + listOfRequirements.put(attributeValue); + } + requirement.put(reqName, listOfRequirements); + resourceRequirement.put(requirement); + } + return resourceRequirement; + } + + + public JSONArray getAppRequirements(int startIndex) { + JSONArray appRequirements = new JSONArray(); + Element requirementModels = camelModelRoot.getChild("requirementModels"); + // Get component Req + List compRequirements = requirementModels.getChildren("requirements"); + for(int i=startIndex; i images = requirement.getChildren("images"); + JSONArray imagesValue = new JSONArray(); + for(Element image: images) { + imagesValue.put(image.getValue()); + } + + if(imagesValue.length()>0) { + instancesRequirementObject.put("Images for: " + reqName, imagesValue); + } + + if(!instancesReq.isEmpty()) { + instancesRequirementObject.put(reqName, instancesReq); + } + + //instancesRequirementObject.get() + + if(!instancesRequirementObject.isEmpty()) { + appRequirements.put(instancesRequirementObject); + } + } + return appRequirements; + } + + + public JSONArray getWorkflowArchitecture() { + JSONArray results = new JSONArray(); + List components = camelModelRoot.getChild("deploymentModels").getChildren("softwareComponents"); + for(Element component: components) { + JSONArray cnx = new JSONArray(); + List requiredCommunications = component.getChildren("requiredCommunications"); + List providedCommunications = component.getChildren("providedCommunications"); + for(Element requiredCommunication: requiredCommunications) { + String connectionName = WfAnalyserXmiElementUtils.findProvidedComponent(components, requiredCommunication.getAttributeValue("portNumber")); + if(!connectionName.isEmpty()) { + cnx.put(connectionName); + } + } + for(Element providedCommunication: providedCommunications) { + String connectionName = WfAnalyserXmiElementUtils.findProvidedComponent(components, providedCommunication.getAttributeValue("portNumber")); + if(!connectionName.isEmpty()) { + cnx.put(connectionName); + } + } + JSONObject compConnections = new JSONObject(); + compConnections.put(component.getAttributeValue("name"), cnx); + results.put(compConnections); + } + return results; + } + + +} diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserXmiElementUtils.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserXmiElementUtils.java new file mode 100644 index 00000000..7e3e2dd2 --- /dev/null +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserXmiElementUtils.java @@ -0,0 +1,43 @@ +package org.activeeon.morphemic.workflow.analyser; + +import org.jdom2.Element; +import org.json.JSONArray; + +import java.util.List; + +public class WfAnalyserXmiElementUtils { + + + public static String findRequiredComponent(List components, String portNumber) { + for(Element component: components) { + if(component.getChildren("providedCommunications").stream().anyMatch(provComm -> provComm.getAttributeValue("portNumber").equals(portNumber))) { + return component.getAttributeValue("name"); + } + } + return ""; + } + + public static String findProvidedComponent(List components, String portNumber) { + for(Element component: components) { + if(component.getChildren("requiredCommunications").stream().anyMatch(provComm -> provComm.getAttributeValue("portNumber").equals(portNumber))) { + return component.getAttributeValue("name"); + } + } + return ""; + } + + public static JSONArray getVariants(Element component) { + JSONArray variants = new JSONArray(); + List attributes = component.getChildren("attributes"); + for(Element element: attributes) { + String value = element.getChild("value").getAttributeValue("value"); + if(value.contains("VM") || value.contains("DOCKER") || value.contains("SERVERLESS") || value.contains("HPC")) { + variants.put(value); + } + } + return variants; + } + + private WfAnalyserXmiElementUtils() {} + +} -- GitLab From ed2b7952a2845ae13d99d3d9e5464a420474c591 Mon Sep 17 00:00:00 2001 From: marounkoussaifi Date: Wed, 20 Jul 2022 10:22:25 +0200 Subject: [PATCH 4/5] Add author section --- .../activeeon/morphemic/workflow/analyser/WfAnalyser.java | 8 ++++++++ .../morphemic/workflow/analyser/WfAnalyserCamelUtils.java | 8 ++++++++ .../workflow/analyser/WfAnalyserXmiElementUtils.java | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java index 8fcb13d1..a77f54eb 100644 --- a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java @@ -1,3 +1,11 @@ +/* + * This class contains the java endpoints that build from a Camel model the component grouping json + * and the dot graph syntax of the application. + * + * Developed by Activeeon in the context of H2020 MORPHEMIC project. + * @author Activeeon R&D Department + */ + package org.activeeon.morphemic.workflow.analyser; import org.jdom2.Document; diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserCamelUtils.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserCamelUtils.java index 2c92cfac..6ae834bb 100644 --- a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserCamelUtils.java +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserCamelUtils.java @@ -1,3 +1,11 @@ +/* + * This class contains the methods that are used by the WfAnalyser endpoints to handle an XMI model and to generate + * the corresponding Json elements. + * + * Developed by Activeeon in the context of H2020 MORPHEMIC project. + * @author Activeeon R&D Department + */ + package org.activeeon.morphemic.workflow.analyser; import lombok.AllArgsConstructor; diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserXmiElementUtils.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserXmiElementUtils.java index 7e3e2dd2..501c5328 100644 --- a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserXmiElementUtils.java +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserXmiElementUtils.java @@ -1,3 +1,11 @@ +/* + * This class contains the methods that are used by the WfAnalyser endpoints to handle XMI elemens + * and to generate the corresponding Json elements. + * + * Developed by Activeeon in the context of H2020 MORPHEMIC project. + * @author Activeeon R&D Department + */ + package org.activeeon.morphemic.workflow.analyser; import org.jdom2.Element; -- GitLab From 4b61529ede435aee8d2159db2209ce36b1a65a09 Mon Sep 17 00:00:00 2001 From: marounkoussaifi Date: Wed, 20 Jul 2022 10:49:29 +0200 Subject: [PATCH 5/5] Fix the authors description --- .../morphemic/workflow/analyser/WfAnalyser.java | 16 ++++++++-------- .../workflow/analyser/WfAnalyserCamelUtils.java | 15 +++++++-------- .../analyser/WfAnalyserXmiElementUtils.java | 15 +++++++-------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java index a77f54eb..322ff401 100644 --- a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyser.java @@ -1,11 +1,3 @@ -/* - * This class contains the java endpoints that build from a Camel model the component grouping json - * and the dot graph syntax of the application. - * - * Developed by Activeeon in the context of H2020 MORPHEMIC project. - * @author Activeeon R&D Department - */ - package org.activeeon.morphemic.workflow.analyser; import org.jdom2.Document; @@ -19,6 +11,14 @@ import java.io.File; import java.io.IOException; import java.util.List; +/* + * This class contains the java endpoints that build from a Camel model the component grouping JSON + * and the dot graph syntax of the application. + * + * Developed by Activeeon in the context of H2020 MORPHEMIC project. + * @author Activeeon R&D Department + */ + public class WfAnalyser { // Environment Variable Name for the camel xmi model path = CAMEL_XMI_DIR, e.g. CAMEL_XMI_DIR = "/users/user1/Documents/camel.xmi" diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserCamelUtils.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserCamelUtils.java index 6ae834bb..cd81ca84 100644 --- a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserCamelUtils.java +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserCamelUtils.java @@ -1,11 +1,3 @@ -/* - * This class contains the methods that are used by the WfAnalyser endpoints to handle an XMI model and to generate - * the corresponding Json elements. - * - * Developed by Activeeon in the context of H2020 MORPHEMIC project. - * @author Activeeon R&D Department - */ - package org.activeeon.morphemic.workflow.analyser; import lombok.AllArgsConstructor; @@ -15,6 +7,13 @@ import org.json.JSONObject; import java.util.List; +/* + * This class contains the methods that handle an XMI model to generate the corresponding JSON objects. + * + * Developed by Activeeon in the context of H2020 MORPHEMIC project. + * @author Activeeon R&D Department + */ + @AllArgsConstructor public class WfAnalyserCamelUtils { diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserXmiElementUtils.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserXmiElementUtils.java index 501c5328..6ca625eb 100644 --- a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserXmiElementUtils.java +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/workflow/analyser/WfAnalyserXmiElementUtils.java @@ -1,11 +1,3 @@ -/* - * This class contains the methods that are used by the WfAnalyser endpoints to handle XMI elemens - * and to generate the corresponding Json elements. - * - * Developed by Activeeon in the context of H2020 MORPHEMIC project. - * @author Activeeon R&D Department - */ - package org.activeeon.morphemic.workflow.analyser; import org.jdom2.Element; @@ -13,6 +5,13 @@ import org.json.JSONArray; import java.util.List; +/* + * This class contains the methods that handle XMI elements to generate the corresponding JSON objects. + * + * Developed by Activeeon in the context of H2020 MORPHEMIC project. + * @author Activeeon R&D Department + */ + public class WfAnalyserXmiElementUtils { -- GitLab