This is an automated email from the ASF dual-hosted git repository.

wiener pushed a commit to branch edge-extensions
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git


The following commit(s) were added to refs/heads/edge-extensions by this push:
     new 2733b56  adapt invocation graph of selected node
2733b56 is described below

commit 2733b564ac8eda523fd141282a17fa6b635d6c5f
Author: Patrick Wiener <[email protected]>
AuthorDate: Thu Jul 16 22:16:32 2020 +0200

    adapt invocation graph of selected node
---
 streampipes-connect/pom.xml                        |  4 +-
 .../streampipes/container/util/ConsulUtil.java     | 25 ++++++-
 streampipes-node-controller-container/pom.xml      | 36 ++++++++--
 .../http/InvocableEntityUrlGenerator.java          | 82 ++++++++++++++++------
 .../save-pipeline/save-pipeline.controller.ts      | 35 +++++++--
 5 files changed, 144 insertions(+), 38 deletions(-)

diff --git a/streampipes-connect/pom.xml b/streampipes-connect/pom.xml
index 7ab2256..c716bd3 100755
--- a/streampipes-connect/pom.xml
+++ b/streampipes-connect/pom.xml
@@ -72,12 +72,12 @@
         <dependency>
             <groupId>org.apache.streampipes</groupId>
             <artifactId>streampipes-messaging-jms</artifactId>
-            <version>0.65.1-SNAPSHOT</version>
+            <version>0.67.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.streampipes</groupId>
             <artifactId>streampipes-messaging-mqtt</artifactId>
-            <version>0.65.1-SNAPSHOT</version>
+            <version>0.67.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.streampipes</groupId>
diff --git 
a/streampipes-container/src/main/java/org/apache/streampipes/container/util/ConsulUtil.java
 
b/streampipes-container/src/main/java/org/apache/streampipes/container/util/ConsulUtil.java
index 618444f..ecfc10e 100644
--- 
a/streampipes-container/src/main/java/org/apache/streampipes/container/util/ConsulUtil.java
+++ 
b/streampipes-container/src/main/java/org/apache/streampipes/container/util/ConsulUtil.java
@@ -49,6 +49,7 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 public class ConsulUtil {
 
@@ -169,14 +170,32 @@ public class ConsulUtil {
   }
 
 
-  public static String getPortForService(String route) {
-    String values = ConsulUtil.getKeyValue(route)
+  public static int getElementEndpointPort(String route) {
+    String value = ConsulUtil.getKeyValue(route)
             .values()
             .stream()
             .findFirst()
             .get();
 
-    return new Gson().fromJson(values, ConfigItem.class).getValue();
+//    List<String> list = ConsulUtil.getKeyValue(route)
+//            .entrySet()
+//            .stream()
+//            .map(m -> {
+//              return new Gson().fromJson(m.getValue(), 
ConfigItem.class).getValue();
+//            })
+//            .collect(Collectors.toList());
+
+    return Integer.parseInt(new Gson().fromJson(value, 
ConfigItem.class).getValue());
+  }
+
+  public static String getElementEndpointHostname(String route) {
+    String value = ConsulUtil.getKeyValue(route)
+            .values()
+            .stream()
+            .findFirst()
+            .get();
+
+    return new Gson().fromJson(value, ConfigItem.class).getValue();
   }
 
   public static void updateConfig(String key, String entry, boolean password) {
diff --git a/streampipes-node-controller-container/pom.xml 
b/streampipes-node-controller-container/pom.xml
index 036e1b7..4753dc5 100644
--- a/streampipes-node-controller-container/pom.xml
+++ b/streampipes-node-controller-container/pom.xml
@@ -57,17 +57,43 @@
 
         <!--external dependencies-->
         <!-- parse yaml config -->
-        <dependency>
-            <groupId>org.yaml</groupId>
-            <artifactId>snakeyaml</artifactId>
-            <version>1.21</version>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>org.yaml</groupId>-->
+<!--            <artifactId>snakeyaml</artifactId>-->
+<!--            <version>1.21</version>-->
+<!--        </dependency>-->
         <!-- docker client for java -->
         <dependency>
             <groupId>com.spotify</groupId>
             <artifactId>docker-client</artifactId>
             <classifier>shaded</classifier>
             <version>8.16.0</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.ow2.asm</groupId>
+                    <artifactId>asm-tree</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.ow2.asm</groupId>
+                    <artifactId>asm-util</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.ow2.asm</groupId>
+                    <artifactId>asm-commons</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.ow2.asm</groupId>
+                    <artifactId>asm-analysis</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.fasterxml.jackson.module</groupId>
+                    <artifactId>jackson-module-jaxb-annotations</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.fasterxml.jackson.datatype</groupId>
+                    <artifactId>jackson-datatype-guava</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 <!--        </dependency>-->
         <!-- used for gathering system information-->
diff --git 
a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/execution/http/InvocableEntityUrlGenerator.java
 
b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/execution/http/InvocableEntityUrlGenerator.java
index 8fe3a4b..2e6cff8 100644
--- 
a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/execution/http/InvocableEntityUrlGenerator.java
+++ 
b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/execution/http/InvocableEntityUrlGenerator.java
@@ -34,6 +34,9 @@ public class InvocableEntityUrlGenerator extends 
EndpointUrlGenerator<InvocableS
     private static final String DEFAULT_NODE_ID = "default";
     private static final String COLON = ":";
     private static final String PE_PORT_KEY = "SP_PORT";
+    private static final String PE_HOST_KEY = "SP_HOST";
+
+    private static final String NODE_CONTROLLER_ROUTE = 
"node/container/invoke";
 
     public InvocableEntityUrlGenerator(InvocableStreamPipesEntity 
pipelineElement) {
         super(pipelineElement);
@@ -41,22 +44,22 @@ public class InvocableEntityUrlGenerator extends 
EndpointUrlGenerator<InvocableS
 
     @Override
     public String generateStartPipelineEndpointUrl() {
-        // TODO: normal setup
-        return URLPREFIX
-                + getHost()
-                + SLASH
-                + getIdentifier()
-                + SLASH
-                + pipelineElement.getAppId();
-        // TODO: uncomment for edge tests
+//        // TODO: normal setup
 //        return URLPREFIX
 //                + getHost()
 //                + SLASH
-//                + "node/container/invoke"
-//                + SLASH
 //                + getIdentifier()
 //                + SLASH
 //                + pipelineElement.getAppId();
+        // TODO: uncomment for edge tests
+        return URLPREFIX
+                + getHost()
+                + SLASH
+                + NODE_CONTROLLER_ROUTE
+                + SLASH
+                + getIdentifier()
+                + SLASH
+                + pipelineElement.getAppId();
     }
 
     @Override
@@ -70,11 +73,10 @@ public class InvocableEntityUrlGenerator extends 
EndpointUrlGenerator<InvocableS
         if (pipelineElement.getDeploymentTargetNodeId() == null ||
                 
pipelineElement.getDeploymentTargetNodeId().equals(DEFAULT_NODE_ID)) {
             return defaultHost();
-        } else {
-            Optional<NodeInfo> nodeInfoOpt = getNodeInfo();
-            if (nodeInfoOpt.isPresent()) {
-                NodeInfo nodeInfo = nodeInfoOpt.get();
-                // TODO: get port from Consul
+        }
+        else {
+            if (deploymentTargetNodeRunning()) {
+
                 String route = ConsulSpConfig.SERVICE_ROUTE_PREFIX
                         + pipelineElement.getElementEndpointServiceName()
                         + SLASH
@@ -82,18 +84,47 @@ public class InvocableEntityUrlGenerator extends 
EndpointUrlGenerator<InvocableS
                         + SLASH
                         + ConsulSpConfig.SECONDARY_NODE_KEY
                         + SLASH
-                        + nodeInfo.getNodeControllerId()
-                        + SLASH
-                        + PE_PORT_KEY;
+                        + pipelineElement.getDeploymentTargetNodeId()
+                        + SLASH;
+
+                // Needed because secondary PE uses information from primary
+                
pipelineElement.setElementEndpointPort(ConsulUtil.getElementEndpointPort(route 
+ PE_PORT_KEY));
+                
pipelineElement.setElementEndpointHostname(ConsulUtil.getElementEndpointHostname(route
 + PE_HOST_KEY));
+                // TODO: adapt elementId + belongsTo
 
-                return nodeInfo.getNodeMetadata().getNodeAddress()
+                return pipelineElement.getDeploymentTargetNodeHostname()
                         + COLON
-                        + nodeInfo.getNodeControllerPort();
-                        //+ ConsulUtil.getPortForService(route);
-            } else {
+                        + pipelineElement.getDeploymentTargetNodePort();
+            }
+            else {
                 return defaultHost();
             }
         }
+//        else {
+//            Optional<NodeInfo> nodeInfoOpt = getNodeInfo();
+//            if (nodeInfoOpt.isPresent()) {
+//                NodeInfo nodeInfo = nodeInfoOpt.get();
+//                // TODO: get port from Consul
+//                String route = ConsulSpConfig.SERVICE_ROUTE_PREFIX
+//                        + pipelineElement.getElementEndpointServiceName()
+//                        + SLASH
+//                        + ConsulSpConfig.BASE_PREFIX
+//                        + SLASH
+//                        + ConsulSpConfig.SECONDARY_NODE_KEY
+//                        + SLASH
+//                        + nodeInfo.getNodeControllerId()
+//                        + SLASH
+//                        + PE_PORT_KEY;
+//
+//                return nodeInfo.getNodeMetadata().getNodeAddress()
+//                        + COLON
+//                        + nodeInfo.getNodeControllerPort();
+//                        //+ ConsulUtil.getPortForService(route);
+//            }
+//            else {
+//                return defaultHost();
+//            }
+//        }
     }
 
     private String defaultHost() {
@@ -114,4 +145,11 @@ public class InvocableEntityUrlGenerator extends 
EndpointUrlGenerator<InvocableS
                 .findFirst();
     }
 
+    private boolean deploymentTargetNodeRunning() {
+        return new AvailableNodesFetcher()
+                .fetchNodes()
+                .stream()
+                .anyMatch(node -> 
node.getNodeControllerId().equals(pipelineElement.getDeploymentTargetNodeId()));
+    }
+
 }
diff --git a/ui/src/app/editor/dialog/save-pipeline/save-pipeline.controller.ts 
b/ui/src/app/editor/dialog/save-pipeline/save-pipeline.controller.ts
index 839d3d0..2054f78 100644
--- a/ui/src/app/editor/dialog/save-pipeline/save-pipeline.controller.ts
+++ b/ui/src/app/editor/dialog/save-pipeline/save-pipeline.controller.ts
@@ -36,6 +36,7 @@ export class SavePipelineController {
     submitPipelineForm: any;
     TransitionService: any;
     ShepherdService: any;
+    edgeNodes: NodeInfo[]
 
     advancedSettings: boolean = false;
 
@@ -74,9 +75,10 @@ export class SavePipelineController {
 
     loadAndPrepareEdgeNodes() {
         this.RestApi.getAvailableEdgeNodes().then(response => {
-           let edgeNodes = response.data as NodeInfo[];
-           this.addAppIds(this.pipeline.sepas, edgeNodes);
-           this.addAppIds(this.pipeline.actions, edgeNodes);
+           //let edgeNodes = response.data as NodeInfo[];
+            this.edgeNodes = response.data;
+           this.addAppIds(this.pipeline.sepas, this.edgeNodes);
+           this.addAppIds(this.pipeline.actions, this.edgeNodes);
         });
     }
 
@@ -127,6 +129,26 @@ export class SavePipelineController {
 
     };
 
+    modifyPipelineElementsDeployments(pipelineElements) {
+        pipelineElements.forEach(p => {
+            let selectedTargetNodeId = p.deploymentTargetNodeId
+            if(selectedTargetNodeId != "default") {
+                let selectedNode = this.edgeNodes
+                    .filter(node => node.nodeControllerId === 
selectedTargetNodeId)
+
+                p.deploymentTargetNodeHostname = selectedNode
+                    .map(node => node.nodeMetadata.nodeAddress)[0]
+
+                p.deploymentTargetNodePort = selectedNode
+                    .map(node => node.nodeControllerPort)[0]
+            }
+            else {
+                p.deploymentTargetNodeHostname = null
+                p.deploymentTargetNodePort = null
+            }
+        })
+    }
+
 
     savePipelineName(switchTab) {
         if (this.pipeline.name == "") {
@@ -135,13 +157,14 @@ export class SavePipelineController {
         }
 
         let storageRequest;
-        this.pipeline.sepas;
-
-        console.log(this.pipeline);
 
         if (this.modificationMode && this.updateMode === 'update') {
+            this.modifyPipelineElementsDeployments(this.pipeline.sepas)
+            this.modifyPipelineElementsDeployments(this.pipeline.actions)
             storageRequest = this.RestApi.updatePipeline(this.pipeline);
         } else {
+            this.modifyPipelineElementsDeployments(this.pipeline.sepas)
+            this.modifyPipelineElementsDeployments(this.pipeline.actions)
             storageRequest = this.RestApi.storePipeline(this.pipeline);
         }
 

Reply via email to