diff options
author | Priyadharshini <priyadharshini.b96@wipro.com> | 2020-08-23 04:48:42 -0700 |
---|---|---|
committer | Priyadharshini <priyadharshini.b96@wipro.com> | 2020-08-24 01:05:50 -0700 |
commit | 1bc42e219ad96e8c61483b99d0f98e67909649b6 (patch) | |
tree | b3ec7c5cb358455d885f42be1af5232269a7b317 /src/main/java/org | |
parent | ac2672f417dabb4d097e485457089a0945ab8a71 (diff) |
Implement E2EService activation/deactivation for NetworkSlicing
Issue-ID: EXTAPI-502
Signed-off-by: Priyadharshini <priyadharshini.b96@wipro.com>
Change-Id: I0fa7221bfdeaa0c8c94c10719adbbf4b4605504f
Diffstat (limited to 'src/main/java/org')
8 files changed, 231 insertions, 25 deletions
diff --git a/src/main/java/org/onap/nbi/OnapComponentsUrlPaths.java b/src/main/java/org/onap/nbi/OnapComponentsUrlPaths.java index 417fa51..eb59d31 100644 --- a/src/main/java/org/onap/nbi/OnapComponentsUrlPaths.java +++ b/src/main/java/org/onap/nbi/OnapComponentsUrlPaths.java @@ -64,6 +64,7 @@ public final class OnapComponentsUrlPaths { "/onap/so/infra/serviceInstantiation/v7/serviceInstances/"; public static final String MSO_CREATE_E2ESERVICE_INSTANCE_PATH = "/onap/so/infra/e2eServiceInstances/v3"; public static final String MSO_DELETE_E2ESERVICE_INSTANCE_PATH = "/onap/so/infra/e2eServiceInstances/v3/"; + public static final String MSO_ACTIVATION_E2ESERVICE_INSTANCE_PATH = "/onap/so/infra/e2eServiceInstances/v3/"; public static final String MSO_GET_E2EREQUEST_STATUS_PATH = "/onap/so/infra/e2eServiceInstances/v3/$serviceId/operations/$operationId"; public static final String MSO_HEALTH_CHECK = "/globalhealthcheck"; 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 95009b8..8e58c39 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java @@ -24,6 +24,8 @@ import org.onap.nbi.apis.serviceorder.model.consumer.GetE2ERequestStatusResponse import org.onap.nbi.apis.serviceorder.model.consumer.GetRequestStatusResponse; import org.onap.nbi.apis.serviceorder.model.consumer.MSODeleteE2EPayload; import org.onap.nbi.apis.serviceorder.model.consumer.MSOE2EPayload; +import org.onap.nbi.apis.serviceorder.model.consumer.MSOE2EServiceActivationPayload; +import org.onap.nbi.apis.serviceorder.model.consumer.MSOE2EServiceActivationReponse; import org.onap.nbi.apis.serviceorder.model.consumer.MSOPayload; import org.onap.nbi.apis.serviceorder.model.consumer.ServiceResponse; import org.onap.nbi.exceptions.BackendFunctionalException; @@ -68,6 +70,7 @@ public class SoClient { private String getSoStatus; private String getE2ESoStatus; private String deleteE2ESoUrl; + private String activationE2ESoUrl; private String deleteSoUrl; private String SoHealthCheck; @@ -81,7 +84,9 @@ public class SoClient { .append(OnapComponentsUrlPaths.MSO_DELETE_REQUEST_STATUS_PATH).toString(); deleteE2ESoUrl = new StringBuilder().append(soHostname) .append(OnapComponentsUrlPaths.MSO_DELETE_E2ESERVICE_INSTANCE_PATH).toString(); - getSoStatus = new StringBuilder().append(soHostname).append(OnapComponentsUrlPaths.MSO_GET_REQUEST_STATUS_PATH) + activationE2ESoUrl = new StringBuilder().append(soHostname) + .append(OnapComponentsUrlPaths.MSO_ACTIVATION_E2ESERVICE_INSTANCE_PATH).toString(); + getSoStatus = new StringBuilder().append(soHostname).append(OnapComponentsUrlPaths.MSO_GET_REQUEST_STATUS_PATH) .toString(); getE2ESoStatus = new StringBuilder().append(soHostname) .append(OnapComponentsUrlPaths.MSO_GET_E2EREQUEST_STATUS_PATH).toString(); @@ -92,7 +97,8 @@ public class SoClient { LOGGER.info("SO create e2e service url : " + createE2ESoUrl); LOGGER.info("SO delete service url : " + deleteSoUrl); LOGGER.info("SO delete e2e service url : " + deleteE2ESoUrl); - LOGGER.info("SO get so status url : " + getSoStatus); + LOGGER.info("SO e2e service actiavtion url : " + activationE2ESoUrl); + LOGGER.info("SO get so status url : " + getSoStatus); LOGGER.info("SO get e2e so status url : " + getE2ESoStatus); LOGGER.info("SO healthCheck : " + SoHealthCheck); @@ -208,15 +214,8 @@ public class SoClient { HttpMethod.DELETE, new HttpEntity<>(msoDeleteE2EPayload, buildRequestHeader()), DeleteE2EServiceInstanceResponse.class); - // For E2E Services , Create and Delete Service responses are different, to maintain - // consistentcy with ServiceInstances - // Copy contents of DeleteE2EServiceInstanceResponse to CreateE2EServiceInstanceResponse - CreateE2EServiceInstanceResponse dummyresponse = new CreateE2EServiceInstanceResponse(); - ServiceResponse serviceResponse = new ServiceResponse(); - dummyresponse.setService(serviceResponse); - dummyresponse.getService().setOperationId(deleteresponse.getBody().getOperationId()); - dummyresponse.getService().setServiceId(serviceInstanceId); - + CreateE2EServiceInstanceResponse dummyresponse = buildDummyResponse(serviceInstanceId, + deleteresponse.getBody().getOperationId()); ResponseEntity<CreateE2EServiceInstanceResponse> response = new ResponseEntity(dummyresponse, deleteresponse.getStatusCode()); logE2EResponsePost(url, response); @@ -230,7 +229,57 @@ public class SoClient { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } + public ResponseEntity<CreateE2EServiceInstanceResponse> callServiceActivationE2EService(String globalSubscriberId, + String serviceType, String serviceInstanceId, String operation) { + String url = new StringBuilder(activationE2ESoUrl).append(serviceInstanceId).append("/").append(operation).toString(); + MSOE2EServiceActivationPayload msoE2EServiceActivationPayload = new MSOE2EServiceActivationPayload(); + msoE2EServiceActivationPayload.setGlobalSubscriberId(globalSubscriberId); + msoE2EServiceActivationPayload.setServiceType(serviceType); + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Calling SO E2E Service Activation/Deactivation with url : " + url + " MSOE2EServiceActivationPayload : " + + msoE2EServiceActivationPayload.toString()); + } + + try { + ResponseEntity<MSOE2EServiceActivationReponse> activationResponse = restTemplate.exchange(url, + HttpMethod.POST, new HttpEntity<>(msoE2EServiceActivationPayload, buildRequestHeader()), + MSOE2EServiceActivationReponse.class); + CreateE2EServiceInstanceResponse dummyresponse = buildDummyResponse(serviceInstanceId, + activationResponse.getBody().getOperationId()); + + ResponseEntity<CreateE2EServiceInstanceResponse> response = + new ResponseEntity(dummyresponse, activationResponse.getStatusCode()); + logE2EResponsePost(url, response); + return response; + + } catch (BackendFunctionalException e) { + LOGGER.error(ERROR_ON_CALLING + url + " ," + e); + return new ResponseEntity<>(e.getHttpStatus()); + } catch (ResourceAccessException e) { + LOGGER.error(ERROR_ON_CALLING + url + " ," + e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + /** + * @param serviceInstanceId + * @param operationId + * @return + * For E2E Services , Create and Delete/Activate/Deactivate Service responses are different, + * to maintain consistentcy with ServiceInstances Copy contents of ServiceActivationE2EReponse + * to CreateE2EServiceInstanceResponse + */ + private CreateE2EServiceInstanceResponse buildDummyResponse(String serviceInstanceId, + String operationId) { + CreateE2EServiceInstanceResponse dummyresponse = new CreateE2EServiceInstanceResponse(); + ServiceResponse serviceResponse = new ServiceResponse(); + dummyresponse.setService(serviceResponse); + dummyresponse.getService().setOperationId(operationId); + dummyresponse.getService().setServiceId(serviceInstanceId); + return dummyresponse; + } private void logResponsePost(String url, ResponseEntity<CreateServiceInstanceResponse> response) { LOGGER.info(RESPONSE_STATUS + response.getStatusCodeValue()); if (LOGGER.isDebugEnabled()) { @@ -362,4 +411,4 @@ public class SoClient { return httpHeaders; } -}
\ No newline at end of file +} diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/Service.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/Service.java index 31802f2..6b35130 100755 --- a/src/main/java/org/onap/nbi/apis/serviceorder/model/Service.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/Service.java @@ -68,7 +68,7 @@ public class Service { private String name = null; @JsonProperty("serviceState") - private String serviceState = null; + private ServiceStateType serviceState = null; @JsonProperty("@type") private String type = null; @@ -158,7 +158,7 @@ public class Service { this.name = name; } - public Service serviceState(String serviceState) { + public Service serviceState(ServiceStateType serviceState) { this.serviceState = serviceState; return this; } @@ -170,11 +170,11 @@ public class Service { **/ @JsonProperty("serviceState") @ApiModelProperty(value = "The lifecycle state of the service") - public String getServiceState() { + public ServiceStateType getServiceState() { return serviceState; } - public void setServiceState(String serviceState) { + public void setServiceState(ServiceStateType serviceState) { this.serviceState = serviceState; } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/ServiceStateType.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/ServiceStateType.java new file mode 100644 index 0000000..a461080 --- /dev/null +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/ServiceStateType.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2020 Wipro Limited + * + * 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; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +public enum ServiceStateType { + + ACTIVE("active"), + + INACTIVE("inactive"); + + private String value; + + ServiceStateType(String value) { + this.value = value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static ServiceStateType fromValue(String text) { + for (ServiceStateType b : ServiceStateType.values()) { + if (String.valueOf(b.value).equals(text)) { + return b; + } + } + return null; + } + + @JsonValue + public String value() { + return this.value; + } + +} + diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/MSOE2EServiceActivationPayload.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/MSOE2EServiceActivationPayload.java new file mode 100644 index 0000000..fca0a22 --- /dev/null +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/MSOE2EServiceActivationPayload.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2020 Wipro Limited + * + * 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 MSOE2EServiceActivationPayload { + + private String globalSubscriberId; + + private String serviceType; + + public String getGlobalSubscriberId() { + return globalSubscriberId; + } + + public void setGlobalSubscriberId(String globalSubscriberId) { + this.globalSubscriberId = globalSubscriberId; + } + + public String getServiceType() { + return serviceType; + } + + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + @Override + public String toString() { + return "MSOE2EServiceActivationPayload{" + "globalSubscriberId='" + globalSubscriberId + '\'' + ", serviceType='" + + serviceType + '\'' + '}'; + } + +} + diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/MSOE2EServiceActivationReponse.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/MSOE2EServiceActivationReponse.java new file mode 100644 index 0000000..e74cf93 --- /dev/null +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/MSOE2EServiceActivationReponse.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2020 Wipro Limited + * + * 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 MSOE2EServiceActivationReponse { + + private String operationId; + + + public String getOperationId() { + return operationId; + } + + public void setOperationId(String operationId) { + this.operationId = operationId; + } + + @Override + public String toString() { + return "MSOE2EServiceActivationReponse{" + "operationId='" + operationId + '\'' + '}'; + } +} + 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 e590afc..9c673f9 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 @@ -27,6 +27,7 @@ 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.ServiceStateType; import org.onap.nbi.apis.serviceorder.model.consumer.CloudConfiguration; import org.onap.nbi.apis.serviceorder.model.consumer.CreateE2EServiceInstanceResponse; import org.onap.nbi.apis.serviceorder.model.consumer.CreateMacroServiceInstanceResponse; @@ -180,20 +181,34 @@ public class PostSoProcessor { service.getServiceType(), serviceOrderItem.getService().getId()); break; case MODIFY: - if (StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState()) { + //EXT-API supports E2E service activation/deactivation with action=modify and seviceState=active/inactive + boolean isActivateReq = ServiceStateType.ACTIVE == serviceOrderItem.getService().getServiceState() || + ServiceStateType.INACTIVE == serviceOrderItem.getService().getServiceState(); + + if (ServiceStateType.ACTIVE == serviceOrderItem.getService().getServiceState()) { + response = soClient.callServiceActivationE2EService(service.getGlobalSubscriberId(), + service.getServiceType(), serviceOrderItem.getService().getId(),"activate"); + } + if (ServiceStateType.INACTIVE == serviceOrderItem.getService().getServiceState()) { + response = soClient.callServiceActivationE2EService(service.getGlobalSubscriberId(), + service.getServiceType(), serviceOrderItem.getService().getId(),"deactivate"); + } + //Other E2E service modification follows Deletion followed by activation. + //For service modification, do not send serviceState=active/inactive + if (!isActivateReq && StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState()) { response = soClient.callE2ECreateServiceInstance(msoE2EPayload); } - if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) { + if (!isActivateReq && StateType.ACKNOWLEDGED == serviceOrderItem.getState()) { response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(), service.getServiceType(), serviceOrderItem.getService().getId()); } break; - default: + default: break; } return response; } - + private ResponseEntity<CreateMacroServiceInstanceResponse> postSOMacroRequest(ServiceOrderItem serviceOrderItem, ServiceOrderInfo serviceOrderInfo) { @@ -564,4 +579,4 @@ public class PostSoProcessor { return userParams; } -}
\ No newline at end of file +} diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOGetStatusManager.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOGetStatusManager.java index bbe1160..d5d12bb 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOGetStatusManager.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOGetStatusManager.java @@ -17,6 +17,7 @@ import org.onap.nbi.apis.serviceorder.SoClient; import org.onap.nbi.apis.serviceorder.model.ActionType; import org.onap.nbi.apis.serviceorder.model.ServiceOrder; import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem; +import org.onap.nbi.apis.serviceorder.model.ServiceStateType; import org.onap.nbi.apis.serviceorder.model.StateType; import org.onap.nbi.apis.serviceorder.model.consumer.GetE2ERequestStatusResponse; import org.onap.nbi.apis.serviceorder.model.consumer.GetRequestStatusResponse; @@ -64,7 +65,8 @@ public class SOGetStatusManager { LOGGER.debug("orderitem id {} failed, response from request status {}", orderItem.getId(), response.getRequest().getRequestStatus().getRequestState()); } else { - updateOrderItemIfStatusCompleted(serviceOrder, orderItem); + boolean e2eService = false; + updateOrderItemIfStatusCompleted(serviceOrder, orderItem, e2eService); LOGGER.debug("orderitem id {} completed"); } } else { @@ -73,10 +75,14 @@ public class SOGetStatusManager { } - private void updateOrderItemIfStatusCompleted(ServiceOrder serviceOrder, ServiceOrderItem orderItem) { + private void updateOrderItemIfStatusCompleted(ServiceOrder serviceOrder, ServiceOrderItem orderItem,boolean e2eService) { + boolean serviceActivationReq = orderItem.getService().getServiceState() == ServiceStateType.ACTIVE || + orderItem.getService().getServiceState() == ServiceStateType.INACTIVE; if (orderItem.getAction() != ActionType.MODIFY) { serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.COMPLETED); - } else { + }else if(orderItem.getAction() == ActionType.MODIFY && serviceActivationReq && e2eService) { + serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.COMPLETED); + }else { if (StateType.INPROGRESS_MODIFY_REQUEST_CREATE_SEND == orderItem.getState()) { serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.COMPLETED); } else { @@ -105,7 +111,8 @@ public class SOGetStatusManager { LOGGER.debug("orderitem id {} failed, response from request status {}", orderItem.getId(), response.getOperation().getResult()); } else if (FINISHED.equals(result)) { - updateOrderItemIfStatusCompleted(serviceOrder, orderItem); + boolean e2eService = true; + updateOrderItemIfStatusCompleted(serviceOrder, orderItem,e2eService); LOGGER.debug("orderitem id {} completed"); } } else { |