diff options
Diffstat (limited to 'adapters/mso-catalog-db-adapter/src/main')
7 files changed, 301 insertions, 112 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java index 20198d1543..ee2d590939 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java @@ -50,15 +50,10 @@ min and initial counts can be 0. max can be null to indicate no maximum. Once the network-level distribution artifacts are defined, similar updates can be made to the NETWORK_RESOURCE table. */ -import java.util.Map; +import java.util.ArrayList; import java.util.List; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.HEAD; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -67,8 +62,6 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.GenericEntity; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; -import javax.xml.ws.Holder; - import org.apache.http.HttpStatus; import org.openecomp.mso.logger.MessageEnum; @@ -80,8 +73,10 @@ import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceVnfs; import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceNetworks; import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceMacroHolder; import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryAllottedResourceCustomization; +import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryVfModule; import org.openecomp.mso.db.catalog.CatalogDatabase; -import org.openecomp.mso.db.catalog.beans.VnfResource; +import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization; +import org.openecomp.mso.db.catalog.beans.VfModuleCustomization; import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization; import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder; import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization; @@ -116,15 +111,8 @@ public class CatalogDbAdapterRest { return Response.ok().entity(CHECK_HTML).build(); } - /* - * GET {http-catalog-adapter-root}/v1/serviceVnfs?vnfModelCustomizationUuid=<vnf-model-customization-uuid> - * URL:http://localhost:8080/ecomp/mso/catalog/v1/getVfModuleType?vnfType=Test/vSAMP10&vfModuleType=vSAMP10::base::module-0 - * RESP: - * {"queryVfModule":{"version":1,"asdcUuid":"MANUAL RECORD","created":{"nanos":0},"description":"vSAMP10","environmentId":15184,"id":2312,"isBase":1,"modelName":"vSAMP10::base::module-0","modelVersion":1,"templateId":15123,"type":"Test\/vSAMP10::vSAMP10::base::module-0","vnfResourceId":15187}} - */ - @GET - @Path("vnfs/{vnfModelCustomizationUuid}") + @Path("vnfResources/{vnfModelCustomizationUuid}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response serviceVnfs ( @PathParam("version") String version, @@ -151,9 +139,9 @@ public class CatalogDbAdapterRest { QueryServiceVnfs qryResp; int respStatus = HttpStatus.SC_OK; String uuid = ""; - List<VnfResource> ret; + List<VnfResourceCustomization> ret; - try (CatalogDatabase db = new CatalogDatabase()) { + try (CatalogDatabase db = CatalogDatabase.getInstance()) { if (vnfUuid != null && !vnfUuid.equals("")) { uuid = vnfUuid; LOGGER.debug ("Query serviceVnfs getAllVnfsByVnfModelCustomizationUuid vnfModelCustomizationUuid: " + uuid); @@ -185,16 +173,6 @@ public class CatalogDbAdapterRest { ret = db.getAllVnfsByServiceName(smName); } } - else if (smName != null && !smName.equals("")) { - if (smVer != null && !smVer.equals("")) { - LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceName serviceModelInvariantName: " + smName+ " serviceModelVersion: "+ smVer); - ret = db.getAllVnfsByServiceName(smName, smVer); - } - else { - LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceName serviceModelName: " + smName); - ret = db.getAllVnfsByServiceName(smName); - } - } else { throw(new Exception("no matching parameters")); } @@ -221,7 +199,7 @@ public class CatalogDbAdapterRest { } @GET - @Path("networks/{networkModelCustomizationUuid}") + @Path("networkResources/{networkModelCustomizationUuid}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response serviceNetworks ( @PathParam("version") String version, @@ -237,10 +215,15 @@ public class CatalogDbAdapterRest { @PathParam("version") String version, @QueryParam("networkModelCustomizationUuid") String nUuid, @QueryParam("networkType") String nType, + @QueryParam("networkModelName") String nModelName, @QueryParam("serviceModelUuid") String smUuid, @QueryParam("serviceModelInvariantUuid") String smiUuid, - @QueryParam("serviceModelVersion") String smVer + @QueryParam("serviceModelVersion") String smVer, + @QueryParam("networkModelVersion") String nmVer ) { + if (nModelName != null && !nModelName.equals("")) { + nType = nModelName; + } return serviceNetworksImpl (version, IS_ARRAY, nUuid, nType, smUuid, smiUuid, smVer); } @@ -250,7 +233,7 @@ public class CatalogDbAdapterRest { String uuid = ""; List<NetworkResourceCustomization> ret; - try (CatalogDatabase db = new CatalogDatabase()) { + try (CatalogDatabase db = CatalogDatabase.getInstance()) { if (nUuid != null && !nUuid.equals("")) { uuid = nUuid; LOGGER.debug ("Query serviceNetworks getAllNetworksByNetworkModelCustomizationUuid networkModelCustomizationUuid: " + uuid); @@ -315,7 +298,7 @@ public class CatalogDbAdapterRest { String uuid = ""; ServiceMacroHolder ret; - try (CatalogDatabase db = new CatalogDatabase()) { + try (CatalogDatabase db = CatalogDatabase.getInstance()) { if (smUuid != null && !smUuid.equals("")) { uuid = smUuid; LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: " + uuid); @@ -386,7 +369,7 @@ public class CatalogDbAdapterRest { String uuid = ""; List<AllottedResourceCustomization > ret; - try (CatalogDatabase db = new CatalogDatabase()) { + try (CatalogDatabase db = CatalogDatabase.getInstance()) { if (smUuid != null && !smUuid.equals("")) { uuid = smUuid; LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelUuid serviceModelUuid: " + uuid); @@ -432,4 +415,55 @@ public class CatalogDbAdapterRest { .build(); } } + + // Added for DHV in 1702. Might be a temporary solution! + // Changing to use QueryVfModule so the modelCustomizationUuid is included in response + @GET + @Path("vfModules") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public Response vfModules(@QueryParam("vfModuleModelName") String vfModuleModelName) { + QueryVfModule qryResp; + int respStatus = HttpStatus.SC_OK; + List<VfModuleCustomization> ret = null; + CatalogDatabase db = CatalogDatabase.getInstance(); + + try{ + if(vfModuleModelName != null && !vfModuleModelName.equals("")){ + LOGGER.debug ("Query vfModules by vfModuleModuleName: " + vfModuleModelName); + VfModuleCustomization vfModule = db.getVfModuleCustomizationByModelName(vfModuleModelName); + if(vfModule != null){ + ret = new ArrayList<VfModuleCustomization>(1); + ret.add(vfModule); + } + }else{ + throw(new Exception("Incoming parameter is null or blank")); + } + if(ret == null || ret.isEmpty()){ + LOGGER.debug ("vfModules not found"); + respStatus = HttpStatus.SC_NOT_FOUND; + qryResp = new QueryVfModule(); + }else{ + LOGGER.debug ("vfModules found"); + qryResp = new QueryVfModule(ret); + LOGGER.debug ("vfModules query Results is: "+ qryResp); + LOGGER.debug ("vfModules tojsonstring is: "+ qryResp.JSON2(false, false)); + } + LOGGER.debug ("Query vfModules exit"); + return Response + .status(respStatus) + .entity(qryResp.JSON2(false, false)) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .build(); + }catch(Exception e){ + LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleModelName, "", "queryVfModules", MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query VfModules by vfModuleModuleName: ", e); + CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); + return Response + .status(HttpStatus.SC_INTERNAL_SERVER_ERROR) + .entity(new GenericEntity<CatalogQueryException>(excResp) {}) + .build(); + }finally { + db.close(); + } + } + }
\ No newline at end of file diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java index 9c81476f5d..503436fa99 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java @@ -33,14 +33,26 @@ import java.util.Map; public class QueryAllottedResourceCustomization extends CatalogQuery { private List<AllottedResourceCustomization> allottedResourceCustomization; private final String template = - "\t{ \"allottedResource\" : {\n"+ - "\t\t\"modelName\" : <MODEL_NAME>,\n"+ - "\t\t\"modelUuid\" : <MODEL_UUID>,\n"+ - "\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+ - "\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+ - "\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+ - "\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>\n"+ - "\t}}"; + "\t{\n"+ +// "\t{ \"allottedResource\" : {\n"+ + "\t\t\"modelInfo\" : {\n"+ + "\t\t\t\"modelName\" : <MODEL_NAME>,\n"+ + "\t\t\t\"modelUuid\" : <MODEL_UUID>,\n"+ + "\t\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+ + "\t\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+ + "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+ + "\t\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>\n"+ + "\t\t},\n"+ + "\t\t\"toscaNodeType\" : <TOSCA_NODE_TYPE>,\n"+ + "\t\t\"allottedResourceType\" : <ALLOTTED_RESOURCE_TYPE>,\n"+ + "\t\t\"allottedResourceRole\" : <ALLOTTED_RESOURCE_ROLE>,\n"+ + "\t\t\"providingServiceModelInvariantUuid\" : <PROVIDING_SERVICE_MODEL_INVARIANT_UUID>,\n"+ + "\t\t\"nfFunction\" : <NF_FUNCTION>,\n"+ + "\t\t\"nfType\" : <NF_TYPE>,\n"+ + "\t\t\"nfRole\" : <NF_ROLE>,\n"+ + "\t\t\"nfNamingCode\" : <NF_NAMING_CODE>\n"+ + "\t}"; +// "\t}}"; public QueryAllottedResourceCustomization() { super(); allottedResourceCustomization = new ArrayList<AllottedResourceCustomization>(); } public QueryAllottedResourceCustomization(List<AllottedResourceCustomization> vlist) { allottedResourceCustomization = vlist; } @@ -71,19 +83,31 @@ public class QueryAllottedResourceCustomization extends CatalogQuery { String sep = ""; boolean first = true; + if (this.allottedResourceCustomization != null) { for (AllottedResourceCustomization o : allottedResourceCustomization) { if (first) buf.append("\n"); first = false; - put(valueMap, "MODEL_NAME", o.getModelName()); - put(valueMap, "MODEL_UUID", o.getModelUuid()); - put(valueMap, "MODEL_INVARIANT_ID", o.getModelInvariantId()); - put(valueMap, "MODEL_VERSION", o.getModelVersion()); + boolean arNull = o.getAllottedResource() == null ? true : false; + + put(valueMap, "MODEL_NAME", arNull ? null : o.getAllottedResource().getModelName()); + put(valueMap, "MODEL_UUID", arNull ? null : o.getAllottedResource().getModelUuid()); + put(valueMap, "MODEL_INVARIANT_ID", arNull ? null : o.getAllottedResource().getModelInvariantUuid()); + put(valueMap, "MODEL_VERSION", arNull ? null : o.getAllottedResource().getModelVersion()); put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid()); put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName()); + put(valueMap, "TOSCA_NODE_TYPE", arNull ? null : o.getAllottedResource().getToscaNodeType()); + put(valueMap, "ALLOTTED_RESOURCE_TYPE", o.getNfType()); + put(valueMap, "ALLOTTED_RESOURCE_ROLE", o.getNfRole()); + put(valueMap, "NF_TYPE", o.getNfType()); + put(valueMap, "NF_ROLE", o.getNfRole()); + put(valueMap, "NF_FUNCTION", o.getNfFunction()); + put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode()); + put(valueMap, "PROVIDING_SERVICE_MODEL_INVARIANT_UUID", o.getProvidingServiceModelInvariantUuid()); buf.append(sep+ this.setTemplate(template, valueMap)); sep = ",\n"; } + } if (!first) buf.append("\n"); if (isArray) buf.append("]"); if (!isEmbed && isArray) buf.append("}"); diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java index 5ac54164c7..0e5b56f577 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java @@ -33,11 +33,14 @@ public class QueryServiceMacroHolder extends CatalogQuery { private ServiceMacroHolder serviceMacroHolder; private final String template = "{ \"serviceResources\" : {\n"+ - "\t\"modelName\" : <SERVICE_MODEL_NAME>,\n"+ - "\t\"modelUuid\" : <SERVICE_MODEL_UUID>,\n"+ - "\t\"modelInvariantUuid\" : <SERVICE_MODEL_INVARIANT_ID>,\n"+ - "\t\"modelVersion\" : <SERVICE_MODEL_VERSION>,\n"+ - + "\t\"modelInfo\" : {\n"+ + "\t\t\"modelName\" : <SERVICE_MODEL_NAME>,\n"+ + "\t\t\"modelUuid\" : <SERVICE_MODEL_UUID>,\n"+ + "\t\t\"modelInvariantUuid\" : <SERVICE_MODEL_INVARIANT_ID>,\n"+ + "\t\t\"modelVersion\" : <SERVICE_MODEL_VERSION>\n"+ + "\t},\n"+ + "\t\"serviceType\" : <SERVICE_TYPE>,\n"+ + "\t\"serviceRole\" : <SERVICE_ROLE>,\n"+ "<_SERVICEVNFS_>,\n"+ "<_SERVICENETWORKS_>,\n"+ "<_SERVICEALLOTTEDRESOURCES_>\n"+ @@ -60,13 +63,15 @@ public class QueryServiceMacroHolder extends CatalogQuery { StringBuffer buf = new StringBuffer(); Map<String, String> valueMap = new HashMap<String, String>(); - put(valueMap, "SERVICE_MODEL_NAME", service.getServiceName()); //getServiceModelName()); - put(valueMap, "SERVICE_MODEL_UUID", service.getServiceNameVersionId()); //getServiceModelUuid()); + put(valueMap, "SERVICE_MODEL_NAME", service.getModelName()); //getServiceModelName()); + put(valueMap, "SERVICE_MODEL_UUID", service.getModelUUID()); //getServiceModelUuid()); put(valueMap, "SERVICE_MODEL_INVARIANT_ID", service.getModelInvariantUUID()); //getServiceModelInvariantId()); - put(valueMap, "SERVICE_MODEL_VERSION", service.getServiceVersion()); //getServiceModelVersion()); + put(valueMap, "SERVICE_MODEL_VERSION", service.getVersion()); //getServiceModelVersion()); + put(valueMap, "SERVICE_TYPE", service.getServiceType()); + put(valueMap, "SERVICE_ROLE", service.getServiceRole()); String subitem; - subitem = new QueryServiceVnfs(serviceMacroHolder.getVnfResources()).JSON2(true, true); + subitem = new QueryServiceVnfs(serviceMacroHolder.getVnfResourceCustomizations()).JSON2(true, true); valueMap.put("_SERVICEVNFS_", subitem.replaceAll("(?m)^", "\t")); subitem = new QueryServiceNetworks(serviceMacroHolder.getNetworkResourceCustomization()).JSON2(true, true); diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworks.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworks.java index 573a0c77a2..96a7c4f8d5 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworks.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworks.java @@ -33,15 +33,23 @@ import java.util.Map; public class QueryServiceNetworks extends CatalogQuery { private List<NetworkResourceCustomization> serviceNetworks; private final String template = - "\t{ \"network\" : {\n"+ - "\t\t\"modelName\" : <MODEL_NAME>,\n"+ - "\t\t\"modelUuid\" : <MODEL_UUID>,\n"+ - "\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+ - "\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+ - "\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+ - "\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>,\n"+ - "\t\t\"networkType\" : <NETWORK_TYPE>\n"+ - "\t}}"; + "\t{\n"+ +// "\t{ \"networkResource\" : {\n"+ + "\t\t\"modelInfo\" : {\n"+ + "\t\t\t\"modelName\" : <MODEL_NAME>,\n"+ + "\t\t\t\"modelUuid\" : <MODEL_UUID>,\n"+ + "\t\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+ + "\t\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+ + "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+ + "\t\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>\n"+ + "\t},\n"+ + "\t\t\"toscaNodeType\" : <TOSCA_NODE_TYPE>,\n"+ + "\t\t\"networkType\" : <NETWORK_TYPE>,\n"+ + "\t\t\"networkTechnology\" : <NETWORK_TECHNOLOGY>,\n"+ + "\t\t\"networkRole\" : <NETWORK_ROLE>,\n"+ + "\t\t\"networkScope\" : <NETWORK_SCOPE>\n"+ + "\t}"; +// "\t}}"; public QueryServiceNetworks() { super(); serviceNetworks = new ArrayList<NetworkResourceCustomization>(); } public QueryServiceNetworks(List<NetworkResourceCustomization> vlist) { @@ -76,20 +84,25 @@ public class QueryServiceNetworks extends CatalogQuery { StringBuffer buf = new StringBuffer(); if (!isEmbed && isArray) buf.append("{ "); if (isArray) buf.append("\"serviceNetworks\": ["); + //if (isArray) buf.append("["); Map<String, String> valueMap = new HashMap<String, String>(); String sep = ""; boolean first = true; for (NetworkResourceCustomization o : serviceNetworks) { if (first) buf.append("\n"); first = false; - - put(valueMap, "MODEL_NAME", o.getModelName()); - put(valueMap, "MODEL_UUID", o.getModelUuid()); - put(valueMap, "MODEL_INVARIANT_ID", o.getModelInvariantId()); - put(valueMap, "MODEL_VERSION", o.getModelVersion()); + boolean nrNull = o.getNetworkResource() == null ? true : false; + put(valueMap, "MODEL_NAME", nrNull ? null : o.getNetworkResource().getModelName()); + put(valueMap, "MODEL_UUID", nrNull ? null : o.getNetworkResource().getModelUUID()); + put(valueMap, "MODEL_INVARIANT_ID", nrNull ? null : o.getNetworkResource().getModelInvariantUUID()); + put(valueMap, "MODEL_VERSION", nrNull ? null : o.getNetworkResource().getVersion()); put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid()); put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName()); + put(valueMap, "TOSCA_NODE_TYPE", nrNull ? null : o.getNetworkResource().getToscaNodeType()); put(valueMap, "NETWORK_TYPE", o.getNetworkType()); + put(valueMap, "NETWORK_ROLE", o.getNetworkRole()); + put(valueMap, "NETWORK_SCOPE", o.getNetworkScope()); + put(valueMap, "NETWORK_TECHNOLOGY", o.getNetworkTechnology()); buf.append(sep+ this.setTemplate(template, valueMap)); sep = ",\n"; diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfs.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfs.java index a917cd9efe..796fec41b0 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfs.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfs.java @@ -21,6 +21,7 @@ package org.openecomp.mso.adapters.catalogdb.catalogrest; /* should be called QueryVnfResource.java */ import org.openecomp.mso.db.catalog.beans.VnfResource; +import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization; import org.jboss.resteasy.annotations.providers.NoJackson; import javax.xml.bind.annotation.XmlRootElement; @@ -32,23 +33,33 @@ import java.util.Map; @XmlRootElement(name = "serviceVnfs") @NoJackson public class QueryServiceVnfs extends CatalogQuery { - private List<VnfResource> serviceVnfs; + private List<VnfResourceCustomization> serviceVnfs; private final String template = - "\t{ \"vnf\" : {\n"+ + "\n"+ +// "\t{ \"vnfResource\" : {\n"+ + "\t{ \"modelInfo\" : {\n"+ "\t\t\"modelName\" : <MODEL_NAME>,\n"+ "\t\t\"modelUuid\" : <MODEL_UUID>,\n"+ "\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+ "\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+ "\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+ - "\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>,\n"+ - "<_VFMODULES_>\n"+ - "\t}}"; + "\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>\n"+ + "\t\t},\n"+ + "\t\"toscaNodeType\" : <TOSCA_NODE_TYPE>,\n"+ + "\t\"nfFunction\" : <NF_FUNCTION>,\n"+ + "\t\"nfType\" : <NF_TYPE>,\n"+ + "\t\"nfRole\" : <NF_ROLE>,\n"+ + "\t\"nfNamingCode\" : <NF_NAMING_CODE>,\n"+ +// "\t}\n"+ + "<_VFMODULES_>\n" + + "\t}"; +// "\t}}"; - public QueryServiceVnfs() { super(); serviceVnfs = new ArrayList<VnfResource>(); } - public QueryServiceVnfs(List<VnfResource> vlist) { + public QueryServiceVnfs() { super(); serviceVnfs = new ArrayList<VnfResourceCustomization>(); } + public QueryServiceVnfs(List<VnfResourceCustomization> vlist) { LOGGER.debug ("QueryServiceVnfs:"); - serviceVnfs = new ArrayList<VnfResource>(); - for (VnfResource o : vlist) { + serviceVnfs = new ArrayList<VnfResourceCustomization>(); + for (VnfResourceCustomization o : vlist) { LOGGER.debug ("-- o is a serviceVnfs ----"); LOGGER.debug (o.toString()); serviceVnfs.add(o); @@ -56,8 +67,8 @@ public class QueryServiceVnfs extends CatalogQuery { } } - public List<VnfResource> getServiceVnfs(){ return this.serviceVnfs; } - public void setServiceVnfs(List<VnfResource> v) { this.serviceVnfs = v; } + public List<VnfResourceCustomization> getServiceVnfs(){ return this.serviceVnfs; } + public void setServiceVnfs(List<VnfResourceCustomization> v) { this.serviceVnfs = v; } @Override public String toString () { @@ -65,7 +76,7 @@ public class QueryServiceVnfs extends CatalogQuery { boolean first = true; int i = 1; - for (VnfResource o : serviceVnfs) { + for (VnfResourceCustomization o : serviceVnfs) { buf.append(i+"\t"); if (!first) buf.append("\n"); first = false; buf.append(o); @@ -82,17 +93,24 @@ public class QueryServiceVnfs extends CatalogQuery { String sep = ""; boolean first = true; - for (VnfResource o : serviceVnfs) { + for (VnfResourceCustomization o : serviceVnfs) { if (first) buf.append("\n"); first = false; - put(valueMap, "MODEL_NAME", o.getModelName()); - put(valueMap, "MODEL_UUID", o.getModelUuid()); - put(valueMap, "MODEL_INVARIANT_ID", o.getModelInvariantId()); - put(valueMap, "MODEL_VERSION", o.getModelVersion()); + boolean vrNull = o.getVnfResource() == null ? true : false; + + put(valueMap, "MODEL_NAME", vrNull ? null : o.getVnfResource().getModelName()); + put(valueMap, "MODEL_UUID", vrNull ? null : o.getVnfResource().getModelUuid()); + put(valueMap, "MODEL_INVARIANT_ID", vrNull ? null : o.getVnfResource().getModelInvariantId()); + put(valueMap, "MODEL_VERSION", vrNull ? null : o.getVnfResource().getVersion()); put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid()); put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName()); + put(valueMap, "TOSCA_NODE_TYPE", vrNull ? null : o.getVnfResource().getToscaNodeType()); + put(valueMap, "NF_FUNCTION", o.getNfFunction()); + put(valueMap, "NF_TYPE", o.getNfType()); + put(valueMap, "NF_ROLE", o.getNfRole()); + put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode()); - String subitem = new QueryVfModule(o.getVfModules()).JSON2(true, true); + String subitem = new QueryVfModule(vrNull ? null : o.getVfModuleCustomizations()).JSON2(true, true); valueMap.put("_VFMODULES_", subitem.replaceAll("(?m)^", "\t\t")); buf.append(sep+ this.setTemplate(template, valueMap)); diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModule.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModule.java index e7113e60c5..873a8dbe1b 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModule.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModule.java @@ -20,6 +20,7 @@ package org.openecomp.mso.adapters.catalogdb.catalogrest; import org.openecomp.mso.db.catalog.beans.VfModule; +import org.openecomp.mso.db.catalog.beans.VfModuleCustomization; import org.jboss.resteasy.annotations.providers.NoJackson; import javax.xml.bind.annotation.XmlRootElement; @@ -31,34 +32,40 @@ import java.util.Map; @XmlRootElement(name = "vfModules") @NoJackson public class QueryVfModule extends CatalogQuery { - private List<VfModule> vfModules; + private List<VfModuleCustomization> vfModules; private final String template = - "\t{ \"vfModule\" : { \n"+ - "\t\t\"modelName\" : <MODEL_NAME>,\n"+ - "\t\t\"modelUuid\" : <MODEL_UUID>,\n"+ - "\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+ - "\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+ - "\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+ - "\t\t\"vfModuleType\" : <VF_MODULE_TYPE>,\n"+ + "\t{\n"+ +// "\t{ \"vfModule\" : { \n"+ + "\t\t\"modelInfo\" : { \n"+ + "\t\t\t\"modelName\" : <MODEL_NAME>,\n"+ + "\t\t\t\"modelUuid\" : <MODEL_UUID>,\n"+ + "\t\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+ + "\t\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+ + "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>\n"+ + "\t\t},"+ "\t\t\"isBase\" : <IS_BASE>,\n"+ "\t\t\"vfModuleLabel\" : <VF_MODULE_LABEL>,\n"+ - "\t\t\"initialCount\" : <INITIAL_COUNT>\n"+ - "\t}}"; + "\t\t\"initialCount\" : <INITIAL_COUNT>,\n"+ + "\t\t\"hasVolumeGroup\" : <HAS_VOLUME_GROUP>\n"+ + "\t}"; +// "\t}}"; - public QueryVfModule() { super(); vfModules = new ArrayList<VfModule>(); } - public QueryVfModule(List<VfModule> vlist) { + public QueryVfModule() { super(); vfModules = new ArrayList<VfModuleCustomization>(); } + public QueryVfModule(List<VfModuleCustomization> vlist) { LOGGER.debug ("QueryVfModule:"); - vfModules = new ArrayList<VfModule>(); - for (VfModule o : vlist) { + vfModules = new ArrayList<VfModuleCustomization>(); + if (vlist != null) { + for (VfModuleCustomization o : vlist) { LOGGER.debug ("-- o is a vfModules ----"); LOGGER.debug (o.toString()); vfModules.add(o); LOGGER.debug ("-------------------"); } } + } - public List<VfModule> getVfModule(){ return this.vfModules; } - public void setVfModule(List<VfModule> v) { this.vfModules = v; } + public List<VfModuleCustomization> getVfModule(){ return this.vfModules; } + public void setVfModule(List<VfModuleCustomization> v) { this.vfModules = v; } @Override public String toString () { @@ -66,7 +73,7 @@ public class QueryVfModule extends CatalogQuery { boolean first = true; int i = 1; - for (VfModule o : vfModules) { + for (VfModuleCustomization o : vfModules) { buf.append(i+"\t"); if (!first) buf.append("\n"); first = false; buf.append(o); @@ -82,18 +89,25 @@ public class QueryVfModule extends CatalogQuery { String sep = ""; boolean first = true; - for (VfModule o : vfModules) { + for (VfModuleCustomization o : vfModules) { if (first) buf.append("\n"); first = false; - put(valueMap, "MODEL_NAME", o.getModelName()); - put(valueMap, "MODEL_UUID", o.getModelUuid()); - put(valueMap, "MODEL_INVARIANT_ID", o.getModelInvariantId()); - put(valueMap, "MODEL_VERSION", o.getModelVersion()); + boolean vfNull = o.getVfModule() == null ? true : false; + boolean hasVolumeGroup = false; + String envt = o.getHeatEnvironmentArtifactUuid(); + if (envt != null && !envt.equals("")) { + hasVolumeGroup = true; + } + + put(valueMap, "MODEL_NAME", vfNull ? null : o.getVfModule().getModelName()); + put(valueMap, "MODEL_UUID", vfNull ? null : o.getVfModule().getModelUUID()); + put(valueMap, "MODEL_INVARIANT_ID", vfNull ? null : o.getVfModule().getModelInvariantUuid()); + put(valueMap, "MODEL_VERSION", vfNull ? null : o.getVfModule().getVersion()); put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid()); - put(valueMap, "VF_MODULE_TYPE", o.getVfModuleType()); - put(valueMap, "IS_BASE", new Boolean(o.isBase()? true: false)); - put(valueMap, "VF_MODULE_LABEL", o.getVfModuleLabel()); + put(valueMap, "IS_BASE", vfNull ? false : new Boolean(o.getVfModule().isBase()? true: false)); + put(valueMap, "VF_MODULE_LABEL", o.getLabel()); put(valueMap, "INITIAL_COUNT", o.getInitialCount()); + put(valueMap, "HAS_VOLUME_GROUP", new Boolean(hasVolumeGroup)); buf.append(sep+ this.setTemplate(template, valueMap)); sep = ",\n"; diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModules.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModules.java new file mode 100644 index 0000000000..3d7c5f9c6e --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModules.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.openecomp.mso.adapters.catalogdb.catalogrest; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlRootElement; + +import org.codehaus.jackson.map.ObjectMapper; +import org.jboss.resteasy.annotations.providers.NoJackson; + +import org.openecomp.mso.db.catalog.beans.VfModule; +import org.openecomp.mso.logger.MsoLogger; + +@XmlRootElement(name = "vfModules") +@NoJackson +public class QueryVfModules { + private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + private List<VfModule> vfModules; + + public QueryVfModules() { super(); vfModules = new ArrayList<VfModule>(); } + public QueryVfModules(List<VfModule> vlist) { + LOGGER.debug ("QueryVfModules:"); + vfModules = new ArrayList<VfModule>(); + for (VfModule o : vlist) { + LOGGER.debug ("-- o is a vfModules ----"); + LOGGER.debug (o.toString()); + vfModules.add(o); + LOGGER.debug ("-------------------"); + } + } + + public List<VfModule> getVfModules(){ return this.vfModules; } + + public void setVfModules(List<VfModule> v) { this.vfModules = v; } + + @Override + public String toString () { + StringBuffer buf = new StringBuffer(); + + boolean first = true; + int i = 1; + for (VfModule o : vfModules) { + buf.append(i+"\t"); + if (!first) buf.append("\n"); first = false; + buf.append(o); + } + return buf.toString(); + } + + public String toJsonString() { + String jsonString = null; + try { + ObjectMapper mapper = new ObjectMapper(); + jsonString = mapper.writeValueAsString(this); + LOGGER.debug ("QueryVfModules jsonString: "+jsonString); + } + catch (Exception e) { + LOGGER.debug ("QueryVfModules jsonString exception:"+e.getMessage()); + } + return jsonString; + } +} |