From 62cd6aaaf74aa91ee0037c0e155c8e7284f07567 Mon Sep 17 00:00:00 2001 From: Arthur Martella Date: Fri, 8 Sep 2017 13:27:46 -0400 Subject: 1710 Rebase - Second Attempt This commit rebases changes from openecomp-mso/internal-staging-1710 up to and including this codecloud commit: 54483fc6606ddb1591a2e9da61bff8712325f924 Wed Sep 6 18:12:56 2017 -0400 Rebasing was done on a branch on top of this commit in so/master in ONAP: 93fbdfbe46104f8859d4754040f979cb7997c157 Thu Sep 7 16:42:59 2017 +0000 Change-Id: I4ad9abf40da32bf5bdca43e868b8fa2dbcd9dc59 Issue-id: SO-107 Signed-off-by: Arthur Martella --- .../adapters/catalogdb/CatalogDbAdapterRest.java | 102 ++++++++++++++------- .../QueryAllottedResourceCustomization.java | 48 +++++++--- .../catalogrest/QueryServiceMacroHolder.java | 23 +++-- .../catalogrest/QueryServiceNetworks.java | 41 ++++++--- .../catalogdb/catalogrest/QueryServiceVnfs.java | 54 +++++++---- .../catalogdb/catalogrest/QueryVfModule.java | 64 ++++++++----- .../catalogdb/catalogrest/QueryVfModules.java | 81 ++++++++++++++++ 7 files changed, 301 insertions(+), 112 deletions(-) create mode 100644 adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModules.java (limited to 'adapters/mso-catalog-db-adapter/src/main') 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= - * 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 ret; + List 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 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 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 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(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(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; private final String template = - "\t{ \"allottedResource\" : {\n"+ - "\t\t\"modelName\" : ,\n"+ - "\t\t\"modelUuid\" : ,\n"+ - "\t\t\"modelInvariantUuid\" : ,\n"+ - "\t\t\"modelVersion\" : ,\n"+ - "\t\t\"modelCustomizationUuid\" : ,\n"+ - "\t\t\"modelInstanceName\" : \n"+ - "\t}}"; + "\t{\n"+ +// "\t{ \"allottedResource\" : {\n"+ + "\t\t\"modelInfo\" : {\n"+ + "\t\t\t\"modelName\" : ,\n"+ + "\t\t\t\"modelUuid\" : ,\n"+ + "\t\t\t\"modelInvariantUuid\" : ,\n"+ + "\t\t\t\"modelVersion\" : ,\n"+ + "\t\t\t\"modelCustomizationUuid\" : ,\n"+ + "\t\t\t\"modelInstanceName\" : \n"+ + "\t\t},\n"+ + "\t\t\"toscaNodeType\" : ,\n"+ + "\t\t\"allottedResourceType\" : ,\n"+ + "\t\t\"allottedResourceRole\" : ,\n"+ + "\t\t\"providingServiceModelInvariantUuid\" : ,\n"+ + "\t\t\"nfFunction\" : ,\n"+ + "\t\t\"nfType\" : ,\n"+ + "\t\t\"nfRole\" : ,\n"+ + "\t\t\"nfNamingCode\" : \n"+ + "\t}"; +// "\t}}"; public QueryAllottedResourceCustomization() { super(); allottedResourceCustomization = new ArrayList(); } public QueryAllottedResourceCustomization(List vlist) { allottedResourceCustomization = vlist; } @@ -71,18 +83,30 @@ 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("]"); 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\" : ,\n"+ - "\t\"modelUuid\" : ,\n"+ - "\t\"modelInvariantUuid\" : ,\n"+ - "\t\"modelVersion\" : ,\n"+ - + "\t\"modelInfo\" : {\n"+ + "\t\t\"modelName\" : ,\n"+ + "\t\t\"modelUuid\" : ,\n"+ + "\t\t\"modelInvariantUuid\" : ,\n"+ + "\t\t\"modelVersion\" : \n"+ + "\t},\n"+ + "\t\"serviceType\" : ,\n"+ + "\t\"serviceRole\" : ,\n"+ "<_SERVICEVNFS_>,\n"+ "<_SERVICENETWORKS_>,\n"+ "<_SERVICEALLOTTEDRESOURCES_>\n"+ @@ -60,13 +63,15 @@ public class QueryServiceMacroHolder extends CatalogQuery { StringBuffer buf = new StringBuffer(); Map valueMap = new HashMap(); - 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 serviceNetworks; private final String template = - "\t{ \"network\" : {\n"+ - "\t\t\"modelName\" : ,\n"+ - "\t\t\"modelUuid\" : ,\n"+ - "\t\t\"modelInvariantUuid\" : ,\n"+ - "\t\t\"modelVersion\" : ,\n"+ - "\t\t\"modelCustomizationUuid\" : ,\n"+ - "\t\t\"modelInstanceName\" : ,\n"+ - "\t\t\"networkType\" : \n"+ - "\t}}"; + "\t{\n"+ +// "\t{ \"networkResource\" : {\n"+ + "\t\t\"modelInfo\" : {\n"+ + "\t\t\t\"modelName\" : ,\n"+ + "\t\t\t\"modelUuid\" : ,\n"+ + "\t\t\t\"modelInvariantUuid\" : ,\n"+ + "\t\t\t\"modelVersion\" : ,\n"+ + "\t\t\t\"modelCustomizationUuid\" : ,\n"+ + "\t\t\t\"modelInstanceName\" : \n"+ + "\t},\n"+ + "\t\t\"toscaNodeType\" : ,\n"+ + "\t\t\"networkType\" : ,\n"+ + "\t\t\"networkTechnology\" : ,\n"+ + "\t\t\"networkRole\" : ,\n"+ + "\t\t\"networkScope\" : \n"+ + "\t}"; +// "\t}}"; public QueryServiceNetworks() { super(); serviceNetworks = new ArrayList(); } public QueryServiceNetworks(List 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 valueMap = new HashMap(); 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 serviceVnfs; + private List serviceVnfs; private final String template = - "\t{ \"vnf\" : {\n"+ + "\n"+ +// "\t{ \"vnfResource\" : {\n"+ + "\t{ \"modelInfo\" : {\n"+ "\t\t\"modelName\" : ,\n"+ "\t\t\"modelUuid\" : ,\n"+ "\t\t\"modelInvariantUuid\" : ,\n"+ "\t\t\"modelVersion\" : ,\n"+ "\t\t\"modelCustomizationUuid\" : ,\n"+ - "\t\t\"modelInstanceName\" : ,\n"+ - "<_VFMODULES_>\n"+ - "\t}}"; + "\t\t\"modelInstanceName\" : \n"+ + "\t\t},\n"+ + "\t\"toscaNodeType\" : ,\n"+ + "\t\"nfFunction\" : ,\n"+ + "\t\"nfType\" : ,\n"+ + "\t\"nfRole\" : ,\n"+ + "\t\"nfNamingCode\" : ,\n"+ +// "\t}\n"+ + "<_VFMODULES_>\n" + + "\t}"; +// "\t}}"; - public QueryServiceVnfs() { super(); serviceVnfs = new ArrayList(); } - public QueryServiceVnfs(List vlist) { + public QueryServiceVnfs() { super(); serviceVnfs = new ArrayList(); } + public QueryServiceVnfs(List vlist) { LOGGER.debug ("QueryServiceVnfs:"); - serviceVnfs = new ArrayList(); - for (VnfResource o : vlist) { + serviceVnfs = new ArrayList(); + 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 getServiceVnfs(){ return this.serviceVnfs; } - public void setServiceVnfs(List v) { this.serviceVnfs = v; } + public List getServiceVnfs(){ return this.serviceVnfs; } + public void setServiceVnfs(List 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 vfModules; + private List vfModules; private final String template = - "\t{ \"vfModule\" : { \n"+ - "\t\t\"modelName\" : ,\n"+ - "\t\t\"modelUuid\" : ,\n"+ - "\t\t\"modelInvariantUuid\" : ,\n"+ - "\t\t\"modelVersion\" : ,\n"+ - "\t\t\"modelCustomizationUuid\" : ,\n"+ - "\t\t\"vfModuleType\" : ,\n"+ + "\t{\n"+ +// "\t{ \"vfModule\" : { \n"+ + "\t\t\"modelInfo\" : { \n"+ + "\t\t\t\"modelName\" : ,\n"+ + "\t\t\t\"modelUuid\" : ,\n"+ + "\t\t\t\"modelInvariantUuid\" : ,\n"+ + "\t\t\t\"modelVersion\" : ,\n"+ + "\t\t\t\"modelCustomizationUuid\" : \n"+ + "\t\t},"+ "\t\t\"isBase\" : ,\n"+ "\t\t\"vfModuleLabel\" : ,\n"+ - "\t\t\"initialCount\" : \n"+ - "\t}}"; + "\t\t\"initialCount\" : ,\n"+ + "\t\t\"hasVolumeGroup\" : \n"+ + "\t}"; +// "\t}}"; - public QueryVfModule() { super(); vfModules = new ArrayList(); } - public QueryVfModule(List vlist) { + public QueryVfModule() { super(); vfModules = new ArrayList(); } + public QueryVfModule(List vlist) { LOGGER.debug ("QueryVfModule:"); - vfModules = new ArrayList(); - for (VfModule o : vlist) { + vfModules = new ArrayList(); + if (vlist != null) { + for (VfModuleCustomization o : vlist) { LOGGER.debug ("-- o is a vfModules ----"); LOGGER.debug (o.toString()); vfModules.add(o); LOGGER.debug ("-------------------"); } } + } - public List getVfModule(){ return this.vfModules; } - public void setVfModule(List v) { this.vfModules = v; } + public List getVfModule(){ return this.vfModules; } + public void setVfModule(List 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 vfModules; + + public QueryVfModules() { super(); vfModules = new ArrayList(); } + public QueryVfModules(List vlist) { + LOGGER.debug ("QueryVfModules:"); + vfModules = new ArrayList(); + for (VfModule o : vlist) { + LOGGER.debug ("-- o is a vfModules ----"); + LOGGER.debug (o.toString()); + vfModules.add(o); + LOGGER.debug ("-------------------"); + } + } + + public List getVfModules(){ return this.vfModules; } + + public void setVfModules(List 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; + } +} -- cgit 1.2.3-korg