diff options
5 files changed, 140 insertions, 15 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInput.java b/server/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInput.java index c847f573..9207f9a5 100644 --- a/server/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInput.java +++ b/server/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInput.java @@ -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; } diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInputRsp.java b/server/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInputRsp.java index f4228739..403b991e 100644 --- a/server/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInputRsp.java +++ b/server/src/main/java/org/onap/usecaseui/server/bean/lcm/ServiceTemplateInputRsp.java @@ -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; } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/SDCCatalogService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/SDCCatalogService.java index 46d5389c..690edad1 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/SDCCatalogService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/SDCCatalogService.java @@ -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 diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/SDCServiceTemplate.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/SDCServiceTemplate.java index 48da58a4..38afd558 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/SDCServiceTemplate.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/bean/SDCServiceTemplate.java @@ -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; + } } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateService.java index 9a0204ab..588c0b2f 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateService.java @@ -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); } } |