instantiate and terminate servce 91/14891/1
authorLuji7 <lu.ji3@zte.com.cn>
Sun, 24 Sep 2017 17:31:18 +0000 (01:31 +0800)
committerLuji7 <lu.ji3@zte.com.cn>
Sun, 24 Sep 2017 17:31:29 +0000 (01:31 +0800)
Change-Id: Id41c300d6750170e62ce211dab434d1e862c9c05
Issue-Id: USECASEUI-36
Signed-off-by: Luji7 <lu.ji3@zte.com.cn>
22 files changed:
pom.xml
src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInput.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInputRsp.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/bean/lcm/TemplateInput.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/bean/lcm/VfNsPackageInfo.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionController.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmController.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceTemplateController.java
src/main/java/org/onap/usecaseui/server/service/lcm/PackageDistributionService.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/service/lcm/ServiceLcmService.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/service/lcm/ServiceTemplateService.java
src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/AAIService.java
src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/bean/VimInfo.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/SDCCatalogService.java
src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/SOService.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/bean/OperationProgressInformation.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/bean/ServiceInstantiationRequest.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/bean/ServiceOperation.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/exceptions/SOException.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionService.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java [new file with mode: 0644]
src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateService.java

diff --git a/pom.xml b/pom.xml
index 341cc60..32866ac 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <artifactId>converter-jackson</artifactId>
             <version>2.3.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.openecomp.sdc.jtosca</groupId>
+            <artifactId>jtosca</artifactId>
+            <version>1.1.3-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>23.0</version>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInput.java b/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInput.java
new file mode 100644 (file)
index 0000000..c847f57
--- /dev/null
@@ -0,0 +1,45 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.bean.lcm;
+
+import java.util.List;
+
+public class ServiceTemplateInput {
+
+    private String name;
+
+    private String type;
+
+    private List<TemplateInput> inputs;
+
+    public ServiceTemplateInput(String name, String type, List<TemplateInput> inputs) {
+        this.name = name;
+        this.type = type;
+        this.inputs = inputs;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public List<TemplateInput> getInputs() {
+        return inputs;
+    }
+}
diff --git a/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInputRsp.java b/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInputRsp.java
new file mode 100644 (file)
index 0000000..f422873
--- /dev/null
@@ -0,0 +1,40 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.bean.lcm;
+
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo;
+
+import java.util.List;
+
+public class ServiceTemplateInputRsp {
+
+    private ServiceTemplateInput serviceTemplateInput;
+
+    private List<VimInfo> vimInfos;
+
+    public ServiceTemplateInputRsp(ServiceTemplateInput serviceTemplateInput, List<VimInfo> vimInfos) {
+        this.serviceTemplateInput = serviceTemplateInput;
+        this.vimInfos = vimInfos;
+    }
+
+    public ServiceTemplateInput getServiceTemplateInput() {
+        return serviceTemplateInput;
+    }
+
+    public List<VimInfo> getVimInfos() {
+        return vimInfos;
+    }
+}
diff --git a/src/main/java/org/onap/usecaseui/server/bean/lcm/TemplateInput.java b/src/main/java/org/onap/usecaseui/server/bean/lcm/TemplateInput.java
new file mode 100644 (file)
index 0000000..6367d58
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.bean.lcm;
+
+public class TemplateInput {
+
+    private String name;
+
+    private String type;
+
+    private String description;
+
+    private String isRequired;
+
+    private String defaultValue;
+
+    public TemplateInput(String name, String type, String description, String isRequired, String defaultValue) {
+        this.name = name;
+        this.type = type;
+        this.description = description;
+        this.isRequired = isRequired;
+        this.defaultValue = defaultValue;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public String getIsRequired() {
+        return isRequired;
+    }
+
+    public String getDefaultValue() {
+        return defaultValue;
+    }
+}
diff --git a/src/main/java/org/onap/usecaseui/server/bean/lcm/VfNsPackageInfo.java b/src/main/java/org/onap/usecaseui/server/bean/lcm/VfNsPackageInfo.java
new file mode 100644 (file)
index 0000000..d51ec4b
--- /dev/null
@@ -0,0 +1,49 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.bean.lcm;
+
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo;
+import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
+import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
+
+import java.util.List;
+
+public class VfNsPackageInfo {
+
+    private List<SDCServiceTemplate> nsPackage;
+
+    private List<Vnf> vnfPackages;
+
+    private List<VimInfo> vimInfos;
+
+    public VfNsPackageInfo(List<SDCServiceTemplate> nsPackage, List<Vnf> vnfPackages, List<VimInfo> vimInfos) {
+        this.nsPackage = nsPackage;
+        this.vnfPackages = vnfPackages;
+        this.vimInfos = vimInfos;
+    }
+
+    public List<SDCServiceTemplate> getNsPackage() {
+        return nsPackage;
+    }
+
+    public List<Vnf> getVnfPackages() {
+        return vnfPackages;
+    }
+
+    public List<VimInfo> getVimInfos() {
+        return vimInfos;
+    }
+}
diff --git a/src/main/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionController.java b/src/main/java/org/onap/usecaseui/server/controller/lcm/PackageDistributionController.java
new file mode 100644 (file)
index 0000000..05364b2
--- /dev/null
@@ -0,0 +1,45 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.controller.lcm;
+
+import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
+import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.annotation.Resource;
+
+@Controller
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+public class PackageDistributionController {
+
+    private static final Logger logger = LoggerFactory.getLogger(PackageDistributionController.class);
+
+    @Resource(name="PackageDistributionService")
+    private PackageDistributionService packageDistributionService;
+
+    @ResponseBody
+    @RequestMapping(value = {"/lcm/vf-ns-packages"}, method = RequestMethod.GET , produces = "application/json")
+    public VfNsPackageInfo instantiateService(){
+        return packageDistributionService.retrievePackageInfo();
+    }
+}
diff --git a/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmController.java b/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmController.java
new file mode 100644 (file)
index 0000000..d0c9552
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.controller.lcm;
+
+import org.onap.usecaseui.server.service.lcm.ServiceLcmService;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.OperationProgressInformation;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceInstantiationRequest;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+@Controller
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+public class ServiceLcmController {
+
+    private static final Logger logger = LoggerFactory.getLogger(ServiceLcmController.class);
+
+    @Resource(name="ServiceLcmService")
+    private ServiceLcmService serviceLcmService;
+
+    @ResponseBody
+    @RequestMapping(value = {"/lcm/services"}, method = RequestMethod.POST , produces = "application/json")
+    public ServiceOperation instantiateService(@RequestBody ServiceInstantiationRequest request){
+        return serviceLcmService.instantiateService(request);
+    }
+
+    @ResponseBody
+    @RequestMapping(value = {"/lcm/services/{serviceId}/operations/{operationId}"}, method = RequestMethod.GET , produces = "application/json")
+    public OperationProgressInformation instantiateService(@PathVariable(value="serviceId") String serviceId, @PathVariable(value="operationId") String operationId){
+        return serviceLcmService.queryOperationProgress(serviceId, operationId);
+    }
+
+    @ResponseBody
+    @RequestMapping(value = {"/lcm/services/{serviceId}"}, method = RequestMethod.DELETE , produces = "application/json")
+    public ServiceOperation terminateService(@PathVariable(value = "serviceId") String serviceId){
+        return serviceLcmService.terminateService(serviceId);
+    }
+}
index 53f77ee..2d8333a 100644 (file)
  */
 package org.onap.usecaseui.server.controller.lcm;
 
-import org.onap.usecaseui.server.bean.lcm.ServiceTemplate;
+import org.onap.usecaseui.server.bean.lcm.ServiceTemplateInputRsp;
 import org.onap.usecaseui.server.service.lcm.ServiceTemplateService;
+import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
 import java.util.List;
 
 @Controller
@@ -41,9 +39,13 @@ public class ServiceTemplateController {
 
     @ResponseBody
     @RequestMapping(value = {"/lcm/service-templates"}, method = RequestMethod.GET , produces = "application/json")
-    public List<ServiceTemplate> getServiceTemplates(HttpServletRequest request){
+    public List<SDCServiceTemplate> getServiceTemplates(){
         return serviceTemplateService.listDistributedServiceTemplate();
     }
 
-
+    @ResponseBody
+    @RequestMapping(value = {"/lcm/service-templates/service-template/{uuid}"}, method = RequestMethod.GET , produces = "application/json")
+    public ServiceTemplateInputRsp getServiceTemplateInput(@PathVariable("uuid") String uuid, @RequestParam("toscaModelPath") String toscaModelPath){
+        return serviceTemplateService.fetchServiceTemplateInput(uuid, toscaModelPath);
+    }
 }
diff --git a/src/main/java/org/onap/usecaseui/server/service/lcm/PackageDistributionService.java b/src/main/java/org/onap/usecaseui/server/service/lcm/PackageDistributionService.java
new file mode 100644 (file)
index 0000000..867df4d
--- /dev/null
@@ -0,0 +1,23 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.service.lcm;
+
+import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
+
+public interface PackageDistributionService {
+
+    VfNsPackageInfo retrievePackageInfo();
+}
diff --git a/src/main/java/org/onap/usecaseui/server/service/lcm/ServiceLcmService.java b/src/main/java/org/onap/usecaseui/server/service/lcm/ServiceLcmService.java
new file mode 100644 (file)
index 0000000..fc893f3
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.service.lcm;
+
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.OperationProgressInformation;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceInstantiationRequest;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceOperation;
+
+public interface ServiceLcmService {
+
+    ServiceOperation instantiateService(ServiceInstantiationRequest request);
+
+    OperationProgressInformation queryOperationProgress(String serviceId, String operationId);
+
+    ServiceOperation terminateService(String serviceId);
+}
index ea2d818..22479e6 100644 (file)
  */
 package org.onap.usecaseui.server.service.lcm;
 
-import org.onap.usecaseui.server.bean.lcm.ServiceTemplate;
+import org.onap.usecaseui.server.bean.lcm.ServiceTemplateInputRsp;
+import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
 
 import java.util.List;
 
 public interface ServiceTemplateService {
 
-    List<ServiceTemplate> listDistributedServiceTemplate();
-}
+    List<SDCServiceTemplate> listDistributedServiceTemplate();
+
+    ServiceTemplateInputRsp fetchServiceTemplateInput(String uuid, String toscaModelPath);
+}
\ No newline at end of file
index b4683b2..fc83f4f 100644 (file)
@@ -17,6 +17,7 @@ package org.onap.usecaseui.server.service.lcm.domain.aai;
 
 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAICustomer;
 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceInstance;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo;
 import retrofit2.Call;
 import retrofit2.http.GET;
 import retrofit2.http.Headers;
@@ -41,4 +42,12 @@ public interface AAIService {
     })
     @GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances")
     Call<List<ServiceInstance>> listServiceInstances(@Path("global-customer-id") String customerId, @Path("service-type") String serviceType);
+
+    @Headers({
+            "X-TransactionId: 7777",
+            "X-FromAppId: uui",
+            "Authorization: QUFJOkFBSQ=="
+    })
+    @GET("/cloud-infrastructure/cloud-regions")
+    Call<List<VimInfo>> listVimInfo();
 }
diff --git a/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/bean/VimInfo.java b/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/bean/VimInfo.java
new file mode 100644 (file)
index 0000000..73a9873
--- /dev/null
@@ -0,0 +1,44 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.service.lcm.domain.aai.bean;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class VimInfo {
+
+    private String cloudOwner;
+
+    private String cloudRegionId;
+
+    @JsonCreator
+    public VimInfo(
+            @JsonProperty("cloud-owner") String cloudOwner,
+            @JsonProperty("cloud-region-id") String cloudRegionId) {
+        this.cloudOwner = cloudOwner;
+        this.cloudRegionId = cloudRegionId;
+    }
+
+    @JsonProperty("cloud-owner")
+    public String getCloudOwner() {
+        return cloudOwner;
+    }
+
+    @JsonProperty("cloud-region-id")
+    public String getCloudRegionId() {
+        return cloudRegionId;
+    }
+}
index f6abba0..46d5389 100644 (file)
@@ -20,6 +20,7 @@ import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
 import retrofit2.Call;
 import retrofit2.http.GET;
+import retrofit2.http.Headers;
 import retrofit2.http.Query;
 import retrofit2.http.Url;
 
@@ -30,9 +31,13 @@ public interface SDCCatalogService {
     @GET("sdc/v1/catalog/services")
     Call<List<SDCServiceTemplate>> listServices(@Query("category")String category, @Query("distributionStatus") String distributionStatus);
 
+    @Headers({
+            "X-ECOMP-InstanceID: 777",
+            "Authorization: what?"
+    })
     @GET
     Call<ResponseBody> downloadCsar(@Url String fileUrl);
 
     @GET("sdc/v1/catalog/resources")
     Call<List<Vnf>> listResources(@Query("resourceType") String resourceType, @Query("distributionStatus") String distributionStatus);
-}
+}
\ No newline at end of file
diff --git a/src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/SOService.java b/src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/SOService.java
new file mode 100644 (file)
index 0000000..4d8fac9
--- /dev/null
@@ -0,0 +1,37 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.service.lcm.domain.so;
+
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.OperationProgressInformation;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceInstantiationRequest;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceOperation;
+import retrofit2.Call;
+import retrofit2.http.DELETE;
+import retrofit2.http.GET;
+import retrofit2.http.POST;
+import retrofit2.http.Path;
+
+public interface SOService {
+
+    @POST("/so/e2eServiceInstances/v2")
+    Call<ServiceOperation> instantiateService(ServiceInstantiationRequest request);
+
+    @GET("/so/e2eServiceInstances/v2/{serviceId}/operations/{operationId}")
+    Call<OperationProgressInformation> queryOperationProgress(@Path("serviceId") String serviceId, @Path("operationId") String operationId);
+
+    @DELETE("/so/e2eServiceInstances/v2/{serviceId}")
+    Call<ServiceOperation> terminateService(@Path("serviceId") String serviceId);
+}
diff --git a/src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/bean/OperationProgressInformation.java b/src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/bean/OperationProgressInformation.java
new file mode 100644 (file)
index 0000000..3c70452
--- /dev/null
@@ -0,0 +1,19 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.service.lcm.domain.so.bean;
+
+public class OperationProgressInformation {
+}
diff --git a/src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/bean/ServiceInstantiationRequest.java b/src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/bean/ServiceInstantiationRequest.java
new file mode 100644 (file)
index 0000000..9898409
--- /dev/null
@@ -0,0 +1,59 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.service.lcm.domain.so.bean;
+
+import java.util.Map;
+
+public class ServiceInstantiationRequest {
+
+    private String name;
+
+    private String description;
+
+    private String serviceDefId;
+
+    private String templateId;
+
+    private Map<String, String> parameters;
+
+    public ServiceInstantiationRequest(String name, String description, String serviceDefId, String templateId, Map<String, String> parameters) {
+        this.name = name;
+        this.description = description;
+        this.serviceDefId = serviceDefId;
+        this.templateId = templateId;
+        this.parameters = parameters;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public String getServiceDefId() {
+        return serviceDefId;
+    }
+
+    public String getTemplateId() {
+        return templateId;
+    }
+
+    public Map<String, String> getParameters() {
+        return parameters;
+    }
+}
diff --git a/src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/bean/ServiceOperation.java b/src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/bean/ServiceOperation.java
new file mode 100644 (file)
index 0000000..8a64287
--- /dev/null
@@ -0,0 +1,36 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.service.lcm.domain.so.bean;
+
+public class ServiceOperation {
+
+    private String serviceId;
+
+    private String operationId;
+
+    public ServiceOperation(String serviceId, String operationId) {
+        this.serviceId = serviceId;
+        this.operationId = operationId;
+    }
+
+    public String getServiceId() {
+        return serviceId;
+    }
+
+    public String getOperationId() {
+        return operationId;
+    }
+}
diff --git a/src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/exceptions/SOException.java b/src/main/java/org/onap/usecaseui/server/service/lcm/domain/so/exceptions/SOException.java
new file mode 100644 (file)
index 0000000..409fd0e
--- /dev/null
@@ -0,0 +1,23 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.service.lcm.domain.so.exceptions;
+
+public class SOException extends RuntimeException {
+
+    public SOException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}
diff --git a/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionService.java b/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionService.java
new file mode 100644 (file)
index 0000000..477e457
--- /dev/null
@@ -0,0 +1,64 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.service.lcm.impl;
+
+import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
+import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
+import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo;
+import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
+import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
+import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
+import org.onap.usecaseui.server.service.lcm.domain.sdc.exceptions.SDCCatalogException;
+import org.onap.usecaseui.server.util.RestfulServices;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.List;
+
+import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.*;
+
+@Service("PackageDistributionService")
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+public class DefaultPackageDistributionService implements PackageDistributionService {
+
+    private SDCCatalogService sdcCatalogService;
+
+    private AAIService aaiService;
+
+    public DefaultPackageDistributionService() {
+        this(RestfulServices.create(SDCCatalogService.class), RestfulServices.create(AAIService.class));
+    }
+
+    public DefaultPackageDistributionService(SDCCatalogService sdcCatalogService, AAIService aaiService) {
+        this.sdcCatalogService = sdcCatalogService;
+        this.aaiService = aaiService;
+    }
+
+    @Override
+    public VfNsPackageInfo retrievePackageInfo() {
+        try {
+            List<SDCServiceTemplate> nsTemplate = sdcCatalogService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED).execute().body();
+            List<Vnf> vnfs = sdcCatalogService.listResources(RESOURCETYPE_VF, DISTRIBUTION_STATUS_DISTRIBUTED).execute().body();
+            List<VimInfo> vim = aaiService.listVimInfo().execute().body();
+            return new VfNsPackageInfo(nsTemplate, vnfs, vim);
+        } catch (IOException e) {
+            throw new SDCCatalogException("SDC Service is not available!", e);
+        }
+    }
+}
diff --git a/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java b/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java
new file mode 100644 (file)
index 0000000..7bb3777
--- /dev/null
@@ -0,0 +1,71 @@
+/**
+ * Copyright 2016-2017 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.usecaseui.server.service.lcm.impl;
+
+import org.onap.usecaseui.server.service.lcm.ServiceLcmService;
+import org.onap.usecaseui.server.service.lcm.domain.so.SOService;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.OperationProgressInformation;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceInstantiationRequest;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceOperation;
+import org.onap.usecaseui.server.service.lcm.domain.so.exceptions.SOException;
+import org.onap.usecaseui.server.util.RestfulServices;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+
+@Service("ServiceLcmService")
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+public class DefaultServiceLcmService implements ServiceLcmService {
+
+    private SOService soService;
+
+    public DefaultServiceLcmService() {
+        this(RestfulServices.create(SOService.class));
+    }
+
+    public DefaultServiceLcmService(SOService soService) {
+        this.soService = soService;
+    }
+
+    @Override
+    public ServiceOperation instantiateService(ServiceInstantiationRequest request) {
+        try {
+            return soService.instantiateService(request).execute().body();
+        } catch (IOException e) {
+            throw new SOException("SO Service is not available!", e);
+        }
+    }
+
+    @Override
+    public OperationProgressInformation queryOperationProgress(String serviceId, String operationId) {
+        try {
+            return soService.queryOperationProgress(serviceId, operationId).execute().body();
+        } catch (IOException e) {
+            throw new SOException("SO Service is not available!", e);
+        }
+    }
+
+    @Override
+    public ServiceOperation terminateService(String serviceId) {
+        try {
+            return soService.terminateService(serviceId).execute().body();
+        } catch (IOException e) {
+            throw new SOException("SO Service is not available!", e);
+        }
+    }
+}
index a5d90ed..9a0204a 100644 (file)
  */
 package org.onap.usecaseui.server.service.lcm.impl;
 
-import org.onap.usecaseui.server.bean.lcm.ServiceTemplate;
+import com.google.common.io.Files;
+import okhttp3.ResponseBody;
+import org.onap.usecaseui.server.bean.lcm.ServiceTemplateInput;
+import org.onap.usecaseui.server.bean.lcm.ServiceTemplateInputRsp;
+import org.onap.usecaseui.server.bean.lcm.TemplateInput;
 import org.onap.usecaseui.server.service.lcm.ServiceTemplateService;
+import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo;
 import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
 import org.onap.usecaseui.server.service.lcm.domain.sdc.exceptions.SDCCatalogException;
 import org.onap.usecaseui.server.util.RestfulServices;
+import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
+import org.openecomp.sdc.toscaparser.api.common.JToscaException;
+import org.openecomp.sdc.toscaparser.api.parameters.Input;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.stereotype.Service;
 
-import javax.transaction.Transactional;
+import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.CATEGORY_E2E_SERVICE;
 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.DISTRIBUTION_STATUS_DISTRIBUTED;
 
 @Service("ServiceTemplateService")
-@Transactional
 @org.springframework.context.annotation.Configuration
 @EnableAspectJAutoProxy
 public class DefaultServiceTemplateService implements ServiceTemplateService {
@@ -43,19 +52,21 @@ public class DefaultServiceTemplateService implements ServiceTemplateService {
 
     private SDCCatalogService sdcCatalog;
 
+    private AAIService aaiService;
+
     public DefaultServiceTemplateService() {
-        this(RestfulServices.create(SDCCatalogService.class));
+        this(RestfulServices.create(SDCCatalogService.class), RestfulServices.create(AAIService.class));
     }
 
-    public DefaultServiceTemplateService(SDCCatalogService sdcCatalog) {
+    public DefaultServiceTemplateService(SDCCatalogService sdcCatalog, AAIService aaiService) {
         this.sdcCatalog = sdcCatalog;
+        this.aaiService = aaiService;
     }
 
     @Override
-    public List<ServiceTemplate> listDistributedServiceTemplate() {
+    public List<SDCServiceTemplate> listDistributedServiceTemplate() {
         try {
-            List<SDCServiceTemplate> serviceTemplate = this.sdcCatalog.listServices(CATEGORY_E2E_SERVICE, DISTRIBUTION_STATUS_DISTRIBUTED).execute().body();
-            return translate(serviceTemplate);
+            return this.sdcCatalog.listServices(CATEGORY_E2E_SERVICE, DISTRIBUTION_STATUS_DISTRIBUTED).execute().body();
         } catch (IOException e) {
             logger.error("Visit SDC Catalog occur exception");
             logger.info("SDC Catalog Exception: ", e);
@@ -63,7 +74,49 @@ public class DefaultServiceTemplateService implements ServiceTemplateService {
         }
     }
 
-    private List<ServiceTemplate> translate(List<SDCServiceTemplate> serviceTemplate) {
-        return null;
+    @Override
+    public ServiceTemplateInputRsp fetchServiceTemplateInput(String uuid, String toscaModelPath) {
+        String rootPath = "http://localhost";// get from msb
+        String templateUrl = String.format("%s/%s", rootPath, toscaModelPath);
+
+        String toPath = String.format("temp/%s.csar", uuid);
+        try {
+            downloadFile(templateUrl, toPath);
+            ServiceTemplateInput serviceTemplateInput = extractInputs(toPath);
+            List<VimInfo> vimInfos = aaiService.listVimInfo().execute().body();
+            return new ServiceTemplateInputRsp(serviceTemplateInput, vimInfos);
+        }  catch (IOException e) {
+            throw new SDCCatalogException("download csar file failed!", e);
+        } catch (JToscaException e) {
+            throw new SDCCatalogException("parse csar file failed!", e);
+        }
+    }
+
+    private void downloadFile(String templateUrl, String toPath) throws IOException {
+        try {
+            ResponseBody body = sdcCatalog.downloadCsar(templateUrl).execute().body();
+            Files.write(body.bytes(),new File(toPath));
+        } catch (IOException e) {
+            logger.error(String.format("Download %s failed!", templateUrl));
+            throw e;
+        }
+    }
+
+    private ServiceTemplateInput extractInputs(String toPath) throws JToscaException {
+        ToscaTemplate tosca = new ToscaTemplate(toPath,null,true,null,true);
+        String name = tosca.getMetaData().getValue("name");
+        String type = tosca.getMetaData().getValue("type");
+        List<TemplateInput> templateInputs = new ArrayList<>();
+        for(Input input : tosca.getInputs()) {
+            templateInputs.add(new TemplateInput(
+                    input.getName(),
+                    input.getType(),
+                    input.getDescription(),
+                    String.valueOf(input.isRequired()),
+                    String.valueOf(input.getDefault())
+            ));
+
+        }
+        return new ServiceTemplateInput(name, type, templateInputs);
     }
 }