Implement to store network service to AAI 39/15939/5
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>
Wed, 27 Sep 2017 11:57:14 +0000 (17:27 +0530)
committersubhash kumar singh <subhash.kumar.singh@huawei.com>
Thu, 19 Oct 2017 12:07:17 +0000 (12:07 +0000)
Implement to store network service to AAI

Change-Id: I09adfc19d64bfffbfcdb62a1b0353b446a5c5cf5
Issue-ID: VFC-462
Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
ResmanagementService/service/pom.xml
ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java
ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/aai/NsAaiDaoImpl.java [new file with mode: 0644]
ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/NsEntity.java
ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/NsServiceImpl.java
ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/NsService.java
ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/listener/AaiNamespaceInitializer.java
ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/NsRoa.java
ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml

index f5028b1..8d391d2 100644 (file)
@@ -24,7 +24,7 @@
     </parent>
 
     <artifactId>vfc-nfvo-resmanagement-service</artifactId>
-    <version>1.0.0-SNAPSHOT</version>
+     <version>1.0.0-SNAPSHOT</version>
     <name>vfc/nfvo/resmanagement/ResmanagementService/service</name>
     <packaging>war</packaging>
     <dependencies>
index 1f4534f..2f96c05 100644 (file)
@@ -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 (file)
index 0000000..9328f94
--- /dev/null
@@ -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;
+    }
+}
index 55e5a54..3a30015 100644 (file)
-/*\r
- * Copyright 2017 Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.vfc.nfvo.resmanagement.service.entity;\r
-\r
-import java.io.Serializable;\r
-\r
-import org.apache.commons.lang.StringUtils;\r
-import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil;\r
-\r
-import net.sf.json.JSONObject;\r
-\r
-/**\r
- * <br>\r
- * <p>\r
- * </p>\r
- * \r
- * @author\r
- * @version VFC 1.0 Sep 1, 2017\r
- */\r
-public class NsEntity implements Serializable {\r
-\r
-    /**  */\r
-    private String id;\r
-\r
-    /**  */\r
-    private String name;\r
-\r
-    /**  */\r
-    private String nsdId;\r
-\r
-    /**  */\r
-    private String description;\r
-\r
-    /**  */\r
-    private String status;\r
-\r
-    /**  */\r
-    private String createTime;\r
-\r
-    /**  */\r
-    private String lastUpdate;\r
-\r
-    private static final long serialVersionUID = 1L;\r
-\r
-    public String getId() {\r
-        return id;\r
-    }\r
-\r
-    public void setId(String id) {\r
-        this.id = id;\r
-    }\r
-\r
-    public String getName() {\r
-        return name;\r
-    }\r
-\r
-    public void setName(String name) {\r
-        this.name = name;\r
-    }\r
-\r
-    public String getNsdId() {\r
-        return nsdId;\r
-    }\r
-\r
-    public void setNsdId(String nsdId) {\r
-        this.nsdId = nsdId;\r
-    }\r
-\r
-    public String getDescription() {\r
-        return description;\r
-    }\r
-\r
-    public void setDescription(String description) {\r
-        this.description = description;\r
-    }\r
-\r
-    public String getStatus() {\r
-        return status;\r
-    }\r
-\r
-    public void setStatus(String status) {\r
-        this.status = status;\r
-    }\r
-\r
-    public String getCreateTime() {\r
-        return createTime;\r
-    }\r
-\r
-    public void setCreateTime(String createTime) {\r
-        this.createTime = createTime;\r
-    }\r
-\r
-    public String getLastUpdate() {\r
-        return lastUpdate;\r
-    }\r
-\r
-    public void setLastUpdate(String lastUpdate) {\r
-        this.lastUpdate = lastUpdate;\r
-    }\r
-\r
-    public static NsEntity toEntity(JSONObject jsonObject) {\r
-        NsEntity nsEntity = new NsEntity();\r
-        nsEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id"));\r
-        nsEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name"));\r
-        nsEntity.setNsdId(JsonUtil.getJsonFieldStr(jsonObject, "nsdId"));\r
-        nsEntity.setDescription(JsonUtil.getJsonFieldStr(jsonObject, "description"));\r
-        nsEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "status"));\r
-        nsEntity.setCreateTime(JsonUtil.getJsonFieldStr(jsonObject, "createTime"));\r
-        nsEntity.setLastUpdate(JsonUtil.getJsonFieldStr(jsonObject, "lastUpdate"));\r
-        return nsEntity;\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        JSONObject nsResJson = new JSONObject();\r
-        nsResJson.put("id", StringUtils.trimToEmpty(this.getId()));\r
-        nsResJson.put("name", StringUtils.trimToEmpty(this.getName()));\r
-        nsResJson.put("nsdId", StringUtils.trimToEmpty(this.getNsdId()));\r
-        nsResJson.put("description", StringUtils.trimToEmpty(this.getDescription()));\r
-        nsResJson.put("status", StringUtils.trimToEmpty(this.getStatus()));\r
-        nsResJson.put("createTime", StringUtils.trimToEmpty(this.getCreateTime()));\r
-        nsResJson.put("lastUpdate", StringUtils.trimToEmpty(this.getLastUpdate()));\r
-        return nsResJson.toString();\r
-    }\r
-}\r
+/*
+ * 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;
+    }
+
+}
index 336315b..a228114 100644 (file)
@@ -1,95 +1,94 @@
-/*\r
- * Copyright 2017 Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.vfc.nfvo.resmanagement.service.group.impl;\r
-\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.UUID;\r
-\r
-import org.apache.commons.lang.StringUtils;\r
-import org.onap.vfc.nfvo.resmanagement.service.dao.inf.NsDao;\r
-import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity;\r
-import org.onap.vfc.nfvo.resmanagement.service.group.inf.NsService;\r
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import net.sf.json.JSONObject;\r
-\r
-/**\r
- * <br>\r
- * <p>\r
- * </p>\r
- * \r
- * @author\r
- * @version VFC 1.0 Sep 4, 2017\r
- */\r
-public class NsServiceImpl implements NsService {\r
-\r
-    private static final Logger LOGGER = LoggerFactory.getLogger(NsServiceImpl.class);\r
-\r
-    private NsDao nsDao;\r
-\r
-    @Override\r
-    public JSONObject addNs(JSONObject object) {\r
-        NsEntity nsEntity = NsEntity.toEntity(object);\r
-        JSONObject restJson = new JSONObject();\r
-\r
-        if(!checkId(nsEntity.getId())) {\r
-            LOGGER.error("function=addVnf; msg=add error, because id is already exist.");\r
-            restJson.put("message", "Ns id is already exist.");\r
-            return restJson;\r
-        }\r
-\r
-        if(StringUtils.isEmpty(nsEntity.getId())) {\r
-            nsEntity.setId(UUID.randomUUID().toString());\r
-        }\r
-        int result = nsDao.addNs(nsEntity);\r
-\r
-        if(result > 0) {\r
-            restJson.put("id", nsEntity.getId());\r
-            restJson.put("name", nsEntity.getName());\r
-        } else {\r
-            LOGGER.error("function=addNs; msg=add ns into DB error.");\r
-            restJson.put("message", "Add ns into DB error.");\r
-        }\r
-        return restJson;\r
-    }\r
-\r
-    private boolean checkId(String id) {\r
-        NsEntity nsEntity = nsDao.getNs(id);\r
-        if(null == nsEntity) {\r
-            return true;\r
-        }\r
-        return false;\r
-    }\r
-\r
-    public void setNsDao(NsDao nsDao) {\r
-        this.nsDao = nsDao;\r
-    }\r
-\r
-    @Override\r
-    public List<NsEntity> getList(Map<String, Object> map) throws ServiceException {\r
-        return nsDao.getAllNs(map);\r
-    }\r
-\r
-    @Override\r
-    public int delete(String id) throws ServiceException {\r
-        return nsDao.deleteNsById(id);\r
-    }\r
-\r
-}\r
+/*
+ * 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);
+    }
+
+}
index 43760ab..1ee4ec1 100644 (file)
@@ -1,66 +1,66 @@
-/*\r
- * Copyright 2017 Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.vfc.nfvo.resmanagement.service.group.inf;\r
-\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity;\r
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;\r
-\r
-import net.sf.json.JSONObject;\r
-\r
-/**\r
- * <br>\r
- * <p>\r
- * </p>\r
- * \r
- * @author\r
- * @version VFC 1.0 Sep 4, 2017\r
- */\r
-public interface NsService {\r
-\r
-    /**\r
-     * <br>\r
-     * \r
-     * @param object\r
-     * @return\r
-     * @since VFC 1.0\r
-     */\r
-    JSONObject addNs(JSONObject object);\r
-\r
-    /**\r
-     * <br>\r
-     * \r
-     * @param map\r
-     * @return\r
-     * @throws ServiceException\r
-     * @since VFC 1.0\r
-     */\r
-    List<NsEntity> getList(Map<String, Object> map) throws ServiceException;\r
-\r
-    /**\r
-     * <br>\r
-     * \r
-     * @param id\r
-     * @return\r
-     * @throws ServiceException\r
-     * @since VFC 1.0\r
-     */\r
-    int delete(String id) throws ServiceException;\r
-\r
-}\r
+/*
+ * 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;
+
+}
index a6ac37d..6671bfc 100644 (file)
 
 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();
     }
index 3a825f0..25b4c5d 100644 (file)
-/*\r
- * Copyright 2017 Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.vfc.nfvo.resmanagement.service.rest;\r
-\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-import javax.ws.rs.Consumes;\r
-import javax.ws.rs.DELETE;\r
-import javax.ws.rs.GET;\r
-import javax.ws.rs.POST;\r
-import javax.ws.rs.Path;\r
-import javax.ws.rs.PathParam;\r
-import javax.ws.rs.Produces;\r
-import javax.ws.rs.core.Context;\r
-import javax.ws.rs.core.MediaType;\r
-\r
-import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant;\r
-import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant;\r
-import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;\r
-import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;\r
-import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil;\r
-import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil;\r
-import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity;\r
-import org.onap.vfc.nfvo.resmanagement.service.group.inf.NsService;\r
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import net.sf.json.JSONObject;\r
-\r
-@Path(UrlConstant.NS_URL)\r
-@Produces(MediaType.APPLICATION_JSON)\r
-@Consumes(MediaType.APPLICATION_JSON)\r
-public class NsRoa {\r
-\r
-    private static final Logger LOGGER = LoggerFactory.getLogger(VirtualLinkRoa.class);\r
-\r
-    private NsService nsService;\r
-\r
-    /**\r
-     * <br>\r
-     * \r
-     * @param context\r
-     * @param resp\r
-     * @return\r
-     * @throws ServiceException\r
-     * @since VFC 1.0\r
-     */\r
-    @POST\r
-    public JSONObject addNs(@Context HttpServletRequest context, @Context HttpServletResponse resp)\r
-            throws ServiceException {\r
-        JSONObject object = RequestUtil.getJsonRequestBody(context);\r
-        JSONObject restJson = new JSONObject();\r
-        if(null == object) {\r
-            LOGGER.error("function=addNs; msg=add error, because ns is null.");\r
-            restJson.put("message", "ns is null");\r
-            resp.setStatus(HttpConstant.HTTP_BAD_REQUEST);\r
-            return restJson;\r
-        }\r
-\r
-        LOGGER.info("VnfRoa::addVnf:{}", object.toString());\r
-        return nsService.addNs(object);\r
-    }\r
-\r
-    /**\r
-     * <br>\r
-     * \r
-     * @param context\r
-     * @return\r
-     * @throws ServiceException\r
-     * @since VFC 1.0\r
-     */\r
-    @GET\r
-    public JSONObject getAllNs(@Context HttpServletRequest context) throws ServiceException {\r
-        Map<String, Object> map = new HashMap<>(10);\r
-        List<NsEntity> allNs = nsService.getList(map);\r
-        LOGGER.info("NsRoa::getAllNs:{}", allNs.toString());\r
-        JSONObject result = new JSONObject();\r
-        result.put("ns", allNs);\r
-        return result;\r
-    }\r
-\r
-    /**\r
-     * <br>\r
-     * \r
-     * @param context\r
-     * @param id\r
-     * @return\r
-     * @throws ServiceException\r
-     * @since VFC 1.0\r
-     */\r
-    @GET\r
-    @Path("/{nsId}")\r
-    public JSONObject getNs(@Context HttpServletRequest context, @PathParam("nsId") String id) throws ServiceException {\r
-        LOGGER.info("NsRoa::getNs id:{}", id);\r
-        Map<String, Object> map = new HashMap<>(10);\r
-        map.put(ParamConstant.PARAM_ID, id);\r
-        List<NsEntity> ns = nsService.getList(map);\r
-        LOGGER.info("NsRoa::getNs:{}", ns.toString());\r
-        JSONObject result = new JSONObject();\r
-        result.put("ns", ns.get(0));\r
-        return result;\r
-    }\r
-\r
-    @DELETE\r
-    @Path("/{id}")\r
-    public JSONObject deleteNs(@Context HttpServletRequest context, @Context HttpServletResponse resp,\r
-            @PathParam(ParamConstant.PARAM_ID) String id) throws ServiceException {\r
-        JSONObject restJson = new JSONObject();\r
-        if(id == null) {\r
-            LOGGER.error("function=deleteNs; msg=delete error, because id is null.");\r
-            restJson.put("message", "ns id is null");\r
-            resp.setStatus(HttpConstant.HTTP_BAD_REQUEST);\r
-            return restJson;\r
-        }\r
-        LOGGER.info("NsRoa::deleteNs id:{}", id);\r
-        try {\r
-            int result = nsService.delete(id);\r
-            return RoaResponseUtil.delete(result);\r
-        } catch(ServiceException se) {\r
-            LOGGER.error("NsRoa::deleteNs error:{}" + se);\r
-            return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage());\r
-        }\r
-    }\r
-\r
-    public void setNsService(NsService nsService) {\r
-        this.nsService = nsService;\r
-    }\r
-}\r
+/*
+ * 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;
+    }
+}
index 5c72315..8cbb9a5 100644 (file)
         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">