From f14b68c0ef0a5305bdf88eb87ac53c3e5cd18844 Mon Sep 17 00:00:00 2001 From: romaingimbert Date: Wed, 11 Dec 2019 09:57:46 +0100 Subject: Update SO request to use GR_API instead of VNF_API - add GR_API to so request - request to AAI to retrieve cloud owner id -add status "inprogress" after check Issue-ID: EXTAPI-337 Signed-off-by: romaingimbert Change-Id: I34911a3c785aac24f5feb71fede36a142f8fcffe --- .../java/org/onap/nbi/OnapComponentsUrlPaths.java | 5 +- .../onap/nbi/apis/serviceorder/MultiClient.java | 43 +++++++++++++++ .../apis/serviceorder/ServiceOrderResource.java | 7 +++ .../nbi/apis/serviceorder/model/StateType.java | 21 ++++++++ .../model/consumer/RequestDetails.java | 12 +++-- .../model/consumer/RequestParameters.java | 17 +++++- .../model/orchestrator/ServiceOrderInfo.java | 9 ++++ .../workflow/CreateAAIOwningEntityManager.java | 62 ++++++++++++++++++++++ .../serviceorder/workflow/PostSoProcessor.java | 19 +++---- .../nbi/commons/MultiCriteriaRequestBuilder.java | 3 +- 10 files changed, 179 insertions(+), 19 deletions(-) create mode 100644 src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAIOwningEntityManager.java (limited to 'src/main/java') diff --git a/src/main/java/org/onap/nbi/OnapComponentsUrlPaths.java b/src/main/java/org/onap/nbi/OnapComponentsUrlPaths.java index d9d2cb9..602b88c 100644 --- a/src/main/java/org/onap/nbi/OnapComponentsUrlPaths.java +++ b/src/main/java/org/onap/nbi/OnapComponentsUrlPaths.java @@ -55,7 +55,10 @@ public final class OnapComponentsUrlPaths { "/aai/v14/nodes/service-instances/service-instance/$serviceId?format=resource_and_url"; public static final String AAI_GET_SERVICE_INSTANCES_PATH = "/aai/v14/business/customers/customer/$customerId/service-subscriptions/service-subscription/$serviceSpecName/service-instances/"; - + public static final String AAI_GET_OWNING_ENTITIES = + "/aai/v14/business/owning-entities"; + public static final String AAI_PUT_OWNING_ENTITIES = + "/aai/v14/business/owning-entities/owning-entity/$onap.owning.entity.id"; // MSO public static final String MSO_CREATE_SERVICE_INSTANCE_PATH = "/onap/so/infra/serviceInstantiation/v7/serviceInstances/"; diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/MultiClient.java b/src/main/java/org/onap/nbi/apis/serviceorder/MultiClient.java index 2bc654b..6a38fbc 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/MultiClient.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/MultiClient.java @@ -69,6 +69,12 @@ public class MultiClient { @Value("${onap.cloudOwner}") private String cloudOwner; + @Value("${so.owning.entity.id}") + private String owningEntityId; + + @Value("${so.owning.entity.name}") + private String owningEntityName; + @Autowired private ServiceCatalogUrl serviceCatalogUrl; @@ -148,6 +154,27 @@ public class MultiClient { return false; } + + public String getOwningEntityIdInAAI(ServiceOrder serviceOrder) { + StringBuilder callURL = new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_OWNING_ENTITIES); + String callUrlFormated = callURL.toString(); + + ResponseEntity response = callApiGet(callUrlFormated, buildRequestHeaderForAAI(), null); + if (response.getStatusCode().is2xxSuccessful()) { + LinkedHashMap body = (LinkedHashMap) response.getBody(); + List owningEntities = (List) body.get("owning-entity"); + for (LinkedHashMap owningEntity : owningEntities) { + if (owningEntityName.equalsIgnoreCase((String) owningEntity.get("owning-entity-name"))) { + return owningEntity.get("owning-entity-id").toString(); + } + } + } else { + serviceOrderService.addOrderMessage(serviceOrder, "501"); + } + return null; + } + + public boolean isCustomerPresentInAAI(String customerId, ServiceOrder serviceOrder) { StringBuilder callURL = new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_CUSTOMER_PATH) @@ -161,6 +188,22 @@ public class MultiClient { } + public boolean putOwningEntity(ServiceOrder serviceOrder) { + Map param = new HashMap<>(); + param.put("owning-entity-id", owningEntityId); + param.put("owning-entity-name", owningEntityName); + String callURL = + aaiHost + OnapComponentsUrlPaths.AAI_PUT_OWNING_ENTITIES; + String callUrlFormated = callURL.replace("$onap.owning.entity.id", owningEntityId); + ResponseEntity response = putRequest(param, callUrlFormated, buildRequestHeaderForAAI()); + if(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)) { + serviceOrderService.addOrderMessage(serviceOrder, "501"); + return false; + } + return response.getStatusCode().equals(HttpStatus.CREATED); + } + + public boolean putCustomer(SubscriberInfo subscriberInfo, ServiceOrder serviceOrder) { Map param = new HashMap<>(); diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java b/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java index 90d84a4..c48965a 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Optional; import javax.validation.Valid; import org.onap.nbi.OnapComponentsUrlPaths; +import org.onap.nbi.apis.serviceorder.workflow.CreateAAIOwningEntityManager; import org.onap.nbi.commons.EWInterfaceUtils; import org.onap.nbi.apis.serviceorder.model.ServiceOrder; import org.onap.nbi.apis.serviceorder.model.StateType; @@ -61,6 +62,9 @@ public class ServiceOrderResource extends ResourceManagement { @Autowired CreateAAICustomerManager createAAICustomer; + @Autowired + CreateAAIOwningEntityManager createAAIOwningEntityManager; + @Autowired CreateAAIServiceTypeManager createAAIServiceType; @@ -158,10 +162,13 @@ public class ServiceOrderResource extends ResourceManagement { serviceOrderService.updateOrderState(serviceOrder, StateType.COMPLETED); } else { createAAICustomer.createAAICustomer(serviceOrder, serviceOrderInfo); + createAAIOwningEntityManager.createAAIOwningEntity(serviceOrder, serviceOrderInfo); + if (StateType.ACKNOWLEDGED == serviceOrder.getState()) { createAAIServiceType.createAAIServiceType(serviceOrder, serviceOrderInfo); if (StateType.ACKNOWLEDGED == serviceOrder.getState()) { serviceOrchestratorManager.registerServiceOrder(serviceOrder, serviceOrderInfo); + serviceOrderService.updateOrderState(serviceOrder, StateType.INPROGRESS_TASK_CREATED); } } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/StateType.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/StateType.java index af5e6e6..9f51eac 100755 --- a/src/main/java/org/onap/nbi/apis/serviceorder/model/StateType.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/StateType.java @@ -40,6 +40,8 @@ package org.onap.nbi.apis.serviceorder.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; +import java.util.ArrayList; +import java.util.List; /** * @@ -64,6 +66,8 @@ public enum StateType { PARTIAL("partial"), + INPROGRESS_TASK_CREATED("inProgressTaskCreated"), + INPROGRESS_MODIFY_REQUEST_DELETE_SEND("inProgressModifyRequestDeleteSend"), INPROGRESS_MODIFY_ITEM_TO_CREATE("inProgressModifyItemToCreate"), @@ -92,10 +96,27 @@ public enum StateType { return null; } + public static List fromValueSearch(String text){ + List values = new ArrayList<>(); + for (StateType b : StateType.values()) { + if (String.valueOf(b.value).equals(text)) { + if(b.equals(StateType.INPROGRESS)) { + values.add(INPROGRESS_TASK_CREATED); + values.add(INPROGRESS_MODIFY_REQUEST_DELETE_SEND); + values.add(INPROGRESS_MODIFY_ITEM_TO_CREATE); + values.add(INPROGRESS_MODIFY_REQUEST_CREATE_SEND); + } + values.add(b); + } + } + return values; + } + @JsonValue public String value() { if("inProgressModifyRequestDeleteSend".equalsIgnoreCase(this.value) || "inProgressModifyItemToCreate".equalsIgnoreCase(this.value) + || "inProgressTaskCreated".equalsIgnoreCase(this.value) || "inProgressModifyRequestCreateSend".equalsIgnoreCase(this.value)) { return INPROGRESS.value; } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestDetails.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestDetails.java index 2354b39..748af0d 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestDetails.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestDetails.java @@ -89,8 +89,14 @@ public class RequestDetails { @Override public String toString() { - return "RequestDetails{" + "modelInfo=" + modelInfo + ", subscriberInfo=" + subscriberInfo + ", requestInfo=" - + requestInfo + ", requestParameters=" + requestParameters + ", cloudConfiguration=" - + cloudConfiguration + '}'; + return "RequestDetails{" + + "modelInfo=" + modelInfo + + ", subscriberInfo=" + subscriberInfo + + ", requestInfo=" + requestInfo + + ", requestParameters=" + requestParameters + + ", cloudConfiguration=" + cloudConfiguration + + ", owningEntity=" + owningEntity + + ", project=" + project + + '}'; } } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestParameters.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestParameters.java index e4bbfbb..147ad71 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestParameters.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestParameters.java @@ -26,6 +26,15 @@ public class RequestParameters { private boolean aLaCarte; + private String testApi; + + public String getTestApi() { + return testApi; + } + + public void setTestApi(String testApi) { + this.testApi = testApi; + } public String getSubscriptionServiceType() { return subscriptionServiceType; @@ -69,7 +78,11 @@ public class RequestParameters { @Override public String toString() { - return "RequestParameters{" + "subscriptionServiceType='" + subscriptionServiceType + '\'' + ", userParams=" - + userParams + ", aLaCarte=" + aLaCarte + '}'; + return "RequestParameters{" + + "subscriptionServiceType='" + subscriptionServiceType + '\'' + + ", userParams=" + userParams + + ", aLaCarte=" + aLaCarte + + ", testApi='" + testApi + '\'' + + '}'; } } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/orchestrator/ServiceOrderInfo.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/orchestrator/ServiceOrderInfo.java index fd0eed5..2068fdf 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/model/orchestrator/ServiceOrderInfo.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/orchestrator/ServiceOrderInfo.java @@ -29,6 +29,15 @@ public class ServiceOrderInfo { private boolean allItemsCompleted; private boolean serviceOrderRejected= false; private String serviceOrderId; + private String owningEntityId; + + public String getOwningEntityId() { + return owningEntityId; + } + + public void setOwningEntityId(String owningEntityId) { + this.owningEntityId = owningEntityId; + } public String getServiceOrderId() { return serviceOrderId; diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAIOwningEntityManager.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAIOwningEntityManager.java new file mode 100644 index 0000000..27cb6c8 --- /dev/null +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAIOwningEntityManager.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2019 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.workflow; + +import org.onap.nbi.apis.serviceorder.MultiClient; +import org.onap.nbi.apis.serviceorder.model.ServiceOrder; +import org.onap.nbi.apis.serviceorder.model.StateType; +import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo; +import org.onap.nbi.apis.serviceorder.service.ServiceOrderService; +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.stereotype.Service; + +@Service +public class CreateAAIOwningEntityManager { + + + @Autowired + private MultiClient serviceOrderConsumerService; + + @Autowired + ServiceOrderService serviceOrderService; + + @Value("${so.owning.entity.id}") + private String owningEntityId; + + + private static final Logger LOGGER = LoggerFactory.getLogger(CreateAAIOwningEntityManager.class); + + + public void createAAIOwningEntity(ServiceOrder serviceOrder, + ServiceOrderInfo serviceOrderInfo) { + + String owningEntityIdToSo=serviceOrderConsumerService.getOwningEntityIdInAAI(serviceOrder); + if (owningEntityIdToSo==null) { + owningEntityIdToSo=owningEntityId; + boolean owningEntity = serviceOrderConsumerService.putOwningEntity(serviceOrder); + if (!owningEntity) { + serviceOrderService.updateOrderState(serviceOrder, StateType.REJECTED); + LOGGER.warn("serviceOrder {} rejected : cannot create owning entity ", serviceOrder.getId()); + serviceOrderService.addOrderMessage(serviceOrder, "501"); + } + } + serviceOrderInfo.setOwningEntityId(owningEntityIdToSo); + } + + +} + + diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java index deb4e55..7fdcdaa 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java @@ -117,10 +117,7 @@ public class PostSoProcessor { private ResponseEntity postSORequest( ServiceOrderItem serviceOrderItem, ServiceOrderInfo serviceOrderInfo) { RequestDetails requestDetails = - buildSoRequest( - serviceOrderItem, serviceOrderInfo.getServiceOrderItemInfos() - .get(serviceOrderItem.getId()).getCatalogResponse(), - serviceOrderInfo.getSubscriberInfo()); + buildSoRequest(serviceOrderItem,serviceOrderInfo); MSOPayload msoPayload = new MSOPayload(requestDetails); ResponseEntity response = null; @@ -186,16 +183,15 @@ public class PostSoProcessor { * Build SO CREATE request from the ServiceOrder and catalog informations from SDC * * @param orderItem - * @param sdcInfos - * @param subscriberInfo + * @param serviceOrderInfo * @return */ - private RequestDetails buildSoRequest(ServiceOrderItem orderItem, Map sdcInfos, - SubscriberInfo subscriberInfo) { + private RequestDetails buildSoRequest(ServiceOrderItem orderItem,ServiceOrderInfo serviceOrderInfo) { RequestDetails requestDetails = new RequestDetails(); - requestDetails.setSubscriberInfo(subscriberInfo); - + requestDetails.setSubscriberInfo( serviceOrderInfo.getSubscriberInfo()); + Map sdcInfos=serviceOrderInfo.getServiceOrderItemInfos() + .get(orderItem.getId()).getCatalogResponse(); ModelInfo modelInfo = new ModelInfo(); modelInfo.setModelType("service"); modelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID")); @@ -217,13 +213,14 @@ public class PostSoProcessor { requestParameters.setUserParams(retrieveUserParamsFromServiceCharacteristics( orderItem.getService().getServiceCharacteristic())); requestParameters.setaLaCarte(true); + requestParameters.setTestApi("GR_API"); requestDetails.setRequestParameters(requestParameters); CloudConfiguration cloudConfiguration = new CloudConfiguration(lcpCloudRegionId, tenantId, cloudOwner); requestDetails.setCloudConfiguration(cloudConfiguration); OwningEntity owningEntity = new OwningEntity(); - owningEntity.setOwningEntityId(soOwningEntityId); + owningEntity.setOwningEntityId(serviceOrderInfo.getOwningEntityId()); owningEntity.setOwningEntityName(soOwningEntityName); requestDetails.setOwningEntity(owningEntity); diff --git a/src/main/java/org/onap/nbi/commons/MultiCriteriaRequestBuilder.java b/src/main/java/org/onap/nbi/commons/MultiCriteriaRequestBuilder.java index 968f1dd..36902fe 100644 --- a/src/main/java/org/onap/nbi/commons/MultiCriteriaRequestBuilder.java +++ b/src/main/java/org/onap/nbi/commons/MultiCriteriaRequestBuilder.java @@ -51,8 +51,7 @@ public class MultiCriteriaRequestBuilder { if (!CollectionUtils.isEmpty(states)) { String state = states.get(0); LOGGER.debug("add criterion state {}", state); - query.addCriteria(Criteria.where("state").is(StateType.fromValue(state))); - + query.addCriteria(Criteria.where("state").in(StateType.fromValueSearch(state))); } List descriptions = params.get("description"); if (!CollectionUtils.isEmpty(descriptions)) { -- cgit 1.2.3-korg