summaryrefslogtreecommitdiffstats
path: root/ResmanagementService/service/src
diff options
context:
space:
mode:
Diffstat (limited to 'ResmanagementService/service/src')
-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/service/dao/impl/aai/NsAaiDaoImpl.java135
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/NsEntity.java307
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/NsServiceImpl.java189
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/NsService.java132
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/listener/AaiNamespaceInitializer.java17
-rw-r--r--ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/NsRoa.java305
-rw-r--r--ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml5
8 files changed, 633 insertions, 461 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 1f4534f..2f96c05 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,10 +87,6 @@ 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";
-
public static final String CONF = "config.properties";
public static final String HOST = "host_url";
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/NsAaiDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/NsAaiDaoImpl.java
new file mode 100644
index 0000000..9328f94
--- /dev/null
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/NsAaiDaoImpl.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2016 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.conf.Config;
+import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;
+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.NsDao;
+import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+public class NsAaiDaoImpl implements NsDao {
+
+ private static int VFC_SUCCESS_RESPONSE = 1;
+
+ private static int VFC_ERROR_RESPONSE = -1;
+
+ @Override
+ public NsEntity getNs(String id) {
+
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+
+ RestfulResponse response =
+ RestfulUtil.getRestfulResponse(Config.getHost() +":" + Config.getPort() + UrlConstant.CUSTOMER_URL
+ + Config.getGlobalCustomerId() + UrlConstant.SERVICE_SUBSCRIPTION_URL + Config.getServiceType()
+ + UrlConstant.SERVICE_INSTANCE_URL + id, restfulParametes, "get");
+
+ JSONObject jsonObject = JSONObject.fromObject(response.getResponseContent());
+ NsEntity nsEntity = NsEntity.toEntityFromAai(jsonObject);
+
+ return nsEntity;
+ }
+
+ @Override
+ public List<NsEntity> getAllNs(Map<String, Object> condition) {
+ List<NsEntity> nsEntities = new ArrayList<>();
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+
+ RestfulResponse response =
+ RestfulUtil.getRestfulResponse(Config.getHost() +":" + Config.getPort() + UrlConstant.CUSTOMER_URL
+ + Config.getGlobalCustomerId() + UrlConstant.SERVICE_SUBSCRIPTION_URL + Config.getServiceType()
+ + "/service-instances", restfulParametes, "get");
+
+ JSONObject jsonObject = JSONObject.fromObject(response.getResponseContent());
+ JSONArray jsonArray = jsonObject.getJSONArray("service-instance");
+
+ jsonArray.forEach(svcInstance -> nsEntities.add(NsEntity.toEntityFromAai((JSONObject)svcInstance)));
+ return nsEntities;
+ }
+
+ @Override
+ public int addNs(NsEntity nsEntity) {
+
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+ restfulParametes.setRawData(nsEntity.toStringForAai());
+
+ RestfulResponse response =
+ RestfulUtil.getRestfulResponse(Config.getHost() +":" + Config.getPort() + UrlConstant.CUSTOMER_URL
+ + Config.getGlobalCustomerId() + UrlConstant.SERVICE_SUBSCRIPTION_URL + Config.getServiceType()
+ + UrlConstant.SERVICE_INSTANCE_URL + nsEntity.getId(), restfulParametes, "put");
+
+ if(response.isSuccess()){
+ return VFC_SUCCESS_RESPONSE;
+ }
+ return VFC_ERROR_RESPONSE;
+ }
+
+ @Override
+ public int updateNs(NsEntity nsEntity) {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+ restfulParametes.put("resource-version", nsEntity.getResourceVersion());
+
+ RestfulResponse response = RestfulUtil.getRestfulResponse(
+ Config.getHost() +":" + Config.getPort() + UrlConstant.CUSTOMER_URL + Config.getGlobalCustomerId()
+ + UrlConstant.SERVICE_SUBSCRIPTION_URL + Config.getServiceType()
+ + UrlConstant.SERVICE_INSTANCE_URL + nsEntity.getResourceVersion(),
+ restfulParametes, "put");
+
+ if(response.isSuccess()){
+ return VFC_SUCCESS_RESPONSE;
+ }
+ return VFC_ERROR_RESPONSE;
+ }
+
+ @Override
+ public int deleteNsById(String id) {
+
+ NsEntity nsEntity = getNs(id);
+
+ if(nsEntity != null) {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+ restfulParametes.put("resource-version", nsEntity.getResourceVersion());
+
+ RestfulResponse response = RestfulUtil
+ .getRestfulResponse(
+ Config.getHost() +":" + Config.getPort() + UrlConstant.CUSTOMER_URL + Config.getGlobalCustomerId()
+ + UrlConstant.SERVICE_SUBSCRIPTION_URL + Config.getServiceType()
+ + UrlConstant.SERVICE_INSTANCE_URL + nsEntity.getId(),
+ restfulParametes, "delete");
+ if(response.isSuccess()){
+ return VFC_SUCCESS_RESPONSE;
+ }
+ return VFC_ERROR_RESPONSE;
+ }
+ return VFC_ERROR_RESPONSE;
+ }
+}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/NsEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/NsEntity.java
index 55e5a54..3a30015 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/NsEntity.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/NsEntity.java
@@ -1,139 +1,168 @@
-/*
- * 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.entity;
-
-import java.io.Serializable;
-
-import org.apache.commons.lang.StringUtils;
-import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil;
-
-import net.sf.json.JSONObject;
-
-/**
- * <br>
- * <p>
- * </p>
- *
- * @author
- * @version VFC 1.0 Sep 1, 2017
- */
-public class NsEntity implements Serializable {
-
- /** */
- private String id;
-
- /** */
- private String name;
-
- /** */
- private String nsdId;
-
- /** */
- private String description;
-
- /** */
- private String status;
-
- /** */
- private String createTime;
-
- /** */
- private String lastUpdate;
-
- private static final long serialVersionUID = 1L;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getNsdId() {
- return nsdId;
- }
-
- public void setNsdId(String nsdId) {
- this.nsdId = nsdId;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getStatus() {
- return status;
- }
-
- public void setStatus(String status) {
- this.status = status;
- }
-
- public String getCreateTime() {
- return createTime;
- }
-
- public void setCreateTime(String createTime) {
- this.createTime = createTime;
- }
-
- public String getLastUpdate() {
- return lastUpdate;
- }
-
- public void setLastUpdate(String lastUpdate) {
- this.lastUpdate = lastUpdate;
- }
-
- public static NsEntity toEntity(JSONObject jsonObject) {
- NsEntity nsEntity = new NsEntity();
- nsEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id"));
- nsEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name"));
- nsEntity.setNsdId(JsonUtil.getJsonFieldStr(jsonObject, "nsdId"));
- nsEntity.setDescription(JsonUtil.getJsonFieldStr(jsonObject, "description"));
- nsEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "status"));
- nsEntity.setCreateTime(JsonUtil.getJsonFieldStr(jsonObject, "createTime"));
- nsEntity.setLastUpdate(JsonUtil.getJsonFieldStr(jsonObject, "lastUpdate"));
- return nsEntity;
- }
-
- @Override
- public String toString() {
- JSONObject nsResJson = new JSONObject();
- nsResJson.put("id", StringUtils.trimToEmpty(this.getId()));
- nsResJson.put("name", StringUtils.trimToEmpty(this.getName()));
- nsResJson.put("nsdId", StringUtils.trimToEmpty(this.getNsdId()));
- nsResJson.put("description", StringUtils.trimToEmpty(this.getDescription()));
- nsResJson.put("status", StringUtils.trimToEmpty(this.getStatus()));
- nsResJson.put("createTime", StringUtils.trimToEmpty(this.getCreateTime()));
- nsResJson.put("lastUpdate", StringUtils.trimToEmpty(this.getLastUpdate()));
- return nsResJson.toString();
- }
-}
+/*
+ * 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.entity;
+
+import java.io.Serializable;
+
+import org.apache.commons.lang.StringUtils;
+import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil;
+
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version VFC 1.0 Sep 1, 2017
+ */
+public class NsEntity implements Serializable {
+
+ private String id;
+
+ private String name;
+
+ private String nsdId;
+
+ private String description;
+
+ private String status;
+
+ private String createTime;
+
+ private String lastUpdate;
+
+ private String resourceVersion;
+
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+ private static final long serialVersionUID = 1L;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getNsdId() {
+ return nsdId;
+ }
+
+ public void setNsdId(String nsdId) {
+ this.nsdId = nsdId;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(String createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getLastUpdate() {
+ return lastUpdate;
+ }
+
+ public void setLastUpdate(String lastUpdate) {
+ this.lastUpdate = lastUpdate;
+ }
+
+ public static NsEntity toEntity(JSONObject jsonObject) {
+ NsEntity nsEntity = new NsEntity();
+ nsEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id"));
+ nsEntity.setNsdId(JsonUtil.getJsonFieldStr(jsonObject, "nsdId"));
+ nsEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name"));
+ nsEntity.setDescription(JsonUtil.getJsonFieldStr(jsonObject, "description"));
+ nsEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "status"));
+ nsEntity.setCreateTime(JsonUtil.getJsonFieldStr(jsonObject, "createTime"));
+ nsEntity.setLastUpdate(JsonUtil.getJsonFieldStr(jsonObject, "lastUpdate"));
+ return nsEntity;
+ }
+
+ @Override
+ public String toString() {
+ JSONObject nsResJson = new JSONObject();
+ nsResJson.put("id", StringUtils.trimToEmpty(this.getId()));
+ nsResJson.put("nsdId", StringUtils.trimToEmpty(this.getNsdId()));
+ nsResJson.put("name", StringUtils.trimToEmpty(this.getName()));
+ nsResJson.put("description", StringUtils.trimToEmpty(this.getDescription()));
+ nsResJson.put("status", StringUtils.trimToEmpty(this.getStatus()));
+ nsResJson.put("createTime", StringUtils.trimToEmpty(this.getCreateTime()));
+ nsResJson.put("lastUpdate", StringUtils.trimToEmpty(this.getLastUpdate()));
+ return nsResJson.toString();
+ }
+
+ public String toStringForAai() {
+ JSONObject nsResJson = new JSONObject();
+ nsResJson.put("service-instnace-id", StringUtils.trimToEmpty(this.getId()));
+ nsResJson.put("service-instance-name", StringUtils.trimToEmpty(this.getName()));
+ nsResJson.put("description", StringUtils.trimToEmpty(this.getDescription()));
+ nsResJson.put("orchestration-status", StringUtils.trimToEmpty(this.getStatus()));
+ nsResJson.put("created-at", StringUtils.trimToEmpty(this.getCreateTime()));
+ nsResJson.put("updated-at", StringUtils.trimToEmpty(this.getLastUpdate()));
+ nsResJson.put("resource-version", StringUtils.trimToEmpty(this.getResourceVersion()));
+ return nsResJson.toString();
+ }
+
+ public static NsEntity toEntityFromAai(JSONObject jsonObject) {
+ NsEntity nsEntity = new NsEntity();
+ nsEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "service-instance-id"));
+ nsEntity.setNsdId(JsonUtil.getJsonFieldStr(jsonObject, "service-instance-id"));
+ nsEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "service-instance-name"));
+ nsEntity.setDescription(JsonUtil.getJsonFieldStr(jsonObject, "description"));
+ nsEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "orchestration-status"));
+ nsEntity.setCreateTime(JsonUtil.getJsonFieldStr(jsonObject, "created-at"));
+ nsEntity.setLastUpdate(JsonUtil.getJsonFieldStr(jsonObject, "updated-at"));
+ nsEntity.setResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, "resource-version"));
+ return nsEntity;
+ }
+
+}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/NsServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/NsServiceImpl.java
index 336315b..a228114 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/NsServiceImpl.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/NsServiceImpl.java
@@ -1,95 +1,94 @@
-/*
- * 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.group.impl;
-
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.apache.commons.lang.StringUtils;
-import org.onap.vfc.nfvo.resmanagement.service.dao.inf.NsDao;
-import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity;
-import org.onap.vfc.nfvo.resmanagement.service.group.inf.NsService;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import net.sf.json.JSONObject;
-
-/**
- * <br>
- * <p>
- * </p>
- *
- * @author
- * @version VFC 1.0 Sep 4, 2017
- */
-public class NsServiceImpl implements NsService {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(NsServiceImpl.class);
-
- private NsDao nsDao;
-
- @Override
- public JSONObject addNs(JSONObject object) {
- NsEntity nsEntity = NsEntity.toEntity(object);
- JSONObject restJson = new JSONObject();
-
- if(!checkId(nsEntity.getId())) {
- LOGGER.error("function=addVnf; msg=add error, because id is already exist.");
- restJson.put("message", "Ns id is already exist.");
- return restJson;
- }
-
- if(StringUtils.isEmpty(nsEntity.getId())) {
- nsEntity.setId(UUID.randomUUID().toString());
- }
- int result = nsDao.addNs(nsEntity);
-
- if(result > 0) {
- restJson.put("id", nsEntity.getId());
- restJson.put("name", nsEntity.getName());
- } else {
- LOGGER.error("function=addNs; msg=add ns into DB error.");
- restJson.put("message", "Add ns into DB error.");
- }
- return restJson;
- }
-
- private boolean checkId(String id) {
- NsEntity nsEntity = nsDao.getNs(id);
- if(null == nsEntity) {
- return true;
- }
- return false;
- }
-
- public void setNsDao(NsDao nsDao) {
- this.nsDao = nsDao;
- }
-
- @Override
- public List<NsEntity> getList(Map<String, Object> map) throws ServiceException {
- return nsDao.getAllNs(map);
- }
-
- @Override
- public int delete(String id) throws ServiceException {
- return nsDao.deleteNsById(id);
- }
-
-}
+/*
+ * 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.group.impl;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.commons.lang.StringUtils;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
+import org.onap.vfc.nfvo.resmanagement.service.dao.inf.NsDao;
+import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity;
+import org.onap.vfc.nfvo.resmanagement.service.group.inf.NsService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version VFC 1.0 Sep 4, 2017
+ */
+public class NsServiceImpl implements NsService {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(NsServiceImpl.class);
+
+ private NsDao nsDao;
+
+ @Override
+ public JSONObject addNs(JSONObject object) {
+ NsEntity nsEntity = NsEntity.toEntity(object);
+ JSONObject restJson = new JSONObject();
+
+ if(!checkId(nsEntity.getId())) {
+ LOGGER.error("function=addNs; msg=add error, because id is already exist.");
+ restJson.put("message", "Ns id is already exist.");
+ return restJson;
+ }
+
+ if(StringUtils.isEmpty(nsEntity.getId())) {
+ nsEntity.setId(UUID.randomUUID().toString());
+ }
+ int result = nsDao.addNs(nsEntity);
+
+ if(result > 0) {
+ restJson.put("ns", nsEntity);
+ } else {
+ LOGGER.error("function=addNs; msg=add ns into DB error.");
+ restJson.put("message", "Add ns into DB error.");
+ }
+ return restJson;
+ }
+
+ private boolean checkId(String id) {
+ NsEntity nsEntity = nsDao.getNs(id);
+ if(nsEntity.getId() == null) {
+ return true;
+ }
+ return false;
+ }
+
+ public void setNsDao(NsDao nsDao) {
+ this.nsDao = nsDao;
+ }
+
+ @Override
+ public List<NsEntity> getList(Map<String, Object> map) throws ServiceException {
+ return nsDao.getAllNs(map);
+ }
+
+ @Override
+ public int delete(String id) throws ServiceException {
+ return nsDao.deleteNsById(id);
+ }
+
+}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/NsService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/NsService.java
index 43760ab..1ee4ec1 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/NsService.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/NsService.java
@@ -1,66 +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.group.inf;
-
-import java.util.List;
-import java.util.Map;
-
-import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
-
-import net.sf.json.JSONObject;
-
-/**
- * <br>
- * <p>
- * </p>
- *
- * @author
- * @version VFC 1.0 Sep 4, 2017
- */
-public interface NsService {
-
- /**
- * <br>
- *
- * @param object
- * @return
- * @since VFC 1.0
- */
- JSONObject addNs(JSONObject object);
-
- /**
- * <br>
- *
- * @param map
- * @return
- * @throws ServiceException
- * @since VFC 1.0
- */
- List<NsEntity> getList(Map<String, Object> map) throws ServiceException;
-
- /**
- * <br>
- *
- * @param id
- * @return
- * @throws ServiceException
- * @since VFC 1.0
- */
- int delete(String id) throws ServiceException;
-
-}
+/*
+ * 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.group.inf;
+
+import java.util.List;
+import java.util.Map;
+
+import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
+
+import net.sf.json.JSONObject;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version VFC 1.0 Sep 4, 2017
+ */
+public interface NsService {
+
+ /**
+ * <br>
+ *
+ * @param object
+ * @return
+ * @since VFC 1.0
+ */
+ JSONObject addNs(JSONObject object);
+
+ /**
+ * <br>
+ *
+ * @param map
+ * @return
+ * @throws ServiceException
+ * @since VFC 1.0
+ */
+ List<NsEntity> getList(Map<String, Object> map) throws ServiceException;
+
+ /**
+ * <br>
+ *
+ * @param id
+ * @return
+ * @throws ServiceException
+ * @since VFC 1.0
+ */
+ int delete(String id) throws ServiceException;
+
+}
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
index a6ac37d..6671bfc 100644
--- 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
@@ -16,12 +16,11 @@
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.conf.Config;
+import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;
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;
@@ -42,11 +41,11 @@ public class AaiNamespaceInitializer implements ServletContextListener {
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 + "\"}");
+ restfulParametes.setRawData("{\"global-customer-id\": \"" + Config.getGlobalCustomerId() + "\"," + "\"subscriber-name\": \""
+ + Config.getGlobalCustomerId() + "\"," + "\"subscriber-type\": \"" + Config.getGlobalCustomerId() + "\"}");
RestfulResponse response = RestfulUtil.getRestfulResponse(
- "https://192.168.17.24:8443/aai/v11/business/customers/customer/" + VFC_CUSTOMER_ID, restfulParametes,
+ Config.getHost() + ":" + Config.getPort() + UrlConstant.CUSTOMER_URL + Config.getGlobalCustomerId(), restfulParametes,
"put");
return response.getStatus();
}
@@ -54,11 +53,11 @@ public class AaiNamespaceInitializer implements ServletContextListener {
private int createServiceSubscription() {
RestfulParametes restfulParametes = new RestfulParametes();
restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
- restfulParametes.setRawData("{\"service-type\": \"" + VFC_SERVICE_SUBSCRIPTION_ID + "\"}");
+ restfulParametes.setRawData("{\"service-type\": \"" + Config.getServiceType() + "\"}");
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,
+ Config.getHost() + ":" + Config.getPort() + UrlConstant.CUSTOMER_URL + Config.getGlobalCustomerId()
+ + UrlConstant.SERVICE_SUBSCRIPTION_URL + Config.getServiceType(),
restfulParametes, "put");
return response.getStatus();
}
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/NsRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/NsRoa.java
index 3a825f0..25b4c5d 100644
--- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/NsRoa.java
+++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/NsRoa.java
@@ -1,147 +1,158 @@
-/*
- * 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.rest;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-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.Context;
-import javax.ws.rs.core.MediaType;
-
-import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant;
-import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant;
-import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;
-import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
-import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil;
-import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil;
-import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity;
-import org.onap.vfc.nfvo.resmanagement.service.group.inf.NsService;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import net.sf.json.JSONObject;
-
-@Path(UrlConstant.NS_URL)
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class NsRoa {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(VirtualLinkRoa.class);
-
- private NsService nsService;
-
- /**
- * <br>
- *
- * @param context
- * @param resp
- * @return
- * @throws ServiceException
- * @since VFC 1.0
- */
- @POST
- public JSONObject addNs(@Context HttpServletRequest context, @Context HttpServletResponse resp)
- throws ServiceException {
- JSONObject object = RequestUtil.getJsonRequestBody(context);
- JSONObject restJson = new JSONObject();
- if(null == object) {
- LOGGER.error("function=addNs; msg=add error, because ns is null.");
- restJson.put("message", "ns is null");
- resp.setStatus(HttpConstant.HTTP_BAD_REQUEST);
- return restJson;
- }
-
- LOGGER.info("VnfRoa::addVnf:{}", object.toString());
- return nsService.addNs(object);
- }
-
- /**
- * <br>
- *
- * @param context
- * @return
- * @throws ServiceException
- * @since VFC 1.0
- */
- @GET
- public JSONObject getAllNs(@Context HttpServletRequest context) throws ServiceException {
- Map<String, Object> map = new HashMap<>(10);
- List<NsEntity> allNs = nsService.getList(map);
- LOGGER.info("NsRoa::getAllNs:{}", allNs.toString());
- JSONObject result = new JSONObject();
- result.put("ns", allNs);
- return result;
- }
-
- /**
- * <br>
- *
- * @param context
- * @param id
- * @return
- * @throws ServiceException
- * @since VFC 1.0
- */
- @GET
- @Path("/{nsId}")
- public JSONObject getNs(@Context HttpServletRequest context, @PathParam("nsId") String id) throws ServiceException {
- LOGGER.info("NsRoa::getNs id:{}", id);
- Map<String, Object> map = new HashMap<>(10);
- map.put(ParamConstant.PARAM_ID, id);
- List<NsEntity> ns = nsService.getList(map);
- LOGGER.info("NsRoa::getNs:{}", ns.toString());
- JSONObject result = new JSONObject();
- result.put("ns", ns.get(0));
- return result;
- }
-
- @DELETE
- @Path("/{id}")
- public JSONObject deleteNs(@Context HttpServletRequest context, @Context HttpServletResponse resp,
- @PathParam(ParamConstant.PARAM_ID) String id) throws ServiceException {
- JSONObject restJson = new JSONObject();
- if(id == null) {
- LOGGER.error("function=deleteNs; msg=delete error, because id is null.");
- restJson.put("message", "ns id is null");
- resp.setStatus(HttpConstant.HTTP_BAD_REQUEST);
- return restJson;
- }
- LOGGER.info("NsRoa::deleteNs id:{}", id);
- try {
- int result = nsService.delete(id);
- return RoaResponseUtil.delete(result);
- } catch(ServiceException se) {
- LOGGER.error("NsRoa::deleteNs error:{}" + se);
- return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage());
- }
- }
-
- public void setNsService(NsService nsService) {
- this.nsService = nsService;
- }
-}
+/*
+ * 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.rest;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+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.Context;
+import javax.ws.rs.core.MediaType;
+
+import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant;
+import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant;
+import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;
+import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil;
+import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
+import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity;
+import org.onap.vfc.nfvo.resmanagement.service.group.inf.NsService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.sf.json.JSONObject;
+
+@Path(UrlConstant.NS_URL)
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class NsRoa {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(VirtualLinkRoa.class);
+
+ private NsService nsService;
+
+ /**
+ * <br>
+ *
+ * @param context
+ * @param resp
+ * @return
+ * @throws ServiceException
+ * @since VFC 1.0
+ */
+
+ @POST
+ public JSONObject addNs(@Context HttpServletRequest context, @Context HttpServletResponse resp)
+ throws ServiceException {
+ JSONObject object = RequestUtil.getJsonRequestBody(context);
+ JSONObject restJson = new JSONObject();
+ if(null == object) {
+ LOGGER.error("function=addNs; msg=add error, because ns is null.");
+ restJson.put("message", "ns is null");
+ resp.setStatus(HttpConstant.HTTP_BAD_REQUEST);
+ return restJson;
+ }
+
+ LOGGER.info("VnfRoa::addVnf:{}", object.toString());
+ return nsService.addNs(object);
+ }
+
+ /**
+ * <br>
+ *
+ * @param context
+ * @return
+ * @throws ServiceException
+ * @since VFC 1.0
+ */
+ @GET
+ public JSONObject getAllNs(@Context HttpServletRequest context) throws ServiceException {
+ Map<String, Object> map = new HashMap<>(10);
+ List<NsEntity> allNs = nsService.getList(map);
+ LOGGER.info("NsRoa::getAllNs:{}", allNs.toString());
+ JSONObject result = new JSONObject();
+ result.put("ns", allNs);
+ return result;
+ }
+
+ /**
+ * <br>
+ *
+ * @param context
+ * @param id
+ * @return
+ * @throws ServiceException
+ * @since VFC 1.0
+ */
+ @GET
+ @Path("/{nsId}")
+ public JSONObject getNs(@Context HttpServletRequest context, @PathParam("nsId") String id) throws ServiceException {
+ LOGGER.info("NsRoa::getNs id:{}", id);
+ Map<String, Object> map = new HashMap<>(10);
+ map.put(ParamConstant.PARAM_ID, id);
+ List<NsEntity> allNs = nsService.getList(map);
+ LOGGER.info("NsRoa::getNs:{}", allNs.toString());
+ JSONObject result = new JSONObject();
+ result.put("ns", allNs);
+ return result;
+ }
+
+ /**
+ * <br>
+ *
+ * @param context
+ * @param id
+ * @return
+ * @throws ServiceException
+ * @since VFC 1.0
+ */
+
+ @DELETE
+ @Path("/{id}")
+ public JSONObject deleteNs(@Context HttpServletRequest context, @Context HttpServletResponse resp,
+ @PathParam(ParamConstant.PARAM_ID) String id) throws ServiceException {
+ JSONObject restJson = new JSONObject();
+ if(id == null) {
+ LOGGER.error("function=deleteNs; msg=delete error, because id is null.");
+ restJson.put("message", "ns id is null");
+ resp.setStatus(HttpConstant.HTTP_BAD_REQUEST);
+ return restJson;
+ }
+ LOGGER.info("NsRoa::deleteNs id:{}", id);
+ try {
+ int result = nsService.delete(id);
+ return RoaResponseUtil.delete(result);
+ } catch(ServiceException se) {
+ LOGGER.error("NsRoa::deleteNs error:{}" + se);
+ return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage());
+ }
+ }
+
+ public void setNsService(NsService nsService) {
+ this.nsService = nsService;
+ }
+}
diff --git a/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml b/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml
index 5c72315..8cbb9a5 100644
--- a/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml
+++ b/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml
@@ -212,10 +212,13 @@
class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.NsDaoImpl">
<property name="session" ref="session"></property>
</bean>
+
+ <bean id="nsAaiDao" class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.aai.NsAaiDaoImpl">
+ </bean>
<bean id="nsService"
class="org.onap.vfc.nfvo.resmanagement.service.group.impl.NsServiceImpl">
- <property name="nsDao" ref="nsDao"></property>
+ <property name="nsDao" ref="nsAaiDao"></property>
</bean>
<bean id="nsRoa" class="org.onap.vfc.nfvo.resmanagement.service.rest.NsRoa">