summaryrefslogtreecommitdiffstats
path: root/adapters/mso-vfc-adapter
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-vfc-adapter')
-rw-r--r--adapters/mso-vfc-adapter/README0
-rw-r--r--adapters/mso-vfc-adapter/WebContent/META-INF/MANIFEST.MF3
-rw-r--r--adapters/mso-vfc-adapter/WebContent/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector1
-rw-r--r--adapters/mso-vfc-adapter/WebContent/WEB-INF/jboss-deployment-structure.xml16
-rw-r--r--adapters/mso-vfc-adapter/WebContent/WEB-INF/jboss-web.xml3
-rw-r--r--adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml118
-rw-r--r--adapters/mso-vfc-adapter/WebContent/check.html10
-rw-r--r--adapters/mso-vfc-adapter/pom.xml105
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/AaiAdapter.java46
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/HealthCheckHandler.java74
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java183
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java399
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/CommonConstant.java197
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/DriverExceptionID.java68
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/HttpCode.java91
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/exceptions/ApplicationException.java45
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/LocationConstraint.java72
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NSResourceInputParameter.java89
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsCreateReq.java80
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsInstantiateReq.java49
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsOperationKey.java61
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsParameters.java67
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsProgressStatus.java83
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/ResponseDescriptor.java112
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/RestfulResponse.java88
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/JsonUtil.java129
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/RestfulUtil.java229
-rw-r--r--adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/ValidateUtil.java85
-rw-r--r--adapters/mso-vfc-adapter/src/test/java/org/openecomp/mso/adapters/vfc/VfcAdapterTest.java146
-rw-r--r--adapters/mso-vfc-adapter/src/test/resources/logback-test.xml48
30 files changed, 2697 insertions, 0 deletions
diff --git a/adapters/mso-vfc-adapter/README b/adapters/mso-vfc-adapter/README
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/adapters/mso-vfc-adapter/README
diff --git a/adapters/mso-vfc-adapter/WebContent/META-INF/MANIFEST.MF b/adapters/mso-vfc-adapter/WebContent/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..5e9495128c
--- /dev/null
+++ b/adapters/mso-vfc-adapter/WebContent/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
diff --git a/adapters/mso-vfc-adapter/WebContent/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector b/adapters/mso-vfc-adapter/WebContent/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector
new file mode 100644
index 0000000000..1281d32948
--- /dev/null
+++ b/adapters/mso-vfc-adapter/WebContent/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector
@@ -0,0 +1 @@
+com.woorea.openstack.connector.HttpClientConnector \ No newline at end of file
diff --git a/adapters/mso-vfc-adapter/WebContent/WEB-INF/jboss-deployment-structure.xml b/adapters/mso-vfc-adapter/WebContent/WEB-INF/jboss-deployment-structure.xml
new file mode 100644
index 0000000000..58ddb4a08f
--- /dev/null
+++ b/adapters/mso-vfc-adapter/WebContent/WEB-INF/jboss-deployment-structure.xml
@@ -0,0 +1,16 @@
+<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> \ No newline at end of file
diff --git a/adapters/mso-vfc-adapter/WebContent/WEB-INF/jboss-web.xml b/adapters/mso-vfc-adapter/WebContent/WEB-INF/jboss-web.xml
new file mode 100644
index 0000000000..e2433a381f
--- /dev/null
+++ b/adapters/mso-vfc-adapter/WebContent/WEB-INF/jboss-web.xml
@@ -0,0 +1,3 @@
+<jboss-web>
+ <context-root>vfc</context-root>
+</jboss-web> \ No newline at end of file
diff --git a/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml b/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml
new file mode 100644
index 0000000000..5bf8864351
--- /dev/null
+++ b/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml
@@ -0,0 +1,118 @@
+<?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-vfc-adapter</display-name>
+
+ <context-param>
+ <param-name>resteasy.jndi.resources</param-name>
+ <param-value>java:module/MsoPropertiesFactory,java:module/CloudConfigFactory</param-value>
+ </context-param>
+
+ <context-param>
+ <param-name>log.configuration</param-name>
+ <param-value>logback.vfc.xml</param-value>
+ </context-param>
+ <context-param>
+ <param-name>mso.configuration</param-name>
+ <param-value>MSO_PROP_NETWORK_ADAPTER=mso.vfc.properties,MSO_PROP_TOPOLOGY=topology.properties</param-value>
+ </context-param>
+ <context-param>
+ <param-name>mso.cloud_config.configuration</param-name>
+ <param-value>cloud_config.json=2</param-value>
+ </context-param>
+ <context-param>
+ <param-name>resteasy.resources</param-name>
+ <param-value>
+ org.openecomp.mso.MsoStatusHandler,
+ org.openecomp.mso.logger.MsoLoggingServlet,
+ org.openecomp.mso.adapters.vfc.HealthCheckHandler,
+ org.openecomp.mso.adapters.vfc.VfcAdapterRest
+ </param-value>
+ </context-param>
+ <context-param>
+ <param-name>resteasy.servlet.mapping.prefix</param-name>
+ <param-value>/rest</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>/rest/*</url-pattern>
+ </servlet-mapping>
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>SoapRequests</web-resource-name>
+ <description>Soap Ingress Requests</description>
+ <url-pattern>/VfcAdapter</url-pattern>
+ <url-pattern>/VfcAdapterAsync</url-pattern>
+ <http-method>POST</http-method>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>BPEL-Client</role-name>
+ </auth-constraint>
+ </security-constraint>
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>SiteStatus</web-resource-name>
+ <description>SiteStatus APIs</description>
+ <url-pattern>/rest/setStatus/*</url-pattern>
+ <http-method>POST</http-method>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>SiteControl-Client</role-name>
+ </auth-constraint>
+ </security-constraint>
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>RestRequests</web-resource-name>
+ <description>Rest Ingress Requests</description>
+ <url-pattern>/rest/v1/vfc/*</url-pattern>
+ <http-method>DELETE</http-method>
+ <http-method>GET</http-method>
+ <http-method>POST</http-method>
+ <http-method>PUT</http-method>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>BPEL-Client</role-name>
+ </auth-constraint>
+ </security-constraint>
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>MSO internal Requests</web-resource-name>
+ <description>Internal Requests</description>
+ <url-pattern>/rest/logging/*</url-pattern>
+ <url-pattern>/rest/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>
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ <realm-name>ApplicationRealm</realm-name>
+ </login-config>
+ <security-role>
+ <role-name>BPEL-Client</role-name>
+ </security-role>
+ <security-role>
+ <role-name>SiteControl-Client</role-name>
+ </security-role>
+ <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>
+ <welcome-file-list>
+ <welcome-file>check.html</welcome-file>
+ </welcome-file-list>
+</web-app>
+
diff --git a/adapters/mso-vfc-adapter/WebContent/check.html b/adapters/mso-vfc-adapter/WebContent/check.html
new file mode 100644
index 0000000000..00f37d60d1
--- /dev/null
+++ b/adapters/mso-vfc-adapter/WebContent/check.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="ISO-8859-1">
+<title>Health Check</title>
+</head>
+<body>
+Application ready
+</body>
+</html> \ No newline at end of file
diff --git a/adapters/mso-vfc-adapter/pom.xml b/adapters/mso-vfc-adapter/pom.xml
new file mode 100644
index 0000000000..4f049c350f
--- /dev/null
+++ b/adapters/mso-vfc-adapter/pom.xml
@@ -0,0 +1,105 @@
+<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.so</groupId>
+ <artifactId>adapters</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </parent>
+ <groupId>org.openecomp.so.adapters</groupId>
+ <artifactId>mso-vfc-adapter</artifactId>
+ <packaging>war</packaging>
+ <name>mso-vfc-adapter</name>
+ <description>Web service endpoint for vfc operations</description>
+
+ <!-- <properties> -->
+ <!-- <project.build.sourceEncoding/> -->
+ <!-- <project.reporting.outputEncoding/> -->
+ <!-- </properties> -->
+
+ <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>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax</groupId>
+ <artifactId>javaee-web-api</artifactId>
+ <version>6.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.so.adapters</groupId>
+ <artifactId>mso-adapter-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.so.adapters</groupId>
+ <artifactId>mso-adapters-rest-interface</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.10.19</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.spec.javax.ejb</groupId>
+ <artifactId>jboss-ejb-api_3.2_spec</artifactId>
+ <version>1.0.0.Final</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-ext-api</artifactId>
+ <version>2.2.0.Final</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.so</groupId>
+ <artifactId>status-control</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.so</groupId>
+ <artifactId>mso-requests-db</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jmockit</groupId>
+ <artifactId>jmockit</artifactId>
+ <version>1.19</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jmockit</groupId>
+ <artifactId>jmockit-coverage</artifactId>
+ <version>1.19</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/AaiAdapter.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/AaiAdapter.java
new file mode 100644
index 0000000000..6e3eb93126
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/AaiAdapter.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc;
+
+import org.openecomp.mso.adapters.vfc.model.RestfulResponse;
+
+/**
+ * Implement class of operating aai database table
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version ONAP Amsterdam Release 2017-08-28
+ */
+public class AaiAdapter {
+
+ public static RestfulResponse addRelation(String serviceInstanceID, String resourceInstanceID)
+ {
+ //sent rest to aai to add relation for service and ns.
+ return null;
+ }
+
+ public static RestfulResponse removeRelation(String serviceInstanceID ,String resourceInstanceID)
+ {
+ //sent rest to aai to remove relation between service an ns.
+ return null;
+ }
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/HealthCheckHandler.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/HealthCheckHandler.java
new file mode 100644
index 0000000000..13e963fbb3
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/HealthCheckHandler.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.HEAD;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.mso.logger.MsoLogger;
+import org.openecomp.mso.HealthCheckUtils;
+import org.openecomp.mso.utils.UUIDChecker;
+
+/**
+ * Health Check
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version ONAP Amsterdam Release 2017-08-28
+ */
+@Path("/")
+public class HealthCheckHandler {
+
+ private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
+
+ private static final String MSO_PROP_VFC_ADAPTER = "MSO_PROP_VFC_ADAPTER";
+
+ @HEAD
+ @GET
+ @Path("/healthcheck")
+ @Produces("text/html")
+ public Response healthcheck(@QueryParam("requestId") String requestId) {
+ long startTime = System.currentTimeMillis();
+ MsoLogger.setServiceName("Healthcheck");
+ UUIDChecker.verifyOldUUID(requestId, msoLogger);
+ HealthCheckUtils healthCheck = new HealthCheckUtils();
+ if(!healthCheck.siteStatusCheck(msoLogger, startTime)) {
+ return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
+ }
+
+ if(!healthCheck.configFileCheck(msoLogger, startTime, MSO_PROP_VFC_ADAPTER)) {
+ return HealthCheckUtils.NOT_STARTED_RESPONSE;
+ }
+
+ if(!healthCheck.catalogDBCheck(msoLogger, startTime)) {
+ return HealthCheckUtils.NOT_STARTED_RESPONSE;
+ }
+ msoLogger.debug("healthcheck - Successful");
+ return HealthCheckUtils.HEALTH_CHECK_RESPONSE;
+ }
+
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java
new file mode 100644
index 0000000000..1be5bab1c3
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java
@@ -0,0 +1,183 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+import org.openecomp.mso.adapters.vfc.model.NSResourceInputParameter;
+import org.openecomp.mso.adapters.vfc.model.NsOperationKey;
+import org.openecomp.mso.adapters.vfc.model.RestfulResponse;
+import org.openecomp.mso.adapters.vfc.util.JsonUtil;
+import org.openecomp.mso.adapters.vfc.util.RestfulUtil;
+import org.openecomp.mso.adapters.vfc.util.ValidateUtil;
+import org.openecomp.mso.logger.MsoLogger;
+
+/**
+ * The rest class for VF-c Adapter
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version ONAP Amsterdam Release 2017-08-28
+ */
+@Path("/v1/vfcdrivers")
+public class VfcAdapterRest {
+
+ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
+
+ private final VfcManager driverMgr = new VfcManager();
+
+ /**
+ * Create a NS
+ * <br>
+ *
+ * @param servletReq the http request
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ @POST
+ @Path("/ns")
+ @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public Response createNfvoNs(HttpServletRequest servletReq) {
+ // Step 1: get parameters from request for current node
+ String body = RestfulUtil.getRequestBody(servletReq);
+ ValidateUtil.assertObjectNotNull(body);
+ LOGGER.debug("body from request is {}" + body);
+ NSResourceInputParameter nsInput = JsonUtil.unMarshal(body, NSResourceInputParameter.class);
+ RestfulResponse rsp = driverMgr.createNs(nsInput);
+ return buildResponse(rsp);
+ }
+
+ /**
+ * Delete NS instance<br>
+ *
+ * @param servletReq http request
+ * @return response
+ * @since ONAP Amsterdam Release
+ */
+ @POST
+ @Path("/ns/{nsInstanceId}")
+ @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public Response deleteNfvoNs(HttpServletRequest servletReq, @PathParam("nsInstanceId") String nsInstanceId) {
+ // Step 1: get parameters from request for current node
+ String body = RestfulUtil.getRequestBody(servletReq);
+ ValidateUtil.assertObjectNotNull(body);
+ LOGGER.debug("body from request is {}" + body);
+ NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class);
+
+ RestfulResponse rsp = driverMgr.deleteNs(nsOperationKey, nsInstanceId);
+ return buildResponse(rsp);
+ }
+
+ /**
+ * Query Operation job status
+ * <br>
+ *
+ * @param servletReq The Http Request
+ * @param jobId The job id
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ @POST
+ @Path("/jobs/{jobId}")
+ @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public Response queryNfvoJobStatus(HttpServletRequest servletReq, @PathParam("jobId") String jobId) {
+ ValidateUtil.assertObjectNotNull(jobId);
+ String body = RestfulUtil.getRequestBody(servletReq);
+ ValidateUtil.assertObjectNotNull(body);
+ LOGGER.debug("body from request is {}" + body);
+ NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class);
+ RestfulResponse rsp = driverMgr.getNsProgress(nsOperationKey, jobId);
+ return buildResponse(rsp);
+ }
+
+
+ /**
+ * Instantiate NS instance
+ * <br>
+ *
+ * @param servletReq The http request
+ * @param nsInstanceId The NS instance id
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ @POST
+ @Path("/ns/{nsInstanceId}/instantiate")
+ @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public Response instantiateNfvoNs(HttpServletRequest servletReq, @PathParam("nsInstanceId") String nsInstanceId) {
+ String body = RestfulUtil.getRequestBody(servletReq);
+ ValidateUtil.assertObjectNotNull(body);
+ LOGGER.debug("body from request is {}" + body);
+ NSResourceInputParameter nsInput = JsonUtil.unMarshal(body, NSResourceInputParameter.class);
+ RestfulResponse rsp = driverMgr.instantiateNs(nsInstanceId, nsInput);
+ return buildResponse(rsp);
+ }
+
+ /**
+ * Terminate NS instance
+ * <br>
+ *
+ * @param servletReq The http request
+ * @param nsInstanceId The NS instance id
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ @POST
+ @Path("/ns/{nsInstanceId}/terminate")
+ @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public Response terminateNfvoNs(HttpServletRequest servletReq, @PathParam("nsInstanceId") String nsInstanceId) {
+ ValidateUtil.assertObjectNotNull(nsInstanceId);
+ String body = RestfulUtil.getRequestBody(servletReq);
+ ValidateUtil.assertObjectNotNull(body);
+ LOGGER.debug("body from request is {}" + body);
+ NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class);
+ RestfulResponse rsp = driverMgr.terminateNs(nsOperationKey, nsInstanceId);
+ return buildResponse(rsp);
+ }
+
+
+ /**
+ * build response from restful response
+ * <br>
+ *
+ * @param rsp general response object
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ private Response buildResponse(RestfulResponse rsp) {
+ ResponseBuilder rspBuilder = Response.status(rsp.getStatus());
+ rspBuilder.entity(rsp.getResponseContent());
+ return rspBuilder.build();
+ }
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java
new file mode 100644
index 0000000000..221448cb7b
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java
@@ -0,0 +1,399 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.openecomp.mso.adapters.vfc.constant.CommonConstant;
+import org.openecomp.mso.adapters.vfc.constant.CommonConstant.Step;
+import org.openecomp.mso.adapters.vfc.constant.DriverExceptionID;
+import org.openecomp.mso.adapters.vfc.constant.HttpCode;
+import org.openecomp.mso.adapters.vfc.exceptions.ApplicationException;
+import org.openecomp.mso.adapters.vfc.model.NSResourceInputParameter;
+import org.openecomp.mso.adapters.vfc.model.NsCreateReq;
+import org.openecomp.mso.adapters.vfc.model.NsInstantiateReq;
+import org.openecomp.mso.adapters.vfc.model.NsOperationKey;
+import org.openecomp.mso.adapters.vfc.model.NsParameters;
+import org.openecomp.mso.adapters.vfc.model.NsProgressStatus;
+import org.openecomp.mso.adapters.vfc.model.ResponseDescriptor;
+import org.openecomp.mso.adapters.vfc.model.RestfulResponse;
+import org.openecomp.mso.adapters.vfc.util.JsonUtil;
+import org.openecomp.mso.adapters.vfc.util.RestfulUtil;
+import org.openecomp.mso.adapters.vfc.util.ValidateUtil;
+import org.openecomp.mso.requestsdb.RequestsDatabase;
+import org.openecomp.mso.requestsdb.RequestsDbConstant;
+import org.openecomp.mso.requestsdb.ResourceOperationStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * VF-C Manager
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version ONAP Amsterdam Release 2017-08-28
+ */
+public class VfcManager {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(VfcManager.class);
+
+ /**
+ * nfvo url map
+ */
+ private static Map<String, String> nfvoUrlMap;
+
+ static {
+ nfvoUrlMap = new HashMap<String, String>();
+ nfvoUrlMap.put(Step.CREATE, CommonConstant.NFVO_CREATE_URL);
+ nfvoUrlMap.put(Step.INSTANTIATE, CommonConstant.NFVO_INSTANTIATE_URL);
+ nfvoUrlMap.put(Step.TERMINATE, CommonConstant.NFVO_TERMINATE_URL);
+ nfvoUrlMap.put(Step.DELETE, CommonConstant.NFVO_DELETE_URL);
+ nfvoUrlMap.put(Step.QUERY, CommonConstant.NFVO_QUERY_URL);
+ }
+
+ /**
+ * create network service
+ * <br>
+ *
+ * @param segInput input parameters for current node from http request
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ public RestfulResponse createNs(NSResourceInputParameter segInput) {
+
+ // Step1: get service template by node type
+ String nsdId = segInput.getNsOperationKey().getNodeTemplateId();
+ // nsdId for NFVO is "id" in the response, while for SDNO is "servcice template id"
+ LOGGER.info("serviceTemplateId is {}, id is {}", nsdId);
+
+ LOGGER.info("create ns -> begin");
+ // Step2: Prepare url and method type
+ String url = getUrl(null, CommonConstant.Step.CREATE);
+ String methodType = CommonConstant.MethodType.POST;
+
+ // Step3: Prepare restful parameters and options
+ NsCreateReq oRequest = new NsCreateReq();
+ oRequest.setNsdId(nsdId);
+ oRequest.setNsName(segInput.getSubServiceName());
+ oRequest.setDescription(segInput.getSubServiceDesc());
+ String createReq = JsonUtil.marshal(oRequest);
+
+ // Step4: Call NFVO or SDNO lcm to create ns
+ RestfulResponse createRsp = RestfulUtil.send(url, methodType, createReq);
+ ValidateUtil.assertObjectNotNull(createRsp);
+ LOGGER.info("create ns response status is : {}", createRsp.getStatus());
+ LOGGER.info("create ns response content is : {}", createRsp.getResponseContent());
+ @SuppressWarnings("unchecked")
+ Map<String, String> rsp = JsonUtil.unMarshal(createRsp.getResponseContent(), Map.class);
+ String nsInstanceId = rsp.get(CommonConstant.NS_INSTANCE_ID);
+ if(ValidateUtil.isStrEmpty(nsInstanceId)) {
+ LOGGER.error("Invalid instanceId from create operation");
+ throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR,
+ DriverExceptionID.INVALID_RESPONSEE_FROM_CREATE_OPERATION);
+ }
+ LOGGER.info("create ns -> end");
+ LOGGER.info("save segment and operaton info -> begin");
+ // Step 5: add relation between service and NS
+ AaiAdapter.addRelation(segInput.getNsOperationKey().getServiceId(), nsInstanceId);
+
+ // Step 6: save resource operation information
+ ResourceOperationStatus nsOperInfo = RequestsDatabase.getResourceOperationStatus(
+ segInput.getNsOperationKey().getServiceId(), segInput.getNsOperationKey().getOperationId(),
+ segInput.getNsOperationKey().getNodeTemplateId());
+ nsOperInfo.setStatus(RequestsDbConstant.Status.PROCESSING);
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+
+ if(!HttpCode.isSucess(createRsp.getStatus())) {
+ LOGGER.error("update segment operation status : fail to create ns");
+ nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR);
+ nsOperInfo.setErrorCode(String.valueOf(createRsp.getStatus()));
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+ throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_CREATE_NS);
+ }
+ LOGGER.info("save segment and operation info -> end");
+ return createRsp;
+ }
+
+ /**
+ * delete network service
+ * <br>
+ *
+ * @param nsOperationKey The operation key of the NS resource
+ * @param nsInstanceId The NS instance id
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ public RestfulResponse deleteNs(NsOperationKey nsOperationKey, String nsInstanceId) {
+ LOGGER.info("delete ns -> begin");
+ // Step1: prepare url and methodType
+ String url = getUrl(nsInstanceId, CommonConstant.Step.DELETE);
+ String methodType = CommonConstant.MethodType.DELETE;
+
+ // Step2: prepare restful parameters and options
+ RestfulResponse deleteRsp = RestfulUtil.send(url, methodType, "");
+ ValidateUtil.assertObjectNotNull(deleteRsp);
+ LOGGER.info("delete ns response status is : {}", deleteRsp.getStatus());
+ LOGGER.info("delete ns response content is : {}", deleteRsp.getResponseContent());
+ LOGGER.info("delete ns -> end");
+ ResourceOperationStatus nsOperInfo = RequestsDatabase.getResourceOperationStatus(nsOperationKey.getServiceId(),
+ nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateId());
+ if(!HttpCode.isSucess(deleteRsp.getStatus())) {
+ LOGGER.error("fail to delete ns");
+
+ nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR);
+ nsOperInfo.setErrorCode(String.valueOf(deleteRsp.getStatus()));
+ nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED);
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+ throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_DELETE_NS);
+ }
+
+ // Step3: remove relation info between service and ns
+ AaiAdapter.removeRelation(nsOperationKey.getServiceId(), nsInstanceId);
+ LOGGER.info("delete segment information -> end");
+
+ // Step4: update service segment operation status
+ nsOperInfo.setStatus(RequestsDbConstant.Status.FINISHED);
+ nsOperInfo.setErrorCode(String.valueOf(deleteRsp.getStatus()));
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+ LOGGER.info("update segment operaton status for delete -> end");
+
+ return deleteRsp;
+
+ }
+
+ /**
+ * instantiate network service
+ * <br>
+ *
+ * @param nsInstanceId The NS instance id
+ * @param segInput input parameters for current node from http request
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ public RestfulResponse instantiateNs(String nsInstanceId, NSResourceInputParameter segInput) {
+ // Call the NFVO or SDNO service to instantiate service
+ LOGGER.info("instantiate ns -> begin");
+
+ // Step1: Prepare restful parameters and options
+ NsInstantiateReq oRequest = new NsInstantiateReq();
+ oRequest.setNsInstanceId(nsInstanceId);
+ NsParameters nsParameters = segInput.getNsParameters();
+ oRequest.setLocationConstraints(nsParameters.getLocationConstraints());
+ oRequest.setAdditionalParamForNs(nsParameters.getAdditionalParamForNs());
+ String instReq = JsonUtil.marshal(oRequest);
+ // Step2: prepare url and
+ String url = getUrl(nsInstanceId, CommonConstant.Step.INSTANTIATE);
+ String methodType = CommonConstant.MethodType.POST;
+
+ RestfulResponse instRsp = RestfulUtil.send(url, methodType, instReq);
+ ValidateUtil.assertObjectNotNull(instRsp);
+ LOGGER.info("instantiate ns response status is : {}", instRsp.getStatus());
+ LOGGER.info("instantiate ns response content is : {}", instRsp.getResponseContent());
+ ValidateUtil.assertObjectNotNull(instRsp.getResponseContent());
+ @SuppressWarnings("unchecked")
+ Map<String, String> rsp = JsonUtil.unMarshal(instRsp.getResponseContent(), Map.class);
+ String jobId = rsp.get(CommonConstant.JOB_ID);
+ ResourceOperationStatus nsOperInfo = RequestsDatabase.getResourceOperationStatus(
+ segInput.getNsOperationKey().getServiceId(), segInput.getNsOperationKey().getOperationId(),
+ segInput.getNsOperationKey().getNodeTemplateId());
+ if(ValidateUtil.isStrEmpty(jobId)) {
+ LOGGER.error("Invalid jobId from instantiate operation");
+ nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR);
+ nsOperInfo.setErrorCode(String.valueOf(instRsp.getStatus()));
+ nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.INSTANTIATE_NS_FAILED);
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+ throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR,
+ DriverExceptionID.INVALID_RESPONSE_FROM_INSTANTIATE_OPERATION);
+ }
+ LOGGER.info("instantiate ns -> end");
+
+ if(!HttpCode.isSucess(instRsp.getStatus())) {
+ LOGGER.error("update segment operation status : fail to instantiate ns");
+ nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR);
+ nsOperInfo.setErrorCode(String.valueOf(instRsp.getStatus()));
+ nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.INSTANTIATE_NS_FAILED);
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+ throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_INSTANTIATE_NS);
+ }
+
+ // Step 3: update segment operation job id
+ LOGGER.info("update resource operation status job id -> begin");
+ nsOperInfo.setJobId(jobId);
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+ LOGGER.info("update segment operation job id -> end");
+
+ return instRsp;
+ }
+
+ /**
+ * terminate network service
+ * <br>
+ *
+ * @param nsOperationKey The operation key for NS resource
+ * @param nsInstanceId The NS instance id
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ public RestfulResponse terminateNs(NsOperationKey nsOperationKey, String nsInstanceId) {
+ // Step1: save segment operation info for delete process
+ LOGGER.info("save segment operation for delete process");
+ ResourceOperationStatus nsOperInfo = RequestsDatabase.getResourceOperationStatus(nsOperationKey.getServiceId(),
+ nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateId());
+ nsOperInfo.setStatus(RequestsDbConstant.Status.PROCESSING);
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+
+ LOGGER.info("terminate ns -> begin");
+ // Step2: prepare url and method type
+ String url = getUrl(nsInstanceId, CommonConstant.Step.TERMINATE);
+ String methodType = CommonConstant.MethodType.POST;
+
+ // Step3: prepare restful parameters and options
+ Map<String, String> reqBody = new HashMap<>();
+ reqBody.put("nsInstanceId", nsInstanceId);
+ reqBody.put("terminationType", "graceful");
+ reqBody.put("gracefulTerminationTimeout", "60");
+
+ // Step4: Call the NFVO or SDNO service to terminate service
+ RestfulResponse terminateRsp = RestfulUtil.send(url, methodType, JsonUtil.marshal(reqBody));
+ ValidateUtil.assertObjectNotNull(terminateRsp);
+ LOGGER.info("terminate ns response status is : {}", terminateRsp.getStatus());
+ LOGGER.info("terminate ns response content is : {}", terminateRsp.getResponseContent());
+ @SuppressWarnings("unchecked")
+ Map<String, String> rsp = JsonUtil.unMarshal(terminateRsp.getResponseContent(), Map.class);
+ String jobId = rsp.get(CommonConstant.JOB_ID);
+ if(ValidateUtil.isStrEmpty(jobId)) {
+ LOGGER.error("Invalid jobId from terminate operation");
+ nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR);
+ nsOperInfo.setErrorCode(String.valueOf(terminateRsp.getStatus()));
+ nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED);
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+ throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR,
+ DriverExceptionID.INVALID_RESPONSE_FROM_TERMINATE_OPERATION);
+ }
+ LOGGER.info("terminate ns -> end");
+
+ // Step 3: update segment operation
+ if(!HttpCode.isSucess(terminateRsp.getStatus())) {
+ LOGGER.error("fail to instantiate ns");
+ nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR);
+ nsOperInfo.setErrorCode(String.valueOf(terminateRsp.getStatus()));
+ nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED);
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+
+ throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_TERMINATE_NS);
+ }
+ LOGGER.info("update segment job id -> begin");
+ nsOperInfo.setJobId(jobId);
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+ LOGGER.info("update segment job id -> end");
+
+ return terminateRsp;
+ }
+
+ /**
+ * get ns progress by job Id
+ * <br>
+ *
+ * @param nsOperationKey The OperationKey for NS resource
+ * @param jobId the job id
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ public RestfulResponse getNsProgress(NsOperationKey nsOperationKey, String jobId) {
+
+ ValidateUtil.assertObjectNotNull(jobId);
+ ResourceOperationStatus nsOperInfo = RequestsDatabase.getResourceOperationStatus(nsOperationKey.getServiceId(),
+ nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateId());
+
+ // Step 2: start query
+ LOGGER.info("query ns status -> begin");
+ String url = getUrl(jobId, CommonConstant.Step.QUERY);
+ String methodType = CommonConstant.MethodType.GET;
+ // prepare restful parameters and options
+ RestfulResponse rsp = RestfulUtil.send(url, methodType, "");
+ ValidateUtil.assertObjectNotNull(rsp);
+ LOGGER.info("query ns progress response status is : {}", rsp.getStatus());
+ LOGGER.info("query ns progress response content is : {}", rsp.getResponseContent());
+ if(!HttpCode.isSucess(rsp.getStatus())) {
+ LOGGER.info("fail to query job status");
+ nsOperInfo.setErrorCode(String.valueOf(rsp.getStatus()));
+ nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR);
+ nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED);
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+ throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_QUERY_JOB_STATUS);
+ }
+ // Step 4: Process Network Service Instantiate Response
+ NsProgressStatus nsProgress = JsonUtil.unMarshal(rsp.getResponseContent(), NsProgressStatus.class);
+ ResponseDescriptor rspDesc = nsProgress.getResponseDescriptor();
+ // Step 5: update segment operation progress
+
+ nsOperInfo.setProgress(rspDesc.getProgress());
+ nsOperInfo.setStatusDescription(rspDesc.getStatusDescription());
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+
+ // Step 6: update segment operation status
+ if(RequestsDbConstant.Progress.ONE_HUNDRED.equals(rspDesc.getProgress())
+ && RequestsDbConstant.Status.FINISHED.equals(rspDesc.getStatus())) {
+ LOGGER.info("job result is succeeded, operType is {}", nsOperInfo.getOperType());
+ nsOperInfo.setErrorCode(String.valueOf(rsp.getStatus()));
+ nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED);
+
+ if(RequestsDbConstant.OperationType.CREATE.equals(nsOperInfo.getOperType())) {
+ nsOperInfo.setStatus(RequestsDbConstant.Status.FINISHED);
+ }
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+ } else if(RequestsDbConstant.Status.ERROR.equals(rspDesc.getStatus())) {
+ LOGGER.error("job result is failed, operType is {}", nsOperInfo.getOperType());
+ nsOperInfo.setErrorCode(String.valueOf(rsp.getStatus()));
+ nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED);
+ nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR);
+ RequestsDatabase.updateResOperStatus(nsOperInfo);
+ throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.JOB_STATUS_ERROR);
+ } else {
+ // do nothing
+ }
+ LOGGER.info("query ns status -> end");
+
+ return rsp;
+ }
+
+ /**
+ * get url for the operation
+ * <br>
+ *
+ * @param variable variable should be put in the url
+ * @param step step of the operation (terminate,query,delete)
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ private String getUrl(String variable, String step) {
+
+ String url = CommonConstant.STR_EMPTY;
+ String originalUrl;
+ originalUrl = (String)nfvoUrlMap.get(step);
+ url = String.format(originalUrl, variable);
+ return url;
+
+ }
+
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/CommonConstant.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/CommonConstant.java
new file mode 100644
index 0000000000..c2a9a685c9
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/CommonConstant.java
@@ -0,0 +1,197 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.constant;
+
+/**
+ * CommonConstant
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version ONAP Amsterdam Release 2017-08-28
+ */
+public class CommonConstant {
+
+ public static final String STR_EMPTY = "";
+
+ public static final String CATALOGUE_QUERY_SVC_TMPL_NODETYPE_URL = "/openoapi/catalog/v1/servicetemplates/nesting";
+
+ public static final String SDNO_CREATE_URL = "/openoapi/sdnonslcm/v1/ns";
+
+ public static final String SDNO_INSTANTIATE_URL = "/openoapi/sdnonslcm/v1/ns/%s/instantiate";
+
+ public static final String SDNO_TERMINATE_URL = "/openoapi/sdnonslcm/v1/ns/%s/terminate";
+
+ public static final String SDNO_DELETE_URL = "/openoapi/sdnonslcm/v1/ns/%s";
+
+ public static final String SDNO_QUERY_URL = "/openoapi/sdnonslcm/v1/jobs/%s";
+
+ public static final String NFVO_CREATE_URL = "/openoapi/nslcm/v1/ns";
+
+ public static final String NFVO_INSTANTIATE_URL = "/openoapi/nslcm/v1/ns/%s/instantiate";
+
+ public static final String NFVO_TERMINATE_URL = "/openoapi/nslcm/v1/ns/%s/terminate";
+
+ public static final String NFVO_DELETE_URL = "/openoapi/nslcm/v1/ns/%s";
+
+ public static final String NFVO_QUERY_URL = "/openoapi/nslcm/v1/jobs/%s";
+
+ public static final String GSO_CREATE_URL = "/openoapi/gso/v1/services";
+
+ public static final String GSO_DELETE_URL = "/openoapi/gso/v1/services/%s";
+
+ public static final String GSO_QUERY_URL = "/openoapi/gso/v1/services/%s/operations/%s";
+
+ public static final String LEFT_QUOTE_LEFT_BRACE = "\"\\{";
+
+ public static final String LEFT_BRACE = "\\{";
+
+ public static final String RIGHT_BRACE_RIGHT_QUOTE = "\\}\"";
+
+ public static final String RIGHT_BRACE = "\\}";
+
+ public static final String LEFT_QUOTE_LEFT_BRACKET = "\"\\[";
+
+ public static final String LEFT_BRACKET = "\\[";
+
+ public static final String RIGHT_BRACKET_RIGHT_QUOTE = "\\]\"";
+
+ public static final String RIGHT_BRACKET = "\\]";
+
+ /**
+ * HttpContext constant
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version ONAP Amsterdam Release 2017-08-28
+ */
+ public static class HttpContext {
+
+ public static final String CONTENT_TYPE = "Content-Type";
+
+ public static final String MEDIA_TYPE_JSON = "application/json;charset=UTF-8";
+
+ public static final String URL = "url";
+
+ public static final String METHOD_TYPE = "methodType";
+
+ public static final String IP = "ip";
+
+ public static final String PORT = "port";
+
+ public static final String RAW_DATA = "rawData";
+
+ private HttpContext() {
+
+ }
+ }
+
+ /**
+ *
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version ONAP Amsterdam Release 2017-08-28
+ */
+ public static class MethodType {
+
+ public static final String POST = "post";
+
+ public static final String DELETE = "delete";
+
+ public static final String PUT = "put";
+
+ public static final String GET = "get";
+
+ private MethodType() {
+
+ }
+ }
+
+ /**
+ *
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version ONAP Amsterdam Release 2017-08-28
+ */
+ public static class Step {
+
+ public static final String CREATE = "create";
+
+ public static final String INSTANTIATE = "instantiate";
+
+ public static final String STATUS = "status";
+
+ public static final String TERMINATE = "terminate";
+
+ public static final String QUERY = "query";
+
+ public static final String DELETE = "delete";
+
+ private Step() {
+
+ }
+
+ }
+
+
+ public static final String NSD_ID = "nsdId";
+
+ public static final String NS_NAME = "nsName";
+
+ public static final String DESC = "description";
+
+ public static final String NS_INSTANCE_ID = "nsInstanceId";
+
+ public static final String JOB_ID = "jobId";
+
+ public static final String ADDITIONAL_PARAM_FOR_NS = "additionalParamForNs";
+
+ public static final String LOCAL_HOST = "localhost";
+
+ public static class StatusDesc {
+
+ public static final String INSTANTIATE_NS_FAILED = "instantiate ns failed";
+
+ public static final String QUERY_JOB_STATUS_FAILED = "query job status failed";
+
+ public static final String TERMINATE_NS_FAILED = "terminate ns failed";
+
+ public static final String DELETE_NS_FAILED = "delete ns failed";
+
+ public static final String CREATE_NS_FAILED = "create ns failed";
+
+ private StatusDesc() {
+
+ }
+ }
+
+ private CommonConstant() {
+
+ }
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/DriverExceptionID.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/DriverExceptionID.java
new file mode 100644
index 0000000000..5df1a9f684
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/DriverExceptionID.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.constant;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ * identification of adapter exception
+ *
+ * @author
+ * @version GSO 0.5 2016/9/3
+ */
+public class DriverExceptionID {
+
+ public static final String INVALID_PARAM = "Invalid parameter";
+
+ public static final String INTERNAL_ERROR = "Internal error";
+
+ public static final String FAILED_TO_SVCTMPL_CATALOGUE = "Failed to get service template from catalogue";
+
+ public static final String INVALID_RESPONSE_FROM_INSTANTIATE_OPERATION =
+ "Invalid response from instantiate operation";
+
+ public static final String INVALID_RESPONSEE_FROM_CREATE_OPERATION = "Invalid response from create operation";
+
+ public static final String FAIL_TO_INSTANTIATE_NS = "Fail to instantiate ns";
+
+ public static final String FAIL_TO_CREATE_NS = "Fail to create ns";
+
+ public static final String FAIL_TO_CREATE_GSO_NS = "Fail to create gso ns";
+
+ public static final String INVALID_RESPONSEE_FROM_DELETE_OPERATION = "Invalid response from delete operation";
+
+ public static final String INVALID_RESPONSE_FROM_TERMINATE_OPERATION = "Invalid response from terminate operation";
+
+ public static final String FAIL_TO_DELETE_GSO_NS = "Fail to delete gso ns";
+
+ public static final String FAIL_TO_DELETE_NS = "Fail to delete ns";
+
+ public static final String FAIL_TO_TERMINATE_NS = "Fail to terminate ns";
+
+ public static final String JOB_STATUS_ERROR = "Job status error";
+
+ public static final String FAIL_TO_QUERY_JOB_STATUS = "Fail to query job status";
+
+ private DriverExceptionID() {
+
+ }
+
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/HttpCode.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/HttpCode.java
new file mode 100644
index 0000000000..b9bb78689d
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/HttpCode.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.constant;
+
+/**
+ * Constant Class.<br/>
+ * <p>
+ * Define constant for http operation.
+ * </p>
+ *
+ * @author
+ * @version ONAP Amsterdam 2016/8/4
+ */
+public class HttpCode {
+
+ /**
+ * Fail to request.
+ */
+ public static final int BAD_REQUEST = 400;
+
+ /**
+ * Inner error
+ */
+ public static final int INTERNAL_SERVER_ERROR = 500;
+
+ /**
+ * Not accept request.
+ */
+ public static final int NOT_ACCEPTABLE = 406;
+
+ /**
+ * Not found service.
+ */
+ public static final int NOT_FOUND = 404;
+
+ /**
+ * Accept request.
+ */
+ public static final int RESPOND_ACCEPTED = 202;
+
+ /**
+ * Http response is ok.
+ */
+ public static final int RESPOND_OK = 200;
+
+ public static final int CREATED_OK = 201;
+
+ /**
+ * Conflict
+ */
+ public static final int RESPOND_CONFLICT = 409;
+
+ /**
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since GSO 0.5
+ */
+ private HttpCode() {
+
+ }
+
+ /**
+ * Whether request is successful.<br/>
+ *
+ * @param httpCode response code
+ * @return true or false
+ * @since GSO 0.5
+ */
+ public static boolean isSucess(int httpCode) {
+ return httpCode / 100 == 2;
+ }
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/exceptions/ApplicationException.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/exceptions/ApplicationException.java
new file mode 100644
index 0000000000..831eaab3d3
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/exceptions/ApplicationException.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.exceptions;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+public class ApplicationException extends WebApplicationException {
+
+ /**
+ * Serial number.
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @param errorCode error status
+ * @param errorDetail error detail
+ * @since GSO 0.5
+ */
+ public ApplicationException(int errorCode, Object errorDetail) {
+ super(Response.status(errorCode).entity(errorDetail).type(MediaType.APPLICATION_JSON).build());
+ }
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/LocationConstraint.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/LocationConstraint.java
new file mode 100644
index 0000000000..b03145db20
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/LocationConstraint.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.model;
+
+import java.util.Map;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2017/2/21
+ */
+public class LocationConstraint {
+
+ /**
+ * vnf profile id
+ */
+ private String vnfProfileId;
+
+ /**
+ * location constraints: vimId
+ */
+ private Map<String, String> locationConstraints;
+
+ /**
+ * @return Returns the vnfProfileId.
+ */
+ public String getVnfProfileId() {
+ return vnfProfileId;
+ }
+
+ /**
+ * @param vnfProfileId The vnfProfileId to set.
+ */
+ public void setVnfProfileId(String vnfProfileId) {
+ this.vnfProfileId = vnfProfileId;
+ }
+
+ /**
+ * @return Returns the locationConstraints.
+ */
+ public Map<String, String> getLocationConstraints() {
+ return locationConstraints;
+ }
+
+ /**
+ * @param locationConstraints The locationConstraints to set.
+ */
+ public void setLocationConstraints(Map<String, String> locationConstraints) {
+ this.locationConstraints = locationConstraints;
+ }
+
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NSResourceInputParameter.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NSResourceInputParameter.java
new file mode 100644
index 0000000000..ca1807ce62
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NSResourceInputParameter.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.model;
+
+/**
+ * NS Create Input Parameter For VFC Adapter<br>
+ * <p>
+ * </p>
+ *
+ * @version ONAP Amsterdam Release 2017/1/7
+ */
+public class NSResourceInputParameter {
+
+ private NsOperationKey nsOperationKey;
+
+ private String subServiceName;
+
+ private String subServiceDesc;
+
+ private NsParameters nsParameters;
+
+ /**
+ * @return Returns the subServiceName.
+ */
+ public String getSubServiceName() {
+ return subServiceName;
+ }
+
+ /**
+ * @param subServiceName The subServiceName to set.
+ */
+ public void setSubServiceName(String subServiceName) {
+ this.subServiceName = subServiceName;
+ }
+
+ /**
+ * @return Returns the subServiceDesc.
+ */
+ public String getSubServiceDesc() {
+ return subServiceDesc;
+ }
+
+ /**
+ * @param subServiceDesc The subServiceDesc to set.
+ */
+ public void setSubServiceDesc(String subServiceDesc) {
+ this.subServiceDesc = subServiceDesc;
+ }
+
+ /**
+ * @return Returns the nsParameters.
+ */
+ public NsParameters getNsParameters() {
+ return nsParameters;
+ }
+
+ /**
+ * @param nsParameters The nsParameters to set.
+ */
+ public void setNsParameters(NsParameters nsParameters) {
+ this.nsParameters = nsParameters;
+ }
+
+ public NsOperationKey getNsOperationKey() {
+ return nsOperationKey;
+ }
+
+ public void setNsOperationKey(NsOperationKey nsOperationKey) {
+ this.nsOperationKey = nsOperationKey;
+ }
+
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsCreateReq.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsCreateReq.java
new file mode 100644
index 0000000000..848ecf3114
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsCreateReq.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.model;
+
+/**
+ * Network Service Request<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version ONAP Amsterdam Sep 2, 2016
+ */
+public class NsCreateReq {
+
+ String nsdId;
+
+ String nsName;
+
+ String description;
+
+ /**
+ * @return Returns the nsdId.
+ */
+ public String getNsdId() {
+ return nsdId;
+ }
+
+ /**
+ * @param nsdId The nsdId to set.
+ */
+ public void setNsdId(String nsdId) {
+ this.nsdId = nsdId;
+ }
+
+ /**
+ * @return Returns the nsName.
+ */
+ public String getNsName() {
+ return nsName;
+ }
+
+ /**
+ * @param nsName The nsName to set.
+ */
+ public void setNsName(String nsName) {
+ this.nsName = nsName;
+ }
+
+ /**
+ * @return Returns the description.
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @param description The description to set.
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsInstantiateReq.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsInstantiateReq.java
new file mode 100644
index 0000000000..6c1d209399
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsInstantiateReq.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.model;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ * request model for instatiate
+ *
+ * @author
+ * @version GSO 0.5 2016/9/3
+ */
+public class NsInstantiateReq extends NsParameters {
+
+ String nsInstanceId;
+
+ /**
+ * @return Returns the nsInstanceId.
+ */
+ public String getNsInstanceId() {
+ return nsInstanceId;
+ }
+
+ /**
+ * @param nsInstanceId The nsInstanceId to set.
+ */
+ public void setNsInstanceId(String nsInstanceId) {
+ this.nsInstanceId = nsInstanceId;
+ }
+
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsOperationKey.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsOperationKey.java
new file mode 100644
index 0000000000..2c61d805ef
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsOperationKey.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.model;
+
+
+public class NsOperationKey {
+
+ private String serviceId;
+
+ private String operationId;
+
+ private String nodeTemplateId;
+
+
+ public String getServiceId() {
+ return serviceId;
+ }
+
+
+ public void setServiceId(String serviceId) {
+ this.serviceId = serviceId;
+ }
+
+
+ public String getOperationId() {
+ return operationId;
+ }
+
+
+ public void setOperationId(String operationId) {
+ this.operationId = operationId;
+ }
+
+
+ public String getNodeTemplateId() {
+ return nodeTemplateId;
+ }
+
+
+ public void setNodeTemplateId(String nodeTemplateId) {
+ this.nodeTemplateId = nodeTemplateId;
+ }
+
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsParameters.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsParameters.java
new file mode 100644
index 0000000000..ecb77cf762
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsParameters.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.model;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2017/2/21
+ */
+public class NsParameters {
+
+ private List<LocationConstraint> locationConstraints;
+
+ private Map<String, String> additionalParamForNs;
+
+ /**
+ * @return Returns the locationConstraints.
+ */
+ public List<LocationConstraint> getLocationConstraints() {
+ return locationConstraints;
+ }
+
+ /**
+ * @param locationConstraints The locationConstraints to set.
+ */
+ public void setLocationConstraints(List<LocationConstraint> locationConstraints) {
+ this.locationConstraints = locationConstraints;
+ }
+
+ /**
+ * @return Returns the additionalParamForNs.
+ */
+ public Map<String, String> getAdditionalParamForNs() {
+ return additionalParamForNs;
+ }
+
+ /**
+ * @param additionalParamForNs The additionalParamForNs to set.
+ */
+ public void setAdditionalParamForNs(Map<String, String> additionalParamForNs) {
+ this.additionalParamForNs = additionalParamForNs;
+ }
+
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsProgressStatus.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsProgressStatus.java
new file mode 100644
index 0000000000..414c1f19b8
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/NsProgressStatus.java
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.model;
+
+import java.util.List;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ * response model of query operation status
+ *
+ * @author
+ * @version GSO 0.5 2016/9/3
+ */
+public class NsProgressStatus {
+
+ String jobId;
+
+ ResponseDescriptor responseDescriptor;
+
+ List<ResponseDescriptor> responseHistoryList;
+
+ /**
+ * @return Returns the jobId.
+ */
+ public String getJobId() {
+ return jobId;
+ }
+
+ /**
+ * @param jobId The jobId to set.
+ */
+ public void setJobId(String jobId) {
+ this.jobId = jobId;
+ }
+
+ /**
+ * @return Returns the responseDescriptor.
+ */
+ public ResponseDescriptor getResponseDescriptor() {
+ return responseDescriptor;
+ }
+
+ /**
+ * @param responseDescriptor The responseDescriptor to set.
+ */
+ public void setResponseDescriptor(ResponseDescriptor responseDescriptor) {
+ this.responseDescriptor = responseDescriptor;
+ }
+
+ /**
+ * @return Returns the responseHistoryList.
+ */
+ public List<ResponseDescriptor> getResponseHistoryList() {
+ return responseHistoryList;
+ }
+
+ /**
+ * @param responseHistoryList The responseHistoryList to set.
+ */
+ public void setResponseHistoryList(List<ResponseDescriptor> responseHistoryList) {
+ this.responseHistoryList = responseHistoryList;
+ }
+
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/ResponseDescriptor.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/ResponseDescriptor.java
new file mode 100644
index 0000000000..6c40c0df32
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/ResponseDescriptor.java
@@ -0,0 +1,112 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.model;
+/**
+ * <br>
+ * <p>
+ * </p>
+ * response model of query operation status
+ *
+ * @author
+ * @version SDNO 0.5 September 3, 2016
+ */
+public class ResponseDescriptor {
+
+ String status;
+
+ String progress;
+
+ String statusDescription;
+
+ Integer errorCode;
+
+ Integer responseId;
+
+ /**
+ * @return Returns the status.
+ */
+ public String getStatus() {
+ return status;
+ }
+
+ /**
+ * @param status The status to set.
+ */
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ /**
+ * @return Returns the progress.
+ */
+ public String getProgress() {
+ return progress;
+ }
+
+ /**
+ * @param progress The progress to set.
+ */
+ public void setProgress(String progress) {
+ this.progress = progress;
+ }
+
+ /**
+ * @return Returns the statusDescription.
+ */
+ public String getStatusDescription() {
+ return statusDescription;
+ }
+
+ /**
+ * @param statusDescription The statusDescription to set.
+ */
+ public void setStatusDescription(String statusDescription) {
+ this.statusDescription = statusDescription;
+ }
+
+ /**
+ * @return Returns the errorCode.
+ */
+ public Integer getErrorCode() {
+ return errorCode;
+ }
+
+ /**
+ * @param errorCode The errorCode to set.
+ */
+ public void setErrorCode(Integer errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ /**
+ * @return Returns the responseId.
+ */
+ public Integer getResponseId() {
+ return responseId;
+ }
+
+ /**
+ * @param responseId The responseId to set.
+ */
+ public void setResponseId(Integer responseId) {
+ this.responseId = responseId;
+ }
+
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/RestfulResponse.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/RestfulResponse.java
new file mode 100644
index 0000000000..510f61305c
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/model/RestfulResponse.java
@@ -0,0 +1,88 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.model;
+
+import java.util.Map;
+
+public class RestfulResponse {
+
+ private String responseContent;
+
+ private int status;
+
+ private Map<String, String> respHeaderMap;
+
+ public RestfulResponse() {
+ this.status = -1;
+
+ this.respHeaderMap = null;
+ }
+
+ public int getStatus() {
+ return this.status;
+ }
+
+ public void setStatus(int status) {
+ this.status = status;
+ }
+
+ public Map<String, String> getRespHeaderMap() {
+ return this.respHeaderMap;
+ }
+
+ public void setRespHeaderMap(Map<String, String> header) {
+ this.respHeaderMap = header;
+ }
+
+ public int getRespHeaderInt(String key) {
+ if(this.respHeaderMap != null) {
+ String result = (String)this.respHeaderMap.get(key);
+ if(result != null) {
+ return Integer.parseInt(result);
+ }
+ }
+ return -1;
+ }
+
+ public long getRespHeaderLong(String key) {
+ if(this.respHeaderMap != null) {
+ String result = (String)this.respHeaderMap.get(key);
+ if(result != null) {
+ return Long.parseLong(result);
+ }
+ }
+ return -1L;
+ }
+
+ public String getRespHeaderStr(String key) {
+ if(this.respHeaderMap != null) {
+ return ((String)this.respHeaderMap.get(key));
+ }
+ return null;
+ }
+
+ public String getResponseContent() {
+ return this.responseContent;
+ }
+
+ public void setResponseContent(String responseString) {
+ this.responseContent = responseString;
+ }
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/JsonUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/JsonUtil.java
new file mode 100644
index 0000000000..579c607f5b
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/JsonUtil.java
@@ -0,0 +1,129 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.util;
+
+import java.io.IOException;
+
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+import org.codehaus.jackson.type.TypeReference;
+import org.openecomp.mso.adapters.vfc.constant.HttpCode;
+import org.openecomp.mso.adapters.vfc.exceptions.ApplicationException;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoLogger;
+
+
+/**
+ * Interface for json analyzing.<br/>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version GSO 0.5 2016/9/1
+ */
+public class JsonUtil {
+
+ /**
+ * Log service
+ */
+ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
+
+ /**
+ * Mapper.
+ */
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+
+ static {
+ MAPPER.setDeserializationConfig(MAPPER.getDeserializationConfig()
+ .without(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES));
+ MAPPER.setSerializationInclusion(Inclusion.NON_NULL);
+ }
+
+ /**
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since GSO 0.5
+ */
+ private JsonUtil() {
+
+ }
+
+ /**
+ * Parse the string in form of json.<br/>
+ *
+ * @param jsonstr json string.
+ * @param type that convert json string to
+ * @return model object
+ * @since GSO 0.5
+ */
+ public static <T> T unMarshal(String jsonstr, Class<T> type) {
+ try {
+ return MAPPER.readValue(jsonstr, type);
+ } catch(IOException e) {
+ LOGGER.error(MessageEnum.RA_NS_EXC, "","", MsoLogger.ErrorCode.BusinessProcesssError, "fail to unMarshal json", e);
+ throw new ApplicationException(HttpCode.BAD_REQUEST, "fail to unMarshal json");
+ }
+ }
+
+ /**
+ * Parse the string in form of json.<br/>
+ *
+ * @param jsonstr json string.
+ * @param type that convert json string to
+ * @return model object
+ * @since GSO 0.5
+ */
+ public static <T> T unMarshal(String jsonstr, TypeReference<T> type) {
+ try {
+ return MAPPER.readValue(jsonstr, type);
+ } catch(IOException e) {
+ LOGGER.error(MessageEnum.RA_NS_EXC, "","", MsoLogger.ErrorCode.BusinessProcesssError, "fail to unMarshal json", e);
+ throw new ApplicationException(HttpCode.BAD_REQUEST, "fail to unMarshal json");
+ }
+ }
+
+ /**
+ * Convert object to json string.<br/>
+ *
+ * @param srcObj data object
+ * @return json string
+ * @since GSO 0.5
+ */
+ public static String marshal(Object srcObj) {
+ try {
+ return MAPPER.writeValueAsString(srcObj);
+ } catch(IOException e) {
+ LOGGER.error(MessageEnum.RA_NS_EXC, "","", MsoLogger.ErrorCode.BusinessProcesssError, "fail to marshal json", e);
+ throw new ApplicationException(HttpCode.BAD_REQUEST, "srcObj marshal failed!");
+ }
+ }
+
+ /**
+ * Get mapper.<br/>
+ *
+ * @return mapper
+ * @since GSO 0.5
+ */
+ public static ObjectMapper getMapper() {
+ return MAPPER;
+ }
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/RestfulUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/RestfulUtil.java
new file mode 100644
index 0000000000..95025afd10
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/RestfulUtil.java
@@ -0,0 +1,229 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.SocketTimeoutException;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
+import org.openecomp.mso.adapters.vfc.model.RestfulResponse;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoAlarmLogger;
+import org.openecomp.mso.logger.MsoLogger;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ * utility to invoke restclient
+ *
+ * @author
+ * @version GSO 0.5 2016/9/3
+ */
+public class RestfulUtil {
+
+ /**
+ * Log service
+ */
+ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
+
+ private static final MsoAlarmLogger ALARMLOGGER = new MsoAlarmLogger();
+
+ private static final int DEFAULT_TIME_OUT = 60;
+
+ private RestfulUtil() {
+
+ }
+
+ public static RestfulResponse send(String url, String methodType, String content) {
+ LOGGER.info(MessageEnum.RA_NS_EXC, url, "VFC", "");
+ LOGGER.debug("VFC Request Body:\n" + content);
+
+ HttpRequestBase method = null;
+ HttpResponse httpResponse = null;
+
+ try {
+ int timeout = DEFAULT_TIME_OUT;
+
+ RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout)
+ .setConnectionRequestTimeout(timeout).build();
+
+ HttpClient client = HttpClientBuilder.create().build();
+
+ if("POST".equals(methodType)) {
+ HttpPost httpPost = new HttpPost(url);
+ httpPost.setConfig(requestConfig);
+ httpPost.setEntity(new StringEntity(content, ContentType.APPLICATION_JSON));
+ method = httpPost;
+ } else if("PUT".equals(methodType)) {
+ HttpPut httpPut = new HttpPut(url);
+ httpPut.setConfig(requestConfig);
+ httpPut.setEntity(new StringEntity(content, ContentType.APPLICATION_JSON));
+ method = httpPut;
+ } else if("GET".equals(methodType)) {
+ HttpGet httpGet = new HttpGet(url);
+ httpGet.setConfig(requestConfig);
+ method = httpGet;
+ } else if("DELETE".equals(methodType)) {
+ HttpDelete httpDelete = new HttpDelete(url);
+ httpDelete.setConfig(requestConfig);
+ method = httpDelete;
+ }
+
+ // now VFC have no auth
+ // String userCredentials =
+ // SDNCAdapterProperties.getEncryptedProperty(Constants.SDNC_AUTH_PROP,
+ // Constants.DEFAULT_SDNC_AUTH, Constants.ENCRYPTION_KEY);
+ // String authorization = "Basic " +
+ // DatatypeConverter.printBase64Binary(userCredentials.getBytes());
+ // method.setHeader("Authorization", authorization);
+
+ httpResponse = client.execute(method);
+
+ String responseContent = null;
+ if(httpResponse.getEntity() != null) {
+ responseContent = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
+ }
+
+ int statusCode = httpResponse.getStatusLine().getStatusCode();
+ String statusMessage = httpResponse.getStatusLine().getReasonPhrase();
+
+ LOGGER.debug("VFC Response: " + statusCode + " " + statusMessage
+ + (responseContent == null ? "" : System.lineSeparator() + responseContent));
+
+ if(httpResponse.getStatusLine().getStatusCode() >= 300) {
+ String errMsg = "VFC returned " + statusCode + " " + statusMessage;
+ logError(errMsg);
+ return CreateResponse(statusCode, errMsg);
+ }
+
+ httpResponse = null;
+
+ method.reset();
+ method = null;
+
+ LOGGER.info(MessageEnum.RA_RESPONSE_FROM_SDNC, responseContent, "SDNC", "");
+ return CreateResponse(statusCode, responseContent);
+
+ } catch(SocketTimeoutException e) {
+ String errMsg = "Request to SDNC timed out";
+ logError(errMsg, e);
+ return CreateResponse(HttpURLConnection.HTTP_CLIENT_TIMEOUT, errMsg);
+
+ } catch(ConnectTimeoutException e) {
+ String errMsg = "Request to SDNC timed out";
+ logError(errMsg, e);
+ return CreateResponse(HttpURLConnection.HTTP_CLIENT_TIMEOUT, errMsg);
+
+ } catch(Exception e) {
+ String errMsg = "Error processing request to SDNC";
+ logError(errMsg, e);
+ return CreateResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, errMsg);
+
+ } finally {
+ if(httpResponse != null) {
+ try {
+ EntityUtils.consume(httpResponse.getEntity());
+ } catch(Exception e) {
+ // Ignore
+ }
+ }
+
+ if(method != null) {
+ try {
+ method.reset();
+ } catch(Exception e) {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ private static void logError(String errMsg, Throwable t) {
+ LOGGER.error(MessageEnum.RA_NS_EXC, "VFC", "", MsoLogger.ErrorCode.AvailabilityError, errMsg, t);
+ ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, errMsg);
+ }
+
+ private static void logError(String errMsg) {
+ LOGGER.error(MessageEnum.RA_NS_EXC, "VFC", "", MsoLogger.ErrorCode.AvailabilityError, errMsg);
+ ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, errMsg);
+ }
+
+ private static RestfulResponse CreateResponse(int statusCode, String content) {
+ RestfulResponse rsp = new RestfulResponse();
+ rsp.setStatus(statusCode);
+ rsp.setResponseContent(content);
+ return rsp;
+ }
+
+ /**
+ * @param request
+ * @return
+ */
+ public static String getRequestBody(HttpServletRequest request) {
+ String body = null;
+ StringBuilder stringBuilder = new StringBuilder();
+ BufferedReader bufferedReader = null;
+ try {
+ InputStream inputStream = request.getInputStream();
+ if(inputStream != null) {
+ bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
+ char[] charBuffer = new char[128];
+ int bytesRead = -1;
+ while((bytesRead = bufferedReader.read(charBuffer)) > 0)
+ stringBuilder.append(charBuffer, 0, bytesRead);
+ }
+ } catch(IOException ex) {
+ LOGGER.error(MessageEnum.RA_NS_EXC, "VFC", "", MsoLogger.ErrorCode.AvailabilityError,
+ "read inputStream buffer catch exception:", ex);
+ } finally {
+ if(bufferedReader != null) {
+ try {
+ bufferedReader.close();
+ } catch(IOException ex) {
+ LOGGER.error(MessageEnum.RA_NS_EXC, "VFC", "", MsoLogger.ErrorCode.AvailabilityError,
+ "close buffer catch exception:", ex);
+ }
+ }
+ }
+
+ body = stringBuilder.toString();
+ return body;
+ }
+
+}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/ValidateUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/ValidateUtil.java
new file mode 100644
index 0000000000..1d8549c892
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/ValidateUtil.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc.util;
+
+import org.openecomp.mso.adapters.vfc.constant.HttpCode;
+import org.openecomp.mso.adapters.vfc.exceptions.ApplicationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ValidateUtil {
+
+ /**
+ * Log server.
+ */
+ private static final Logger LOGGER = LoggerFactory.getLogger(ValidateUtil.class);
+
+ /**
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since GSO 0.5
+ */
+ private ValidateUtil() {
+
+ }
+
+ /**
+ * Assert String parameter.<br/>
+ *
+ * @param paramValue parameter data
+ * @param name of parameter
+ * @since GSO 0.5
+ */
+ public static void assertStringNotNull(String paramValue, String paramName) {
+ if(null != paramValue && !paramValue.isEmpty()) {
+ return;
+ }
+
+ LOGGER.error(paramName + ": Parameter is null or empty.");
+ throw new ApplicationException(HttpCode.BAD_REQUEST, paramName + ": Invalid parameter.");
+ }
+
+ /**
+ * Assert object is null.<br/>
+ *
+ * @param object data object
+ * @since GSO 0.5
+ */
+ public static void assertObjectNotNull(Object object) {
+ if(null == object) {
+ LOGGER.error("Object is null.");
+ throw new ApplicationException(HttpCode.BAD_REQUEST, "Object is null.");
+ }
+
+ }
+
+ /**
+ * <br>
+ *
+ * @param str
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ public static boolean isStrEmpty(String str) {
+ return null == str || str.isEmpty();
+ }
+}
diff --git a/adapters/mso-vfc-adapter/src/test/java/org/openecomp/mso/adapters/vfc/VfcAdapterTest.java b/adapters/mso-vfc-adapter/src/test/java/org/openecomp/mso/adapters/vfc/VfcAdapterTest.java
new file mode 100644
index 0000000000..3b43a15e50
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/test/java/org/openecomp/mso/adapters/vfc/VfcAdapterTest.java
@@ -0,0 +1,146 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.vfc;
+
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.mockito.Mock;
+import org.openecomp.mso.adapters.vfc.util.RestfulUtil;
+import org.openecomp.mso.adapters.vfc.util.ValidateUtil;
+import org.openecomp.mso.db.catalog.CatalogDatabase;
+
+import mockit.MockUp;
+
+/**
+ * VF-C adapter UT
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version ONAP Amsterdam Release 2017-08-31
+ */
+public class VfcAdapterTest {
+
+ @Mock
+ private static CatalogDatabase db;
+
+ /**
+ * File path
+ */
+ private static final String FILE_PATH = "src/test/resources/json/";
+
+ @Test
+ public void createTest () {
+// // get request
+// mockGetRequestBody(FILE_PATH + "createNfvoNsReq.json");
+// // get service template
+// ServiceTemplate svcTmpl = new ServiceTemplate();
+// svcTmpl.setId("id");
+// svcTmpl.setServiceTemplateId("svcTmplId");
+// new MockUp<CatalogProxyImpl>() {
+// @Mock
+// public ServiceTemplate getSvcTmplByNodeType(String nodeType, String domainHost){
+// return svcTmpl;
+// }
+// };
+// // get response
+// RestfulResponse restRsp = new RestfulResponse();
+// restRsp.setStatus(HttpStatus.SC_OK);
+// restRsp.setResponseJson(getJsonString(FILE_PATH + "createNfvoNsRsp.json"));
+// mockGetRestfulRsp(restRsp);
+// // insert data
+// new MockUp<ServiceSegmentDaoImpl>() {
+// @Mock
+// public void insertSegment(ServiceSegmentModel serviceSegment) {
+// // do nothing
+// }
+// @Mock
+// public void insertSegmentOper(ServiceSegmentOperation svcSegmentOper) {
+// // do nothing
+// }
+// };
+// Response rsp = impl.createNfvoNs(servletReq);
+// JSONObject obj = JSONObject.fromObject(rsp.getEntity());
+// Assert.assertEquals(null, "1", obj.getString("nsInstanceId"));
+ }
+
+ @Test
+ public void deleteTest () {
+
+ }
+
+ @Test
+ public void instantiateTest () {
+
+ }
+
+ @Test
+ public void terminateTest () {
+
+ }
+
+ @Test
+ public void queryJobTest () {
+
+ }
+
+ /**
+ * Mock to get request body.<br/>
+ *
+ * @param file json file path.
+ * @since GSO 0.5
+ */
+ private void mockGetRequestBody(final String file) {
+ new MockUp<RestfulUtil>() {
+
+// @Mock
+// public String getRequestBody(HttpServletRequest request) {
+// return getJsonString(file);
+// }
+ };
+ }
+
+ /**
+ * Get json string from file.<br/>
+ *
+ * @param file the path of file
+ * @return json string
+ * @throws IOException when fail to read
+ * @since GSO 0.5
+ */
+ private String getJsonString(final String file) {
+ if(ValidateUtil.isStrEmpty(file)) {
+ return "";
+ }
+
+ String json = null;
+// try {
+// FileInputStream fileStream = new FileInputStream(new File(file));
+// json = IOUtils.toString(fileStream);
+// } catch(Exception e) {
+// Assert.fail(e.getMessage());
+// }
+
+ return json;
+ }
+}
diff --git a/adapters/mso-vfc-adapter/src/test/resources/logback-test.xml b/adapters/mso-vfc-adapter/src/test/resources/logback-test.xml
new file mode 100644
index 0000000000..26a86877bd
--- /dev/null
+++ b/adapters/mso-vfc-adapter/src/test/resources/logback-test.xml
@@ -0,0 +1,48 @@
+<!--
+ ============LICENSE_START=======================================================
+ ONAP SO
+ ================================================================================
+ Copyright (C) 2017 Huawei 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=========================================================
+ -->
+
+<configuration >
+
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{MM/dd-HH:mm:ss.SSS}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}||%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}||%X{Timer}|%msg%n</pattern>
+ </encoder>
+ </appender>
+
+
+ <logger name="com.att.eelf.audit" level="info" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="com.att.eelf.metrics" level="info" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="com.att.eelf.error" level="trace" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <root level="info">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+
+</configuration>