From ff1cfcf59881838fe6a0f7ea3839ea9dc7fb4093 Mon Sep 17 00:00:00 2001 From: guochuyicmri Date: Thu, 6 Sep 2018 18:45:01 +0800 Subject: [PATCH] add files for sotn business Change-Id: Ic4512fd9ede7eba344613838562cf0d8de498268 Issue-ID: USECASEUI-141 Signed-off-by: guochuyicmri --- .../server/bean/sotn/NetWorkResource.java | 64 +++++ .../server/bean/sotn/NetWorkResourceRsp.java | 32 +++ .../usecaseui/server/bean/sotn/Pinterface.java | 45 ++++ .../usecaseui/server/bean/sotn/PinterfaceRsp.java | 48 ++++ .../org/onap/usecaseui/server/bean/sotn/Pnf.java | 37 +++ .../org/onap/usecaseui/server/bean/sotn/Pnfs.java | 42 ++++ .../onap/usecaseui/server/constant/Constant.java | 4 + .../server/controller/sotn/SotnController.java | 160 +++++++++++++ .../server/service/lcm/domain/aai/AAIService.java | 102 +++++++- .../usecaseui/server/service/sotn/SOTNService.java | 45 ++++ .../server/service/sotn/impl/SOTNServiceImpl.java | 266 +++++++++++++++++++++ 11 files changed, 844 insertions(+), 1 deletion(-) create mode 100644 server/src/main/java/org/onap/usecaseui/server/bean/sotn/NetWorkResource.java create mode 100644 server/src/main/java/org/onap/usecaseui/server/bean/sotn/NetWorkResourceRsp.java create mode 100644 server/src/main/java/org/onap/usecaseui/server/bean/sotn/Pinterface.java create mode 100644 server/src/main/java/org/onap/usecaseui/server/bean/sotn/PinterfaceRsp.java create mode 100644 server/src/main/java/org/onap/usecaseui/server/bean/sotn/Pnf.java create mode 100644 server/src/main/java/org/onap/usecaseui/server/bean/sotn/Pnfs.java create mode 100644 server/src/main/java/org/onap/usecaseui/server/controller/sotn/SotnController.java create mode 100644 server/src/main/java/org/onap/usecaseui/server/service/sotn/SOTNService.java create mode 100644 server/src/main/java/org/onap/usecaseui/server/service/sotn/impl/SOTNServiceImpl.java diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/sotn/NetWorkResource.java b/server/src/main/java/org/onap/usecaseui/server/bean/sotn/NetWorkResource.java new file mode 100644 index 00000000..0af66403 --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/bean/sotn/NetWorkResource.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.server.bean.sotn; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown=true) +public class NetWorkResource { + + private String networkId; + + private List pnfs; + + private List tps; + + public NetWorkResource(String networkId, List pnfs, List tps) { + this.networkId = networkId; + this.pnfs = pnfs; + this.tps = tps; + } + + public NetWorkResource() { + } + + public String getNetworkId() { + return networkId; + } + + public void setNetworkId(String networkId) { + this.networkId = networkId; + } + + public List getPnfs() { + return pnfs; + } + + public void setPnfs(List pnfs) { + this.pnfs = pnfs; + } + + public List getTps() { + return tps; + } + + public void setTps(List tps) { + this.tps = tps; + } + +} diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/sotn/NetWorkResourceRsp.java b/server/src/main/java/org/onap/usecaseui/server/bean/sotn/NetWorkResourceRsp.java new file mode 100644 index 00000000..592c078e --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/bean/sotn/NetWorkResourceRsp.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.server.bean.sotn; + +import java.util.List; + +public class NetWorkResourceRsp { + + private List netWorkResources; + + public void setNetWorkResourceSkins(List netWorkResources) { + this.netWorkResources = netWorkResources; + } + + public List getNetWorkResources() { + return netWorkResources; + } + +} diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/sotn/Pinterface.java b/server/src/main/java/org/onap/usecaseui/server/bean/sotn/Pinterface.java new file mode 100644 index 00000000..bd49aa5c --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/bean/sotn/Pinterface.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.server.bean.sotn; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown=true) +public class Pinterface { + + private String interfaceName; + + public Pinterface() { + } + + @JsonCreator + public Pinterface(@JsonProperty("interface-name") String interfaceName) { + this.interfaceName = interfaceName; + } + + @JsonProperty("interface-name") + public String getInterfaceName() { + return interfaceName; + } + + @JsonProperty("interface-name") + public void setInterfaceName(String interfaceName) { + this.interfaceName = interfaceName; + } + +} diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/sotn/PinterfaceRsp.java b/server/src/main/java/org/onap/usecaseui/server/bean/sotn/PinterfaceRsp.java new file mode 100644 index 00000000..636fe706 --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/bean/sotn/PinterfaceRsp.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.server.bean.sotn; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown=true) +public class PinterfaceRsp { + + private List pinterfaces; + + + public PinterfaceRsp() { + } + + @JsonCreator + public PinterfaceRsp(@JsonProperty("p-interface")List pinterfaces) { + this.pinterfaces = pinterfaces; + } + + @JsonProperty("p-interface") + public List getPinterfaces() { + return pinterfaces; + } + + @JsonProperty("p-interface") + public void setPinterfaces(List pinterfaces) { + this.pinterfaces = pinterfaces; + } + +} diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/sotn/Pnf.java b/server/src/main/java/org/onap/usecaseui/server/bean/sotn/Pnf.java new file mode 100644 index 00000000..702fd928 --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/bean/sotn/Pnf.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.server.bean.sotn; + +public class Pnf { + + private String pnfName; + + public Pnf( String pnfName) { + this.pnfName = pnfName; + } + + public Pnf() { + } + + public String getPnfName() { + return pnfName; + } + + public void setPnfName(String pnfName) { + this.pnfName = pnfName; + } + +} diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/sotn/Pnfs.java b/server/src/main/java/org/onap/usecaseui/server/bean/sotn/Pnfs.java new file mode 100644 index 00000000..72312572 --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/bean/sotn/Pnfs.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.server.bean.sotn; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Pnfs { + + private List pnfs; + + @JsonCreator + public Pnfs(@JsonProperty("pnf") List pnfs) { + this.pnfs = pnfs; + } + + @JsonProperty("pnf") + public List getPnfs() { + return pnfs; + } + + @JsonProperty("pnf") + public void setPnfs(List pnfs) { + this.pnfs = pnfs; + } + +} diff --git a/server/src/main/java/org/onap/usecaseui/server/constant/Constant.java b/server/src/main/java/org/onap/usecaseui/server/constant/Constant.java index ef654768..b2c79b50 100755 --- a/server/src/main/java/org/onap/usecaseui/server/constant/Constant.java +++ b/server/src/main/java/org/onap/usecaseui/server/constant/Constant.java @@ -28,4 +28,8 @@ public final class Constant public static final String RegEX_DATE_FORMAT = "[^0-9-:]"; public static Map netWorkMap = new HashMap(); + + public static final String CONSTANT_SUCCESS="SUCCESS"; + + public static final String CONSTANT_FAILED="FAILED"; } diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/sotn/SotnController.java b/server/src/main/java/org/onap/usecaseui/server/controller/sotn/SotnController.java new file mode 100644 index 00000000..9b24eb7a --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/controller/sotn/SotnController.java @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.server.controller.sotn; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; + +import org.onap.usecaseui.server.bean.sotn.NetWorkResource; +import org.onap.usecaseui.server.bean.sotn.Pinterface; +import org.onap.usecaseui.server.bean.sotn.Pnf; +import org.onap.usecaseui.server.service.sotn.SOTNService; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +@RequestMapping("/uui-sotn") +public class SotnController { + + @Resource(name="SOTNService") + public SOTNService sotnService; + + public SOTNService getSotnService() { + return sotnService; + } + + public void setSotnService(SOTNService sotnService) { + this.sotnService = sotnService; + } + + @ResponseBody + @RequestMapping(value = {"/getNetWorkResources"}, method = RequestMethod.GET , produces = "application/json") + public List getNetWorkResources(){ + List result = new ArrayList(); + String json = sotnService.getNetWorkResources(); + createJson(json,result); + for(NetWorkResource networks:result){ + List pinterfaces = new ArrayList(); + List pnfs = networks.getPnfs(); + for(Pnf pnf :pnfs){ + List tps= sotnService.getPinterfaceByPnfName(pnf.getPnfName()); + pinterfaces.addAll(tps); + } + networks.setTps(pinterfaces); + } + return result; + } + + @ResponseBody + @RequestMapping(value = {"/getPinterfaceByPnfName/{pnfName}"}, method = RequestMethod.GET , produces = "application/json") + public List getPinterfaceByPnfName(@PathVariable(value="pnfName") String pnfName){ + return sotnService.getPinterfaceByPnfName(pnfName); + } + + @ResponseBody + @RequestMapping(value = {"/getLogicalLinks"}, method = RequestMethod.GET , produces = "application/json") + public String getLogicalLinks(){ + return sotnService.getLogicalLinks(); + } + + @ResponseBody + @RequestMapping(value = {"/createTopoNetwork/{networkId}"}, method = RequestMethod.PUT , produces = "application/json") + public String createTopoNetwork(HttpServletRequest request,@PathVariable(value="networkId") String networkId){ + return sotnService.createTopoNetwork(request,networkId); + } + + @ResponseBody + @RequestMapping(value = {"/pnf/{pnfName}/p-interfaces/p-interface/{tp-id}/createTerminationPoint"}, method = RequestMethod.PUT , produces = "application/json") + public String createTerminationPoint(HttpServletRequest request,@PathVariable(value="pnfName") String pnfName,@PathVariable(value="tp-id") String tpId){ + return sotnService.createTerminationPoint(request,pnfName,tpId); + } + + @ResponseBody + @RequestMapping(value = {"/createLink/{linkName}"}, method = RequestMethod.PUT , produces = "application/json") + public String createLink(HttpServletRequest request,@PathVariable(value="linkName") String linkName){ + return sotnService.createLink(request, linkName); + } + + @ResponseBody + @RequestMapping(value = {"/createPnf/{pnfName}"}, method = RequestMethod.PUT , produces = "application/json") + public String createPnf(HttpServletRequest request,@PathVariable(value="pnfName") String pnfName){ + return sotnService.createPnf(request, pnfName); + } + + @ResponseBody + @RequestMapping(value = {"/deleteLink/{linkName}"}, method = RequestMethod.DELETE , produces = "application/json") + public String deleteLink(@PathVariable(value="linkName") String linkName){ + return sotnService.deleteLink(linkName); + } + + @ResponseBody + @RequestMapping(value = {"/getServiceInstanceInfo"}, method = RequestMethod.GET , produces = "application/json") + public String getServiceInstanceInfo(HttpServletRequest request){ + String customerId = request.getParameter("customerId"); + String serviceType = request.getParameter("serviceType"); + String serviceId = request.getParameter("serviceId"); + return sotnService.serviceInstanceInfo(customerId, serviceType, serviceId); + } + + @ResponseBody + @RequestMapping(value = {"/getServiceInstanceList"}, method = RequestMethod.GET , produces = "application/json") + public String getServiceInstanceList(HttpServletRequest request){ + String customerId = request.getParameter("customerId"); + String serviceType = request.getParameter("serviceType"); + return sotnService.getServiceInstances(customerId, serviceType); + } + + private void createJson(String json,List list){ + + ObjectMapper mapper = new ObjectMapper(); + + try { + JsonNode node = mapper.readTree(json); + JsonNode netNode = node.get("network-resource"); + for(int i=0;i pnfs = new ArrayList(); + String networkId=netNode.get(i).get("network-id").toString(); + netResource.setNetworkId(networkId); + String relationJson = netNode.get(i).get("relationship-list").toString(); + JsonNode relationNode = mapper.readTree(relationJson); + + JsonNode shipNode = relationNode.get("relationship"); + for(int j=0;j getAAIServiceInstance(@Path("customerId") String customerId,@Path("service-type") String seviceType,@Path("serviceId") String serviceId); + + @Headers({ + "X-TransactionId: 7777", + "X-FromAppId: uui", + "Authorization: Basic QUFJOkFBSQ==", + "Accept: application/json" + }) + @GET("/api/aai-business/v13/network/network-resources") + Call listNetWorkResources(); + + @Headers({ + "X-TransactionId: 7777", + "X-FromAppId: uui", + "Authorization: Basic QUFJOkFBSQ==", + "Accept: application/json" + }) + @GET("/api/aai-business/v13/network/pnfs/pnf/{pnfName}/p-interfaces") + Call getPinterfaceByPnfName(@Path("pnfName") String pnfName); + + @Headers({ + "X-TransactionId: 7777", + "X-FromAppId: uui", + "Authorization: Basic QUFJOkFBSQ==", + "Accept: application/json" + }) + @GET("/api/aai-business/v13/network/logical-links") + Call getLogicalLinks(); + + @Headers({ + "X-TransactionId: 7777", + "X-FromAppId: uui", + "Authorization: Basic QUFJOkFBSQ==", + "Accept: application/json" + }) + @PUT("/api/aai-business/v13/network/network-resources/network-resource/{networkId}") + Call createTopoNetwork(@Body RequestBody body,@Path("networkId") String networkId); + + @Headers({ + "X-TransactionId: 7777", + "X-FromAppId: uui", + "Authorization: Basic QUFJOkFBSQ==", + "Accept: application/json" + }) + @PUT("/api/aai-business/v13/network/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{tp-id}") + Call createTerminationPoint(@Body RequestBody body,@Path("pnfName") String pnfName,@Path("tp-id") String tpId); + + @Headers({ + "X-TransactionId: 7777", + "X-FromAppId: uui", + "Authorization: Basic QUFJOkFBSQ==", + "Accept: application/json" + }) + @PUT("/api/aai-business/v13/network/pnfs/pnf/{pnfname}") + Call createPnf(@Body RequestBody body,@Path("pnfname") String pnfname); + + @Headers({ + "X-TransactionId: 7777", + "X-FromAppId: uui", + "Authorization: Basic QUFJOkFBSQ==", + "Accept: application/json" + }) + @PUT("/api/aai-business/v13/network/logical-links/logical-link/{linkName}") + Call createLink(@Body RequestBody body,@Path("linkName") String linkName); + + @Headers({ + "X-TransactionId: 7777", + "X-FromAppId: uui", + "Authorization: Basic QUFJOkFBSQ==", + "Accept: application/json" + }) + @DELETE("/api/aai-business/v13/network/logical-links/logical-link/{linkName}") + Call deleteLink(@Path("linkName") String linkName); + + @Headers({ + "X-TransactionId: 7777", + "X-FromAppId: uui", + "Authorization: Basic QUFJOkFBSQ==", + "Accept: application/json" + }) + @GET("/api/aai-business/v13/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}") + Call getServiceInstances(@Path("global-customer-id}") String customerId,@Path("service-type}") String serviceType); + + @Headers({ + "X-TransactionId: 7777", + "X-FromAppId: uui", + "Authorization: Basic QUFJOkFBSQ==", + "Accept: application/json" + }) + @GET("/api/aai-business/v13/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances") + Call serviceInstaneInfo(@Path("global-customer-id}") String globalCustomerId,@Path("service-type") String serviceType,@Query("service-instance-id") String serviceInstanceId); } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/sotn/SOTNService.java b/server/src/main/java/org/onap/usecaseui/server/service/sotn/SOTNService.java new file mode 100644 index 00000000..36262e32 --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/service/sotn/SOTNService.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.server.service.sotn; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.onap.usecaseui.server.bean.sotn.Pinterface; + +public interface SOTNService { + + public String getNetWorkResources(); + + public List getPinterfaceByPnfName(String pnfName); + + public String getLogicalLinks(); + + public String createTopoNetwork(HttpServletRequest request,String networkId); + + public String createTerminationPoint(HttpServletRequest request,String pnfName,String tpId); + + public String createLink(HttpServletRequest request,String linkName); + + public String createPnf(HttpServletRequest request,String pnfName); + + public String deleteLink(String linkName); + + public String getServiceInstances(String customerId,String serviceType); + + public String serviceInstanceInfo(String customerId,String serviceType,String serviceInstanceId); +} diff --git a/server/src/main/java/org/onap/usecaseui/server/service/sotn/impl/SOTNServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/sotn/impl/SOTNServiceImpl.java new file mode 100644 index 00000000..c39b651a --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/service/sotn/impl/SOTNServiceImpl.java @@ -0,0 +1,266 @@ +/* + * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.usecaseui.server.service.sotn.impl; + +import static org.onap.usecaseui.server.util.RestfulServices.extractBody; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.onap.usecaseui.server.bean.sotn.Pinterface; +import org.onap.usecaseui.server.bean.sotn.PinterfaceRsp; +import org.onap.usecaseui.server.constant.Constant; +import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService; +import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException; +import org.onap.usecaseui.server.service.lcm.domain.so.exceptions.SOException; +import org.onap.usecaseui.server.service.sotn.SOTNService; +import org.onap.usecaseui.server.util.RestfulServices; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.stereotype.Service; + +import okhttp3.RequestBody; +import okhttp3.ResponseBody; +import retrofit2.Response; + +@Service("SOTNService") +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +public class SOTNServiceImpl implements SOTNService{ + + private static final Logger logger = LoggerFactory.getLogger(SOTNServiceImpl.class); + + private AAIService aaiService; + + public SOTNServiceImpl() { + this(RestfulServices.create(AAIService.class)); + } + + public SOTNServiceImpl(AAIService aaiService) { + this.aaiService = aaiService; + } + + @Override + public String getNetWorkResources() { + try { + logger.info("aai getNetWorkResources is starting!"); + Response response = this.aaiService.listNetWorkResources().execute(); + logger.info("aai getNetWorkResources has finished!"); + if (response.isSuccessful()) { + String result=new String(response.body().bytes()); + return result; + } else { + logger.info(String.format("Can not get getNetWorkResources[code=%s, message=%s]", response.code(), response.message())); + return ""; + } + } catch (IOException e) { + logger.error("getNetWorkResources occur exception:"+e); + throw new AAIException("AAI is not available.", e); + } + } + + @Override + public List getPinterfaceByPnfName(String pnfName) { + try { + logger.info("aai getPinterfaceByPnfName is starting!"); + Response response = this.aaiService.getPinterfaceByPnfName(pnfName).execute(); + logger.info("aai getPinterfaceByPnfName has finished!"); + if (response.isSuccessful()) { + return response.body().getPinterfaces(); + } else { + logger.info(String.format("Can not get getPinterfaceByPnfName[code=%s, message=%s]", response.code(), response.message())); + return Collections.emptyList(); + } + } catch (IOException e) { + logger.error("getPinterfaceByPnfName occur exception:"+e); + throw new AAIException("AAI is not available.", e); + } + } + + @Override + public String getLogicalLinks() { + try { + logger.info("aai getLogicalLinks is starting!"); + Response response = this.aaiService.getLogicalLinks().execute(); + logger.info("aai getLogicalLinks has finished!"); + if (response.isSuccessful()) { + String result=new String(response.body().bytes()); + return result; + } else { + logger.info(String.format("Can not get getLogicalLinks[code=%s, message=%s]", response.code(), response.message())); + return ""; + } + } catch (IOException e) { + logger.error("getLogicalLinks occur exception:"+e); + throw new AAIException("AAI is not available.", e); + } + } + + @Override + public String createTopoNetwork(HttpServletRequest request,String networkId) { + String result = ""; + try { + logger.info("aai createTopoNetwork is starting"); + RequestBody requestBody = extractBody(request); + Response response = aaiService.createTopoNetwork(requestBody,networkId).execute(); + logger.info("aai createTopoNetwork has finished"); + if (response.isSuccessful()) { + result=Constant.CONSTANT_SUCCESS; + } else { + result=Constant.CONSTANT_FAILED; + logger.error(String.format("Can not createTopoNetwork[code=%s, message=%s]", response.code(), response.message())); + throw new SOException("aai createTopoNetwork failed!"); + } + } catch (Exception e) { + result=Constant.CONSTANT_FAILED; + logger.error("createTopoNetwork occur exception:"+e); + throw new SOException("aai createTopoNetwork is not available!", e); + } + return result; + } + + @Override + public String createTerminationPoint(HttpServletRequest request,String pnfName,String tpId) { + String result = ""; + try { + logger.info("aai createTerminationPoint is starting"); + RequestBody requestBody = extractBody(request); + Response response = aaiService.createTerminationPoint(requestBody,pnfName,tpId).execute(); + logger.info("aai createTerminationPoint has finished"); + if (response.isSuccessful()) { + result=Constant.CONSTANT_SUCCESS; + } else { + result=Constant.CONSTANT_FAILED; + logger.error(String.format("Can not createTerminationPoint[code=%s, message=%s]", response.code(), response.message())); + throw new SOException("aai createTerminationPoint failed!"); + } + } catch (Exception e) { + result=Constant.CONSTANT_FAILED; + logger.error("createTerminationPoint occur exception:"+e); + throw new SOException("aai createTerminationPoint is not available!", e); + } + return result; + } + + @Override + public String createLink(HttpServletRequest request,String linkName) { + String result = ""; + try { + logger.info("aai createLink is starting"); + RequestBody requestBody = extractBody(request); + Response response = aaiService.createLink(requestBody,linkName).execute(); + logger.info("aai createLink has finished"); + if (response.isSuccessful()) { + result=Constant.CONSTANT_SUCCESS; + } else { + result=Constant.CONSTANT_FAILED; + logger.error(String.format("Can not createLink[code=%s, message=%s]", response.code(), response.message())); + throw new SOException("aai createLink failed!"); + } + } catch (Exception e) { + result="FAILED"; + logger.error("createLink occur exception:"+e); + throw new SOException("aai createLink is not available!", e); + } + return result; + } + + @Override + public String createPnf(HttpServletRequest request,String pnfName) { + String result = ""; + try { + logger.info("aai createPnf is starting"); + RequestBody requestBody = extractBody(request); + Response response = aaiService.createPnf(requestBody,pnfName).execute(); + logger.info("aai createPnf has finished"); + if (response.isSuccessful()) { + result=Constant.CONSTANT_SUCCESS; + } else { + result=Constant.CONSTANT_FAILED; + logger.error(String.format("Can not createPnf[code=%s, message=%s]", response.code(), response.message())); + throw new SOException("aai createPnf failed!"); + } + } catch (Exception e) { + result=Constant.CONSTANT_FAILED; + logger.error("createPnf occur exception:"+e); + } + return result; + } + + @Override + public String deleteLink(String linkName) { + String result = ""; + try { + logger.info("aai deleteLink is starting"); + Response response = aaiService.deleteLink(linkName).execute(); + logger.info("aai deleteLink has finished"); + if (response.isSuccessful()) { + result=Constant.CONSTANT_SUCCESS; + } else { + result=Constant.CONSTANT_FAILED; + logger.error(String.format("Can not deleteLink[code=%s, message=%s]", response.code(), response.message())); + throw new SOException("aai deleteLink failed!"); + } + } catch (Exception e) { + result=Constant.CONSTANT_FAILED; + logger.error("deleteLink occur exception:"+e); + throw new SOException("aai deleteLink is not available!", e); + } + return result; + } + + @Override + public String getServiceInstances(String customerId, String serviceType) { + try { + logger.info("aai getServiceInstances is starting"); + Response response = aaiService.getServiceInstances(customerId, serviceType).execute(); + logger.info("aai getServiceInstances has finished"); + if (response.isSuccessful()) { + String result=new String(response.body().bytes()); + return result; + } else { + logger.error(String.format("Can not getServiceInstances[code=%s, message=%s]", response.code(), response.message())); + throw new SOException("aai getServiceInstances failed!"); + } + } catch (Exception e) { + logger.error("getServiceInstances occur exception:"+e); + throw new SOException("aai getServiceInstances is not available!", e); + } + } + + @Override + public String serviceInstanceInfo(String customerId, String serviceType, String serviceInstanceId) { + try { + logger.info("aai serviceInstanceInfo is starting"); + Response response = aaiService.serviceInstaneInfo(customerId, serviceType, serviceInstanceId).execute(); + logger.info("aai serviceInstanceInfo has finished"); + if (response.isSuccessful()) { + String result=new String(response.body().bytes()); + return result; + } else { + logger.error(String.format("Can not serviceInstanceInfo[code=%s, message=%s]", response.code(), response.message())); + throw new SOException("aai serviceInstanceInfo failed!"); + } + } catch (Exception e) { + logger.error("serviceInstanceInfo occur exception:"+e); + throw new SOException("aai serviceInstanceInfo is not available!", e); + } + } +} -- 2.16.6