summaryrefslogtreecommitdiffstats
path: root/ResmanagementService/service/src/main
diff options
context:
space:
mode:
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>2017-09-27 14:33:21 +0530
committersubhash kumar singh <subhash.kumar.singh@huawei.com>2017-09-27 16:05:08 +0530
commitc5f00be504277c8cb0faf9a40e2290c137e08f02 (patch)
tree5b1ef59ebd1c0c7000f5cb9afac73d38494b2bdc /ResmanagementService/service/src/main
parent2a45991d2f400a21ce853db6a29dd587abf82cb2 (diff)
Create customer and ser-subscription for VFC
Create customer and service-subscription for VFC to store service-instance in it. Issue-ID: VFC-462 Change-Id: I23a192dcc0e43098cb49341d07faf211bb945c90 Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
Diffstat (limited to 'ResmanagementService/service/src/main')
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java4
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpsRest.java110
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/listener/AaiNamespaceInitializer.java66
-rw-r--r--ResmanagementService/service/src/main/webapp/WEB-INF/web.xml9
4 files changed, 136 insertions, 53 deletions
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java
index 570598a..2ff3b9c 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java
@@ -87,6 +87,10 @@ public class Constant {
public static final int REPEAT_REG_TIME = 60 * 1000;
+ public static String VFC_CUSTOMER_ID = "vfc";
+
+ public static String VFC_SERVICE_SUBSCRIPTION_ID = "vfc-subsription";
+
private Constant() {
// private constants
}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpsRest.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpsRest.java
index d99e515..d65bbc4 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpsRest.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpsRest.java
@@ -16,6 +16,8 @@
package org.onap.vfc.nfvo.resmanagement.common.util.restclient;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient;
@@ -23,25 +25,10 @@ import org.eclipse.jetty.client.HttpExchange;
import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
-import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil;
import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.HttpBaseRest;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestHttpContentExchange;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulAsyncCallback;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulOptions;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulParametes;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulResponse;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.ws.rs.core.Request;
-import javax.ws.rs.core.UriBuilder;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.Map;
-
public class HttpsRest extends HttpBaseRest {
private static final Logger LOG = LoggerFactory.getLogger(HttpsRest.class);
@@ -55,7 +42,7 @@ public class HttpsRest extends HttpBaseRest {
client.setTimeout(30000); // 30 seconds timeout; if no server reply, the request expires
try {
client.start();
- } catch (Exception e) {
+ } catch(Exception e) {
e.printStackTrace();
}
}
@@ -66,7 +53,8 @@ public class HttpsRest extends HttpBaseRest {
}
@Override
- public RestfulResponse head(String servicePath, RestfulParametes restParametes, RestfulOptions options) throws ServiceException {
+ public RestfulResponse head(String servicePath, RestfulParametes restParametes, RestfulOptions options)
+ throws ServiceException {
return null;
}
@@ -76,12 +64,14 @@ public class HttpsRest extends HttpBaseRest {
}
@Override
- public void asyncGet(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncGet(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
+ throws ServiceException {
}
@Override
- public void asyncGet(String servicePath, RestfulParametes restParametes, RestfulOptions options, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncGet(String servicePath, RestfulParametes restParametes, RestfulOptions options,
+ RestfulAsyncCallback callback) throws ServiceException {
}
@@ -91,12 +81,14 @@ public class HttpsRest extends HttpBaseRest {
}
@Override
- public void asyncPut(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncPut(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
+ throws ServiceException {
}
@Override
- public void asyncPut(String servicePath, RestfulParametes restParametes, RestfulOptions options, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncPut(String servicePath, RestfulParametes restParametes, RestfulOptions options,
+ RestfulAsyncCallback callback) throws ServiceException {
}
@@ -106,17 +98,20 @@ public class HttpsRest extends HttpBaseRest {
}
@Override
- public RestfulResponse post(String servicePath, RestfulParametes restParametes, RestfulOptions options) throws ServiceException {
+ public RestfulResponse post(String servicePath, RestfulParametes restParametes, RestfulOptions options)
+ throws ServiceException {
return null;
}
@Override
- public void asyncPost(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncPost(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
+ throws ServiceException {
}
@Override
- public void asyncPost(String servicePath, RestfulParametes restParametes, RestfulOptions options, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncPost(String servicePath, RestfulParametes restParametes, RestfulOptions options,
+ RestfulAsyncCallback callback) throws ServiceException {
}
@@ -126,12 +121,14 @@ public class HttpsRest extends HttpBaseRest {
}
@Override
- public void asyncDelete(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncDelete(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
+ throws ServiceException {
}
@Override
- public void asyncDelete(String servicePath, RestfulParametes restParametes, RestfulOptions options, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncDelete(String servicePath, RestfulParametes restParametes, RestfulOptions options,
+ RestfulAsyncCallback callback) throws ServiceException {
}
@@ -141,41 +138,46 @@ public class HttpsRest extends HttpBaseRest {
}
@Override
- public RestfulResponse patch(String servicePath, RestfulParametes restParametes, RestfulOptions options) throws ServiceException {
+ public RestfulResponse patch(String servicePath, RestfulParametes restParametes, RestfulOptions options)
+ throws ServiceException {
return null;
}
@Override
- public void asyncPatch(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncPatch(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
+ throws ServiceException {
}
@Override
- public void asyncPatch(String servicePath, RestfulParametes restParametes, RestfulOptions options, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncPatch(String servicePath, RestfulParametes restParametes, RestfulOptions options,
+ RestfulAsyncCallback callback) throws ServiceException {
}
@Override
- public RestfulResponse get(String servicePath, RestfulParametes restParametes, RestfulOptions option) throws ServiceException {
+ public RestfulResponse get(String servicePath, RestfulParametes restParametes, RestfulOptions option)
+ throws ServiceException {
ContentExchange exchange = new ContentExchange(true);
exchange.setURL(servicePath);
exchange.setMethod("GET");
- restParametes.getHeaderMap().entrySet().stream().forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
+ restParametes.getHeaderMap().entrySet().stream()
+ .forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
try {
client.send(exchange);
- } catch (IOException e) {
+ } catch(IOException e) {
e.printStackTrace();
}
try {
int exchangeState = exchange.waitForDone();
- if (exchangeState == HttpExchange.STATUS_COMPLETED) {
+ if(exchangeState == HttpExchange.STATUS_COMPLETED) {
String res = exchange.getResponseContent();
LOG.info(res);
RestfulResponse restfulResponse = new RestfulResponse();
restfulResponse.setResponseJson(exchange.getResponseContent());
- restfulResponse.setStatus(exchange.getStatus());
+ restfulResponse.setStatus(exchange.getResponseStatus());
return restfulResponse;
} else if(exchangeState == HttpExchange.STATUS_EXCEPTED) {
throw new ServiceException(
@@ -184,38 +186,40 @@ public class HttpsRest extends HttpBaseRest {
throw new ServiceException(
"request is expierd: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXPIRED));
}
- } catch (InterruptedException e) {
+ } catch(InterruptedException e) {
e.printStackTrace();
- } catch (UnsupportedEncodingException e) {
+ } catch(UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
@Override
- public RestfulResponse put(String servicePath, RestfulParametes restParametes, RestfulOptions options) throws ServiceException {
+ public RestfulResponse put(String servicePath, RestfulParametes restParametes, RestfulOptions options)
+ throws ServiceException {
ContentExchange exchange = new ContentExchange(true);
exchange.setURL(servicePath);
exchange.setMethod("PUT");
exchange.setRequestContent(new ByteArrayBuffer(restParametes.getRawData()));
- restParametes.getHeaderMap().entrySet().stream().forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
+ restParametes.getHeaderMap().entrySet().stream()
+ .forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
try {
client.send(exchange);
- } catch (IOException e) {
+ } catch(IOException e) {
e.printStackTrace();
}
try {
int exchangeState = exchange.waitForDone();
- if (exchangeState == HttpExchange.STATUS_COMPLETED) {
+ if(exchangeState == HttpExchange.STATUS_COMPLETED) {
String res = exchange.getResponseContent();
LOG.info(res);
RestfulResponse restfulResponse = new RestfulResponse();
restfulResponse.setResponseJson(exchange.getResponseContent());
- restfulResponse.setStatus(exchange.getStatus());
+ restfulResponse.setStatus(exchange.getResponseStatus());
return restfulResponse;
} else if(exchangeState == HttpExchange.STATUS_EXCEPTED) {
throw new ServiceException(
@@ -224,46 +228,48 @@ public class HttpsRest extends HttpBaseRest {
throw new ServiceException(
"request is expierd: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXPIRED));
}
- } catch (InterruptedException e) {
+ } catch(InterruptedException e) {
e.printStackTrace();
- } catch (UnsupportedEncodingException e) {
+ } catch(UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
@Override
- public RestfulResponse delete(String servicePath, RestfulParametes restParametes, RestfulOptions options) throws ServiceException {
+ public RestfulResponse delete(String servicePath, RestfulParametes restParametes, RestfulOptions options)
+ throws ServiceException {
ContentExchange exchange = new ContentExchange(true);
String encodeParams = RequestUtil.encodeParams(restParametes);
- if (encodeParams.isEmpty()) {
+ if(encodeParams.isEmpty()) {
exchange.setURL(servicePath);
} else {
exchange.setURL(servicePath + "?" + encodeParams);
}
exchange.setMethod("DELETE");
- if (restParametes.getRawData() != null) {
+ if(restParametes.getRawData() != null) {
exchange.setRequestContent(new ByteArrayBuffer(restParametes.getRawData()));
}
- restParametes.getHeaderMap().entrySet().stream().forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
+ restParametes.getHeaderMap().entrySet().stream()
+ .forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
try {
client.send(exchange);
- } catch (IOException e) {
+ } catch(IOException e) {
e.printStackTrace();
}
try {
int exchangeState = exchange.waitForDone();
- if (exchangeState == HttpExchange.STATUS_COMPLETED) {
+ if(exchangeState == HttpExchange.STATUS_COMPLETED) {
String res = exchange.getResponseContent();
LOG.info(res);
RestfulResponse restfulResponse = new RestfulResponse();
restfulResponse.setResponseJson(exchange.getResponseContent());
- restfulResponse.setStatus(exchange.getStatus());
+ restfulResponse.setStatus(exchange.getResponseStatus());
return restfulResponse;
} else if(exchangeState == HttpExchange.STATUS_EXCEPTED) {
throw new ServiceException(
@@ -272,9 +278,9 @@ public class HttpsRest extends HttpBaseRest {
throw new ServiceException(
"request is expierd: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXPIRED));
}
- } catch (InterruptedException e) {
+ } catch(InterruptedException e) {
e.printStackTrace();
- } catch (UnsupportedEncodingException e) {
+ } catch(UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/listener/AaiNamespaceInitializer.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/listener/AaiNamespaceInitializer.java
new file mode 100644
index 0000000..a6ac37d
--- /dev/null
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/listener/AaiNamespaceInitializer.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+package org.onap.vfc.nfvo.resmanagement.service.listener;
+
+import static org.onap.vfc.nfvo.resmanagement.common.constant.Constant.VFC_CUSTOMER_ID;
+import static org.onap.vfc.nfvo.resmanagement.common.constant.Constant.VFC_SERVICE_SUBSCRIPTION_ID;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil;
+import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulParametes;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulResponse;
+
+public class AaiNamespaceInitializer implements ServletContextListener {
+
+ @Override
+ public void contextDestroyed(ServletContextEvent arg0) {
+ }
+
+ @Override
+ public void contextInitialized(ServletContextEvent arg0) {
+ createCustomer();
+ createServiceSubscription();
+ }
+
+ private int createCustomer() {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+ restfulParametes.setRawData("{\"global-customer-id\": \"" + VFC_CUSTOMER_ID + "\"," + "\"subscriber-name\": \""
+ + VFC_CUSTOMER_ID + "\"," + "\"subscriber-type\": \"" + VFC_CUSTOMER_ID + "\"}");
+
+ RestfulResponse response = RestfulUtil.getRestfulResponse(
+ "https://192.168.17.24:8443/aai/v11/business/customers/customer/" + VFC_CUSTOMER_ID, restfulParametes,
+ "put");
+ return response.getStatus();
+ }
+
+ private int createServiceSubscription() {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+ restfulParametes.setRawData("{\"service-type\": \"" + VFC_SERVICE_SUBSCRIPTION_ID + "\"}");
+
+ RestfulResponse response = RestfulUtil.getRestfulResponse(
+ "https://192.168.17.24:8443/aai/v11/business/customers/customer/" + VFC_CUSTOMER_ID
+ + "/service-subscriptions/service-subscription/" + VFC_SERVICE_SUBSCRIPTION_ID,
+ restfulParametes, "put");
+ return response.getStatus();
+ }
+
+}
diff --git a/ResmanagementService/service/src/main/webapp/WEB-INF/web.xml b/ResmanagementService/service/src/main/webapp/WEB-INF/web.xml
index eb4ff01..36a989f 100644
--- a/ResmanagementService/service/src/main/webapp/WEB-INF/web.xml
+++ b/ResmanagementService/service/src/main/webapp/WEB-INF/web.xml
@@ -20,7 +20,14 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ <listener-class>
+ org.springframework.web.context.ContextLoaderListener
+ </listener-class>
+ </listener>
+ <listener>
+ <listener-class>
+ org.onap.vfc.nfvo.resmanagement.service.listener.AaiNamespaceInitializer
+ </listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>