summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java33
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java45
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpsRest.java282
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/RestfulFactory.java11
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/VnfAaiDaoImpl.java101
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java43
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfServiceImpl.java8
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java6
-rw-r--r--ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml9
9 files changed, 512 insertions, 26 deletions
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java
index d783ea8..41ce7db 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java
@@ -68,7 +68,9 @@ public class RestfulUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(RestfulUtil.class);
- private static final Restful REST_CLIENT = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP);
+ private static final Restful REST_CLIENT_HTTP = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP);
+
+ private static final Restful REST_CLIENT_HTTPS = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTPS);
private RestfulUtil() {
}
@@ -202,16 +204,17 @@ public class RestfulUtil {
String type) {
RestfulResponse rsp = new RestfulResponse();
try {
+ Restful restClient = url.startsWith("https") ? REST_CLIENT_HTTPS : REST_CLIENT_HTTP;
- if(REST_CLIENT != null) {
+ if(restClient != null) {
if(TYPE_GET.equals(type)) {
- rsp = REST_CLIENT.get(url, restParametes, opt);
+ rsp = restClient.get(url, restParametes, opt);
} else if(TYPE_POST.equals(type)) {
- rsp = REST_CLIENT.post(url, restParametes, opt);
+ rsp = restClient.post(url, restParametes, opt);
} else if(TYPE_PUT.equals(type)) {
- rsp = REST_CLIENT.put(url, restParametes, opt);
+ rsp = restClient.put(url, restParametes, opt);
} else if(TYPE_DEL.equals(type)) {
- rsp = REST_CLIENT.delete(url, restParametes, opt);
+ rsp = restClient.delete(url, restParametes, opt);
}
}
} catch(ServiceException e) {
@@ -231,7 +234,7 @@ public class RestfulUtil {
*/
public static RestfulResponse getRestRes(String methodName, Object... objects) {
try {
- if(objects == null || REST_CLIENT == null) {
+ if(objects == null || REST_CLIENT_HTTP == null) {
return null;
}
@@ -245,8 +248,8 @@ public class RestfulUtil {
Class<?> rtType = methodName.startsWith("async") ? void.class : RestfulResponse.class;
MethodType mt = MethodType.methodType(rtType, classes);
- Object result = MethodHandles.lookup().findVirtual(REST_CLIENT.getClass(), methodName, mt)
- .bindTo(REST_CLIENT).invokeWithArguments(objects);
+ Object result = MethodHandles.lookup().findVirtual(REST_CLIENT_HTTP.getClass(), methodName, mt)
+ .bindTo(REST_CLIENT_HTTP).invokeWithArguments(objects);
if(result != null) {
return (RestfulResponse)result;
}
@@ -279,8 +282,7 @@ public class RestfulUtil {
String result = getResponseContent(url, restParametes, RestfulUtil.TYPE_GET);
if(null == result || result.isEmpty()) {
LOGGER.error("result from url:" + url + " result:" + result);
- throw new ServiceException(
- ResourceUtil.getMessage(NO_RESULT_EXCEPTION));
+ throw new ServiceException(ResourceUtil.getMessage(NO_RESULT_EXCEPTION));
}
JSONArray rsArray = null;
@@ -289,8 +291,7 @@ public class RestfulUtil {
rsArray = rsJson.getJSONArray(ParamConstant.PARAM_DATA);
} catch(JSONException e) {
LOGGER.error("getResources error:" + e);
- throw new ServiceException(
- ResourceUtil.getMessage(NO_RESULT_EXCEPTION));
+ throw new ServiceException(ResourceUtil.getMessage(NO_RESULT_EXCEPTION));
}
return rsArray;
}
@@ -310,8 +311,7 @@ public class RestfulUtil {
String result = getResponseContent(url, restParametes, RestfulUtil.TYPE_GET);
if(null == result || result.isEmpty()) {
LOGGER.error("result from url:" + url + " result:" + result);
- throw new ServiceException(
- ResourceUtil.getMessage(NO_RESULT_EXCEPTION));
+ throw new ServiceException(ResourceUtil.getMessage(NO_RESULT_EXCEPTION));
}
JSONArray rsArray = null;
@@ -327,8 +327,7 @@ public class RestfulUtil {
}
} catch(JSONException e) {
LOGGER.error("getResources error:" + e);
- throw new ServiceException(
- ResourceUtil.getMessage(NO_RESULT_EXCEPTION));
+ throw new ServiceException(ResourceUtil.getMessage(NO_RESULT_EXCEPTION));
}
return rsArray;
}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java
index ed0c675..5c8b989 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java
@@ -18,6 +18,8 @@ package org.onap.vfc.nfvo.resmanagement.common.util.request;
import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@@ -25,6 +27,9 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.IOUtils;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulClientConst;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulParametes;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -126,4 +131,44 @@ public final class RequestUtil {
}
return header;
}
+
+ public static String encodeParams(final RestfulParametes restParametes) throws ServiceException {
+ final Map<String, String> parm = restParametes.getParamMap();
+ String value = null;
+ boolean bHasParma = false;
+ final StringBuilder builder = new StringBuilder();
+ try {
+ for(final String key : parm.keySet()) {
+ value = parm.get(key);
+ if(value == null) {
+ value = "";
+ }
+ String str;
+ if(bHasParma) {
+ str = String.format("&%s=%s", URLEncoder.encode(key, RestfulClientConst.ENCODING),
+ URLEncoder.encode(value, RestfulClientConst.ENCODING));
+ } else {
+ bHasParma = true;
+ str = String.format("%s=%s", URLEncoder.encode(key, RestfulClientConst.ENCODING),
+ URLEncoder.encode(value, RestfulClientConst.ENCODING));
+ }
+ builder.append(str);
+ }
+ } catch(final UnsupportedEncodingException ex) {
+ LOGGER.error("unsupported encoding: ", ex);
+ throw new ServiceException("Broken VM does not support UTF-8");
+ }
+ return builder.toString();
+ }
+
+ public static Map<String, String> getAAIHeaderMap() {
+ HashMap<String, String> headerMap = new HashMap<>();
+ headerMap.put("X-TransactionId", "9999");
+ headerMap.put("X-FromAppId", "jimmy");
+ headerMap.put("Real-Time", "true");
+ headerMap.put("Authorization", "Basic QUFJOkFBSQ==");
+ headerMap.put("Accept", "application/json");
+ headerMap.put("Content-Type", "application/json");
+ return headerMap;
+ }
}
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
new file mode 100644
index 0000000..d99e515
--- /dev/null
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/HttpsRest.java
@@ -0,0 +1,282 @@
+/*
+ * 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.common.util.restclient;
+
+
+import org.eclipse.jetty.client.ContentExchange;
+import org.eclipse.jetty.client.HttpClient;
+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);
+
+ public void initHttpsRest() {
+ SslContextFactory sslContextFactory = new SslContextFactory();
+ client = new HttpClient(sslContextFactory);
+ client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
+ client.setMaxConnectionsPerAddress(200); // max 200 concurrent connections to every address
+ client.setThreadPool(new QueuedThreadPool(250)); // max 250 threads
+ client.setTimeout(30000); // 30 seconds timeout; if no server reply, the request expires
+ try {
+ client.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public RestfulResponse get(String servicePath, RestfulParametes restParametes) throws ServiceException {
+ return null;
+ }
+
+ @Override
+ public RestfulResponse head(String servicePath, RestfulParametes restParametes, RestfulOptions options) throws ServiceException {
+ return null;
+ }
+
+ @Override
+ public RestfulResponse head(String servicePath, RestfulParametes restParametes) throws ServiceException {
+ return null;
+ }
+
+ @Override
+ 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 {
+
+ }
+
+ @Override
+ public RestfulResponse put(String servicePath, RestfulParametes restParametes) throws ServiceException {
+ return null;
+ }
+
+ @Override
+ 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 {
+
+ }
+
+ @Override
+ public RestfulResponse post(String servicePath, RestfulParametes restParametes) throws ServiceException {
+ return null;
+ }
+
+ @Override
+ 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 {
+
+ }
+
+ @Override
+ public void asyncPost(String servicePath, RestfulParametes restParametes, RestfulOptions options, RestfulAsyncCallback callback) throws ServiceException {
+
+ }
+
+ @Override
+ public RestfulResponse delete(String servicePath, RestfulParametes restParametes) throws ServiceException {
+ return null;
+ }
+
+ @Override
+ 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 {
+
+ }
+
+ @Override
+ public RestfulResponse patch(String servicePath, RestfulParametes restParametes) throws ServiceException {
+ return null;
+ }
+
+ @Override
+ 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 {
+
+ }
+
+ @Override
+ 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 {
+ ContentExchange exchange = new ContentExchange(true);
+ exchange.setURL(servicePath);
+ exchange.setMethod("GET");
+ restParametes.getHeaderMap().entrySet().stream().forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
+
+ try {
+ client.send(exchange);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ try {
+ int exchangeState = exchange.waitForDone();
+ if (exchangeState == HttpExchange.STATUS_COMPLETED) {
+ String res = exchange.getResponseContent();
+ LOG.info(res);
+
+ RestfulResponse restfulResponse = new RestfulResponse();
+ restfulResponse.setResponseJson(exchange.getResponseContent());
+ restfulResponse.setStatus(exchange.getStatus());
+ return restfulResponse;
+ } else if(exchangeState == HttpExchange.STATUS_EXCEPTED) {
+ throw new ServiceException(
+ "request is exception: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXCEPTED));
+ } else if(exchangeState == HttpExchange.STATUS_EXPIRED) {
+ throw new ServiceException(
+ "request is expierd: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXPIRED));
+ }
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ 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()));
+
+ try {
+ client.send(exchange);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ try {
+ int exchangeState = exchange.waitForDone();
+ if (exchangeState == HttpExchange.STATUS_COMPLETED) {
+ String res = exchange.getResponseContent();
+ LOG.info(res);
+
+ RestfulResponse restfulResponse = new RestfulResponse();
+ restfulResponse.setResponseJson(exchange.getResponseContent());
+ restfulResponse.setStatus(exchange.getStatus());
+ return restfulResponse;
+ } else if(exchangeState == HttpExchange.STATUS_EXCEPTED) {
+ throw new ServiceException(
+ "request is exception: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXCEPTED));
+ } else if(exchangeState == HttpExchange.STATUS_EXPIRED) {
+ throw new ServiceException(
+ "request is expierd: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXPIRED));
+ }
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ public RestfulResponse delete(String servicePath, RestfulParametes restParametes, RestfulOptions options) throws ServiceException {
+ ContentExchange exchange = new ContentExchange(true);
+
+ String encodeParams = RequestUtil.encodeParams(restParametes);
+ if (encodeParams.isEmpty()) {
+ exchange.setURL(servicePath);
+ } else {
+ exchange.setURL(servicePath + "?" + encodeParams);
+ }
+ exchange.setMethod("DELETE");
+ if (restParametes.getRawData() != null) {
+ exchange.setRequestContent(new ByteArrayBuffer(restParametes.getRawData()));
+ }
+
+ restParametes.getHeaderMap().entrySet().stream().forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
+
+ try {
+ client.send(exchange);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ try {
+ int exchangeState = exchange.waitForDone();
+ if (exchangeState == HttpExchange.STATUS_COMPLETED) {
+ String res = exchange.getResponseContent();
+ LOG.info(res);
+
+ RestfulResponse restfulResponse = new RestfulResponse();
+ restfulResponse.setResponseJson(exchange.getResponseContent());
+ restfulResponse.setStatus(exchange.getStatus());
+ return restfulResponse;
+ } else if(exchangeState == HttpExchange.STATUS_EXCEPTED) {
+ throw new ServiceException(
+ "request is exception: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXCEPTED));
+ } else if(exchangeState == HttpExchange.STATUS_EXPIRED) {
+ throw new ServiceException(
+ "request is expierd: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXPIRED));
+ }
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/RestfulFactory.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/RestfulFactory.java
index 8a79463..ef8e28f 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/RestfulFactory.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/restclient/RestfulFactory.java
@@ -67,6 +67,11 @@ public class RestfulFactory {
rest = createHttpRest();
INSTANCES.put(protocol, rest);
}
+
+ if (PROTO_HTTPS.equals(protocol)) {
+ rest = createHttpsRest();
+ INSTANCES.put(protocol, rest);
+ }
return rest;
}
@@ -76,6 +81,12 @@ public class RestfulFactory {
return rest;
}
+ private static Restful createHttpsRest() {
+ final HttpsRest rest = new HttpsRest();
+ rest.initHttpsRest();
+ return rest;
+ }
+
private static void setRestOption(final HttpRest rest, final String restoptionfile) {
try {
RestfulConfigure config;
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/VnfAaiDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/VnfAaiDaoImpl.java
new file mode 100644
index 0000000..abc4ccb
--- /dev/null
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/VnfAaiDaoImpl.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2016-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.dao.impl.aai;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+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;
+import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VnfDao;
+import org.onap.vfc.nfvo.resmanagement.service.entity.VnfEntity;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+public class VnfAaiDaoImpl implements VnfDao {
+
+ private static int VNF_AAI_DAO_SUCCESS = 1;
+
+ private static int VNF_AAI_DAO_FAIL = -1;
+
+ @Override
+ public List<VnfEntity> getVnfs(Map<String, Object> condition) {
+ ArrayList<VnfEntity> vnfList = new ArrayList<>();
+
+ if(condition.containsKey("id")) {
+ vnfList.add(getVnf((String)condition.get("id")));
+ } else {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+
+ RestfulResponse response = RestfulUtil.getRestfulResponse(
+ "https://192.168.17.24:8443/aai/v11/network/generic-vnfs", restfulParametes, "get");
+
+ JSONObject jsonObject = JSONObject.fromObject(response.getResponseContent());
+ JSONArray jsonArray = jsonObject.getJSONArray("generic-vnf");
+
+ jsonArray.forEach(genericVnf -> vnfList.add(VnfEntity.toEntityFromAai((JSONObject)genericVnf)));
+ }
+ return vnfList;
+ }
+
+ @Override
+ public VnfEntity getVnf(String id) {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+
+ RestfulResponse response = RestfulUtil.getRestfulResponse(
+ "https://192.168.17.24:8443/aai/v11/network/generic-vnfs/generic-vnf/" + id, restfulParametes, "get");
+
+ JSONObject jsonObject = JSONObject.fromObject(response.getResponseContent());
+ VnfEntity vnfEntity = VnfEntity.toEntityFromAai(jsonObject);
+ return vnfEntity;
+ }
+
+ @Override
+ public int addVnf(VnfEntity vnfEntity) {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+ restfulParametes.setRawData(vnfEntity.toStringForAai());
+
+ RestfulResponse response = RestfulUtil.getRestfulResponse(
+ "https://192.168.17.24:8443/aai/v11/network/generic-vnfs/generic-vnf/" + vnfEntity.getVnfInstanceId(),
+ restfulParametes, "put");
+
+ return response == null || response.getStatus() == -1 ? VNF_AAI_DAO_FAIL : VNF_AAI_DAO_SUCCESS;
+ }
+
+ @Override
+ public int deleteVnfById(String id) {
+ VnfEntity vnfEntity = getVnf(id);
+
+ if(vnfEntity != null) {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+ restfulParametes.put("resource-version", vnfEntity.getResourceVersion());
+
+ RestfulResponse response = RestfulUtil
+ .getRestfulResponse("https://192.168.17.24:8443/aai/v11/network/generic-vnfs/generic-vnf/"
+ + vnfEntity.getVnfInstanceId(), restfulParametes, "delete");
+ }
+ return 1;
+ }
+}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java
index 88497fc..2d09546 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java
@@ -95,6 +95,9 @@ public class VnfEntity implements Serializable {
/** */
private String name;
+ /** */
+ private String resourceVersion;
+
private static final long serialVersionUID = 1L;
public String getId() {
@@ -304,9 +307,41 @@ public class VnfEntity implements Serializable {
vnfEntity.setMaxRam(JsonUtil.getJsonFieldInt(jsonObject, "maxRam"));
vnfEntity.setMaxShd(JsonUtil.getJsonFieldInt(jsonObject, "maxShd"));
vnfEntity.setMaxNet(JsonUtil.getJsonFieldInt(jsonObject, "maxNet"));
+ vnfEntity.setResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, "resource-version"));
+ return vnfEntity;
+ }
+
+ public static VnfEntity toEntityFromAai(JSONObject jsonObject) {
+ VnfEntity vnfEntity = new VnfEntity();
+ vnfEntity.setVnfInstanceId(JsonUtil.getJsonFieldStr(jsonObject, "vnf-id"));
+ vnfEntity.setVnfInstanceName(JsonUtil.getJsonFieldStr(jsonObject, "vnf-name"));
+ vnfEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "vnf-name2"));
+ vnfEntity.setNsId(JsonUtil.getJsonFieldStr(jsonObject, "service-id"));
+ vnfEntity.setVnfStatus(JsonUtil.getJsonFieldStr(jsonObject, "orchestration-status"));
+ vnfEntity.setVnfType(JsonUtil.getJsonFieldStr(jsonObject, "vnf-type"));
+ vnfEntity.setMaxCpu(JsonUtil.getJsonFieldInt(jsonObject, "vcpu"));
+ vnfEntity.setMaxDisk(JsonUtil.getJsonFieldInt(jsonObject, "vdisk"));
+ vnfEntity.setMaxRam(JsonUtil.getJsonFieldInt(jsonObject, "vmemory"));
+ vnfEntity.setMaxShd(JsonUtil.getJsonFieldInt(jsonObject, "vdisk-units"));
+ vnfEntity.setResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, "resource-version"));
return vnfEntity;
}
+ public String toStringForAai() {
+
+ JSONObject vnfResJson = new JSONObject();
+ vnfResJson.put("vnf-id", StringUtils.trimToEmpty(this.getVnfInstanceId()));
+ vnfResJson.put("vnf-name", StringUtils.trimToEmpty(this.getVnfInstanceName()));
+ vnfResJson.put("vnf-name2", StringUtils.trimToEmpty(this.getName()));
+ vnfResJson.put("service-id", StringUtils.trimToEmpty(this.getNsId()));
+ vnfResJson.put("vnf-type", StringUtils.trimToEmpty(this.getVnfType()));
+ vnfResJson.put("vcpu", this.getMaxCpu());
+ vnfResJson.put("vdisk", this.getMaxDisk());
+ vnfResJson.put("vmemory", this.getMaxRam());
+ vnfResJson.put("vdisk-units", this.getMaxShd());
+ return vnfResJson.toString();
+ }
+
@Override
public String toString() {
JSONObject vnfResJson = new JSONObject();
@@ -334,4 +369,12 @@ public class VnfEntity implements Serializable {
vnfResJson.put("maxNet", StringUtils.trimToEmpty(this.getName()));
return vnfResJson.toString();
}
+
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfServiceImpl.java
index 4bcdf04..d5b40fc 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfServiceImpl.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfServiceImpl.java
@@ -22,11 +22,11 @@ import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VnfDao;
import org.onap.vfc.nfvo.resmanagement.service.entity.VnfEntity;
import org.onap.vfc.nfvo.resmanagement.service.group.inf.VnfInfoService;
import org.onap.vfc.nfvo.resmanagement.service.group.inf.VnfService;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -72,8 +72,8 @@ public class VnfServiceImpl implements VnfService {
restJson.put("id", vnfEntity.getId());
restJson.put("name", vnfEntity.getName());
} else {
- LOGGER.error("function=addVnf; msg=add vnf into DB error.");
- restJson.put("message", "Add vnf into DB error.");
+ LOGGER.error("function=addVnf; msg=add vnf into AAI error.");
+ restJson.put("message", "Add vnf into AAI error.");
}
return restJson;
}
@@ -123,7 +123,7 @@ public class VnfServiceImpl implements VnfService {
/**
* <br>
*
- * @param id
+ * @param vnfInstanceId
* @throws ServiceException
* @since VFC 1.0
*/
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java
index ec9b3c6..7695fbd 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java
@@ -90,7 +90,7 @@ public class VnfRoa {
@POST
public JSONObject addVnf(@Context HttpServletRequest context) throws ServiceException {
JSONObject object = RequestUtil.getJsonRequestBody(context);
- if(null == object) {
+ if (null == object) {
LOGGER.error("function=addVnf; msg=add error, because vnf is null.");
throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnf.add.null"));
}
@@ -98,7 +98,7 @@ public class VnfRoa {
LOGGER.info("VnfRoa::addVnf:{}", object.toString());
try {
return vnfService.addVnf(VnfEntity.toEntity(object));
- } catch(ServiceException se) {
+ } catch (ServiceException se) {
LOGGER.error("VnfRoa::addVnf error:{}" + se);
return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage());
}
@@ -108,7 +108,7 @@ public class VnfRoa {
@Path("/{id}")
public JSONObject deleteVnf(@Context HttpServletRequest context, @PathParam(ParamConstant.PARAM_ID) String id)
throws ServiceException {
- if(id == null) {
+ if (id == null) {
LOGGER.error("function=deleteVnf; msg=delete error, because id is null.");
throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnf.delete.id.null"));
}
diff --git a/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml b/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml
index aaac15e..de9a982 100644
--- a/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml
+++ b/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml
@@ -224,13 +224,18 @@
<!-- vnf -->
<bean id="vnfDao"
- class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.VnfDaoImpl">
+ class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.VnfDaoImpl">
<property name="session" ref="session"></property>
</bean>
+
+ <!-- vnfAai -->
+ <bean id="vnfAaiDao"
+ class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.aai.VnfAaiDaoImpl">
+ </bean>
<bean id="vnfService"
class="org.onap.vfc.nfvo.resmanagement.service.group.impl.VnfServiceImpl">
- <property name="vnfDao" ref="vnfDao"></property>
+ <property name="vnfDao" ref="vnfAaiDao"></property>
<property name="vnfInfoService" ref="vnfInfoService"></property>
</bean>