diff options
Diffstat (limited to 'src')
12 files changed, 182 insertions, 64 deletions
diff --git a/src/main/java/org/onap/nbi/OnapComponentsUrlPaths.java b/src/main/java/org/onap/nbi/OnapComponentsUrlPaths.java index 989df02..a6e943b 100644 --- a/src/main/java/org/onap/nbi/OnapComponentsUrlPaths.java +++ b/src/main/java/org/onap/nbi/OnapComponentsUrlPaths.java @@ -42,7 +42,7 @@ public final class OnapComponentsUrlPaths { "/aai/v11/business/customers/customer/$customerId/service-subscriptions/service-subscription/$serviceSpecName/service-instances/"; // MSO - public static final String MSO_CREATE_SERVICE_INSTANCE_PATH = "/ecomp/mso/infra/serviceInstance/v4"; + public static final String MSO_CREATE_SERVICE_INSTANCE_PATH = "/ecomp/mso/infra/serviceInstances/v4"; public static final String MSO_GET_REQUEST_STATUS_PATH = "/ecomp/mso/infra/orchestrationRequests/v4/"; - public static final String MSO_DELETE_REQUEST_STATUS_PATH = "/ecomp/mso/infra/serviceInstances/"; + public static final String MSO_DELETE_REQUEST_STATUS_PATH = "/ecomp/mso/infra/serviceInstances/v4/"; } diff --git a/src/main/java/org/onap/nbi/apis/serviceinventory/ServiceInventoryService.java b/src/main/java/org/onap/nbi/apis/serviceinventory/ServiceInventoryService.java index 707c9e9..a4347d4 100644 --- a/src/main/java/org/onap/nbi/apis/serviceinventory/ServiceInventoryService.java +++ b/src/main/java/org/onap/nbi/apis/serviceinventory/ServiceInventoryService.java @@ -102,16 +102,19 @@ public class ServiceInventoryService { List<LinkedHashMap> vnfs = new ArrayList<>(); LinkedHashMap relationShip = (LinkedHashMap) serviceResponse.get("relationship-list"); - List<LinkedHashMap> relationsList = (List<LinkedHashMap>) relationShip.get("relationship"); - for (LinkedHashMap relation : relationsList) { - String relatedLink = (String) relation.get("related-link"); - LinkedHashMap vnf = aaiClient.getVNF(relatedLink); - if (vnf != null) { - vnfs.add(vnf); + if(relationShip!=null) { + List<LinkedHashMap> relationsList = (List<LinkedHashMap>) relationShip.get("relationship"); + if(relationsList!=null) { + for (LinkedHashMap relation : relationsList) { + String relatedLink = (String) relation.get("related-link"); + LinkedHashMap vnf = aaiClient.getVNF(relatedLink); + if (vnf != null) { + vnfs.add(vnf); + } + } + serviceResponse.put("vnfs", vnfs); } } - serviceResponse.put("vnfs", vnfs); - } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java b/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java index c3e41f4..5f10d63 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java @@ -18,17 +18,13 @@ package org.onap.nbi.apis.serviceorder; import org.onap.nbi.OnapComponentsUrlPaths; import org.onap.nbi.apis.serviceorder.model.consumer.CreateServiceInstanceResponse; import org.onap.nbi.apis.serviceorder.model.consumer.GetRequestStatusResponse; -import org.onap.nbi.apis.serviceorder.model.consumer.RequestDetails; +import org.onap.nbi.apis.serviceorder.model.consumer.MSOPayload; import org.onap.nbi.exceptions.BackendFunctionalException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; +import org.springframework.http.*; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; @@ -57,15 +53,15 @@ public class SoClient { private static final Logger LOGGER = LoggerFactory.getLogger(SoClient.class); - public ResponseEntity<CreateServiceInstanceResponse> callCreateServiceInstance(RequestDetails requestDetails) { + public ResponseEntity<CreateServiceInstanceResponse> callCreateServiceInstance(MSOPayload msoPayload) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Calling SO CreateServiceInstance with requestDetails : " + requestDetails.toString()); + LOGGER.debug("Calling SO CreateServiceInstance with msoPayload : " + msoPayload.toString()); } String url = soHostname + OnapComponentsUrlPaths.MSO_CREATE_SERVICE_INSTANCE_PATH; - HttpEntity<RequestDetails> requestDetailEntity = new HttpEntity<>(requestDetails, buildRequestHeader()); + HttpEntity<MSOPayload> requestDetailEntity = new HttpEntity<>(msoPayload, buildRequestHeader()); try { ResponseEntity<CreateServiceInstanceResponse> response = restTemplate.exchange(url, HttpMethod.POST, @@ -80,16 +76,16 @@ public class SoClient { } } - public ResponseEntity<CreateServiceInstanceResponse> callDeleteServiceInstance(RequestDetails requestDetails, + public ResponseEntity<CreateServiceInstanceResponse> callDeleteServiceInstance(MSOPayload msoPayload, String serviceId) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Calling SO DeleteServiceInstance with requestDetails : " + requestDetails.toString()); + LOGGER.debug("Calling SO DeleteServiceInstance with msoPayload : " + msoPayload.toString()); } String url = soHostname + OnapComponentsUrlPaths.MSO_DELETE_REQUEST_STATUS_PATH + serviceId; - HttpEntity<RequestDetails> requestDetailEntity = new HttpEntity<>(requestDetails, buildRequestHeader()); + HttpEntity<MSOPayload> requestDetailEntity = new HttpEntity<>(msoPayload, buildRequestHeader()); try { ResponseEntity<CreateServiceInstanceResponse> response = restTemplate.exchange(url, HttpMethod.DELETE, diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/MSOPayload.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/MSOPayload.java new file mode 100644 index 0000000..76415c3 --- /dev/null +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/MSOPayload.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2018 Orange + * + * 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.nbi.apis.serviceorder.model.consumer; + +public class MSOPayload { + + private RequestDetails requestDetails; + + public MSOPayload(RequestDetails requestDetails) { + this.requestDetails = requestDetails; + } + + public RequestDetails getRequestDetails() { + return requestDetails; + } + + public void setRequestDetails(RequestDetails requestDetails) { + this.requestDetails = requestDetails; + } + + @Override + public String toString() { + return "MSOPayload{" + + "requestDetails=" + requestDetails + + '}'; + } +} diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestInfo.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestInfo.java index 6d3d5d5..a80b1ee 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestInfo.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestInfo.java @@ -25,6 +25,8 @@ public class RequestInfo { private boolean suppressRollback; + private String requestorId; + public String getInstanceName() { return instanceName; } @@ -57,9 +59,22 @@ public class RequestInfo { this.suppressRollback = suppressRollback; } + public String getRequestorId() { + return requestorId; + } + + public void setRequestorId(String requestorId) { + this.requestorId = requestorId; + } + @Override public String toString() { - return "RequestInfo{" + "instanceName='" + instanceName + '\'' + ", productFamilyId='" + productFamilyId + '\'' - + ", source='" + source + '\'' + ", suppressRollback=" + suppressRollback + '}'; + return "RequestInfo{" + + "instanceName='" + instanceName + '\'' + + ", productFamilyId='" + productFamilyId + '\'' + + ", source='" + source + '\'' + + ", suppressRollback=" + suppressRollback + + ", requestorId='" + requestorId + '\'' + + '}'; } } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CheckOrderConsistenceManager.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CheckOrderConsistenceManager.java index 1fb57ef..470b161 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CheckOrderConsistenceManager.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CheckOrderConsistenceManager.java @@ -1,17 +1,17 @@ /** - * Copyright (c) 2018 Orange - * - * 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. + * Copyright (c) 2018 Orange + * <p> + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.nbi.apis.serviceorder.workflow; @@ -28,6 +28,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; + import java.util.LinkedHashMap; @Service @@ -64,7 +65,7 @@ public class CheckOrderConsistenceManager { isAllItemsInAdd = false; if (isCustomerFromServiceOrderPresentInInventory(serviceOrderInfo) && existServiceInInventory(serviceOrderItem, serviceOrderItemInfo, - serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId())) { + serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId())) { serviceOrderInfo.addServiceOrderItemInfos(serviceOrderItem.getId(), serviceOrderItemInfo); } else { isServiceOrderRejected = true; @@ -108,9 +109,11 @@ public class CheckOrderConsistenceManager { private RelatedParty getCustomerFromServiceOrder(ServiceOrder serviceOrder) { - for (RelatedParty relatedParty : serviceOrder.getRelatedParty()) { - if ("ONAPcustomer".equalsIgnoreCase(relatedParty.getRole())) { - return relatedParty; + if (serviceOrder.getRelatedParty() != null) { + for (RelatedParty relatedParty : serviceOrder.getRelatedParty()) { + if ("ONAPcustomer".equalsIgnoreCase(relatedParty.getRole())) { + return relatedParty; + } } } return null; @@ -128,7 +131,7 @@ public class CheckOrderConsistenceManager { } private boolean existServiceInInventory(ServiceOrderItem serviceOrderItem, - ServiceOrderItemInfo serviceOrderItemInfo, String globalSubscriberId) { + ServiceOrderItemInfo serviceOrderItemInfo, String globalSubscriberId) { if (!StringUtils.isEmpty(serviceOrderItem.getService().getId())) { String serviceName = (String) serviceOrderItemInfo.getCatalogResponse().get("name"); boolean serviceExistInInventory = serviceOrderConsumerService.doesServiceExistInServiceInventory( @@ -145,7 +148,7 @@ public class CheckOrderConsistenceManager { } private void handleServiceFromCatalog(ServiceOrderItem serviceOrderItem, - ServiceOrderItemInfo serviceOrderItemInfo) { + ServiceOrderItemInfo serviceOrderItemInfo) { ResponseEntity<Object> response = serviceOrderConsumerService .getServiceCatalog(serviceOrderItem.getService().getServiceSpecification().getId()); if (response != null && (response.getStatusCode().equals(HttpStatus.OK) @@ -156,5 +159,4 @@ public class CheckOrderConsistenceManager { } - } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java index 84a198c..94d5553 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java @@ -13,27 +13,12 @@ */ package org.onap.nbi.apis.serviceorder.workflow; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; import org.onap.nbi.apis.serviceorder.SoClient; import org.onap.nbi.apis.serviceorder.model.ServiceCharacteristic; import org.onap.nbi.apis.serviceorder.model.ServiceOrder; import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem; import org.onap.nbi.apis.serviceorder.model.StateType; -import org.onap.nbi.apis.serviceorder.model.consumer.CloudConfiguration; -import org.onap.nbi.apis.serviceorder.model.consumer.CreateServiceInstanceResponse; -import org.onap.nbi.apis.serviceorder.model.consumer.GetRequestStatusResponse; -import org.onap.nbi.apis.serviceorder.model.consumer.ModelInfo; -import org.onap.nbi.apis.serviceorder.model.consumer.RequestDetails; -import org.onap.nbi.apis.serviceorder.model.consumer.RequestInfo; -import org.onap.nbi.apis.serviceorder.model.consumer.RequestParameters; -import org.onap.nbi.apis.serviceorder.model.consumer.RequestState; -import org.onap.nbi.apis.serviceorder.model.consumer.SubscriberInfo; -import org.onap.nbi.apis.serviceorder.model.consumer.UserParams; +import org.onap.nbi.apis.serviceorder.model.consumer.*; import org.onap.nbi.apis.serviceorder.model.orchestrator.ExecutionTask; import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo; import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfoJson; @@ -49,6 +34,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import java.io.IOException; +import java.util.*; + @Service public class SOTaskProcessor { @@ -147,14 +135,15 @@ public class SOTaskProcessor { RequestDetails requestDetails = buildSoRequest(serviceOrderItem, serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId()).getCatalogResponse(), serviceOrderInfo.getSubscriberInfo()); + MSOPayload msoPayload = new MSOPayload(requestDetails); ResponseEntity<CreateServiceInstanceResponse> response = null; switch (serviceOrderItem.getAction()) { case ADD: - response = soClient.callCreateServiceInstance(requestDetails); + response = soClient.callCreateServiceInstance(msoPayload); break; case DELETE: - response = soClient.callDeleteServiceInstance(requestDetails, serviceOrderItem.getService().getId()); + response = soClient.callDeleteServiceInstance(msoPayload, serviceOrderItem.getService().getId()); break; default: break; @@ -265,6 +254,7 @@ public class SOTaskProcessor { requestInfo.setInstanceName(orderItem.getService().getName()); requestInfo.setSource("VID"); requestInfo.setSuppressRollback(false); + requestInfo.setRequestorId("NBI"); requestDetails.setRequestInfo(requestInfo); RequestParameters requestParameters = new RequestParameters(); diff --git a/src/test/java/org/onap/nbi/apis/ApiTest.java b/src/test/java/org/onap/nbi/apis/ApiTest.java index c65f60b..937f417 100644 --- a/src/test/java/org/onap/nbi/apis/ApiTest.java +++ b/src/test/java/org/onap/nbi/apis/ApiTest.java @@ -180,6 +180,19 @@ public class ApiTest { } + @Test + public void testServiceResourceGetInventoryWithoutRelationShipList() throws Exception { + + String serviceName = "vFW"; + String serviceId = "e4688e5f-61a0-4f8b-ae02-a2fbde623bcbWithoutList"; + MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); + params.add("serviceSpecification.name", serviceName); + params.add("relatedParty.id", "6490"); + ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params); + ServiceInventoryAssertions.assertServiceInventoryGetWithoutList(resource); + + } + @Test public void testServiceResourceGetInventoryWithServiceSpecId() throws Exception { @@ -276,6 +289,24 @@ public class ApiTest { } + + @Test + public void testCheckServiceOrderWithoutRelatedParty() throws Exception { + + ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD); + testServiceOrder.setRelatedParty(null); + testServiceOrder.setState(StateType.ACKNOWLEDGED); + testServiceOrder.setId("test"); + serviceOrderRepository.save(testServiceOrder); + + serviceOrderResource.scheduleCheckServiceOrders(); + + ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.ACKNOWLEDGED); + + + } + @Test public void testCheckServiceOrderWithUnKnonwCustomer() throws Exception { diff --git a/src/test/java/org/onap/nbi/apis/assertions/ServiceInventoryAssertions.java b/src/test/java/org/onap/nbi/apis/assertions/ServiceInventoryAssertions.java index 56a6180..f68b82f 100644 --- a/src/test/java/org/onap/nbi/apis/assertions/ServiceInventoryAssertions.java +++ b/src/test/java/org/onap/nbi/apis/assertions/ServiceInventoryAssertions.java @@ -54,6 +54,28 @@ public class ServiceInventoryAssertions { } + public static void assertServiceInventoryGetWithoutList(ResponseEntity<Object> resource) { + assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK); + LinkedHashMap service = (LinkedHashMap) resource.getBody(); + assertThat(service.get("id")).isEqualTo("e4688e5f-61a0-4f8b-ae02-a2fbde623bcb"); + assertThat(service.get("name")).isEqualTo("NewFreeRadius-service-instance-01"); + assertThat(service.get("hasStarted")).isEqualTo("yes"); + assertThat(service.get("type")).isEqualTo("service-instance"); + assertThat(service.get("@type")).isEqualTo("serviceONAP"); + LinkedHashMap relatedParty = (LinkedHashMap) service.get("relatedParty"); + assertThat(relatedParty.get("role")).isEqualTo("ONAPcustomer"); + assertThat(relatedParty.get("id")).isEqualTo("6490"); + LinkedHashMap serviceSpecification = (LinkedHashMap) service.get("serviceSpecification"); + assertThat(serviceSpecification.get("id")).isEqualTo("98d95267-5e0f-4531-abf8-f14b90031dc5"); + assertThat(serviceSpecification.get("invariantUUID")).isEqualTo("709d157b-52fb-4250-976e-7133dff5c347"); + assertThat(serviceSpecification.get("@type")).isEqualTo("ONAPservice"); + + assertThat(((ArrayList) service.get("supportingResource")).size()).isEqualTo(0); + + } + + + public static void assertServiceInventoryFind(ResponseEntity<Object> resource) { assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.OK); ArrayList body = (ArrayList) resource.getBody(); diff --git a/src/test/resources/mappings/aai_get_service-subscriptionWithoutList.json b/src/test/resources/mappings/aai_get_service-subscriptionWithoutList.json new file mode 100644 index 0000000..2765c77 --- /dev/null +++ b/src/test/resources/mappings/aai_get_service-subscriptionWithoutList.json @@ -0,0 +1,19 @@ +{ + "request": { + "method": "GET", + "url": "/aai/v11/business/customers/customer/6490/service-subscriptions/service-subscription/vFW/service-instances/service-instance/e4688e5f-61a0-4f8b-ae02-a2fbde623bcbWithoutList" + }, + "response": { + "status": 200, + "jsonBody": { + "service-instance-id": "e4688e5f-61a0-4f8b-ae02-a2fbde623bcb", + "service-instance-name": "NewFreeRadius-service-instance-01", + "model-invariant-id": "709d157b-52fb-4250-976e-7133dff5c347", + "model-version-id": "98d95267-5e0f-4531-abf8-f14b90031dc5", + "resource-version": "1518508381261" + }, + "headers": { + "Content-Type": "application/json" + } + } +}
\ No newline at end of file diff --git a/src/test/resources/mappings/so_delete_service_instance.json b/src/test/resources/mappings/so_delete_service_instance.json index a2e854e..fae7b9e 100644 --- a/src/test/resources/mappings/so_delete_service_instance.json +++ b/src/test/resources/mappings/so_delete_service_instance.json @@ -1,7 +1,7 @@ { "request": { "method": "DELETE", - "url": "/ecomp/mso/infra/serviceInstances/e4688e5f-61a0-4f8b-ae02-a2fbde623bcb" + "url": "/ecomp/mso/infra/serviceInstances/v4/e4688e5f-61a0-4f8b-ae02-a2fbde623bcb" }, "response": { "status": 201, diff --git a/src/test/resources/mappings/so_post_create_service_instance.json b/src/test/resources/mappings/so_post_create_service_instance.json index 4b61b2c..239aecb 100644 --- a/src/test/resources/mappings/so_post_create_service_instance.json +++ b/src/test/resources/mappings/so_post_create_service_instance.json @@ -1,7 +1,7 @@ { "request": { "method": "POST", - "url": "/ecomp/mso/infra/serviceInstance/v4" + "url": "/ecomp/mso/infra/serviceInstances/v4" }, "response": { "status": 201, |