Save Workflow Artifact to SDC. 51/36451/3
authorYuanHu <yuan.hu1@zte.com.cn>
Mon, 19 Mar 2018 08:41:15 +0000 (16:41 +0800)
committerYuanHu <yuan.hu1@zte.com.cn>
Mon, 19 Mar 2018 09:30:28 +0000 (17:30 +0800)
Get SDC Serive Proxy Information from conf file.
Call rest api to save workflow artifact to SDC

Issue-ID: SDC-1004

Change-Id: I620674def79bdfb9fd71aebc96d0774bc7dfddd8
Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
distribution/src/main/assembly/conf/workflow-designer.yml
sdc-workflow-designer-server/pom.xml
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/SDCServiceProxyInfo.java [new file with mode: 0644]
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/WorkflowDesignerApp.java
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/WorkflowDesignerConfiguration.java
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/common/WorkflowDesignerException.java [new file with mode: 0644]
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/config/AppConfig.java
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/SDCService.java [new file with mode: 0644]
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/SDCServiceProxy.java [new file with mode: 0644]
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/entity/WorkflowArtifactInfo.java [new file with mode: 0644]

index 2e8409a..b824207 100644 (file)
@@ -16,6 +16,10 @@ defaultName: ${DW_DEFAULT_NAME:-Stranger}
 
 msbServerAddr: http://127.0.0.1:80
 
+sdcServiceProxy:
+  xEcompInstanceId: workflow
+  authorization: Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU=
+
 # use the simple server factory if you only want to run on a single port
 server:
   type: simple
index 98733c9..b47f845 100644 (file)
@@ -27,6 +27,8 @@
     
     <properties>
         <jackson.version>2.9.1</jackson.version>
+        <gson.version>2.2.4</gson.version>
+        <jaxrs.consumer.version>5.0</jaxrs.consumer.version>
         <velocity.version>1.7</velocity.version>
         <junit.version>4.10</junit.version>
         <dropwizard.version>1.2.4</dropwizard.version>
             <version>${jackson.version}</version>
         </dependency>
         
+        <!-- gson -->
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>${gson.version}</version>
+        </dependency>
+        
+        <!-- consumer -->
+        <dependency>
+            <groupId>com.eclipsesource.jaxrs</groupId>
+            <artifactId>consumer</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.eclipsesource.jaxrs</groupId>
+                    <artifactId>jersey-all</artifactId>
+                </exclusion>
+            </exclusions>
+            <version>${jaxrs.consumer.version}</version>
+        </dependency>
+        
         <dependency>
             <groupId>org.apache.velocity</groupId>
             <artifactId>velocity</artifactId>
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/SDCServiceProxyInfo.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/SDCServiceProxyInfo.java
new file mode 100644 (file)
index 0000000..5d8b8ea
--- /dev/null
@@ -0,0 +1,50 @@
+/**\r
+ * Copyright (c) 2018 ZTE Corporation.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the Apache License, Version 2.0\r
+ * and the Eclipse Public License v1.0 which both accompany this distribution,\r
+ * and are available at http://www.eclipse.org/legal/epl-v10.html\r
+ * and http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Contributors:\r
+ *     ZTE - initial API and implementation and/or initial documentation\r
+ */\r
+package org.onap.sdc.workflowdesigner;\r
+\r
+/**\r
+ *\r
+ */\r
+public class SDCServiceProxyInfo {\r
+  private String xEcompInstanceId;\r
+  \r
+  private String authorization;\r
+\r
+  /**\r
+   * @return the xEcompInstanceId\r
+   */\r
+  public String getxEcompInstanceId() {\r
+    return xEcompInstanceId;\r
+  }\r
+\r
+  /**\r
+   * @param xEcompInstanceId the xEcompInstanceId to set\r
+   */\r
+  public void setxEcompInstanceId(String xEcompInstanceId) {\r
+    this.xEcompInstanceId = xEcompInstanceId;\r
+  }\r
+\r
+  /**\r
+   * @return the authorization\r
+   */\r
+  public String getAuthorization() {\r
+    return authorization;\r
+  }\r
+\r
+  /**\r
+   * @param authorization the authorization to set\r
+   */\r
+  public void setAuthorization(String authorization) {\r
+    this.authorization = authorization;\r
+  }\r
+\r
+}\r
index e2ec271..ba0fcd7 100644 (file)
@@ -30,7 +30,6 @@ import io.swagger.jaxrs.config.BeanConfig;
 import io.swagger.jaxrs.listing.ApiListingResource;
 
 public class WorkflowDesignerApp extends Application<WorkflowDesignerConfiguration> {
-
   private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowDesignerApp.class);
 
   public static void main(String[] args) throws Exception {
@@ -55,6 +54,7 @@ public class WorkflowDesignerApp extends Application<WorkflowDesignerConfigurati
     LOGGER.info("Start to initialize Workflow Designer.");
     
     AppConfig.setMsbServerAddr(configuration.getMsbServerAddr());
+    AppConfig.setSdcServiceProxy(configuration.getSdcServiceProxy());
 
     environment.jersey().register(new WorkflowModelerResource());
     environment.jersey().register(new ExtendActivityResource());
index b4ed3d1..dfdffcf 100644 (file)
@@ -27,6 +27,9 @@ public class WorkflowDesignerConfiguration extends Configuration {
   
   @NotEmpty
   private String msbServerAddr;
+  
+  @NotEmpty
+  private SDCServiceProxyInfo sdcServiceProxy;
 
   @JsonProperty
   public String getTemplate() {
@@ -58,4 +61,20 @@ public class WorkflowDesignerConfiguration extends Configuration {
       this.msbServerAddr = msbServerAddr;
   }
 
+  /**
+   * @return the sdcServiceProxy
+   */
+  @JsonProperty
+  public SDCServiceProxyInfo getSdcServiceProxy() {
+    return sdcServiceProxy;
+  }
+
+  /**
+   * @param sdcServiceProxy the sdcServiceProxy to set
+   */
+  @JsonProperty
+  public void setSdcServiceProxy(SDCServiceProxyInfo sdcServiceProxy) {
+    this.sdcServiceProxy = sdcServiceProxy;
+  }
+
 }
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/common/WorkflowDesignerException.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/common/WorkflowDesignerException.java
new file mode 100644 (file)
index 0000000..343df01
--- /dev/null
@@ -0,0 +1,33 @@
+/**
+ * Copyright 2018 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.sdc.workflowdesigner.common;
+
+public class WorkflowDesignerException extends Exception {
+
+  private static final long serialVersionUID = 1L;
+
+  public WorkflowDesignerException() {
+    super();
+  }
+
+  public WorkflowDesignerException(String msg, Exception e) {
+    super(msg, e);
+  }
+
+  public WorkflowDesignerException(String msg) {
+    super(msg);
+  }
+}
index a3cae9c..f9aa060 100644 (file)
  */
 package org.onap.sdc.workflowdesigner.config;
 
+import org.onap.sdc.workflowdesigner.SDCServiceProxyInfo;
+
 /**
  * 
  */
 public class AppConfig {
   private static String msbServerAddr;
+  private static SDCServiceProxyInfo sdcServiceProxy;
 
   private AppConfig() {}
 
-
   public static String getMsbServerAddr() {
     return msbServerAddr;
   }
@@ -31,4 +33,23 @@ public class AppConfig {
   public static void setMsbServerAddr(String msbServerAddr) {
     AppConfig.msbServerAddr = msbServerAddr;
   }
+
+  public static String getSDCAddr() {
+    return msbServerAddr + "/api/sdc/v1";
+  }
+
+  /**
+   * @param sdcServiceProxy
+   */
+  public static void setSdcServiceProxy(SDCServiceProxyInfo sdcServiceProxy) {
+    AppConfig.sdcServiceProxy = sdcServiceProxy;
+  }
+
+  /**
+   * @return the sdcServiceProxy
+   */
+  public static SDCServiceProxyInfo getSdcServiceProxy() {
+    return sdcServiceProxy;
+  }
+
 }
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/SDCService.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/SDCService.java
new file mode 100644 (file)
index 0000000..d5a5566
--- /dev/null
@@ -0,0 +1,51 @@
+/**
+ * Copyright 2018 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.sdc.workflowdesigner.externalservice.sdc;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.onap.sdc.workflowdesigner.externalservice.sdc.entity.WorkflowArtifactInfo;
+
+@Path("/catalog")
+public interface SDCService {
+  @POST
+  @Path("/resource/{uuid}/interfaces/{operationID}/artifacts/{id}")
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Produces(MediaType.APPLICATION_JSON)
+  public void saveWorkflowArtifact(@PathParam("uuid") String uuid,
+      @PathParam("operationID") String operationId, @PathParam("id") String workflowId,
+      @HeaderParam("X-ECOMP-InstanceID") String xEcompInstanceId,
+      @HeaderParam("Authorization") String authorization,
+      WorkflowArtifactInfo workflowArtifactInfo) throws Exception;
+  
+  
+  @GET
+  @Path("/resource/{uuid}/interfaces/{operationID}/artifacts/{id}")
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Produces(MediaType.APPLICATION_JSON)
+  public WorkflowArtifactInfo getWorkflowArtifact(@PathParam("uuid") String uuid,
+      @PathParam("operationID") String operationId, @PathParam("id") String workflowId,
+      @HeaderParam("X-ECOMP-InstanceID") String xEcompInstanceId,
+      @HeaderParam("Authorization") String authorization) throws Exception;
+
+}
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/SDCServiceProxy.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/SDCServiceProxy.java
new file mode 100644 (file)
index 0000000..c9c0f81
--- /dev/null
@@ -0,0 +1,86 @@
+/**
+ * Copyright 2017-2018 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.sdc.workflowdesigner.externalservice.sdc;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.onap.sdc.workflowdesigner.common.WorkflowDesignerException;
+import org.onap.sdc.workflowdesigner.config.AppConfig;
+import org.onap.sdc.workflowdesigner.externalservice.sdc.entity.WorkflowArtifactInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
+
+/**
+ * 
+ */
+public class SDCServiceProxy {
+  private static final Logger LOGGER = LoggerFactory.getLogger(SDCService.class);
+
+  /**
+   * @return
+   */
+  private SDCService getSDCServiceProxy() {
+    ClientConfig config = new ClientConfig();
+    SDCService sdcServiceProxy =
+        ConsumerFactory.createConsumer(AppConfig.getSDCAddr(), config, SDCService.class);
+    return sdcServiceProxy;
+  }
+
+  /**
+   * 
+   * @param uuid
+   * @param operationId
+   * @param workflowId
+   * @param workflowArtifactInfo
+   * @throws WorkflowDesignerException
+   */
+  public void saveWorkflowArtifact(String uuid, String operationId, String workflowId,
+      WorkflowArtifactInfo workflowArtifactInfo) throws WorkflowDesignerException {
+    SDCService sdcServiceProxy = getSDCServiceProxy();
+    try {
+      sdcServiceProxy.saveWorkflowArtifact(uuid, operationId, workflowId,
+          AppConfig.getSdcServiceProxy().getxEcompInstanceId(),
+          AppConfig.getSdcServiceProxy().getAuthorization(), workflowArtifactInfo);
+    } catch (Exception e) {
+      LOGGER.error("Save WorkflowArtifact Failed.", e);
+      throw new WorkflowDesignerException("Save WorkflowArtifact Failed.", e);
+    }
+  }
+
+  /**
+   * 
+   * @param uuid
+   * @param operationId
+   * @param workflowId
+   * @return
+   * @throws WorkflowDesignerException
+   */
+  public WorkflowArtifactInfo getWorkflowArtifact(String uuid, String operationId,
+      String workflowId) throws WorkflowDesignerException {
+    SDCService sdcServiceProxy = getSDCServiceProxy();
+    try {
+      return sdcServiceProxy.getWorkflowArtifact(uuid, operationId, workflowId,
+          AppConfig.getSdcServiceProxy().getxEcompInstanceId(),
+          AppConfig.getSdcServiceProxy().getAuthorization());
+    } catch (Exception e) {
+      LOGGER.error("Get WorkflowArtifact Failed.", e);
+      throw new WorkflowDesignerException("Save WorkflowArtifact Failed.", e);
+    }
+  }
+
+
+}
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/entity/WorkflowArtifactInfo.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/entity/WorkflowArtifactInfo.java
new file mode 100644 (file)
index 0000000..23c8f86
--- /dev/null
@@ -0,0 +1,110 @@
+/**
+ * Copyright 2018 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.sdc.workflowdesigner.externalservice.sdc.entity;
+
+import java.io.Serializable;
+
+public class WorkflowArtifactInfo implements Serializable {
+  public static final long serialVersionUID = 1L;
+
+  private String artifactName;
+  
+  private String description;
+  
+  private String artifactType = "WORKFLOW";
+  
+  private String payloadData;
+  
+
+  /**
+   * @param artifactName
+   * @param description
+   * @param artifactType
+   * @param payloadData
+   */
+  public WorkflowArtifactInfo(String artifactName, String description, String artifactType,
+      String payloadData) {
+    super();
+    this.artifactName = artifactName;
+    this.description = description;
+    this.artifactType = artifactType;
+    this.payloadData = payloadData;
+  }
+
+  /**
+   * @return the artifactName
+   */
+  public String getArtifactName() {
+    return artifactName;
+  }
+
+  /**
+   * @param artifactName the artifactName to set
+   */
+  public void setArtifactName(String artifactName) {
+    this.artifactName = artifactName;
+  }
+
+  /**
+   * @return the description
+   */
+  public String getDescription() {
+    return description;
+  }
+
+  /**
+   * @param description the description to set
+   */
+  public void setDescription(String description) {
+    this.description = description;
+  }
+
+  /**
+   * @return the artifactType
+   */
+  public String getArtifactType() {
+    return artifactType;
+  }
+
+  /**
+   * @param artifactType the artifactType to set
+   */
+  public void setArtifactType(String artifactType) {
+    this.artifactType = artifactType;
+  }
+
+  /**
+   * @return the payloadData
+   */
+  public String getPayloadData() {
+    return payloadData;
+  }
+
+  /**
+   * @param payloadData the payloadData to set
+   */
+  public void setPayloadData(String payloadData) {
+    this.payloadData = payloadData;
+  }
+
+  /**
+   * @return the serialversionuid
+   */
+  public static long getSerialversionuid() {
+    return serialVersionUID;
+  }
+
+}