aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-catalog-db-adapter
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-catalog-db-adapter')
-rw-r--r--adapters/mso-catalog-db-adapter/WebContent/WEB-INF/jboss-deployment-structure.xml17
-rw-r--r--adapters/mso-catalog-db-adapter/WebContent/WEB-INF/jboss-web.xml3
-rw-r--r--adapters/mso-catalog-db-adapter/WebContent/WEB-INF/web.xml64
-rw-r--r--adapters/mso-catalog-db-adapter/pom.xml104
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java435
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQuery.java90
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryException.java57
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryExceptionCategory.java22
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryExceptionCommon.java64
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java93
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java82
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworks.java102
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfs.java106
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModule.java105
14 files changed, 1344 insertions, 0 deletions
diff --git a/adapters/mso-catalog-db-adapter/WebContent/WEB-INF/jboss-deployment-structure.xml b/adapters/mso-catalog-db-adapter/WebContent/WEB-INF/jboss-deployment-structure.xml
new file mode 100644
index 0000000..05f0a32
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/WebContent/WEB-INF/jboss-deployment-structure.xml
@@ -0,0 +1,17 @@
+<jboss-deployment-structure>
+ <deployment>
+ <!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
+ <exclusions>
+ <module name="org.apache.log4j" />
+ <module name="org.slf4j" />
+ <module name="org.slf4j.impl" />
+ </exclusions>
+ <dependencies>
+ <module name="org.jboss.jandex" slot="main" />
+ <module name="org.javassist" slot="main" />
+ <module name="org.antlr" slot="main" />
+ <module name="org.dom4j" slot="main" />
+ </dependencies>
+ </deployment>
+</jboss-deployment-structure>
+
diff --git a/adapters/mso-catalog-db-adapter/WebContent/WEB-INF/jboss-web.xml b/adapters/mso-catalog-db-adapter/WebContent/WEB-INF/jboss-web.xml
new file mode 100644
index 0000000..2493bdb
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/WebContent/WEB-INF/jboss-web.xml
@@ -0,0 +1,3 @@
+<jboss-web>
+ <context-root>ecomp/mso/catalog</context-root>
+</jboss-web> \ No newline at end of file
diff --git a/adapters/mso-catalog-db-adapter/WebContent/WEB-INF/web.xml b/adapters/mso-catalog-db-adapter/WebContent/WEB-INF/web.xml
new file mode 100644
index 0000000..750bba7
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/WebContent/WEB-INF/web.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
+ <display-name>mso-catalog-db</display-name>
+
+ <context-param>
+ <param-name>log.configuration</param-name>
+ <param-value>logback.catalog.xml</param-value>
+ </context-param>
+ <context-param>
+ <param-name>mso.configuration</param-name>
+ <param-value>MSO_PROP_TOPOLOGY=topology.properties</param-value>
+ </context-param>
+ <context-param>
+ <param-name>resteasy.resources</param-name>
+ <param-value>
+ org.openecomp.mso.adapters.catalogdb.CatalogDbAdapterRest
+ </param-value>
+ </context-param>
+ <servlet>
+ <servlet-name>Resteasy</servlet-name>
+ <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Resteasy</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>MSO internal Requests</web-resource-name>
+ <description>Internal Requests</description>
+ <url-pattern>/logging/*</url-pattern>
+ <url-pattern>/properties/*</url-pattern>
+ <http-method>POST</http-method>
+ <http-method>GET</http-method>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>MSO-Client</role-name>
+ </auth-constraint>
+ </security-constraint>
+ <security-role>
+ <role-name>MSO-Client</role-name>
+ </security-role>
+ <filter>
+ <filter-name>LogFilter</filter-name>
+ <filter-class>org.openecomp.mso.logger.LogFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>LogFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+ <context-param>
+ <param-name>resteasy.scan</param-name>
+ <param-value>true</param-value>
+ </context-param>
+ <context-param>
+ <param-name>resteasy.scan.providers</param-name>
+ <param-value>true</param-value>
+ </context-param>
+ <context-param>
+ <param-name>resteasy.scan.resources</param-name>
+ <param-value>true</param-value>
+ </context-param>
+
+</web-app>
diff --git a/adapters/mso-catalog-db-adapter/pom.xml b/adapters/mso-catalog-db-adapter/pom.xml
new file mode 100644
index 0000000..e7c4b53
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/pom.xml
@@ -0,0 +1,104 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.openecomp.mso</groupId>
+ <artifactId>adapters</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.openecomp.mso.adapters</groupId>
+ <artifactId>mso-catalog-db-adapter</artifactId>
+ <packaging>war</packaging>
+
+ <build>
+ <finalName>${project.artifactId}-${project.version}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <warSourceDirectory>WebContent</warSourceDirectory>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <attachClasses>true</attachClasses>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ <pluginManagement>
+ <plugins>
+ <!--This plugin's configuration is used to store Eclipse m2e settings
+ only. It has no influence on the Maven build itself. -->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>
+ org.jvnet.jax-ws-commons
+ </groupId>
+ <artifactId>
+ jaxws-maven-plugin
+ </artifactId>
+ <versionRange>
+ [2.3,)
+ </versionRange>
+ <goals>
+ <goal>wsgen</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore></ignore>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.openecomp.mso</groupId>
+ <artifactId>mso-catalog-db</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jaxrs</artifactId>
+ <version>3.0.19.Final</version>
+ <scope>provided</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jackson-provider</artifactId>
+ <version>3.0.16.Final</version>
+ </dependency>
+ <!--<dependency>
+ <groupId>org.openecomp.mso</groupId>
+ <artifactId>status-control</artifactId>
+ <version>${project.version}</version>
+ </dependency>-->
+ </dependencies>
+
+</project> \ No newline at end of file
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
new file mode 100644
index 0000000..20198d1
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java
@@ -0,0 +1,435 @@
+/*-
+ * ============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;
+
+/*
+Create an initial query to retrieve a VNF Resource definition (including a list of possible module types)
+within the context of a given service. Input is a vnf resource model customization ID (new field for 1702),
+or a composite key (from 1610) of service name, service version, vnf instance name
+
+Returns a structure (JSON?) containing VNF RESOURCE attributes, plus a list of VF Module structures.
+
+Query a NETWORK_RESOURCE from the MSO Catalog, based on a networkModelCustomizationUUID (new for 1702),
+a network type (unique type identifier in 1610), or based on network role within a service.
+
+Create Adapter framework for access to Catalog DB, including connection management,
+login/password access, transaction logic, etc. This can be modeled after the Request DB Adapter
+
+Update the MSO Catalog DB schema to include the new fields defined in this user story.
+
+Note that the resourceModelCustomizationUUID (or vfModuleModelCustomizationUUID) will be unique keys (indexes)
+on the VNF_RESOURCE and VF_MODULE tables respectively.
+The previously constructed "vnf-type" and "vf-module-type" field may continue to be populated,
+but should no longer be needed and can deprecate in future release.
+
+For migration, a new randomly generated UUID field may be generated for the *ModelCustomizationUUID" fields
+until such time that the model is redistributed from ASDC.
+
+All other fields Check with Mike Z for appropriate value for the vfModuleLabel.
+We might be able to derive it's value from the current vnf-type (using the "middle" piece that identifies the module type).
+
+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.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;
+import javax.ws.rs.QueryParam;
+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;
+import org.openecomp.mso.logger.MsoLogger;
+import org.openecomp.mso.adapters.catalogdb.catalogrest.CatalogQueryException;
+import org.openecomp.mso.adapters.catalogdb.catalogrest.CatalogQueryExceptionCategory;
+import org.openecomp.mso.adapters.catalogdb.catalogrest.CatalogQuery;
+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.db.catalog.CatalogDatabase;
+import org.openecomp.mso.db.catalog.beans.VnfResource;
+import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
+import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
+import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
+
+/**
+ * This class services calls to the REST interface for VF Modules (http://host:port/ecomp/mso/catalog/v1)
+ * Both XML and JSON can be produced/consumed. Set Accept: and Content-Type: headers appropriately. XML is the default.
+ * Requests respond synchronously only
+ */
+@Path("/{version: v[0-9]+}")
+public class CatalogDbAdapterRest {
+ private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
+ private static final boolean IS_ARRAY = true;
+
+ public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) {
+ return Response
+ .status(respStatus)
+ //.entity(new GenericEntity<QueryServiceVnfs>(qryResp) {})
+ .entity(qryResp.toJsonString(version, isArray))
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .build();
+ }
+
+ @HEAD
+ @GET
+ @Path("healthcheck")
+ @Produces(MediaType.TEXT_HTML)
+ public Response healthcheck (
+ @PathParam("version") String version
+ ) {
+ String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Health Check</title></head><body>Application "+ version+ " ready</body></html>";
+ 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}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response serviceVnfs (
+ @PathParam("version") String version,
+ @PathParam("vnfModelCustomizationUuid") String vnfUuid
+ ) {
+ return serviceVnfsImpl (version, !IS_ARRAY, vnfUuid, null, null, null, null);
+ }
+
+ @GET
+ @Path("serviceVnfs")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response serviceVnfs(
+ @PathParam("version") String version,
+ @QueryParam("vnfModelCustomizationUuid") String vnfUuid,
+ @QueryParam("serviceModelUuid") String smUuid,
+ @QueryParam("serviceModelInvariantUuid") String smiUuid,
+ @QueryParam("serviceModelVersion") String smVer,
+ @QueryParam("serviceModelName") String smName
+ ) {
+ return serviceVnfsImpl (version, IS_ARRAY, vnfUuid, smUuid, smiUuid, smVer, smName);
+ }
+
+ public Response serviceVnfsImpl(String version, boolean isArray, String vnfUuid, String smUuid, String smiUuid, String smVer, String smName) {
+ QueryServiceVnfs qryResp;
+ int respStatus = HttpStatus.SC_OK;
+ String uuid = "";
+ List<VnfResource> ret;
+
+ try (CatalogDatabase db = new CatalogDatabase()) {
+ if (vnfUuid != null && !vnfUuid.equals("")) {
+ uuid = vnfUuid;
+ LOGGER.debug ("Query serviceVnfs getAllVnfsByVnfModelCustomizationUuid vnfModelCustomizationUuid: " + uuid);
+ ret = db.getAllVnfsByVnfModelCustomizationUuid(uuid);
+ }
+ else if (smUuid != null && !smUuid.equals("")) {
+ uuid = smUuid;
+ LOGGER.debug ("Query serviceVnfs getAllVnfsByServiceModelUuid serviceModelUuid: " + uuid);
+ ret = db.getAllVnfsByServiceModelUuid(uuid);
+ }
+ else if (smiUuid != null && !smiUuid.equals("")) {
+ uuid = smiUuid;
+ if (smVer != null && !smVer.equals("")) {
+ LOGGER.debug ("Query serviceVnfs getAllNetworksByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
+ ret = db.getAllVnfsByServiceModelInvariantUuid(uuid, smVer);
+ }
+ else {
+ LOGGER.debug ("Query serviceVnfs getAllNetworksByServiceModelInvariantUuid serviceModelUuid: " + uuid);
+ ret = db.getAllVnfsByServiceModelInvariantUuid(uuid);
+ }
+ }
+ 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 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"));
+ }
+
+ if (ret == null || ret.isEmpty()) {
+ LOGGER.debug ("serviceVnfs not found");
+ respStatus = HttpStatus.SC_NOT_FOUND;
+ qryResp = new QueryServiceVnfs();
+ } else {
+ LOGGER.debug ("serviceVnfs found");
+ qryResp = new QueryServiceVnfs(ret);
+ LOGGER.debug ("serviceVnfs qryResp="+ qryResp);
+ }
+ LOGGER.debug ("Query serviceVnfs exit");
+ return respond(version, respStatus, isArray, qryResp);
+ } catch (Exception e) {
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, uuid, "", "queryServiceVnfs", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceVnfs", 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();
+ }
+ }
+
+ @GET
+ @Path("networks/{networkModelCustomizationUuid}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response serviceNetworks (
+ @PathParam("version") String version,
+ @PathParam("networkModelCustomizationUuid") String nUuid
+ ) {
+ return serviceNetworksImpl (version, !IS_ARRAY, nUuid, null, null, null, null);
+ }
+
+ @GET
+ @Path("serviceNetworks")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response serviceNetworks (
+ @PathParam("version") String version,
+ @QueryParam("networkModelCustomizationUuid") String nUuid,
+ @QueryParam("networkType") String nType,
+ @QueryParam("serviceModelUuid") String smUuid,
+ @QueryParam("serviceModelInvariantUuid") String smiUuid,
+ @QueryParam("serviceModelVersion") String smVer
+ ) {
+ return serviceNetworksImpl (version, IS_ARRAY, nUuid, nType, smUuid, smiUuid, smVer);
+ }
+
+ public Response serviceNetworksImpl (String version, boolean isArray, String nUuid, String nType, String smUuid, String smiUuid, String smVer) {
+ QueryServiceNetworks qryResp;
+ int respStatus = HttpStatus.SC_OK;
+ String uuid = "";
+ List<NetworkResourceCustomization> ret;
+
+ try (CatalogDatabase db = new CatalogDatabase()) {
+ if (nUuid != null && !nUuid.equals("")) {
+ uuid = nUuid;
+ LOGGER.debug ("Query serviceNetworks getAllNetworksByNetworkModelCustomizationUuid networkModelCustomizationUuid: " + uuid);
+ ret = db.getAllNetworksByNetworkModelCustomizationUuid(uuid);
+ }
+ else if (smUuid != null && !smUuid.equals("")) {
+ uuid = smUuid;
+ LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelUuid serviceModelUuid: " + uuid);
+ ret = db.getAllNetworksByServiceModelUuid(uuid);
+ }
+ else if (nType != null && !nType.equals("")) {
+ uuid = nType;
+ LOGGER.debug ("Query serviceNetworks getAllNetworksByNetworkType serviceModelUuid: " + uuid);
+ ret = db.getAllNetworksByNetworkType(uuid);
+ }
+ else if (smiUuid != null && !smiUuid.equals("")) {
+ uuid = smiUuid;
+ if (smVer != null && !smVer.equals("")) {
+ LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
+ ret = db.getAllNetworksByServiceModelInvariantUuid(uuid, smVer);
+ }
+ else {
+ LOGGER.debug ("Query serviceNetworks getAllNetworksByServiceModelInvariantUuid serviceModelUuid: " + uuid);
+ ret = db.getAllNetworksByServiceModelInvariantUuid(uuid);
+ }
+ }
+ else {
+ throw(new Exception("no matching parameters"));
+ }
+
+ if (ret == null || ret.isEmpty()) {
+ LOGGER.debug ("serviceNetworks not found");
+ respStatus = HttpStatus.SC_NOT_FOUND;
+ qryResp = new QueryServiceNetworks();
+ } else {
+ LOGGER.debug ("serviceNetworks found");
+ qryResp = new QueryServiceNetworks(ret);
+ LOGGER.debug ("serviceNetworks qryResp="+ qryResp);
+ }
+ LOGGER.debug ("Query serviceNetworks exit");
+ return respond(version, respStatus, isArray, qryResp);
+ } catch (Exception e) {
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, uuid, "", "queryServiceNetworks", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceNetworks", 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();
+ }
+ }
+
+ @GET
+ @Path("serviceResources")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response serviceResources(
+ @PathParam("version") String version,
+ @QueryParam("serviceModelUuid") String smUuid,
+ @QueryParam("serviceModelInvariantUuid") String smiUuid,
+ @QueryParam("serviceModelVersion") String smVer) {
+ QueryServiceMacroHolder qryResp;
+ int respStatus = HttpStatus.SC_OK;
+ String uuid = "";
+ ServiceMacroHolder ret;
+
+ try (CatalogDatabase db = new CatalogDatabase()) {
+ if (smUuid != null && !smUuid.equals("")) {
+ uuid = smUuid;
+ LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelUuid serviceModelUuid: " + uuid);
+ ret = db.getAllResourcesByServiceModelUuid(uuid);
+ }
+ else if (smiUuid != null && !smiUuid.equals("")) {
+ uuid = smiUuid;
+ if (smVer != null && !smVer.equals("")) {
+ LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
+ ret = db.getAllResourcesByServiceModelInvariantUuid(uuid, smVer);
+ }
+ else {
+ LOGGER.debug ("Query serviceMacroHolder getAllResourcesByServiceModelInvariantUuid serviceModelUuid: " + uuid);
+ ret = db.getAllResourcesByServiceModelInvariantUuid(uuid);
+ }
+ }
+ else {
+ throw(new Exception("no matching parameters"));
+ }
+
+ if (ret == null) {
+ LOGGER.debug ("serviceMacroHolder not found");
+ respStatus = HttpStatus.SC_NOT_FOUND;
+ qryResp = new QueryServiceMacroHolder();
+ } else {
+ LOGGER.debug ("serviceMacroHolder found");
+ qryResp = new QueryServiceMacroHolder(ret);
+ LOGGER.debug ("serviceMacroHolder qryResp="+ qryResp);
+ }
+ LOGGER.debug ("Query serviceMacroHolder exit");
+ return respond(version, respStatus, IS_ARRAY, qryResp);
+ } catch (Exception e) {
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, uuid, "", "queryServiceMacroHolder", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryServiceMacroHolder", 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();
+ }
+ }
+
+ @GET
+ @Path("allottedResources/{arModelCustomizationUuid}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response serviceAllottedResources (
+ @PathParam("version") String version,
+ @PathParam("arModelCustomizationUuid") String aUuid
+ ) {
+ return serviceAllottedResourcesImpl(version, !IS_ARRAY, aUuid, null, null, null);
+ }
+
+ @GET
+ @Path("serviceAllottedResources")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response serviceAllottedResources(
+ @PathParam("version") String version,
+ @QueryParam("serviceModelUuid") String smUuid,
+ @QueryParam("serviceModelInvariantUuid") String smiUuid,
+ @QueryParam("serviceModelVersion") String smVer,
+ @QueryParam("arModelCustomizationUuid") String aUuid
+ ) {
+ return serviceAllottedResourcesImpl(version, IS_ARRAY, aUuid, smUuid, smiUuid, smVer);
+ }
+
+ public Response serviceAllottedResourcesImpl(String version, boolean isArray, String aUuid, String smUuid, String smiUuid, String smVer) {
+ QueryAllottedResourceCustomization qryResp;
+ int respStatus = HttpStatus.SC_OK;
+ String uuid = "";
+ List<AllottedResourceCustomization > ret;
+
+ try (CatalogDatabase db = new CatalogDatabase()) {
+ if (smUuid != null && !smUuid.equals("")) {
+ uuid = smUuid;
+ LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelUuid serviceModelUuid: " + uuid);
+ ret = db.getAllAllottedResourcesByServiceModelUuid(uuid);
+ }
+ else if (smiUuid != null && !smiUuid.equals("")) {
+ uuid = smiUuid;
+ if (smVer != null && !smVer.equals("")) {
+ LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelInvariantUuid serviceModelInvariantUuid: " + uuid+ " serviceModelVersion: "+ smVer);
+ ret = db.getAllAllottedResourcesByServiceModelInvariantUuid(uuid, smVer);
+ }
+ else {
+ LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByServiceModelInvariantUuid serviceModelUuid: " + uuid);
+ ret = db.getAllAllottedResourcesByServiceModelInvariantUuid(uuid);
+ }
+ }
+ else if (aUuid != null && !aUuid.equals("")) {
+ uuid = aUuid;
+ LOGGER.debug ("Query AllottedResourceCustomization getAllAllottedResourcesByArModelCustomizationUuid serviceModelUuid: " + uuid);
+ ret = db.getAllAllottedResourcesByArModelCustomizationUuid(uuid);
+ }
+ else {
+ throw(new Exception("no matching parameters"));
+ }
+
+ if (ret == null || ret.isEmpty()) {
+ LOGGER.debug ("AllottedResourceCustomization not found");
+ respStatus = HttpStatus.SC_NOT_FOUND;
+ qryResp = new QueryAllottedResourceCustomization();
+ } else {
+ LOGGER.debug ("AllottedResourceCustomization found");
+ qryResp = new QueryAllottedResourceCustomization(ret);
+ LOGGER.debug ("AllottedResourceCustomization qryResp="+ qryResp);
+ }
+ LOGGER.debug ("Query AllottedResourceCustomization exit");
+ return respond(version, respStatus, isArray, qryResp);
+ } catch (Exception e) {
+ LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, uuid, "", "queryAllottedResourceCustomization", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - queryAllottedResourceCustomization", 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();
+ }
+ }
+} \ No newline at end of file
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQuery.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQuery.java
new file mode 100644
index 0000000..565c4ff
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQuery.java
@@ -0,0 +1,90 @@
+/*-
+ * ============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 org.openecomp.mso.logger.MsoLogger;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public abstract class CatalogQuery {
+ protected static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
+ private static final boolean IS_EMBED = true;
+
+ public abstract String JSON2(boolean isArray, boolean isEmbed);
+
+ protected void put(Map<String, String> valueMap, String key, String value) {
+ valueMap.put(key, value == null? "null": '"'+ value+ '"');
+ }
+
+ protected void put(Map<String, String> valueMap, String key, Integer value) {
+ valueMap.put(key, value == null? "null": value.toString());
+ }
+
+ protected void put(Map<String, String> valueMap, String key, Boolean value) {
+ valueMap.put(key, value == null? "null": value? "true": "false");
+ }
+
+ protected String setTemplate(String template, Map<String, String> valueMap) {
+ LOGGER.debug ("CatalogQuery setTemplate");
+ StringBuffer result = new StringBuffer();
+
+ String pattern = "<.*>";
+ Pattern r = Pattern.compile(pattern);
+ Matcher m = r.matcher(template);
+
+ LOGGER.debug ("CatalogQuery template:"+ template);
+ while(m.find()) {
+ String key = template.substring(m.start()+1, m.end()-1);
+ LOGGER.debug ("CatalogQuery key:"+ key+ " contains key? "+ valueMap.containsKey(key));
+ m.appendReplacement(result, valueMap.containsKey(key)? valueMap.get(key): "\"TBD\"");
+ }
+ m.appendTail(result);
+ LOGGER.debug ("CatalogQuery return:"+ result.toString());
+ return result.toString();
+ }
+
+ /**
+ * The simple, clean, generic way to handle the interface
+ */
+ protected String smartToJSON() {
+ String jsonString = null;
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ jsonString = mapper.writeValueAsString(this);
+ }
+ catch (Exception e) {
+ LOGGER.debug ("jsonString exception:"+e.getMessage());
+ jsonString = "invalid"; //throws instead?
+ }
+ return jsonString;
+ }
+
+ public String toJsonString(String version, boolean isArray) {
+ switch(version) {
+ case "v1": return smartToJSON();
+ case "v2": return JSON2(isArray, !IS_EMBED);
+ default:
+ return ("invalid version: "+ version);
+ }
+ }
+} \ No newline at end of file
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryException.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryException.java
new file mode 100644
index 0000000..0fed791
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryException.java
@@ -0,0 +1,57 @@
+/*-
+ * ============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 org.jboss.resteasy.annotations.providers.NoJackson;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+
+@XmlRootElement(name = "catalogQueryException")
+@NoJackson
+public class CatalogQueryException extends CatalogQueryExceptionCommon implements Serializable {
+ private static final long serialVersionUID = -9062290006520066109L;
+
+ private String message;
+ private CatalogQueryExceptionCategory category;
+ private Boolean rolledBack;
+
+ public CatalogQueryException () {}
+
+ public CatalogQueryException (String message) {
+ this.message = message;
+ }
+
+ public CatalogQueryException (String message, CatalogQueryExceptionCategory category, boolean rolledBack, String messageid) {
+ super(messageid);
+ this.message = message;
+ this.category = category;
+ this.rolledBack = rolledBack;
+ }
+
+ public String getMessage() { return message; }
+ public void setMessage(String message) { this.message = message; }
+
+ public CatalogQueryExceptionCategory getCategory () { return category; }
+ public void setCategory (CatalogQueryExceptionCategory category) { this.category = category; }
+
+ public Boolean getRolledBack() { return rolledBack; }
+ public void setRolledBack(Boolean rolledBack) { this.rolledBack = rolledBack; }
+}
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryExceptionCategory.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryExceptionCategory.java
new file mode 100644
index 0000000..4fef8ac
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryExceptionCategory.java
@@ -0,0 +1,22 @@
+/*-
+ * ============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;
+
+public enum CatalogQueryExceptionCategory { OPENSTACK, IO, INTERNAL, USERDATA }
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryExceptionCommon.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryExceptionCommon.java
new file mode 100644
index 0000000..09a469d
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryExceptionCommon.java
@@ -0,0 +1,64 @@
+/*-
+ * ============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 org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import java.io.ByteArrayOutputStream;
+
+public abstract class CatalogQueryExceptionCommon {
+ private String messageId;
+
+ public CatalogQueryExceptionCommon() { messageId = null; }
+ public CatalogQueryExceptionCommon(String messageId) { this.messageId = messageId; }
+
+ public String getMessageId() { return messageId; }
+ public void setMessageId(String messageId) { this.messageId = messageId; }
+
+ public String toJsonString() {
+ try {
+ String jsonString = null;
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ jsonString = mapper.writeValueAsString(this);
+ return jsonString;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "";
+ }
+ }
+
+ public String toXmlString() {
+ try {
+ ByteArrayOutputStream bs = new ByteArrayOutputStream();
+ JAXBContext context = JAXBContext.newInstance(this.getClass());
+ Marshaller marshaller = context.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); //pretty print XML
+ marshaller.marshal(this, bs);
+ return bs.toString();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "";
+ }
+ }
+}
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
new file mode 100644
index 0000000..9c81476
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java
@@ -0,0 +1,93 @@
+/*-
+ * ============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 org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
+import org.jboss.resteasy.annotations.providers.NoJackson;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@XmlRootElement(name = "serviceAllottedResources")
+@NoJackson
+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}}";
+
+ public QueryAllottedResourceCustomization() { super(); allottedResourceCustomization = new ArrayList<AllottedResourceCustomization>(); }
+ public QueryAllottedResourceCustomization(List<AllottedResourceCustomization> vlist) { allottedResourceCustomization = vlist; }
+
+ public List<AllottedResourceCustomization> getServiceAllottedResources(){ return this.allottedResourceCustomization; }
+ public void setServiceAllottedResources(List<AllottedResourceCustomization> v) { this.allottedResourceCustomization = v; }
+
+ @Override
+ public String toString () {
+ StringBuffer buf = new StringBuffer();
+
+ boolean first = true;
+ int i = 1;
+ for (AllottedResourceCustomization o : allottedResourceCustomization) {
+ buf.append(i+"\t");
+ if (!first) buf.append("\n"); first = false;
+ buf.append(o);
+ }
+ return buf.toString();
+ }
+
+ @Override
+ public String JSON2(boolean isArray, boolean isEmbed) {
+ StringBuffer buf = new StringBuffer();
+ if (!isEmbed && isArray) buf.append("{ ");
+ if (isArray) buf.append("\"serviceAllottedResources\": [");
+ Map<String, String> valueMap = new HashMap<String, String>();
+ String sep = "";
+ boolean first = true;
+
+ 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());
+ put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid());
+ put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName());
+
+ buf.append(sep+ this.setTemplate(template, valueMap));
+ sep = ",\n";
+ }
+ if (!first) buf.append("\n");
+ if (isArray) buf.append("]");
+ if (!isEmbed && isArray) buf.append("}");
+ return buf.toString();
+ }
+
+} \ No newline at end of file
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
new file mode 100644
index 0000000..5ac5416
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java
@@ -0,0 +1,82 @@
+/*-
+ * ============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 org.openecomp.mso.db.catalog.beans.Service;
+import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
+import org.jboss.resteasy.annotations.providers.NoJackson;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.HashMap;
+import java.util.Map;
+
+@XmlRootElement(name = "serviceResources")
+@NoJackson
+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"+
+
+ "<_SERVICEVNFS_>,\n"+
+ "<_SERVICENETWORKS_>,\n"+
+ "<_SERVICEALLOTTEDRESOURCES_>\n"+
+ "\t}}";
+
+ public QueryServiceMacroHolder() { super(); serviceMacroHolder = new ServiceMacroHolder(); }
+ public QueryServiceMacroHolder(ServiceMacroHolder vlist) { serviceMacroHolder = vlist; }
+
+ public ServiceMacroHolder getServiceResources(){ return this.serviceMacroHolder; }
+ public void setServiceResources(ServiceMacroHolder v) { this.serviceMacroHolder = v; }
+
+ @Override
+ public String toString () { return serviceMacroHolder.toString(); }
+
+ @Override
+ public String JSON2(boolean isArray, boolean x) {
+ Service service = serviceMacroHolder.getService();
+ if (service == null) return "\"serviceResources\": null";
+
+ 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_INVARIANT_ID", service.getModelInvariantUUID()); //getServiceModelInvariantId());
+ put(valueMap, "SERVICE_MODEL_VERSION", service.getServiceVersion()); //getServiceModelVersion());
+
+ String subitem;
+ subitem = new QueryServiceVnfs(serviceMacroHolder.getVnfResources()).JSON2(true, true);
+ valueMap.put("_SERVICEVNFS_", subitem.replaceAll("(?m)^", "\t"));
+
+ subitem = new QueryServiceNetworks(serviceMacroHolder.getNetworkResourceCustomization()).JSON2(true, true);
+ valueMap.put("_SERVICENETWORKS_", subitem.replaceAll("(?m)^", "\t"));
+
+ subitem = new QueryAllottedResourceCustomization(serviceMacroHolder.getAllottedResourceCustomization()).JSON2(true, true);
+ valueMap.put("_SERVICEALLOTTEDRESOURCES_", subitem.replaceAll("(?m)^", "\t"));
+
+ buf.append(this.setTemplate(template, valueMap));
+ return buf.toString();
+ }
+
+} \ No newline at end of file
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
new file mode 100644
index 0000000..573a0c7
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceNetworks.java
@@ -0,0 +1,102 @@
+/*-
+ * ============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 org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
+import org.jboss.resteasy.annotations.providers.NoJackson;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@XmlRootElement(name = "serviceNetworks")
+@NoJackson
+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}}";
+
+ public QueryServiceNetworks() { super(); serviceNetworks = new ArrayList<NetworkResourceCustomization>(); }
+ public QueryServiceNetworks(List<NetworkResourceCustomization> vlist) {
+ LOGGER.debug ("QueryServiceNetworks:");
+ serviceNetworks = new ArrayList<NetworkResourceCustomization>();
+ for (NetworkResourceCustomization o : vlist) {
+ LOGGER.debug (o.toString());
+ serviceNetworks.add(o);
+ LOGGER.debug ("-------------------");
+ }
+ }
+
+ public List<NetworkResourceCustomization> getServiceNetworks(){ return this.serviceNetworks; }
+ public void setServiceNetworks(List<NetworkResourceCustomization> v) { this.serviceNetworks = v; }
+
+ @Override
+ public String toString () {
+ StringBuffer buf = new StringBuffer();
+
+ boolean first = true;
+ int i = 1;
+ for (NetworkResourceCustomization o : serviceNetworks) {
+ buf.append(i+"\t");
+ if (!first) buf.append("\n"); first = false;
+ buf.append(o);
+ }
+ return buf.toString();
+ }
+
+ @Override
+ public String JSON2(boolean isArray, boolean isEmbed) {
+ StringBuffer buf = new StringBuffer();
+ if (!isEmbed && isArray) buf.append("{ ");
+ if (isArray) buf.append("\"serviceNetworks\": [");
+ 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());
+ put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid());
+ put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName());
+ put(valueMap, "NETWORK_TYPE", o.getNetworkType());
+
+ buf.append(sep+ this.setTemplate(template, valueMap));
+ sep = ",\n";
+ }
+ if (!first) buf.append("\n");
+ if (isArray) buf.append("]");
+ if (!isEmbed && isArray) buf.append("}");
+ return buf.toString();
+ }
+} \ No newline at end of file
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
new file mode 100644
index 0000000..a917cd9
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceVnfs.java
@@ -0,0 +1,106 @@
+/*-
+ * ============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;
+/* should be called QueryVnfResource.java */
+
+import org.openecomp.mso.db.catalog.beans.VnfResource;
+import org.jboss.resteasy.annotations.providers.NoJackson;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@XmlRootElement(name = "serviceVnfs")
+@NoJackson
+public class QueryServiceVnfs extends CatalogQuery {
+ private List<VnfResource> serviceVnfs;
+ private final String template =
+ "\t{ \"vnf\" : {\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}}";
+
+ public QueryServiceVnfs() { super(); serviceVnfs = new ArrayList<VnfResource>(); }
+ public QueryServiceVnfs(List<VnfResource> vlist) {
+ LOGGER.debug ("QueryServiceVnfs:");
+ serviceVnfs = new ArrayList<VnfResource>();
+ for (VnfResource o : vlist) {
+ LOGGER.debug ("-- o is a serviceVnfs ----");
+ LOGGER.debug (o.toString());
+ serviceVnfs.add(o);
+ LOGGER.debug ("-------------------");
+ }
+ }
+
+ public List<VnfResource> getServiceVnfs(){ return this.serviceVnfs; }
+ public void setServiceVnfs(List<VnfResource> v) { this.serviceVnfs = v; }
+
+ @Override
+ public String toString () {
+ StringBuffer buf = new StringBuffer();
+
+ boolean first = true;
+ int i = 1;
+ for (VnfResource o : serviceVnfs) {
+ buf.append(i+"\t");
+ if (!first) buf.append("\n"); first = false;
+ buf.append(o);
+ }
+ return buf.toString();
+ }
+
+ @Override
+ public String JSON2(boolean isArray, boolean isEmbed) {
+ StringBuffer buf = new StringBuffer();
+ if (!isEmbed && isArray) buf.append("{ ");
+ if (isArray) buf.append("\"serviceVnfs\": [");
+ Map<String, String> valueMap = new HashMap<String, String>();
+ String sep = "";
+ boolean first = true;
+
+ for (VnfResource 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());
+ put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid());
+ put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName());
+
+ String subitem = new QueryVfModule(o.getVfModules()).JSON2(true, true);
+ valueMap.put("_VFMODULES_", subitem.replaceAll("(?m)^", "\t\t"));
+
+ buf.append(sep+ this.setTemplate(template, valueMap));
+ sep = ",\n";
+ }
+ if (!first) buf.append("\n");
+ if (isArray) buf.append("]");
+ if (!isEmbed && isArray) buf.append("}");
+ return buf.toString();
+ }
+} \ No newline at end of file
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
new file mode 100644
index 0000000..e7113e6
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModule.java
@@ -0,0 +1,105 @@
+/*-
+ * ============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 org.openecomp.mso.db.catalog.beans.VfModule;
+import org.jboss.resteasy.annotations.providers.NoJackson;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@XmlRootElement(name = "vfModules")
+@NoJackson
+public class QueryVfModule extends CatalogQuery {
+ private List<VfModule> 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\t\"isBase\" : <IS_BASE>,\n"+
+ "\t\t\"vfModuleLabel\" : <VF_MODULE_LABEL>,\n"+
+ "\t\t\"initialCount\" : <INITIAL_COUNT>\n"+
+ "\t}}";
+
+ public QueryVfModule() { super(); vfModules = new ArrayList<VfModule>(); }
+ public QueryVfModule(List<VfModule> vlist) {
+ LOGGER.debug ("QueryVfModule:");
+ 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> getVfModule(){ return this.vfModules; }
+ public void setVfModule(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();
+ }
+
+ @Override
+ public String JSON2(boolean isArray, boolean x) {
+ StringBuffer buf = new StringBuffer();
+ if (isArray) buf.append("\"vfModules\": [");
+ Map<String, String> valueMap = new HashMap<String, String>();
+ String sep = "";
+ boolean first = true;
+
+ for (VfModule 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());
+ 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, "INITIAL_COUNT", o.getInitialCount());
+
+ buf.append(sep+ this.setTemplate(template, valueMap));
+ sep = ",\n";
+ }
+ if (!first) buf.append("\n");
+ if (isArray) buf.append("]");
+ return buf.toString();
+ }
+} \ No newline at end of file