Fix parse csar wrong. 41/15041/1
authorLuji7 <lu.ji3@zte.com.cn>
Mon, 25 Sep 2017 11:57:34 +0000 (19:57 +0800)
committerLuji7 <lu.ji3@zte.com.cn>
Mon, 25 Sep 2017 11:57:40 +0000 (19:57 +0800)
Change-Id: I30281550a7531ce07fd07cb8d4dd3c60692481eb
Issue-Id: USECASEUI-36
Signed-off-by: Luji7 <lu.ji3@zte.com.cn>
server/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInput.java
server/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInputRsp.java
server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/SDCCatalogService.java
server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/SDCServiceTemplate.java
server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateService.java

index c847f57..9207f9a 100644 (file)
@@ -19,18 +19,49 @@ import java.util.List;
 
 public class ServiceTemplateInput {
 
+    private String invariantUUID;
+
+    private String uuid;
+
     private String name;
 
     private String type;
 
+    private String description;
+
+    private String category;
+
+    private String subcategory;
+
     private List<TemplateInput> inputs;
 
-    public ServiceTemplateInput(String name, String type, List<TemplateInput> inputs) {
+    public ServiceTemplateInput(
+            String invariantUUID,
+            String uuid,
+            String name,
+            String type,
+            String description,
+            String category,
+            String subcategory,
+            List<TemplateInput> inputs) {
+        this.invariantUUID = invariantUUID;
+        this.uuid = uuid;
         this.name = name;
         this.type = type;
+        this.description = description;
+        this.category = category;
+        this.subcategory = subcategory;
         this.inputs = inputs;
     }
 
+    public String getInvariantUUID() {
+        return invariantUUID;
+    }
+
+    public String getUuid() {
+        return uuid;
+    }
+
     public String getName() {
         return name;
     }
@@ -39,6 +70,18 @@ public class ServiceTemplateInput {
         return type;
     }
 
+    public String getDescription() {
+        return description;
+    }
+
+    public String getCategory() {
+        return category;
+    }
+
+    public String getSubcategory() {
+        return subcategory;
+    }
+
     public List<TemplateInput> getInputs() {
         return inputs;
     }
index f422873..403b991 100644 (file)
@@ -21,16 +21,16 @@ import java.util.List;
 
 public class ServiceTemplateInputRsp {
 
-    private ServiceTemplateInput serviceTemplateInput;
+    private List<ServiceTemplateInput> serviceTemplateInput;
 
     private List<VimInfo> vimInfos;
 
-    public ServiceTemplateInputRsp(ServiceTemplateInput serviceTemplateInput, List<VimInfo> vimInfos) {
+    public ServiceTemplateInputRsp(List<ServiceTemplateInput> serviceTemplateInput, List<VimInfo> vimInfos) {
         this.serviceTemplateInput = serviceTemplateInput;
         this.vimInfos = vimInfos;
     }
 
-    public ServiceTemplateInput getServiceTemplateInput() {
+    public List<ServiceTemplateInput> getServiceTemplateInput() {
         return serviceTemplateInput;
     }
 
index 46d5389..690edad 100644 (file)
@@ -19,25 +19,37 @@ import okhttp3.ResponseBody;
 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;
+import retrofit2.http.*;
 
 import java.util.List;
 
 public interface SDCCatalogService {
 
+    @Headers({
+            "X-ECOMP-InstanceID: 777",
+            "authorization :  Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU="
+    })
     @GET("sdc/v1/catalog/services")
     Call<List<SDCServiceTemplate>> listServices(@Query("category")String category, @Query("distributionStatus") String distributionStatus);
 
     @Headers({
             "X-ECOMP-InstanceID: 777",
-            "Authorization: what?"
+            "authorization :  Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU="
+    })
+    @GET("sdc/v1/catalog/services/{uuid}/metadata")
+    Call<SDCServiceTemplate> getService(@Path("uuid") String uuid);
+
+    @Headers({
+            "X-ECOMP-InstanceID: 777",
+            "authorization :  Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU="
     })
     @GET
     Call<ResponseBody> downloadCsar(@Url String fileUrl);
 
+    @Headers({
+            "X-ECOMP-InstanceID: 777",
+            "authorization :  Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU="
+    })
     @GET("sdc/v1/catalog/resources")
     Call<List<Vnf>> listResources(@Query("resourceType") String resourceType, @Query("distributionStatus") String distributionStatus);
 }
\ No newline at end of file
index 48da58a..38afd55 100644 (file)
@@ -17,5 +17,41 @@ package org.onap.usecaseui.server.service.lcm.domain.sdc.bean;
 
 public class SDCServiceTemplate {
 
+    private String uuid;
 
+    private String invariantUUID;
+
+    private String name;
+
+    private String toscaModelURL;
+
+    private String category;
+
+    public SDCServiceTemplate(String uuid, String invariantUUID, String name, String toscaModelURL, String category) {
+        this.uuid = uuid;
+        this.invariantUUID = invariantUUID;
+        this.name = name;
+        this.toscaModelURL = toscaModelURL;
+        this.category = category;
+    }
+
+    public String getUuid() {
+        return uuid;
+    }
+
+    public String getInvariantUUID() {
+        return invariantUUID;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getToscaModelURL() {
+        return toscaModelURL;
+    }
+
+    public String getCategory() {
+        return category;
+    }
 }
index 9a0204a..588c0b2 100644 (file)
@@ -27,6 +27,7 @@ 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.NodeTemplate;
 import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
 import org.openecomp.sdc.toscaparser.api.common.JToscaException;
 import org.openecomp.sdc.toscaparser.api.parameters.Input;
@@ -82,9 +83,10 @@ public class DefaultServiceTemplateService implements ServiceTemplateService {
         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);
+            List<ServiceTemplateInput> serviceTemplateInputs = new ArrayList<>();
+            serviceTemplateInputs = extractInputs(toPath, serviceTemplateInputs);
+            List<VimInfo> vimInfo = aaiService.listVimInfo().execute().body();
+            return new ServiceTemplateInputRsp(serviceTemplateInputs, vimInfo);
         }  catch (IOException e) {
             throw new SDCCatalogException("download csar file failed!", e);
         } catch (JToscaException e) {
@@ -102,10 +104,35 @@ public class DefaultServiceTemplateService implements ServiceTemplateService {
         }
     }
 
-    private ServiceTemplateInput extractInputs(String toPath) throws JToscaException {
+    private List<ServiceTemplateInput> extractInputs(String toPath, List<ServiceTemplateInput> serviceTemplateInputs) throws JToscaException, IOException {
         ToscaTemplate tosca = new ToscaTemplate(toPath,null,true,null,true);
+        ServiceTemplateInput serviceTemplateInput = fetchServiceTemplateInput(tosca);
+        serviceTemplateInputs.add(serviceTemplateInput);
+        for (NodeTemplate nodeTemplate : tosca.getNodeTemplates()) {
+            String nodeUUID = nodeTemplate.getMetaData().getValue("UUID");
+            SDCServiceTemplate template = sdcCatalog.getService(nodeUUID).execute().body();
+            String toscaModelURL = template.getToscaModelURL();
+            if (toscaModelURL == null) {
+                continue;
+            }
+            String savePath = String.format("temp/%s.csar", nodeUUID);
+            downloadFile(toscaModelURL, savePath);
+            extractInputs(savePath, serviceTemplateInputs);
+        }
+        return serviceTemplateInputs;
+    }
+
+    private static ServiceTemplateInput fetchServiceTemplateInput(ToscaTemplate tosca) {
+        String invariantUUID = tosca.getMetaData().getValue("invariantUUID");
+        String uuid = tosca.getMetaData().getValue("UUID");
         String name = tosca.getMetaData().getValue("name");
         String type = tosca.getMetaData().getValue("type");
+        String description = tosca.getMetaData().getValue("description");
+        String category = tosca.getMetaData().getValue("category");
+        String subcategory = tosca.getMetaData().getValue("subcategory");
+        if(subcategory == null) {
+            subcategory = "";
+        }
         List<TemplateInput> templateInputs = new ArrayList<>();
         for(Input input : tosca.getInputs()) {
             templateInputs.add(new TemplateInput(
@@ -115,8 +142,15 @@ public class DefaultServiceTemplateService implements ServiceTemplateService {
                     String.valueOf(input.isRequired()),
                     String.valueOf(input.getDefault())
             ));
-
         }
-        return new ServiceTemplateInput(name, type, templateInputs);
+        return new ServiceTemplateInput(
+                invariantUUID,
+                uuid,
+                name,
+                type,
+                description,
+                category,
+                subcategory,
+                templateInputs);
     }
 }