diff options
20 files changed, 2003 insertions, 1856 deletions
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/RestfulUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/RestfulUtil.java index fcbbf8515a..0bedd12eb1 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/RestfulUtil.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/RestfulUtil.java @@ -83,7 +83,7 @@ public class RestfulUtil { msbPort = msoPropertiesFactory.getMsoJavaProperties("MSO_PROP_TOPOLOGY").getProperty("msb-port", DEFAULT_MSB_PORT); } } catch(MsoPropertiesException e) { - LOGGER.error(MessageEnum.RA_NS_EXC, "VFC Adapter", "", MsoLogger.ErrorCode.AvailabilityError, "Get msb properties failed"); + LOGGER.error(MessageEnum.RA_NS_EXC, "VFC Adapter", "", MsoLogger.ErrorCode.AvailabilityError, "Get msb properties failed",e); e.printStackTrace(); } return "http://" + msbIp + ":" + msbPort; diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/ASDCConfiguration.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/ASDCConfiguration.java index a151b5dae7..7cc6ab8a89 100644 --- a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/ASDCConfiguration.java +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/ASDCConfiguration.java @@ -31,6 +31,7 @@ import java.util.Map.Entry; import java.util.Properties; import org.openecomp.mso.asdc.client.exceptions.ASDCParametersException; +import org.openecomp.mso.logger.MsoLogger; import org.openecomp.mso.properties.MsoJsonProperties; import org.openecomp.mso.properties.MsoPropertiesException; import org.openecomp.mso.properties.MsoPropertiesFactory; @@ -80,7 +81,8 @@ public class ASDCConfiguration implements IConfiguration { public static final String TOSCA_CSAR="TOSCA_CSAR"; public static final String VF_MODULES_METADATA="VF_MODULES_METADATA"; - + private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL); + private static final String[] SUPPORTED_ARTIFACT_TYPES = {HEAT, HEAT_ARTIFACT, HEAT_ENV, @@ -284,6 +286,7 @@ public class ASDCConfiguration implements IConfiguration { return null; } } catch (IOException e) { + msoLogger.debug("IOException occured", e); return null; } } @@ -376,6 +379,7 @@ public class ASDCConfiguration implements IConfiguration { return null; } } catch (IOException e) { + msoLogger.debug("IOException occured", e); return null; } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/ResourceInput.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/ResourceInput.java index 00e4ae71d6..13b1666991 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/ResourceInput.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/ResourceInput.java @@ -1,293 +1,296 @@ -/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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.
- * ============LICENSE_END=========================================================
- */
-package org.openecomp.mso.bpmn.common.recipe;
-
-import org.openecomp.mso.bpmn.core.domain.ModelInfo;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonPropertyOrder;
-import com.fasterxml.jackson.annotation.JsonRootName;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-
-/**
- * the inputs for the resource recipe
- * <br>
- * <p>
- * </p>
- *
- * @author
- * @version ONAP Beijing Release 2018-03-08
- */
-@JsonPropertyOrder({"resourceInstanceName", "resourceInstanceDes", "globalSubscriberId", "serviceType", "serviceId", "operationId", "serviceModelInfo","resourceModelInfo", "resourceInstancenUuid","resourceParameters","operationType"})
-@JsonRootName("variables")
-public class ResourceInput {
-
- @JsonProperty("resourceInstanceName")
- private String resourceInstanceName;
-
- @JsonProperty("resourceInstanceDes")
- private String resourceInstanceDes;
-
- @JsonProperty("globalSubscriberId")
- private String globalSubscriberId;
-
- @JsonProperty("serviceType")
- private String serviceType;
-
- @JsonProperty("serviceInstanceId")
- private String serviceInstanceId;
-
- @JsonProperty("operationId")
- private String operationId;
-
- @JsonProperty("serviceModelInfo")
- private ModelInfo serviceModelInfo;
-
- @JsonProperty("resourceModelInfo")
- private ModelInfo resourceModelInfo;
-
- //for delete resource
- @JsonProperty("resourceInstancenUuid")
- private String resourceInstancenUuid;
-
- @JsonProperty("resourceParameters")
- private String resourceParameters;
-
- @JsonProperty("operationType")
- private String operationType;
-
-
- /**
- * @return Returns the resourceInstanceName.
- */
- @JsonProperty("resourceInstanceName")
- public String getResourceInstanceName() {
- return resourceInstanceName;
- }
-
-
- /**
- * @param resourceInstanceName The resourceInstanceName to set.
- */
- @JsonProperty("resourceInstanceName")
- public void setResourceInstanceName(String resourceInstanceName) {
- this.resourceInstanceName = resourceInstanceName;
- }
-
-
- /**
- * @return Returns the resourceInstanceDes.
- */
- @JsonProperty("resourceInstanceDes")
- public String getResourceInstanceDes() {
- return resourceInstanceDes;
- }
-
-
- /**
- * @param resourceInstanceDes The resourceInstanceDes to set.
- */
- @JsonProperty("resourceInstanceDes")
- public void setResourceInstanceDes(String resourceInstanceDes) {
- this.resourceInstanceDes = resourceInstanceDes;
- }
-
-
- /**
- * @return Returns the globalSubscriberId.
- */
- @JsonProperty("globalSubscriberId")
- public String getGlobalSubscriberId() {
- return globalSubscriberId;
- }
-
-
- /**
- * @param globalSubscriberId The globalSubscriberId to set.
- */
- @JsonProperty("globalSubscriberId")
- public void setGlobalSubscriberId(String globalSubscriberId) {
- this.globalSubscriberId = globalSubscriberId;
- }
-
-
- /**
- * @return Returns the serviceType.
- */
- @JsonProperty("serviceType")
- public String getServiceType() {
- return serviceType;
- }
-
-
- /**
- * @param serviceType The serviceType to set.
- */
- @JsonProperty("serviceType")
- public void setServiceType(String serviceType) {
- this.serviceType = serviceType;
- }
-
-
- /**
- * @return Returns the serviceId.
- */
- @JsonProperty("serviceInstanceId")
- public String getServiceInstanceId() {
- return serviceInstanceId;
- }
-
-
- /**
- * @param serviceId The serviceId to set.
- */
- @JsonProperty("serviceInstanceId")
- public void setServiceInstanceId(String serviceId) {
- this.serviceInstanceId = serviceId;
- }
-
-
- /**
- * @return Returns the operationId.
- */
- @JsonProperty("operationId")
- public String getOperationId() {
- return operationId;
- }
-
-
- /**
- * @param operationId The operationId to set.
- */
- @JsonProperty("operationId")
- public void setOperationId(String operationId) {
- this.operationId = operationId;
- }
-
- /**
- * @return Returns the serviceModelInfo.
- */
- @JsonProperty("serviceModelInfo")
- public ModelInfo getServiceModelInfo() {
- return serviceModelInfo;
- }
-
-
-
- /**
- * @param serviceModelInfo The serviceModelInfo to set.
- */
- @JsonProperty("serviceModelInfo")
- public void setServiceModelInfo(ModelInfo serviceModelInfo) {
- this.serviceModelInfo = serviceModelInfo;
- }
-
-
-
- /**
- * @return Returns the resourceModelInfo.
- */
- @JsonProperty("resourceModelInfo")
- public ModelInfo getResourceModelInfo() {
- return resourceModelInfo;
- }
-
-
-
- /**
- * @param resourceModelInfo The resourceModelInfo to set.
- */
- @JsonProperty("resourceModelInfo")
- public void setResourceModelInfo(ModelInfo resourceModelInfo) {
- this.resourceModelInfo = resourceModelInfo;
- }
-
-
- /**
- * @return Returns the resourceParameters.
- */
- @JsonProperty("resourceParameters")
- public String getResourceParameters() {
- return resourceParameters;
- }
-
-
- /**
- * @param resourceParameters The resourceParameters to set.
- */
- @JsonProperty("resourceParameters")
- public void setResourceParameters(String resourceParameters) {
- this.resourceParameters = resourceParameters;
- }
-
-
- /**
- * @return Returns the operationType.
- */
- @JsonProperty("operationType")
- public String getOperationType() {
- return operationType;
- }
-
-
- /**
- * @param operationType The operationType to set.
- */
- @JsonProperty("operationType")
- public void setOperationType(String operationType) {
- this.operationType = operationType;
- }
-
-
-
- /**
- * @return Returns the resourceInstancenUuid.
- */
- @JsonProperty("resourceInstancenUuid")
- public String getResourceInstancenUuid() {
- return resourceInstancenUuid;
- }
-
-
-
- /**
- * @param resourceInstancenUuid The resourceInstancenUuid to set.
- */
- @JsonProperty("resourceInstancenUuid")
- public void setResourceInstancenUuid(String resourceInstancenUuid) {
- this.resourceInstancenUuid = resourceInstancenUuid;
- }
-
- @Override
- public String toString() {
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
- String jsonStr = "";
- try {
- jsonStr = mapper.writeValueAsString(this);
- } catch(JsonProcessingException e) {
-
- e.printStackTrace();
- }
- return jsonStr;
- }
-}
+/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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. + * ============LICENSE_END========================================================= + */ +package org.openecomp.mso.bpmn.common.recipe; + +import org.openecomp.mso.bpmn.core.domain.ModelInfo; +import org.openecomp.mso.logger.MsoLogger; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.JsonRootName; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + +/** + * the inputs for the resource recipe + * <br> + * <p> + * </p> + * + * @author + * @version ONAP Beijing Release 2018-03-08 + */ +@JsonPropertyOrder({"resourceInstanceName", "resourceInstanceDes", "globalSubscriberId", "serviceType", "serviceId", "operationId", "serviceModelInfo","resourceModelInfo", "resourceInstancenUuid","resourceParameters","operationType"}) +@JsonRootName("variables") +public class ResourceInput { + + private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL); + + @JsonProperty("resourceInstanceName") + private String resourceInstanceName; + + @JsonProperty("resourceInstanceDes") + private String resourceInstanceDes; + + @JsonProperty("globalSubscriberId") + private String globalSubscriberId; + + @JsonProperty("serviceType") + private String serviceType; + + @JsonProperty("serviceInstanceId") + private String serviceInstanceId; + + @JsonProperty("operationId") + private String operationId; + + @JsonProperty("serviceModelInfo") + private ModelInfo serviceModelInfo; + + @JsonProperty("resourceModelInfo") + private ModelInfo resourceModelInfo; + + //for delete resource + @JsonProperty("resourceInstancenUuid") + private String resourceInstancenUuid; + + @JsonProperty("resourceParameters") + private String resourceParameters; + + @JsonProperty("operationType") + private String operationType; + + + /** + * @return Returns the resourceInstanceName. + */ + @JsonProperty("resourceInstanceName") + public String getResourceInstanceName() { + return resourceInstanceName; + } + + + /** + * @param resourceInstanceName The resourceInstanceName to set. + */ + @JsonProperty("resourceInstanceName") + public void setResourceInstanceName(String resourceInstanceName) { + this.resourceInstanceName = resourceInstanceName; + } + + + /** + * @return Returns the resourceInstanceDes. + */ + @JsonProperty("resourceInstanceDes") + public String getResourceInstanceDes() { + return resourceInstanceDes; + } + + + /** + * @param resourceInstanceDes The resourceInstanceDes to set. + */ + @JsonProperty("resourceInstanceDes") + public void setResourceInstanceDes(String resourceInstanceDes) { + this.resourceInstanceDes = resourceInstanceDes; + } + + + /** + * @return Returns the globalSubscriberId. + */ + @JsonProperty("globalSubscriberId") + public String getGlobalSubscriberId() { + return globalSubscriberId; + } + + + /** + * @param globalSubscriberId The globalSubscriberId to set. + */ + @JsonProperty("globalSubscriberId") + public void setGlobalSubscriberId(String globalSubscriberId) { + this.globalSubscriberId = globalSubscriberId; + } + + + /** + * @return Returns the serviceType. + */ + @JsonProperty("serviceType") + public String getServiceType() { + return serviceType; + } + + + /** + * @param serviceType The serviceType to set. + */ + @JsonProperty("serviceType") + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + + /** + * @return Returns the serviceId. + */ + @JsonProperty("serviceInstanceId") + public String getServiceInstanceId() { + return serviceInstanceId; + } + + + /** + * @param serviceId The serviceId to set. + */ + @JsonProperty("serviceInstanceId") + public void setServiceInstanceId(String serviceId) { + this.serviceInstanceId = serviceId; + } + + + /** + * @return Returns the operationId. + */ + @JsonProperty("operationId") + public String getOperationId() { + return operationId; + } + + + /** + * @param operationId The operationId to set. + */ + @JsonProperty("operationId") + public void setOperationId(String operationId) { + this.operationId = operationId; + } + + /** + * @return Returns the serviceModelInfo. + */ + @JsonProperty("serviceModelInfo") + public ModelInfo getServiceModelInfo() { + return serviceModelInfo; + } + + + + /** + * @param serviceModelInfo The serviceModelInfo to set. + */ + @JsonProperty("serviceModelInfo") + public void setServiceModelInfo(ModelInfo serviceModelInfo) { + this.serviceModelInfo = serviceModelInfo; + } + + + + /** + * @return Returns the resourceModelInfo. + */ + @JsonProperty("resourceModelInfo") + public ModelInfo getResourceModelInfo() { + return resourceModelInfo; + } + + + + /** + * @param resourceModelInfo The resourceModelInfo to set. + */ + @JsonProperty("resourceModelInfo") + public void setResourceModelInfo(ModelInfo resourceModelInfo) { + this.resourceModelInfo = resourceModelInfo; + } + + + /** + * @return Returns the resourceParameters. + */ + @JsonProperty("resourceParameters") + public String getResourceParameters() { + return resourceParameters; + } + + + /** + * @param resourceParameters The resourceParameters to set. + */ + @JsonProperty("resourceParameters") + public void setResourceParameters(String resourceParameters) { + this.resourceParameters = resourceParameters; + } + + + /** + * @return Returns the operationType. + */ + @JsonProperty("operationType") + public String getOperationType() { + return operationType; + } + + + /** + * @param operationType The operationType to set. + */ + @JsonProperty("operationType") + public void setOperationType(String operationType) { + this.operationType = operationType; + } + + + + /** + * @return Returns the resourceInstancenUuid. + */ + @JsonProperty("resourceInstancenUuid") + public String getResourceInstancenUuid() { + return resourceInstancenUuid; + } + + + + /** + * @param resourceInstancenUuid The resourceInstancenUuid to set. + */ + @JsonProperty("resourceInstancenUuid") + public void setResourceInstancenUuid(String resourceInstancenUuid) { + this.resourceInstancenUuid = resourceInstancenUuid; + } + + @Override + public String toString() { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); + String jsonStr = ""; + try { + jsonStr = mapper.writeValueAsString(this); + } catch(JsonProcessingException e) { + msoLogger.debug("JsonProcessingException", e); + e.printStackTrace(); + } + return jsonStr; + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/ResourceRecipeRequest.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/ResourceRecipeRequest.java index 194f7c43ec..a1809fe754 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/ResourceRecipeRequest.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/recipe/ResourceRecipeRequest.java @@ -20,6 +20,8 @@ package org.openecomp.mso.bpmn.common.recipe; +import org.openecomp.mso.logger.MsoLogger; + import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonRootName; @@ -35,6 +37,8 @@ import com.fasterxml.jackson.databind.SerializationFeature; @JsonRootName("variables") public class ResourceRecipeRequest { + private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL); + @JsonProperty("resourceInput") private BpmnParam resourceInput; @@ -147,7 +151,7 @@ public class ResourceRecipeRequest { try { jsonStr = mapper.writeValueAsString(this); } catch(JsonProcessingException e) { - + msoLogger.debug("JsonProcessingException", e); e.printStackTrace(); } return jsonStr; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilder.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilder.java index 7c3ea37817..c88800273c 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilder.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilder.java @@ -109,6 +109,7 @@ public class ResourceRequestBuilder { Map<String, Object> resourceInputsFromServiceDeclaredLevel = buildResouceRequest(serviceUuid, resourceCustomizationUuid, serviceInput); resourceInputsFromUuiMap.putAll(resourceInputsFromServiceDeclaredLevel); } catch(SdcToscaParserException e) { + LOGGER.debug("SdcToscaParserException", e); e.printStackTrace(); } String resourceInputsStr = getJsonString(resourceInputsFromUuiMap); @@ -216,7 +217,7 @@ public class ResourceRequestBuilder { try { jsonStr = mapper.writeValueAsString(srcObj); } catch(JsonProcessingException e) { - + LOGGER.debug("SdcToscaParserException", e); e.printStackTrace(); } return jsonStr; diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CancelDmaapSubscription.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CancelDmaapSubscription.java new file mode 100644 index 0000000000..92169b202b --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CancelDmaapSubscription.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.openecomp.mso.bpmn.infrastructure.pnf.dmaap.DmaapClient; +import org.springframework.beans.factory.annotation.Autowired; + +public class CancelDmaapSubscription implements JavaDelegate { + + private DmaapClient dmaapClient; + + @Override + public void execute(DelegateExecution execution) throws Exception { + String correlationId = (String) execution.getVariable(ExecutionVariableNames.CORRELATION_ID); + dmaapClient.unregister(correlationId); + } + + @Autowired + public void setDmaapClient(DmaapClient dmaapClient) { + this.dmaapClient = dmaapClient; + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java index e2dfedb6e4..0e65dd7441 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java @@ -32,6 +32,7 @@ import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil; import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiConnection; import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiResponse; import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.CheckAaiForCorrelationIdImplementation; +import org.openecomp.mso.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; /** @@ -46,7 +47,7 @@ import org.springframework.beans.factory.annotation.Autowired; */ public class CheckAaiForCorrelationIdDelegate implements JavaDelegate { - + private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL); private CheckAaiForCorrelationIdImplementation implementation = new CheckAaiForCorrelationIdImplementation(); private AaiConnection aaiConnection; @@ -68,6 +69,7 @@ public class CheckAaiForCorrelationIdDelegate implements JavaDelegate { execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, aaiResponse.getContainsInfoAboutPnf()); execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, aaiResponse.getContainsInfoAboutIp()); } catch (IOException e) { + LOGGER.error("IOException",e); new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, e.getMessage()); } } diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java index 0d64f2c8b7..94d221a054 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java @@ -23,8 +23,7 @@ package org.openecomp.mso.bpmn.infrastructure.pnf.delegate; @SuppressWarnings("ALL") public class ExecutionVariableNames { - private ExecutionVariableNames() { - } + private ExecutionVariableNames() {} public final static String CORRELATION_ID = "correlationId"; public final static String AAI_CONTAINS_INFO_ABOUT_PNF = "aaiContainsInfoAboutPnf"; diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/DmaapClient.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/DmaapClient.java index c6b6be6842..12a6c7c51f 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/DmaapClient.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/DmaapClient.java @@ -23,4 +23,6 @@ package org.openecomp.mso.bpmn.infrastructure.pnf.dmaap; public interface DmaapClient { void registerForUpdate(String correlationId, Runnable informConsumer); + + Runnable unregister(String correlationId); } diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java index 8c9903e87a..1fd2de97f2 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java @@ -86,6 +86,15 @@ public class PnfEventReadyConsumer implements DmaapClient { } } + @Override + public synchronized Runnable unregister(String correlationId) { + Runnable runnable = pnfCorrelationIdToThreadMap.remove(correlationId); + if (pnfCorrelationIdToThreadMap.isEmpty()) { + stopDmaapThreadListener(); + } + return runnable; + } + private synchronized void startDmaapThreadListener() { if (!dmaapThreadListenerIsRunning) { executor = Executors.newScheduledThreadPool(1); @@ -123,13 +132,9 @@ public class PnfEventReadyConsumer implements DmaapClient { private synchronized void informAboutPnfReadyIfCorrelationIdFound(String correlationId) { - Runnable runnable = pnfCorrelationIdToThreadMap.remove(correlationId); + Runnable runnable = unregister(correlationId); if (runnable != null) { runnable.run(); - - if (pnfCorrelationIdToThreadMap.isEmpty()) { - stopDmaapThreadListener(); - } } } diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java index 25141a0c40..ee047c9dd5 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java @@ -359,7 +359,7 @@ public abstract class AbstractSdncOperationTask extends BaseTask { return vlaue; } } catch (Exception e) { - msoLogger.error(MessageEnum.GENERAL_EXCEPTION, " getMsbIp catch exception: ", "", this.getTaskName(), MsoLogger.ErrorCode.UnknownError, e.getClass().toString()); + msoLogger.error(MessageEnum.GENERAL_EXCEPTION, " getMsbIp catch exception: ", "", this.getTaskName(), MsoLogger.ErrorCode.UnknownError, e.getClass().toString(),e); } return defaultValue; } diff --git a/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn b/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn index 177bd98b44..c118105e35 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn +++ b/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn @@ -9,10 +9,10 @@ <bpmn:messageFlow id="MessageFlow_0vjul4t" sourceRef="Participant_0atuyq0" targetRef="CheckAiiForCorrelationId" /> <bpmn:messageFlow id="MessageFlow_1vrcp2d" sourceRef="Participant_19w87ws" targetRef="WaitForDmaapPnfReadyNotification" /> <bpmn:messageFlow id="MessageFlow_0tg4hw9" sourceRef="InformDmaapClient" targetRef="Participant_19w87ws" /> - <bpmn:messageFlow id="MessageFlow_1py54jr" sourceRef="Task_1rwv8g6" targetRef="Participant_19w87ws" /> + <bpmn:messageFlow id="MessageFlow_1py54jr" sourceRef="CancelDmaapClientSubscription" targetRef="Participant_19w87ws" /> </bpmn:collaboration> <bpmn:process id="CreateAndActivatePnfResource" name="CreateAndActivatePnfResource" isExecutable="true"> - <bpmn:sequenceFlow id="SequenceFlow_1kc34bc" sourceRef="WaitForDmaapTimeout" targetRef="Task_1rwv8g6" /> + <bpmn:sequenceFlow id="SequenceFlow_1kc34bc" sourceRef="WaitForDmaapTimeout" targetRef="CancelDmaapClientSubscription" /> <bpmn:sequenceFlow id="SequenceFlow_1o8od8e" sourceRef="InformDmaapClient" targetRef="WaitForDmaapPnfReadyNotification" /> <bpmn:sequenceFlow id="SequenceFlow_17s9025" sourceRef="AaiEntryExists" targetRef="InformDmaapClient" /> <bpmn:sequenceFlow id="SequenceFlow_1ls8pua" name="No" sourceRef="DoesAaiContainInfoAboutIp" targetRef="AaiEntryExists"> @@ -31,24 +31,34 @@ <bpmn:sequenceFlow id="SequenceFlow_1h6yz62" name="Yes" sourceRef="DoesAaiContainInfoAboutIp" targetRef="AaiEntryAlreadyUpToDate"> <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{aaiContainsInfoAboutIp}</bpmn:conditionExpression> </bpmn:sequenceFlow> - <bpmn:startEvent id="CreateAndActivatePnf_StartEvent"> - <bpmn:outgoing>SequenceFlow_0j5ksz1</bpmn:outgoing> - </bpmn:startEvent> - <bpmn:endEvent id="AaiEntryUpdated" name="AAI entry updated"> - <bpmn:incoming>SequenceFlow_0p09qgm</bpmn:incoming> - </bpmn:endEvent> <bpmn:endEvent id="AaiEntryAlreadyUpToDate" name="AAI entry already up-to-date"> <bpmn:incoming>SequenceFlow_1h6yz62</bpmn:incoming> </bpmn:endEvent> - <bpmn:sequenceFlow id="SequenceFlow_1miyzfe" sourceRef="Task_1rwv8g6" targetRef="ThrowTimeoutException" /> + <bpmn:exclusiveGateway id="DoesAaiContainInfoAboutIp" name="Does AAI contain info about IPv4 or IPv6?"> + <bpmn:incoming>SequenceFlow_1l1t6ak</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_1h6yz62</bpmn:outgoing> + <bpmn:outgoing>SequenceFlow_1ls8pua</bpmn:outgoing> + </bpmn:exclusiveGateway> <bpmn:endEvent id="ThrowTimeoutException" name="Throw timeout exception"> <bpmn:incoming>SequenceFlow_1miyzfe</bpmn:incoming> <bpmn:errorEventDefinition errorRef="Error_1" /> </bpmn:endEvent> + <bpmn:sequenceFlow id="SequenceFlow_1miyzfe" sourceRef="CancelDmaapClientSubscription" targetRef="ThrowTimeoutException" /> <bpmn:serviceTask id="CheckAiiForCorrelationId" name="Check AAI for correlation_id" camunda:delegateExpression="${checkAaiForCorrelationIdDelegate}"> <bpmn:incoming>SequenceFlow_0j5ksz1</bpmn:incoming> <bpmn:outgoing>SequenceFlow_1j4r3zt</bpmn:outgoing> </bpmn:serviceTask> + <bpmn:startEvent id="CreateAndActivatePnf_StartEvent"> + <bpmn:outgoing>SequenceFlow_0j5ksz1</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:intermediateThrowEvent id="AaiEntryExists" name="AAI entry exists, lacking IP"> + <bpmn:incoming>SequenceFlow_1qr6cmf</bpmn:incoming> + <bpmn:incoming>SequenceFlow_1ls8pua</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_17s9025</bpmn:outgoing> + </bpmn:intermediateThrowEvent> + <bpmn:endEvent id="AaiEntryUpdated" name="AAI entry updated"> + <bpmn:incoming>SequenceFlow_0p09qgm</bpmn:incoming> + </bpmn:endEvent> <bpmn:exclusiveGateway id="DoesAaiContainInfoAboutPnf" name="Does AAI contain info about pnf?"> <bpmn:incoming>SequenceFlow_1j4r3zt</bpmn:incoming> <bpmn:outgoing>SequenceFlow_1l1t6ak</bpmn:outgoing> @@ -58,16 +68,6 @@ <bpmn:incoming>SequenceFlow_0v5ffpe</bpmn:incoming> <bpmn:outgoing>SequenceFlow_1qr6cmf</bpmn:outgoing> </bpmn:serviceTask> - <bpmn:exclusiveGateway id="DoesAaiContainInfoAboutIp" name="Does AAI contain info about IPv4 or IPv6?"> - <bpmn:incoming>SequenceFlow_1l1t6ak</bpmn:incoming> - <bpmn:outgoing>SequenceFlow_1h6yz62</bpmn:outgoing> - <bpmn:outgoing>SequenceFlow_1ls8pua</bpmn:outgoing> - </bpmn:exclusiveGateway> - <bpmn:intermediateThrowEvent id="AaiEntryExists" name="AAI entry exists, lacking IP"> - <bpmn:incoming>SequenceFlow_1qr6cmf</bpmn:incoming> - <bpmn:incoming>SequenceFlow_1ls8pua</bpmn:incoming> - <bpmn:outgoing>SequenceFlow_17s9025</bpmn:outgoing> - </bpmn:intermediateThrowEvent> <bpmn:serviceTask id="InformDmaapClient" name="Inform DmaapClient about business key and corresponding pnf-id" camunda:delegateExpression="${informDmaapClient}"> <bpmn:incoming>SequenceFlow_17s9025</bpmn:incoming> <bpmn:outgoing>SequenceFlow_1o8od8e</bpmn:outgoing> @@ -82,10 +82,10 @@ <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">#{timeoutForPnfEntryNotification}</bpmn:timeDuration> </bpmn:timerEventDefinition> </bpmn:boundaryEvent> - <bpmn:task id="Task_1rwv8g6" name="Cancel DmaapClient subscription"> + <bpmn:serviceTask id="CancelDmaapClientSubscription" name="Cancel DmaapClient subscription" camunda:delegateExpression="${cancelDmaapSubscription}"> <bpmn:incoming>SequenceFlow_1kc34bc</bpmn:incoming> <bpmn:outgoing>SequenceFlow_1miyzfe</bpmn:outgoing> - </bpmn:task> + </bpmn:serviceTask> <bpmn:association id="Association_0d7oxnz" sourceRef="CreateAndActivatePnf_StartEvent" targetRef="TextAnnotation_1eyzes8" /> <bpmn:textAnnotation id="TextAnnotation_1eyzes8"> <bpmn:text><![CDATA[Inputs: @@ -99,12 +99,12 @@ <bpmndi:BPMNDiagram id="BPMNDiagram_1"> <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1d0w8lf"> <bpmndi:BPMNShape id="Participant_1egg397_di" bpmnElement="Participant_1egg397"> - <dc:Bounds x="0" y="0" width="1482" height="353" /> + <dc:Bounds x="0" y="0" width="1488" height="437" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="ExclusiveGateway_1cttgdo_di" bpmnElement="DoesAaiContainInfoAboutPnf" isMarkerVisible="true"> - <dc:Bounds x="338" y="230" width="50" height="50" /> + <dc:Bounds x="338" y="182" width="50" height="50" /> <bpmndi:BPMNLabel> - <dc:Bounds x="318" y="283" width="85" height="20" /> + <dc:Bounds x="320" y="283" width="85" height="20" /> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="ExclusiveGateway_0yamdfm_di" bpmnElement="DoesAaiContainInfoAboutIp" isMarkerVisible="true"> @@ -114,43 +114,43 @@ </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="EndEvent_0k52gr7_di" bpmnElement="AaiEntryUpdated"> - <dc:Bounds x="1312" y="237" width="36" height="36" /> + <dc:Bounds x="1312" y="189" width="36" height="36" /> <bpmndi:BPMNLabel> - <dc:Bounds x="1286" y="278" width="89" height="10" /> + <dc:Bounds x="1286" y="230" width="89" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="StartEvent_0j5ok9h_di" bpmnElement="CreateAndActivatePnf_StartEvent"> - <dc:Bounds x="49" y="237" width="36" height="36" /> + <dc:Bounds x="49" y="189" width="36" height="36" /> <bpmndi:BPMNLabel> - <dc:Bounds x="23" y="276" width="90" height="20" /> + <dc:Bounds x="23" y="228" width="90" height="20" /> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="ServiceTask_0a5uk9o_di" bpmnElement="CheckAiiForCorrelationId"> - <dc:Bounds x="159" y="215" width="100" height="80" /> + <dc:Bounds x="159" y="167" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="ServiceTask_0iimk5v_di" bpmnElement="CreateAndActivatePnf_CreateAaiEntry"> - <dc:Bounds x="467" y="215" width="100" height="80" /> + <dc:Bounds x="467" y="167" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="SequenceFlow_1j4r3zt_di" bpmnElement="SequenceFlow_1j4r3zt"> - <di:waypoint xsi:type="dc:Point" x="259" y="255" /> - <di:waypoint xsi:type="dc:Point" x="338" y="255" /> + <di:waypoint xsi:type="dc:Point" x="259" y="207" /> + <di:waypoint xsi:type="dc:Point" x="338" y="207" /> <bpmndi:BPMNLabel> - <dc:Bounds x="253.5" y="235" width="90" height="10" /> + <dc:Bounds x="253.5" y="187" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="SequenceFlow_1l1t6ak_di" bpmnElement="SequenceFlow_1l1t6ak"> - <di:waypoint xsi:type="dc:Point" x="363" y="230" /> + <di:waypoint xsi:type="dc:Point" x="363" y="182" /> <di:waypoint xsi:type="dc:Point" x="363" y="66" /> <di:waypoint xsi:type="dc:Point" x="646" y="66" /> <bpmndi:BPMNLabel> - <dc:Bounds x="368" y="206" width="19" height="10" /> + <dc:Bounds x="378" y="159" width="19" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="SequenceFlow_0v5ffpe_di" bpmnElement="SequenceFlow_0v5ffpe"> - <di:waypoint xsi:type="dc:Point" x="388" y="255" /> - <di:waypoint xsi:type="dc:Point" x="467" y="255" /> + <di:waypoint xsi:type="dc:Point" x="388" y="207" /> + <di:waypoint xsi:type="dc:Point" x="467" y="207" /> <bpmndi:BPMNLabel> - <dc:Bounds x="395.48275862068965" y="237" width="15" height="10" /> + <dc:Bounds x="396.3963414634147" y="210" width="15" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="SequenceFlow_1h6yz62_di" bpmnElement="SequenceFlow_1h6yz62"> @@ -164,56 +164,58 @@ <di:waypoint xsi:type="dc:Point" x="671" y="91" /> <di:waypoint xsi:type="dc:Point" x="671" y="164" /> <di:waypoint xsi:type="dc:Point" x="671" y="164" /> - <di:waypoint xsi:type="dc:Point" x="671" y="237" /> + <di:waypoint xsi:type="dc:Point" x="671" y="189" /> <bpmndi:BPMNLabel> <dc:Bounds x="681" y="105" width="15" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="SequenceFlow_1qr6cmf_di" bpmnElement="SequenceFlow_1qr6cmf"> - <di:waypoint xsi:type="dc:Point" x="567" y="255" /> - <di:waypoint xsi:type="dc:Point" x="653" y="255" /> + <di:waypoint xsi:type="dc:Point" x="567" y="207" /> + <di:waypoint xsi:type="dc:Point" x="653" y="207" /> <bpmndi:BPMNLabel> - <dc:Bounds x="565" y="235" width="90" height="10" /> + <dc:Bounds x="565" y="187" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="SequenceFlow_0j5ksz1_di" bpmnElement="SequenceFlow_0j5ksz1"> - <di:waypoint xsi:type="dc:Point" x="85" y="255" /> - <di:waypoint xsi:type="dc:Point" x="159" y="255" /> + <di:waypoint xsi:type="dc:Point" x="85" y="207" /> + <di:waypoint xsi:type="dc:Point" x="122" y="207" /> + <di:waypoint xsi:type="dc:Point" x="122" y="207" /> + <di:waypoint xsi:type="dc:Point" x="159" y="207" /> <bpmndi:BPMNLabel> - <dc:Bounds x="77" y="235" width="90" height="10" /> + <dc:Bounds x="92" y="202" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNShape id="Participant_0i9ban2_di" bpmnElement="Participant_0atuyq0"> - <dc:Bounds x="123" y="415" width="502" height="60" /> + <dc:Bounds x="123" y="523" width="502" height="60" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="MessageFlow_1h3xu88_di" bpmnElement="MessageFlow_1h3xu88"> - <di:waypoint xsi:type="dc:Point" x="517" y="295" /> - <di:waypoint xsi:type="dc:Point" x="517" y="415" /> + <di:waypoint xsi:type="dc:Point" x="517" y="247" /> + <di:waypoint xsi:type="dc:Point" x="517" y="523" /> <bpmndi:BPMNLabel> - <dc:Bounds x="487" y="350" width="90" height="10" /> + <dc:Bounds x="487" y="380" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="MessageFlow_09ibv5a_di" bpmnElement="MessageFlow_09ibv5a"> - <di:waypoint xsi:type="dc:Point" x="190" y="295" /> - <di:waypoint xsi:type="dc:Point" x="190" y="415" /> + <di:waypoint xsi:type="dc:Point" x="190" y="247" /> + <di:waypoint xsi:type="dc:Point" x="190" y="523" /> <bpmndi:BPMNLabel> - <dc:Bounds x="160" y="350" width="90" height="10" /> + <dc:Bounds x="160" y="404" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="MessageFlow_0vjul4t_di" bpmnElement="MessageFlow_0vjul4t"> - <di:waypoint xsi:type="dc:Point" x="229" y="415" /> - <di:waypoint xsi:type="dc:Point" x="229" y="295" /> + <di:waypoint xsi:type="dc:Point" x="229" y="523" /> + <di:waypoint xsi:type="dc:Point" x="229" y="247" /> <bpmndi:BPMNLabel> - <dc:Bounds x="199" y="350" width="90" height="10" /> + <dc:Bounds x="199" y="404" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNShape id="Participant_0vmrrhf_di" bpmnElement="Participant_19w87ws"> - <dc:Bounds x="804" y="415" width="463" height="60" /> + <dc:Bounds x="804" y="523" width="463" height="60" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="EndEvent_0wbx6tt_di" bpmnElement="ThrowTimeoutException"> - <dc:Bounds x="1312" y="135" width="36" height="36" /> + <dc:Bounds x="1312" y="345" width="36" height="36" /> <bpmndi:BPMNLabel> - <dc:Bounds x="1305" y="172" width="70" height="20" /> + <dc:Bounds x="1305" y="382" width="70" height="20" /> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="EndEvent_00cy7r0_di" bpmnElement="AaiEntryAlreadyUpToDate"> @@ -223,90 +225,90 @@ </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="IntermediateThrowEvent_0fjcdy4_di" bpmnElement="AaiEntryExists"> - <dc:Bounds x="653" y="237" width="36" height="36" /> + <dc:Bounds x="653" y="189" width="36" height="36" /> <bpmndi:BPMNLabel> - <dc:Bounds x="631" y="283" width="80" height="20" /> + <dc:Bounds x="634" y="235" width="80" height="20" /> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="TextAnnotation_1eyzes8_di" bpmnElement="TextAnnotation_1eyzes8"> <dc:Bounds x="66" y="70" width="243" height="54" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="Association_0d7oxnz_di" bpmnElement="Association_0d7oxnz"> - <di:waypoint xsi:type="dc:Point" x="67" y="237" /> + <di:waypoint xsi:type="dc:Point" x="67" y="189" /> <di:waypoint xsi:type="dc:Point" x="67" y="124" /> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="MessageFlow_1vrcp2d_di" bpmnElement="MessageFlow_1vrcp2d"> - <di:waypoint xsi:type="dc:Point" x="1006" y="415" /> - <di:waypoint xsi:type="dc:Point" x="1006" y="295" /> + <di:waypoint xsi:type="dc:Point" x="1006" y="523" /> + <di:waypoint xsi:type="dc:Point" x="1006" y="247" /> <bpmndi:BPMNLabel> - <dc:Bounds x="976" y="350" width="90" height="10" /> + <dc:Bounds x="976" y="380" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="SequenceFlow_17s9025_di" bpmnElement="SequenceFlow_17s9025"> - <di:waypoint xsi:type="dc:Point" x="689" y="255" /> - <di:waypoint xsi:type="dc:Point" x="775" y="255" /> + <di:waypoint xsi:type="dc:Point" x="689" y="207" /> + <di:waypoint xsi:type="dc:Point" x="775" y="207" /> <bpmndi:BPMNLabel> - <dc:Bounds x="687" y="235" width="90" height="10" /> + <dc:Bounds x="687" y="187" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNShape id="BoundaryEvent_15eo1k9_di" bpmnElement="WaitForDmaapTimeout"> - <dc:Bounds x="1008" y="197" width="36" height="36" /> + <dc:Bounds x="1020" y="229" width="36" height="36" /> <bpmndi:BPMNLabel> - <dc:Bounds x="1039" y="192" width="40" height="10" /> + <dc:Bounds x="1051" y="260" width="40" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="SequenceFlow_1kc34bc_di" bpmnElement="SequenceFlow_1kc34bc"> - <di:waypoint xsi:type="dc:Point" x="1026" y="197" /> - <di:waypoint xsi:type="dc:Point" x="1026" y="153" /> - <di:waypoint xsi:type="dc:Point" x="1133" y="153" /> + <di:waypoint xsi:type="dc:Point" x="1038" y="265" /> + <di:waypoint xsi:type="dc:Point" x="1038" y="363" /> + <di:waypoint xsi:type="dc:Point" x="1133" y="363" /> <bpmndi:BPMNLabel> - <dc:Bounds x="996" y="170" width="90" height="10" /> + <dc:Bounds x="1008" y="309" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNShape id="ReceiveTask_1sfysua_di" bpmnElement="WaitForDmaapPnfReadyNotification"> - <dc:Bounds x="954" y="215" width="100" height="80" /> + <dc:Bounds x="954" y="167" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="SequenceFlow_0p09qgm_di" bpmnElement="SequenceFlow_0p09qgm"> - <di:waypoint xsi:type="dc:Point" x="1054" y="255" /> - <di:waypoint xsi:type="dc:Point" x="1312" y="255" /> + <di:waypoint xsi:type="dc:Point" x="1054" y="207" /> + <di:waypoint xsi:type="dc:Point" x="1312" y="207" /> <bpmndi:BPMNLabel> - <dc:Bounds x="1138" y="235" width="90" height="10" /> + <dc:Bounds x="1138" y="187" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="SequenceFlow_1o8od8e_di" bpmnElement="SequenceFlow_1o8od8e"> - <di:waypoint xsi:type="dc:Point" x="875" y="255" /> - <di:waypoint xsi:type="dc:Point" x="954" y="255" /> + <di:waypoint xsi:type="dc:Point" x="875" y="207" /> + <di:waypoint xsi:type="dc:Point" x="954" y="207" /> <bpmndi:BPMNLabel> - <dc:Bounds x="869.5" y="235" width="90" height="10" /> + <dc:Bounds x="869.5" y="187" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="MessageFlow_0tg4hw9_di" bpmnElement="MessageFlow_0tg4hw9"> - <di:waypoint xsi:type="dc:Point" x="825" y="295" /> - <di:waypoint xsi:type="dc:Point" x="825" y="415" /> + <di:waypoint xsi:type="dc:Point" x="825" y="247" /> + <di:waypoint xsi:type="dc:Point" x="825" y="523" /> <bpmndi:BPMNLabel> - <dc:Bounds x="795" y="350" width="90" height="10" /> + <dc:Bounds x="795" y="380" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNShape id="ServiceTask_1iax11n_di" bpmnElement="InformDmaapClient"> - <dc:Bounds x="775" y="215" width="100" height="80" /> - </bpmndi:BPMNShape> - <bpmndi:BPMNShape id="Task_1rwv8g6_di" bpmnElement="Task_1rwv8g6"> - <dc:Bounds x="1133" y="113" width="100" height="80" /> + <dc:Bounds x="775" y="167" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="SequenceFlow_1miyzfe_di" bpmnElement="SequenceFlow_1miyzfe"> - <di:waypoint xsi:type="dc:Point" x="1233" y="153" /> - <di:waypoint xsi:type="dc:Point" x="1312" y="153" /> + <di:waypoint xsi:type="dc:Point" x="1233" y="363" /> + <di:waypoint xsi:type="dc:Point" x="1312" y="363" /> <bpmndi:BPMNLabel> - <dc:Bounds x="1272.5" y="133" width="0" height="10" /> + <dc:Bounds x="1227.5" y="343" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="MessageFlow_1py54jr_di" bpmnElement="MessageFlow_1py54jr"> - <di:waypoint xsi:type="dc:Point" x="1183" y="193" /> - <di:waypoint xsi:type="dc:Point" x="1183" y="415" /> + <di:waypoint xsi:type="dc:Point" x="1183" y="403" /> + <di:waypoint xsi:type="dc:Point" x="1183" y="523" /> <bpmndi:BPMNLabel> - <dc:Bounds x="1198" y="299" width="0" height="10" /> + <dc:Bounds x="1153" y="458" width="90" height="10" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ServiceTask_12j7hox_di" bpmnElement="CancelDmaapClientSubscription"> + <dc:Bounds x="1133" y="323" width="100" height="80" /> + </bpmndi:BPMNShape> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </bpmn:definitions> diff --git a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml index 03fff4f974..4ddeba16be 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml +++ b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml @@ -18,6 +18,10 @@ <property name="dmaapClient" ref="pnfEventReadyConsumer"/>
</bean>
+ <bean id="cancelDmaapSubscription" class="org.openecomp.mso.bpmn.infrastructure.pnf.delegate.CancelDmaapSubscription">
+ <property name="dmaapClient" ref="pnfEventReadyConsumer"/>
+ </bean>
+
<bean id="pnfEventReadyConsumer" class="org.openecomp.mso.bpmn.infrastructure.pnf.dmaap.PnfEventReadyConsumer"
init-method="init">
<property name="dmaapHost" value="${host}"/>
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/web.xml b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/web.xml index e262495537..fb5fc66309 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/web.xml +++ b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/web.xml @@ -50,6 +50,8 @@ </context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+ <listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CancelDmaapSubscriptionTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CancelDmaapSubscriptionTest.java new file mode 100644 index 0000000000..d27cf44342 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CancelDmaapSubscriptionTest.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {CancelDmaapSubscription.class, DmaapClientTestImpl.class}) +public class CancelDmaapSubscriptionTest { + + @Autowired + public CancelDmaapSubscription delegate; + + @Autowired + private DmaapClientTestImpl dmaapClientTest; + + @Test + public void shouldCancelSubscription() throws Exception { + // given + DelegateExecution delegateExecution = mock(DelegateExecution.class); + when(delegateExecution.getVariable(eq(ExecutionVariableNames.CORRELATION_ID))).thenReturn("testCorrelationId"); + when(delegateExecution.getProcessBusinessKey()).thenReturn("testBusinessKey"); + dmaapClientTest.registerForUpdate("testCorrelationId", () -> {}); + // when + delegate.execute(delegateExecution); + // then + assertThat(dmaapClientTest.haveRegisteredConsumer()).isFalse(); + } +}
\ No newline at end of file diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java index 55dd3a968f..8d35f9f8e0 100644 --- a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java @@ -21,8 +21,10 @@ package org.openecomp.mso.bpmn.infrastructure.pnf.delegate; import org.openecomp.mso.bpmn.infrastructure.pnf.dmaap.DmaapClient; +import java.util.Objects; public class DmaapClientTestImpl implements DmaapClient { + private String correlationId; private Runnable informConsumer; @@ -32,6 +34,17 @@ public class DmaapClientTestImpl implements DmaapClient { this.informConsumer = informConsumer; } + @Override + public Runnable unregister(String correlationId) { + if (Objects.equals(this.correlationId, correlationId)) { + this.correlationId = null; + Runnable informConsumer = this.informConsumer; + this.informConsumer = null; + return informConsumer; + } + return null; + } + public String getCorrelationId() { return correlationId; } @@ -39,4 +52,8 @@ public class DmaapClientTestImpl implements DmaapClient { public Runnable getInformConsumer() { return informConsumer; } + + public boolean haveRegisteredConsumer() { + return correlationId != null; + } } diff --git a/common/src/main/java/org/openecomp/mso/client/dmaap/DmaapClient.java b/common/src/main/java/org/openecomp/mso/client/dmaap/DmaapClient.java index aabeb8aabf..5a2fa178de 100644 --- a/common/src/main/java/org/openecomp/mso/client/dmaap/DmaapClient.java +++ b/common/src/main/java/org/openecomp/mso/client/dmaap/DmaapClient.java @@ -60,7 +60,7 @@ public abstract class DmaapClient { try { return new String(Base64.getDecoder().decode(password.getBytes())); } catch(IllegalArgumentException iae) { - + auditLogger.error("llegal Arguments",iae); return password; } } diff --git a/common/src/main/java/org/openecomp/mso/openpojo/rules/HasAnnotationPropertyWithValueMatcher.java b/common/src/main/java/org/openecomp/mso/openpojo/rules/HasAnnotationPropertyWithValueMatcher.java index f0c1b18df2..d1b2fb1d11 100644 --- a/common/src/main/java/org/openecomp/mso/openpojo/rules/HasAnnotationPropertyWithValueMatcher.java +++ b/common/src/main/java/org/openecomp/mso/openpojo/rules/HasAnnotationPropertyWithValueMatcher.java @@ -28,10 +28,12 @@ import java.lang.reflect.Method; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; +import org.openecomp.mso.logger.MsoLogger; import com.openpojo.reflection.PojoField; public class HasAnnotationPropertyWithValueMatcher<T extends PojoField> extends TypeSafeDiagnosingMatcher<T> { + private MsoLogger logger=MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL); private final String attribute; private final Matcher<?> annotationMatcher; private final Class<? extends Annotation> annotationClass; @@ -59,6 +61,7 @@ public class HasAnnotationPropertyWithValueMatcher<T extends PojoField> extends } } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { mismatchDescription.appendText("does not have property ").appendText(attribute); + logger.debug("Error occured", e); return false; } return true; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java index cb3e8e6a82..95da5b6a95 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java @@ -1,1455 +1,1455 @@ -/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.mso.apihandlerinfra;
-
-import java.io.IOException;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.hibernate.Session;
-import org.json.JSONObject;
-import org.openecomp.mso.apihandler.common.ErrorNumbers;
-import org.openecomp.mso.apihandler.common.RequestClient;
-import org.openecomp.mso.apihandler.common.RequestClientFactory;
-import org.openecomp.mso.apihandler.common.ResponseHandler;
-import org.openecomp.mso.apihandlerinfra.Messages;
-import org.openecomp.mso.apihandlerinfra.MsoException;
-import org.openecomp.mso.apihandlerinfra.MsoRequest;
-import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.CompareModelsRequest;
-import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.DelE2ESvcResp;
-import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceDeleteRequest;
-import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceRequest;
-import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EUserParam;
-import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse;
-import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.*;
-import org.openecomp.mso.serviceinstancebeans.ModelInfo;
-import org.openecomp.mso.serviceinstancebeans.ModelType;
-import org.openecomp.mso.serviceinstancebeans.RequestDetails;
-import org.openecomp.mso.serviceinstancebeans.RequestInfo;
-import org.openecomp.mso.serviceinstancebeans.RequestParameters;
-import org.openecomp.mso.serviceinstancebeans.ServiceInstancesRequest;
-import org.openecomp.mso.serviceinstancebeans.SubscriberInfo;
-import org.openecomp.mso.db.AbstractSessionFactoryManager;
-import org.openecomp.mso.db.catalog.CatalogDatabase;
-import org.openecomp.mso.db.catalog.beans.Service;
-import org.openecomp.mso.db.catalog.beans.ServiceRecipe;
-import org.openecomp.mso.logger.MessageEnum;
-import org.openecomp.mso.logger.MsoAlarmLogger;
-import org.openecomp.mso.logger.MsoLogger;
-import org.openecomp.mso.properties.MsoDatabaseException;
-import org.openecomp.mso.requestsdb.OperationStatus;
-import org.openecomp.mso.requestsdb.RequestsDatabase;
-import org.openecomp.mso.requestsdb.RequestsDbSessionFactoryManager;
-import org.openecomp.mso.utils.UUIDChecker;
-
-import com.wordnik.swagger.annotations.Api;
-import com.wordnik.swagger.annotations.ApiOperation;
-
-@Path("/e2eServiceInstances")
-@Api(value = "/e2eServiceInstances", description = "API Requests for E2E Service Instances")
-public class E2EServiceInstances {
-
- private HashMap<String, String> instanceIdMap = new HashMap<>();
- private static MsoLogger msoLogger = MsoLogger
- .getMsoLogger(MsoLogger.Catalog.APIH);
- private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger();
- public static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA";
- private ServiceInstancesRequest sir = null;
-
- public static final String END_OF_THE_TRANSACTION = "End of the transaction, the final response is: ";
- public static final String EXCEPTION_CREATING_DB_RECORD = "Exception while creating record in DB";
- public static final String EXCEPTION_COMMUNICATE_BPMN_ENGINE = "Exception while communicate with BPMN engine";
-
- /**
- * POST Requests for E2E Service create Instance on a version provided
- */
-
- @POST
- @Path("/{version:[vV][3-5]}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @ApiOperation(value = "Create an E2E Service Instance on a version provided", response = Response.class)
- public Response createE2EServiceInstance(String request,
- @PathParam("version") String version) {
-
- return processE2EserviceInstances(request, Action.createInstance, null,
- version);
- }
-
- /**
- * PUT Requests for E2E Service update Instance on a version provided
- */
-
- @PUT
- @Path("/{version:[vV][3-5]}/{serviceId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @ApiOperation(value = "Update an E2E Service Instance on a version provided and serviceId", response = Response.class)
- public Response updateE2EServiceInstance(String request,
- @PathParam("version") String version,
- @PathParam("serviceId") String serviceId) {
-
- instanceIdMap.put("serviceId", serviceId);
-
- return updateE2EserviceInstances(request, Action.updateInstance, instanceIdMap,
- version);
- }
-
- /**
- * DELETE Requests for E2E Service delete Instance on a specified version
- * and serviceId
- */
-
- @DELETE
- @Path("/{version:[vV][3-5]}/{serviceId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @ApiOperation(value = "Delete E2E Service Instance on a specified version and serviceId", response = Response.class)
- public Response deleteE2EServiceInstance(String request,
- @PathParam("version") String version,
- @PathParam("serviceId") String serviceId) {
-
- instanceIdMap.put("serviceId", serviceId);
-
- return deleteE2EserviceInstances(request, Action.deleteInstance,
- instanceIdMap, version);
- }
-
- @GET
- @Path("/{version:[vV][3-5]}/{serviceId}/operations/{operationId}")
- @ApiOperation(value = "Find e2eServiceInstances Requests for a given serviceId and operationId", response = Response.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Response getE2EServiceInstances(
- @PathParam("serviceId") String serviceId,
- @PathParam("version") String version,
- @PathParam("operationId") String operationId) {
- return getE2EServiceInstances(serviceId, operationId);
- }
-
- /**
- * Scale Requests for E2E Service scale Instance on a specified version
- */
-
- @POST
- @Path("/{version:[vV][3-5]}/{serviceId}/scale")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @ApiOperation(value="Scale E2E Service Instance on a specified version",response=Response.class)
- public Response scaleE2EServiceInstance(String request,
- @PathParam("version") String version,
- @PathParam("serviceId") String serviceId) {
-
- msoLogger.debug("------------------scale begin------------------");
- instanceIdMap.put("serviceId", serviceId);
- return scaleE2EserviceInstances(request, Action.scaleInstance, instanceIdMap, version);
- }
- /**
- * GET Requests for Comparing model of service instance with target version
- */
-
- @POST
- @Path("/{version:[vV][3-5]}/{serviceId}/modeldifferences")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @ApiOperation(value = "Find added and deleted resources of target model for the e2eserviceInstance on a given serviceId ", response = Response.class)
- public Response compareModelwithTargetVersion(String request,
- @PathParam("serviceId") String serviceId,
- @PathParam("version") String version) {
-
- instanceIdMap.put("serviceId", serviceId);
-
- return compareModelwithTargetVersion(request, Action.compareModel, instanceIdMap, version);
- }
-
- private Response compareModelwithTargetVersion(String requestJSON, Action action,
- HashMap<String, String> instanceIdMap, String version) {
-
- String requestId = instanceIdMap.get("serviceId");
- long startTime = System.currentTimeMillis();
- msoLogger.debug("requestId is: " + requestId);
-
- CompareModelsRequest e2eCompareModelReq = null;
-
- MsoRequest msoRequest = new MsoRequest(requestId);
-
- ObjectMapper mapper = new ObjectMapper();
- try {
- e2eCompareModelReq = mapper.readValue(requestJSON, CompareModelsRequest.class);
-
- } catch (Exception e) {
-
- msoLogger.debug("Mapping of request to JSON object failed : ", e);
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,
- MsoException.ServiceException, "Mapping of request to JSON object failed. " + e.getMessage(),
- ErrorNumbers.SVC_BAD_PARAMETER, null);
- msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.SchemaError, requestJSON, e);
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError,
- "Mapping of request to JSON object failed");
- msoLogger.debug("End of the transaction, the final response is: " + response.getEntity().toString());
-
- return response;
- }
-
- Response returnResp = runCompareModelBPMWorkflow(e2eCompareModelReq, msoRequest, requestJSON, requestId,
- startTime, action);
-
- return returnResp;
-
- }
-
- private Response runCompareModelBPMWorkflow(CompareModelsRequest e2eCompareModelReq, MsoRequest msoRequest,
- String requestJSON, String requestId, long startTime, Action action) {
-
- // Define RecipeLookupResult info here instead of query DB for efficiency
- String workflowUrl = "/mso/async/services/CompareModelofE2EServiceInstance";
- int recipeTimeout = 180;
-
- RequestClient requestClient = null;
- HttpResponse response = null;
-
- long subStartTime = System.currentTimeMillis();
-
- try {
- requestClient = RequestClientFactory.getRequestClient(workflowUrl, MsoPropertiesUtils.loadMsoProperties());
-
- JSONObject jjo = new JSONObject(requestJSON);
- String bpmnRequest = jjo.toString();
-
- // Capture audit event
- msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl());
- String serviceId = instanceIdMap.get("serviceId");
- String serviceType = e2eCompareModelReq.getServiceType();
- response = requestClient.post(requestId, false, recipeTimeout, action.name(), serviceId, null, null, null,
- null, null, serviceType, null, null, null, bpmnRequest, null);
-
- msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- "Successfully received response from BPMN engine", "BPMN", workflowUrl, null);
- } catch (Exception e) {
- msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN",
- workflowUrl, null);
- Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
- MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(),
- ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- alarmLogger.sendAlarm("MsoConfigurationError", MsoAlarmLogger.CRITICAL,
- Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL));
- msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine");
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
- "Exception while communicate with BPMN engine");
- msoLogger.debug("End of the transaction, the final response is: " + resp.getEntity().toString());
- return resp;
- }
-
- if (response == null) {
- Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
- MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL");
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError,
- "Null response from BPMN");
- msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity().toString());
- return resp;
- }
-
- ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());
- int bpelStatus = respHandler.getStatus();
- // String responseBody = respHandler.getResponseBody();
- // CompareModelsResult modelDiffResponse = new CompareModelsResult();
-
- return beplStatusUpdate(requestId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action,
- instanceIdMap);
- }
-
- private Response getE2EServiceInstances(String serviceId, String operationId) {
- RequestsDatabase requestsDB = RequestsDatabase.getInstance();
-
- GetE2EServiceInstanceResponse e2eServiceResponse = new GetE2EServiceInstanceResponse();
-
- MsoRequest msoRequest = new MsoRequest(serviceId);
-
- long startTime = System.currentTimeMillis();
-
- OperationStatus operationStatus = null;
-
- try {
- operationStatus = requestsDB.getOperationStatus(serviceId,
- operationId);
-
- } catch (Exception e) {
- msoLogger
- .error(MessageEnum.APIH_DB_ACCESS_EXC,
- MSO_PROP_APIHANDLER_INFRA,
- "",
- "",
- MsoLogger.ErrorCode.AvailabilityError,
- "Exception while communciate with Request DB - Infra Request Lookup",
- e);
- msoRequest
- .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response response = msoRequest.buildServiceErrorResponse(
- HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,
- e.getMessage(),
- ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null);
- alarmLogger.sendAlarm("MsoDatabaseAccessError",
- MsoAlarmLogger.CRITICAL, Messages.errors
- .get(ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB));
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.DBAccessError,
- "Exception while communciate with Request DB");
- msoLogger.debug("End of the transaction, the final response is: "
- + (String) response.getEntity());
- return response;
-
- }
-
- if (operationStatus == null) {
- Response resp = msoRequest.buildServiceErrorResponse(
- HttpStatus.SC_NO_CONTENT, MsoException.ServiceException,
- "E2E serviceId " + serviceId + " is not found in DB",
- ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null);
- msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR,
- MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.BusinessProcesssError,
- "Null response from RequestDB when searching by serviceId");
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.DataNotFound,
- "Null response from RequestDB when searching by serviceId");
- msoLogger.debug("End of the transaction, the final response is: "
- + (String) resp.getEntity());
- return resp;
-
- }
-
- e2eServiceResponse.setOperationStatus(operationStatus);
-
- return Response.status(200).entity(e2eServiceResponse).build();
- }
-
- private Response deleteE2EserviceInstances(String requestJSON,
- Action action, HashMap<String, String> instanceIdMap, String version) {
- // TODO should be a new one or the same service instance Id
- String requestId = instanceIdMap.get("serviceId");
- long startTime = System.currentTimeMillis();
- msoLogger.debug("requestId is: " + requestId);
- E2EServiceInstanceDeleteRequest e2eDelReq = null;
-
- MsoRequest msoRequest = new MsoRequest(requestId);
-
- ObjectMapper mapper = new ObjectMapper();
- try {
- e2eDelReq = mapper.readValue(requestJSON,
- E2EServiceInstanceDeleteRequest.class);
-
- } catch (Exception e) {
-
- msoLogger.debug("Mapping of request to JSON object failed : ", e);
- Response response = msoRequest.buildServiceErrorResponse(
- HttpStatus.SC_BAD_REQUEST,
- MsoException.ServiceException,
- "Mapping of request to JSON object failed. "
- + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER,
- null);
- msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR,
- MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.SchemaError, requestJSON, e);
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.SchemaError,
- "Mapping of request to JSON object failed");
- msoLogger.debug("End of the transaction, the final response is: "
- + (String) response.getEntity());
- createOperationStatusRecordForError(action, requestId);
- return response;
- }
-
- CatalogDatabase db = null;
- RecipeLookupResult recipeLookupResult = null;
- try {
- db = CatalogDatabase.getInstance();
- //TODO Get the service template model version uuid from AAI.
- recipeLookupResult = getServiceInstanceOrchestrationURI(db, null, action);
- } catch (Exception e) {
- msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC,
- MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.AvailabilityError,
- "Exception while communciate with Catalog DB", e);
- msoRequest
- .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response response = msoRequest.buildServiceErrorResponse(
- HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,
- "No communication to catalog DB " + e.getMessage(),
- ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- alarmLogger.sendAlarm("MsoDatabaseAccessError",
- MsoAlarmLogger.CRITICAL, Messages.errors
- .get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB));
- msoRequest.createRequestRecord(Status.FAILED, action);
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.DBAccessError,
- "Exception while communciate with DB");
- msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) response.getEntity());
- return response;
- } finally {
- closeCatalogDB(db);
- }
- if (recipeLookupResult == null) {
- msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND,
- MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.DataError, "No recipe found in DB");
- msoRequest
- .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response response = msoRequest.buildServiceErrorResponse(
- HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,
- "Recipe does not exist in catalog DB",
- ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null);
- msoRequest.createRequestRecord(Status.FAILED, action);
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.DataNotFound,
- "No recipe found in DB");
- msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) response.getEntity());
- createOperationStatusRecordForError(action, requestId);
- return response;
- }
-
- RequestClient requestClient = null;
- HttpResponse response = null;
-
- long subStartTime = System.currentTimeMillis();
- // String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON);
-
- try {
- requestClient = RequestClientFactory.getRequestClient(
- recipeLookupResult.getOrchestrationURI(),
- MsoPropertiesUtils.loadMsoProperties());
-
- JSONObject jjo = new JSONObject(requestJSON);
- jjo.put("operationId", UUIDChecker.generateUUID(msoLogger));
-
- String bpmnRequest = jjo.toString();
-
- // Capture audit event
- msoLogger
- .debug("MSO API Handler Posting call to BPEL engine for url: "
- + requestClient.getUrl());
- String serviceId = instanceIdMap.get("serviceId");
- String serviceInstanceType = e2eDelReq.getServiceType();
- response = requestClient.post(requestId, false,
- recipeLookupResult.getRecipeTimeout(), action.name(),
- serviceId, null, null, null, null, null, serviceInstanceType,
- null, null, null, bpmnRequest, recipeLookupResult.getRecipeParamXsd());
-
- msoLogger.recordMetricEvent(subStartTime,
- MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- "Successfully received response from BPMN engine", "BPMN",
- recipeLookupResult.getOrchestrationURI(), null);
- } catch (Exception e) {
- msoLogger.recordMetricEvent(subStartTime,
- MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.CommunicationError,
- "Exception while communicate with BPMN engine", "BPMN",
- recipeLookupResult.getOrchestrationURI(), null);
- Response resp = msoRequest.buildServiceErrorResponse(
- HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException,
- "Failed calling bpmn " + e.getMessage(),
- ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- alarmLogger.sendAlarm("MsoConfigurationError",
- MsoAlarmLogger.CRITICAL,
- Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL));
- msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR,
- MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.AvailabilityError,
- "Exception while communicate with BPMN engine");
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.CommunicationError,
- "Exception while communicate with BPMN engine");
- msoLogger.debug("End of the transaction, the final response is: "
- + (String) resp.getEntity());
- createOperationStatusRecordForError(action, requestId);
- return resp;
- }
-
- if (response == null) {
- Response resp = msoRequest.buildServiceErrorResponse(
- HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException,
- "bpelResponse is null",
- ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR,
- MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.BusinessProcesssError,
- "Null response from BPEL");
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.InternalError,
- "Null response from BPMN");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity());
- createOperationStatusRecordForError(action, requestId);
- return resp;
- }
-
- ResponseHandler respHandler = new ResponseHandler(response,
- requestClient.getType());
- int bpelStatus = respHandler.getStatus();
-
- return beplStatusUpdate(requestId, startTime, msoRequest,
- requestClient, respHandler, bpelStatus, action, instanceIdMap);
- }
-
- private Response updateE2EserviceInstances(String requestJSON, Action action,
- HashMap<String, String> instanceIdMap, String version) {
-
- String requestId = UUIDChecker.generateUUID(msoLogger);
- long startTime = System.currentTimeMillis();
- msoLogger.debug("requestId is: " + requestId);
- E2EServiceInstanceRequest e2eSir = null;
- String serviceId = instanceIdMap.get("serviceId");
-
- MsoRequest msoRequest = new MsoRequest(requestId);
- ObjectMapper mapper = new ObjectMapper();
- try {
- e2eSir = mapper.readValue(requestJSON, E2EServiceInstanceRequest.class);
-
- } catch (Exception e) {
-
- msoLogger.debug("Mapping of request to JSON object failed : ", e);
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,
- MsoException.ServiceException, "Mapping of request to JSON object failed. " + e.getMessage(),
- ErrorNumbers.SVC_BAD_PARAMETER, null);
- msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.SchemaError, requestJSON, e);
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError,
- "Mapping of request to JSON object failed");
- msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
- return response;
- }
-
- mapReqJsonToSvcInstReq(e2eSir, requestJSON);
- sir.getRequestDetails().getRequestParameters().setaLaCarte(true);
- try {
- msoRequest.parse(sir, instanceIdMap, action, version, requestJSON);
- } catch (Exception e) {
- msoLogger.debug("Validation failed: ", e);
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,
- MsoException.ServiceException, "Error parsing request. " + e.getMessage(),
- ErrorNumbers.SVC_BAD_PARAMETER, null);
- if (msoRequest.getRequestId() != null) {
- msoLogger.debug("Logging failed message to the database");
- }
- msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.SchemaError, requestJSON, e);
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError,
- "Validation of the input request failed");
- msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
- return response;
- }
-
- //check for the current operation status
-// Response resp = checkE2ESvcInstStatus(action, serviceId, startTime, msoRequest);
-// if(resp != null && resp.getStatus() != 200) {
-// return resp;
-// }
-
- CatalogDatabase db = null;
- RecipeLookupResult recipeLookupResult = null;
- try {
- db = CatalogDatabase.getInstance();
- recipeLookupResult = getServiceInstanceOrchestrationURI(db, e2eSir.getService().getServiceUuid(), action);
- } catch (Exception e) {
- msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.AvailabilityError, "Exception while communciate with Catalog DB", e);
- msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
- MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(),
- ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- alarmLogger.sendAlarm("MsoDatabaseAccessError", MsoAlarmLogger.CRITICAL,
- Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB));
-
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,
- "Exception while communciate with DB");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
-
- return response;
- } finally {
- closeCatalogDB(db);
- }
-
- if (recipeLookupResult == null) {
- msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.DataError, "No recipe found in DB");
- msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
- MsoException.ServiceException, "Recipe does not exist in catalog DB",
- ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null);
-
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound,
- "No recipe found in DB");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
-
- return response;
- }
-
- String serviceInstanceType = e2eSir.getService().getServiceType();
-
- RequestClient requestClient = null;
- HttpResponse response = null;
-
- long subStartTime = System.currentTimeMillis();
- String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON);
-
- try {
- requestClient = RequestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI(),
- MsoPropertiesUtils.loadMsoProperties());
-
- // Capture audit event
- msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl());
-
- response = requestClient.post(requestId, false, recipeLookupResult.getRecipeTimeout(), action.name(),
- serviceId, null, null, null, null, null, serviceInstanceType, null, null, null, sirRequestJson,
- recipeLookupResult.getRecipeParamXsd());
-
- msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- "Successfully received response from BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI(),
- null);
- } catch (Exception e) {
- msoLogger.debug("Exception while communicate with BPMN engine", e);
- msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN",
- recipeLookupResult.getOrchestrationURI(), null);
- Response getBPMNResp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
- MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(),
- ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- alarmLogger.sendAlarm("MsoConfigurationError", MsoAlarmLogger.CRITICAL,
- Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL));
- msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine");
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
- "Exception while communicate with BPMN engine");
- msoLogger.debug("End of the transaction, the final response is: " + (String) getBPMNResp.getEntity());
-
- return getBPMNResp;
- }
-
- if (response == null) {
- Response getBPMNResp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
- MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL");
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError,
- "Null response from BPMN");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) getBPMNResp.getEntity());
-
- return getBPMNResp;
- }
-
- ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());
- int bpelStatus = respHandler.getStatus();
-
- return beplStatusUpdate(serviceId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action, instanceIdMap);
- }
-
- private Response checkE2ESvcInstStatus(Action action, String serviceId, long startTime, MsoRequest msoRequest) {
- OperationStatus curStatus = null;
-// String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();
- String requestScope = sir.getRequestDetails().getModelInfo().getModelType().name();
- try {
- if (!(serviceId == null && "service".equals(requestScope) && (action == Action.updateInstance))) {
- curStatus = chkSvcInstOperStatusbySvcId(serviceId);
- }
- } catch (Exception e) {
- msoLogger.error(MessageEnum.APIH_DUPLICATE_CHECK_EXC, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.DataError, "Error during current operation status check ", e);
-
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR,
- MsoException.ServiceException, e.getMessage(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null);
-
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,
- "Error during current operation status check");
- msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
- return response;
- }
-
- if (curStatus != null && curStatus.getResult() != null && curStatus.getResult().equalsIgnoreCase("processing")) {
- String chkMessage = "Error: Locked instance - This " + requestScope + " (" + serviceId + ") "
- + "now being worked with a status of " + curStatus.getResult()
- + ". The latest workflow of instance must be finished or cleaned up.";
-
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_CONFLICT,
- MsoException.ServiceException, chkMessage, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null);
-
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict,
- chkMessage);
-
- msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
-
- return response;
- }
-
- return Response.status(200).entity(null).build();
- }
-
- private Response processE2EserviceInstances(String requestJSON, Action action,
- HashMap<String, String> instanceIdMap, String version) {
-
- String requestId = UUIDChecker.generateUUID(msoLogger);
- long startTime = System.currentTimeMillis();
- msoLogger.debug("requestId is: " + requestId);
- E2EServiceInstanceRequest e2eSir = null;
-
- MsoRequest msoRequest = new MsoRequest(requestId);
- ObjectMapper mapper = new ObjectMapper();
- try {
- e2eSir = mapper.readValue(requestJSON, E2EServiceInstanceRequest.class);
-
- } catch (Exception e) {
- //TODO update the service name
- this.createOperationStatusRecordForError(action, requestId);
-
- msoLogger.debug("Mapping of request to JSON object failed : ", e);
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,
- MsoException.ServiceException, "Mapping of request to JSON object failed. " + e.getMessage(),
- ErrorNumbers.SVC_BAD_PARAMETER, null);
- msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.SchemaError, requestJSON, e);
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError,
- "Mapping of request to JSON object failed");
- msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
- return response;
- }
-
- mapReqJsonToSvcInstReq(e2eSir, requestJSON);
- sir.getRequestDetails().getRequestParameters().setaLaCarte(true);
- try {
- msoRequest.parse(sir, instanceIdMap, action, version, requestJSON);
- } catch (Exception e) {
- msoLogger.debug("Validation failed: ", e);
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,
- MsoException.ServiceException, "Error parsing request. " + e.getMessage(),
- ErrorNumbers.SVC_BAD_PARAMETER, null);
- if (msoRequest.getRequestId() != null) {
- msoLogger.debug("Logging failed message to the database");
- //TODO update the service name
- this.createOperationStatusRecordForError(action, requestId);
- }
- msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.SchemaError, requestJSON, e);
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError,
- "Validation of the input request failed");
- msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
- return response;
- }
-
- OperationStatus dup = null;
- String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();
- String requestScope = sir.getRequestDetails().getModelInfo().getModelType().name();
- try {
- if (!(instanceName == null && "service".equals(requestScope)
- && (action == Action.createInstance || action == Action.activateInstance))) {
- //TODO : Need to check for the duplicate record from the operation status,
- //TODO : commenting this check for unblocking current testing for now... induces dead code...
- dup = chkDuplicateServiceNameInOperStatus( instanceName);
- }
- } catch (Exception e) {
- msoLogger.error(MessageEnum.APIH_DUPLICATE_CHECK_EXC, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.DataError, "Error during duplicate check ", e);
-
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR,
- MsoException.ServiceException, e.getMessage(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null);
-
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,
- "Error during duplicate check");
- msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
- return response;
- }
-
- if (dup != null) {
- // Found the duplicate record. Return the appropriate error.
- String instance = null;
- if (instanceName != null) {
- instance = instanceName;
- } else {
- instance = instanceIdMap.get(requestScope + "InstanceId");
- }
- String dupMessage = "Error: Locked instance - This " + requestScope + " (" + instance + ") "
- + "already has a request being worked with a status of " + dup.getProgress() + " (ServiceId - "
- + dup.getServiceId() + "). The existing request must finish or be cleaned up before proceeding.";
-
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_CONFLICT,
- MsoException.ServiceException, dupMessage, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null);
-
- msoLogger.warn(MessageEnum.APIH_DUPLICATE_FOUND, dupMessage, "", "", MsoLogger.ErrorCode.SchemaError,
- "Duplicate request - Subscriber already has a request for this service");
-
-
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict,
- dupMessage);
- msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
- createOperationStatusRecordForError(action, requestId);
- return response;
- }
-
- CatalogDatabase db = null;
- RecipeLookupResult recipeLookupResult = null;
- try {
- db = CatalogDatabase.getInstance();
- recipeLookupResult = getServiceInstanceOrchestrationURI(db, e2eSir.getService().getServiceUuid(), action);
- } catch (Exception e) {
- msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.AvailabilityError, "Exception while communciate with Catalog DB", e);
- msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
- MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(),
- ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- alarmLogger.sendAlarm("MsoDatabaseAccessError", MsoAlarmLogger.CRITICAL,
- Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB));
-
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,
- "Exception while communciate with DB");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
- createOperationStatusRecordForError(action, requestId);
- return response;
- } finally {
- closeCatalogDB(db);
- }
-
- if (recipeLookupResult == null) {
- msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.DataError, "No recipe found in DB");
- msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND,
- MsoException.ServiceException, "Recipe does not exist in catalog DB",
- ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null);
-
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound,
- "No recipe found in DB");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
- createOperationStatusRecordForError(action, requestId);
- return response;
- }
-// try {
-// msoRequest.createRequestRecord(Status.PENDING, action);
-// //createOperationStatusRecord(action, requestId);
-// } catch (Exception e) {
-// msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC_REASON, "Exception while creating record in DB", "", "",
-// MsoLogger.ErrorCode.SchemaError, "Exception while creating record in DB", e);
-// msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
-// Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR,
-// MsoException.ServiceException, "Exception while creating record in DB " + e.getMessage(),
-// ErrorNumbers.SVC_BAD_PARAMETER, null);
-// msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,
-// "Exception while creating record in DB");
-// msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity());
-// return response;
-// }
-
- String serviceInstanceType = e2eSir.getService().getServiceType();
-
- String serviceId = "";
- RequestClient requestClient = null;
- HttpResponse response = null;
-
- long subStartTime = System.currentTimeMillis();
- String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON);
-
- try {
- requestClient = RequestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI(),
- MsoPropertiesUtils.loadMsoProperties());
-
- // Capture audit event
- msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl());
-
- response = requestClient.post(requestId, false, recipeLookupResult.getRecipeTimeout(), action.name(),
- serviceId, null, null, null, null, null, serviceInstanceType, null, null, null, sirRequestJson,
- recipeLookupResult.getRecipeParamXsd());
-
- msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- "Successfully received response from BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI(),
- null);
- } catch (Exception e) {
- msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN",
- recipeLookupResult.getOrchestrationURI(), null);
- Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
- MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(),
- ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- alarmLogger.sendAlarm("MsoConfigurationError", MsoAlarmLogger.CRITICAL,
- Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL));
- msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine");
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
- "Exception while communicate with BPMN engine");
- msoLogger.debug("End of the transaction, the final response is: " + (String) resp.getEntity());
- createOperationStatusRecordForError(action, requestId);
- return resp;
- }
-
- if (response == null) {
- Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
- MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL");
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError,
- "Null response from BPMN");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity());
- return resp;
- }
-
- ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());
- int bpelStatus = respHandler.getStatus();
-
- return beplStatusUpdate(requestId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action, instanceIdMap);
- }
-
- private Response scaleE2EserviceInstances(String requestJSON,
- Action action, HashMap<String, String> instanceIdMap, String version) {
-
- String requestId = instanceIdMap.get("serviceId");
- long startTime = System.currentTimeMillis();
- msoLogger.debug("requestId is: " + requestId);
- E2EServiceInstanceScaleRequest e2eScaleReq = null;
-
- MsoRequest msoRequest = new MsoRequest(requestId);
-
- ObjectMapper mapper = new ObjectMapper();
- try {
- e2eScaleReq = mapper.readValue(requestJSON,
- E2EServiceInstanceScaleRequest.class);
-
- } catch (Exception e) {
-
- msoLogger.debug("Mapping of request to JSON object failed : ", e);
- Response response = msoRequest.buildServiceErrorResponse(
- HttpStatus.SC_BAD_REQUEST,
- MsoException.ServiceException,
- "Mapping of request to JSON object failed. "
- + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER,
- null);
- msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR,
- MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.SchemaError, requestJSON, e);
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.SchemaError,
- "Mapping of request to JSON object failed");
- msoLogger.debug("End of the transaction, the final response is: "
- + (String) response.getEntity());
- createOperationStatusRecordForError(action, requestId);
- return response;
- }
-
- CatalogDatabase db = null;
- RecipeLookupResult recipeLookupResult = null;
- try {
- db = CatalogDatabase.getInstance();
- //TODO Get the service template model version uuid from AAI.
- recipeLookupResult = getServiceInstanceOrchestrationURI(db, null, action);
- } catch (Exception e) {
- msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC,
- MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.AvailabilityError,
- "Exception while communciate with Catalog DB", e);
- msoRequest
- .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response response = msoRequest.buildServiceErrorResponse(
- HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,
- "No communication to catalog DB " + e.getMessage(),
- ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- alarmLogger.sendAlarm("MsoDatabaseAccessError",
- MsoAlarmLogger.CRITICAL, Messages.errors
- .get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB));
- msoRequest.createRequestRecord(Status.FAILED, action);
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.DBAccessError,
- "Exception while communciate with DB");
- msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) response.getEntity());
- return response;
- } finally {
- closeCatalogDB(db);
- }
- if (recipeLookupResult == null) {
- msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND,
- MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.DataError, "No recipe found in DB");
- msoRequest
- .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response response = msoRequest.buildServiceErrorResponse(
- HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,
- "Recipe does not exist in catalog DB",
- ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null);
- msoRequest.createRequestRecord(Status.FAILED, action);
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.DataNotFound,
- "No recipe found in DB");
- msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) response.getEntity());
- createOperationStatusRecordForError(action, requestId);
- return response;
- }
-
- RequestClient requestClient = null;
- HttpResponse response = null;
-
- long subStartTime = System.currentTimeMillis();
- // String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON);
-
- try {
- requestClient = RequestClientFactory.getRequestClient(
- recipeLookupResult.getOrchestrationURI(),
- MsoPropertiesUtils.loadMsoProperties());
-
- JSONObject jjo = new JSONObject(requestJSON);
- jjo.put("operationId", UUIDChecker.generateUUID(msoLogger));
-
- String bpmnRequest = jjo.toString();
-
- // Capture audit event
- msoLogger
- .debug("MSO API Handler Posting call to BPEL engine for url: "
- + requestClient.getUrl());
- String serviceId = instanceIdMap.get("serviceId");
- String serviceInstanceType = e2eScaleReq.getService().getServiceType();
- response = requestClient.post(requestId, false,
- recipeLookupResult.getRecipeTimeout(), action.name(),
- serviceId, null, null, null, null, null, serviceInstanceType,
- null, null, null, bpmnRequest, recipeLookupResult.getRecipeParamXsd());
-
- msoLogger.recordMetricEvent(subStartTime,
- MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- "Successfully received response from BPMN engine", "BPMN",
- recipeLookupResult.getOrchestrationURI(), null);
- } catch (Exception e) {
- msoLogger.recordMetricEvent(subStartTime,
- MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.CommunicationError,
- "Exception while communicate with BPMN engine", "BPMN",
- recipeLookupResult.getOrchestrationURI(), null);
- Response resp = msoRequest.buildServiceErrorResponse(
- HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException,
- "Failed calling bpmn " + e.getMessage(),
- ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- alarmLogger.sendAlarm("MsoConfigurationError",
- MsoAlarmLogger.CRITICAL,
- Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL));
- msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR,
- MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.AvailabilityError,
- "Exception while communicate with BPMN engine");
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.CommunicationError,
- "Exception while communicate with BPMN engine");
- msoLogger.debug("End of the transaction, the final response is: "
- + (String) resp.getEntity());
- createOperationStatusRecordForError(action, requestId);
- return resp;
- }
-
- if (response == null) {
- Response resp = msoRequest.buildServiceErrorResponse(
- HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException,
- "bpelResponse is null",
- ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
- msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR,
- MSO_PROP_APIHANDLER_INFRA, "", "",
- MsoLogger.ErrorCode.BusinessProcesssError,
- "Null response from BPEL");
- msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.InternalError,
- "Null response from BPMN");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity());
- createOperationStatusRecordForError(action, requestId);
- return resp;
- }
-
- ResponseHandler respHandler = new ResponseHandler(response,
- requestClient.getType());
- int bpelStatus = respHandler.getStatus();
-
- return beplStatusUpdate(requestId, startTime, msoRequest,
- requestClient, respHandler, bpelStatus, action, instanceIdMap);
- }
-
- private void closeCatalogDB(CatalogDatabase db) {
- if (db != null) {
- db.close();
- }
- }
-
- private Response beplStatusUpdate(String serviceId, long startTime,
- MsoRequest msoRequest, RequestClient requestClient,
- ResponseHandler respHandler, int bpelStatus, Action action,
- HashMap<String, String> instanceIdMap) {
- // BPMN accepted the request, the request is in progress
- if (bpelStatus == HttpStatus.SC_ACCEPTED) {
- String camundaJSONResponseBody = respHandler.getResponseBody();
- msoLogger.debug("Received from Camunda: " + camundaJSONResponseBody);
-
- // currently only for delete case we update the status here
- if (action == Action.deleteInstance) {
- ObjectMapper mapper = new ObjectMapper();
- try {
- DelE2ESvcResp jo = mapper.readValue(
- camundaJSONResponseBody, DelE2ESvcResp.class);
- String operationId = jo.getOperationId();
- this.createOperationStatusRecord("DELETE", serviceId,
- operationId);
- } catch (Exception ex) {
- msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR,
- requestClient.getUrl(), "", "",
- MsoLogger.ErrorCode.BusinessProcesssError,
- "Response from BPEL engine is failed with HTTP Status="
- + bpelStatus);
- }
- }
-
- msoLogger.recordAuditEvent(startTime,
- MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- "BPMN accepted the request, the request is in progress");
- msoLogger.debug(END_OF_THE_TRANSACTION + camundaJSONResponseBody);
- return Response.status(HttpStatus.SC_ACCEPTED)
- .entity(camundaJSONResponseBody).build();
- } else {
- List<String> variables = new ArrayList<>();
- variables.add(bpelStatus + "");
- String camundaJSONResponseBody = respHandler.getResponseBody();
- if (camundaJSONResponseBody != null
- && !camundaJSONResponseBody.isEmpty()) {
- Response resp = msoRequest.buildServiceErrorResponse(
- bpelStatus, MsoException.ServiceException,
- "Request Failed due to BPEL error with HTTP Status= %1 "
- + '\n' + camundaJSONResponseBody,
- ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, variables);
- msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR,
- requestClient.getUrl(), "", "",
- MsoLogger.ErrorCode.BusinessProcesssError,
- "Response from BPEL engine is failed with HTTP Status="
- + bpelStatus);
- msoLogger.recordAuditEvent(startTime,
- MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.InternalError,
- "Response from BPMN engine is failed");
- msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) resp.getEntity());
- return resp;
- } else {
- Response resp = msoRequest
- .buildServiceErrorResponse(
- bpelStatus,
- MsoException.ServiceException,
- "Request Failed due to BPEL error with HTTP Status= %1",
- ErrorNumbers.SVC_DETAILED_SERVICE_ERROR,
- variables);
- msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR,
- requestClient.getUrl(), "", "",
- MsoLogger.ErrorCode.BusinessProcesssError,
- "Response from BPEL engine is empty");
- msoLogger.recordAuditEvent(startTime,
- MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.InternalError,
- "Response from BPEL engine is empty");
- msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) resp.getEntity());
- return resp;
- }
- }
- }
-
- /**
- * Getting recipes from catalogDb
- *
- * @param db the catalog db
- * @param serviceModelUUID the service model version uuid
- * @param action the action for the service
- * @return the service recipe result
- */
- private RecipeLookupResult getServiceInstanceOrchestrationURI(
- CatalogDatabase db, String serviceModelUUID, Action action) {
-
- RecipeLookupResult recipeLookupResult = getServiceURI(db, serviceModelUUID, action);
-
- if (recipeLookupResult != null) {
- msoLogger.debug("Orchestration URI is: "
- + recipeLookupResult.getOrchestrationURI()
- + ", recipe Timeout is: "
- + Integer.toString(recipeLookupResult.getRecipeTimeout()));
- } else {
- msoLogger.debug("No matching recipe record found");
- }
- return recipeLookupResult;
- }
-
- /**
- * Getting recipes from catalogDb
- * If Service recipe is not set, use default recipe, if set , use special recipe.
- * @param db the catalog db
- * @param serviceModelUUID the service version uuid
- * @param action the action of the service.
- * @return the service recipe result.
- */
- private RecipeLookupResult getServiceURI(CatalogDatabase db, String serviceModelUUID, Action action) {
-
- String defaultServiceModelName = "UUI_DEFAULT";
-
- Service defaultServiceRecord = db
- .getServiceByModelName(defaultServiceModelName);
- ServiceRecipe defaultRecipe = db.getServiceRecipeByModelUUID(
- defaultServiceRecord.getModelUUID(), action.name());
- //set recipe as default generic recipe
- ServiceRecipe recipe = defaultRecipe;
- //check the service special recipe
- if(null != serviceModelUUID && ! serviceModelUUID.isEmpty()){
- ServiceRecipe serviceSpecialRecipe = db.getServiceRecipeByModelUUID(
- serviceModelUUID, action.name());
- if(null != serviceSpecialRecipe){
- //set service special recipe.
- recipe = serviceSpecialRecipe;
- }
- }
-
- if (recipe == null) {
- return null;
- }
- return new RecipeLookupResult(recipe.getOrchestrationUri(),
- recipe.getRecipeTimeout(), recipe.getServiceParamXSD());
-
- }
-
- /**
- * Converting E2EServiceInstanceRequest to ServiceInstanceRequest and
- * passing it to camunda engine.
- *
- * @param e2eSir
- * @return
- */
- private String mapReqJsonToSvcInstReq(E2EServiceInstanceRequest e2eSir,
- String requestJSON) {
-
- sir = new ServiceInstancesRequest();
-
- String returnString = null;
- RequestDetails requestDetails = new RequestDetails();
- ModelInfo modelInfo = new ModelInfo();
-
- // ModelInvariantId
- modelInfo.setModelInvariantId(e2eSir.getService().getServiceInvariantUuid());
-
- // modelNameVersionId
- modelInfo.setModelNameVersionId(e2eSir.getService().getServiceUuid());
-
- // String modelInfoValue =
- // e2eSir.getService().getParameters().getNodeTemplateName();
- // String[] arrayOfInfo = modelInfoValue.split(":");
- // String modelName = arrayOfInfo[0];
- // String modelVersion = arrayOfInfo[1];
-
- // TODO: To ensure, if we dont get the values from the UUI
- String modelName = "voLTE";
- String modelVersion = "1.0";
- // modelName
- modelInfo.setModelName(modelName);
-
- // modelVersion
- modelInfo.setModelVersion(modelVersion);
-
- // modelType
- modelInfo.setModelType(ModelType.service);
-
- // setting modelInfo to requestDetails
- requestDetails.setModelInfo(modelInfo);
-
- SubscriberInfo subscriberInfo = new SubscriberInfo();
-
- // globalsubscriberId
- subscriberInfo.setGlobalSubscriberId(e2eSir.getService().getGlobalSubscriberId());
-
- // setting subscriberInfo to requestDetails
- requestDetails.setSubscriberInfo(subscriberInfo);
-
- RequestInfo requestInfo = new RequestInfo();
-
- // instanceName
- requestInfo.setInstanceName(e2eSir.getService().getName());
-
- // source
- requestInfo.setSource("UUI");
-
- // suppressRollback
- requestInfo.setSuppressRollback(true);
-
- // setting requestInfo to requestDetails
- requestDetails.setRequestInfo(requestInfo);
-
- RequestParameters requestParameters = new RequestParameters();
-
- // subscriptionServiceType
- requestParameters.setSubscriptionServiceType("MOG");
-
- // Userparams
- List<E2EUserParam> userParams;
- // userParams =
- // e2eSir.getService().getParameters().getRequestParameters().getUserParams();
- List<Map<String, Object>> userParamList = new ArrayList<>();
- Map<String, Object> userParamMap = new HashMap<>();
- // complete json request updated in the camunda
- userParamMap.put("UUIRequest", requestJSON);
- userParamMap.put("ServiceInstanceName", e2eSir.getService().getName());
-
- // Map<String, String> userParamMap3 = null;
- // for (E2EUserParam userp : userParams) {
- // userParamMap.put(userp.getName(), userp.getValue());
- //
- // }
- userParamList.add(userParamMap);
- requestParameters.setUserParams(userParamList);
-
- // setting requestParameters to requestDetails
- requestDetails.setRequestParameters(requestParameters);
-
- sir.setRequestDetails(requestDetails);
-
- // converting to string
- ObjectMapper mapper = new ObjectMapper();
- try {
- returnString = mapper.writeValueAsString(sir);
- } catch (IOException e) {
- msoLogger
- .debug("Exception while converting ServiceInstancesRequest object to string",
- e);
- }
-
- return returnString;
- }
-
- private void createOperationStatusRecordForError(Action action,
- String serviceId) throws MsoDatabaseException {
-
- AbstractSessionFactoryManager requestsDbSessionFactoryManager = new RequestsDbSessionFactoryManager();
-
- Session session = null;
- try {
-
- session = requestsDbSessionFactoryManager.getSessionFactory()
- .openSession();
- session.beginTransaction();
-
- OperationStatus os = new OperationStatus();
- os.setOperation(action.name());
- os.setOperationContent("");
- os.setOperationId("");
- os.setProgress("100");
- os.setReason("");
- os.setResult("error");
- os.setServiceId(serviceId);
- os.setUserId("");
- Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());
- Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());
- os.setFinishedAt(endTimeStamp);
- os.setOperateAt(startTimeStamp);
-
- session.save(os);
- session.getTransaction().commit();
-
- } catch (Exception e) {
- msoLogger.error(MessageEnum.APIH_DB_INSERT_EXC, "", "",
- MsoLogger.ErrorCode.DataError,
- "Exception when creation record request in Operation", e);
- throw new MsoDatabaseException(
- "Data did inserted in Operatus Status Table for failure", e);
- } finally {
- if (null != session) {
- session.close();
- }
- }
- }
-
- private void createOperationStatusRecord(String actionNm, String serviceId,
- String operationId) throws MsoDatabaseException {
-
- AbstractSessionFactoryManager requestsDbSessionFactoryManager = new RequestsDbSessionFactoryManager();
-
- Session session = null;
- try {
-
- session = requestsDbSessionFactoryManager.getSessionFactory()
- .openSession();
- session.beginTransaction();
-
- OperationStatus os = new OperationStatus();
- os.setOperation(actionNm);
- os.setOperationContent("");
- os.setOperationId(operationId);
- os.setProgress("0");
- os.setReason("");
- os.setResult("processing");
- os.setServiceId(serviceId);
- // TODO : to be updated...
- os.setUserId("");
- Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());
- Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());
- os.setFinishedAt(endTimeStamp);
- os.setOperateAt(startTimeStamp);
-
- session.save(os);
- session.getTransaction().commit();
-
- } catch (Exception e) {
- msoLogger.error(MessageEnum.APIH_DB_INSERT_EXC, "", "",
- MsoLogger.ErrorCode.DataError,
- "Exception when creation record request in Operation", e);
- throw new MsoDatabaseException(
- "Data did inserted in Operatus Status Table", e);
- } finally {
- if (null != session) {
- session.close();
- }
- }
- }
-
- private OperationStatus chkSvcInstOperStatusbySvcId(String serviceId) {
- OperationStatus svcInstanceOperStatus = (RequestsDatabase.getInstance())
- .getOperationStatusByServiceId(serviceId);
-
- return svcInstanceOperStatus;
- }
-
- private OperationStatus chkDuplicateServiceNameInOperStatus(
- String serviceName) {
- OperationStatus dupServiceName = (RequestsDatabase.getInstance())
- .getOperationStatusByServiceName(serviceName);
-
- return dupServiceName;
- }
-}
+/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.apihandlerinfra; + +import java.io.IOException; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.hibernate.Session; +import org.json.JSONObject; +import org.openecomp.mso.apihandler.common.ErrorNumbers; +import org.openecomp.mso.apihandler.common.RequestClient; +import org.openecomp.mso.apihandler.common.RequestClientFactory; +import org.openecomp.mso.apihandler.common.ResponseHandler; +import org.openecomp.mso.apihandlerinfra.Messages; +import org.openecomp.mso.apihandlerinfra.MsoException; +import org.openecomp.mso.apihandlerinfra.MsoRequest; +import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.CompareModelsRequest; +import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.DelE2ESvcResp; +import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceDeleteRequest; +import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceRequest; +import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EUserParam; +import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse; +import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.*; +import org.openecomp.mso.serviceinstancebeans.ModelInfo; +import org.openecomp.mso.serviceinstancebeans.ModelType; +import org.openecomp.mso.serviceinstancebeans.RequestDetails; +import org.openecomp.mso.serviceinstancebeans.RequestInfo; +import org.openecomp.mso.serviceinstancebeans.RequestParameters; +import org.openecomp.mso.serviceinstancebeans.ServiceInstancesRequest; +import org.openecomp.mso.serviceinstancebeans.SubscriberInfo; +import org.openecomp.mso.db.AbstractSessionFactoryManager; +import org.openecomp.mso.db.catalog.CatalogDatabase; +import org.openecomp.mso.db.catalog.beans.Service; +import org.openecomp.mso.db.catalog.beans.ServiceRecipe; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoAlarmLogger; +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.properties.MsoDatabaseException; +import org.openecomp.mso.requestsdb.OperationStatus; +import org.openecomp.mso.requestsdb.RequestsDatabase; +import org.openecomp.mso.requestsdb.RequestsDbSessionFactoryManager; +import org.openecomp.mso.utils.UUIDChecker; + +import com.wordnik.swagger.annotations.Api; +import com.wordnik.swagger.annotations.ApiOperation; + +@Path("/e2eServiceInstances") +@Api(value = "/e2eServiceInstances", description = "API Requests for E2E Service Instances") +public class E2EServiceInstances { + + private HashMap<String, String> instanceIdMap = new HashMap<>(); + private static MsoLogger msoLogger = MsoLogger + .getMsoLogger(MsoLogger.Catalog.APIH); + private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger(); + public static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA"; + private ServiceInstancesRequest sir = null; + + public static final String END_OF_THE_TRANSACTION = "End of the transaction, the final response is: "; + public static final String EXCEPTION_CREATING_DB_RECORD = "Exception while creating record in DB"; + public static final String EXCEPTION_COMMUNICATE_BPMN_ENGINE = "Exception while communicate with BPMN engine"; + + /** + * POST Requests for E2E Service create Instance on a version provided + */ + + @POST + @Path("/{version:[vV][3-5]}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Create an E2E Service Instance on a version provided", response = Response.class) + public Response createE2EServiceInstance(String request, + @PathParam("version") String version) { + + return processE2EserviceInstances(request, Action.createInstance, null, + version); + } + + /** + * PUT Requests for E2E Service update Instance on a version provided + */ + + @PUT + @Path("/{version:[vV][3-5]}/{serviceId}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Update an E2E Service Instance on a version provided and serviceId", response = Response.class) + public Response updateE2EServiceInstance(String request, + @PathParam("version") String version, + @PathParam("serviceId") String serviceId) { + + instanceIdMap.put("serviceId", serviceId); + + return updateE2EserviceInstances(request, Action.updateInstance, instanceIdMap, + version); + } + + /** + * DELETE Requests for E2E Service delete Instance on a specified version + * and serviceId + */ + + @DELETE + @Path("/{version:[vV][3-5]}/{serviceId}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Delete E2E Service Instance on a specified version and serviceId", response = Response.class) + public Response deleteE2EServiceInstance(String request, + @PathParam("version") String version, + @PathParam("serviceId") String serviceId) { + + instanceIdMap.put("serviceId", serviceId); + + return deleteE2EserviceInstances(request, Action.deleteInstance, + instanceIdMap, version); + } + + @GET + @Path("/{version:[vV][3-5]}/{serviceId}/operations/{operationId}") + @ApiOperation(value = "Find e2eServiceInstances Requests for a given serviceId and operationId", response = Response.class) + @Produces(MediaType.APPLICATION_JSON) + public Response getE2EServiceInstances( + @PathParam("serviceId") String serviceId, + @PathParam("version") String version, + @PathParam("operationId") String operationId) { + return getE2EServiceInstances(serviceId, operationId); + } + + /** + * Scale Requests for E2E Service scale Instance on a specified version + */ + + @POST + @Path("/{version:[vV][3-5]}/{serviceId}/scale") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value="Scale E2E Service Instance on a specified version",response=Response.class) + public Response scaleE2EServiceInstance(String request, + @PathParam("version") String version, + @PathParam("serviceId") String serviceId) { + + msoLogger.debug("------------------scale begin------------------"); + instanceIdMap.put("serviceId", serviceId); + return scaleE2EserviceInstances(request, Action.scaleInstance, instanceIdMap, version); + } + /** + * GET Requests for Comparing model of service instance with target version + */ + + @POST + @Path("/{version:[vV][3-5]}/{serviceId}/modeldifferences") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Find added and deleted resources of target model for the e2eserviceInstance on a given serviceId ", response = Response.class) + public Response compareModelwithTargetVersion(String request, + @PathParam("serviceId") String serviceId, + @PathParam("version") String version) { + + instanceIdMap.put("serviceId", serviceId); + + return compareModelwithTargetVersion(request, Action.compareModel, instanceIdMap, version); + } + + private Response compareModelwithTargetVersion(String requestJSON, Action action, + HashMap<String, String> instanceIdMap, String version) { + + String requestId = instanceIdMap.get("serviceId"); + long startTime = System.currentTimeMillis(); + msoLogger.debug("requestId is: " + requestId); + + CompareModelsRequest e2eCompareModelReq = null; + + MsoRequest msoRequest = new MsoRequest(requestId); + + ObjectMapper mapper = new ObjectMapper(); + try { + e2eCompareModelReq = mapper.readValue(requestJSON, CompareModelsRequest.class); + + } catch (Exception e) { + + msoLogger.debug("Mapping of request to JSON object failed : ", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, + MsoException.ServiceException, "Mapping of request to JSON object failed. " + e.getMessage(), + ErrorNumbers.SVC_BAD_PARAMETER, null); + msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.SchemaError, requestJSON, e); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, + "Mapping of request to JSON object failed"); + msoLogger.debug("End of the transaction, the final response is: " + response.getEntity().toString()); + + return response; + } + + Response returnResp = runCompareModelBPMWorkflow(e2eCompareModelReq, msoRequest, requestJSON, requestId, + startTime, action); + + return returnResp; + + } + + private Response runCompareModelBPMWorkflow(CompareModelsRequest e2eCompareModelReq, MsoRequest msoRequest, + String requestJSON, String requestId, long startTime, Action action) { + + // Define RecipeLookupResult info here instead of query DB for efficiency + String workflowUrl = "/mso/async/services/CompareModelofE2EServiceInstance"; + int recipeTimeout = 180; + + RequestClient requestClient = null; + HttpResponse response = null; + + long subStartTime = System.currentTimeMillis(); + + try { + requestClient = RequestClientFactory.getRequestClient(workflowUrl, MsoPropertiesUtils.loadMsoProperties()); + + JSONObject jjo = new JSONObject(requestJSON); + String bpmnRequest = jjo.toString(); + + // Capture audit event + msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl()); + String serviceId = instanceIdMap.get("serviceId"); + String serviceType = e2eCompareModelReq.getServiceType(); + response = requestClient.post(requestId, false, recipeTimeout, action.name(), serviceId, null, null, null, + null, null, serviceType, null, null, null, bpmnRequest, null); + + msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully received response from BPMN engine", "BPMN", workflowUrl, null); + } catch (Exception e) { + msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN", + workflowUrl, null); + Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, + MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + alarmLogger.sendAlarm("MsoConfigurationError", MsoAlarmLogger.CRITICAL, + Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL)); + msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine",e); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, + "Exception while communicate with BPMN engine"); + msoLogger.debug("End of the transaction, the final response is: " + resp.getEntity().toString()); + return resp; + } + + if (response == null) { + Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, + MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL"); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, + "Null response from BPMN"); + msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity().toString()); + return resp; + } + + ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType()); + int bpelStatus = respHandler.getStatus(); + // String responseBody = respHandler.getResponseBody(); + // CompareModelsResult modelDiffResponse = new CompareModelsResult(); + + return beplStatusUpdate(requestId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action, + instanceIdMap); + } + + private Response getE2EServiceInstances(String serviceId, String operationId) { + RequestsDatabase requestsDB = RequestsDatabase.getInstance(); + + GetE2EServiceInstanceResponse e2eServiceResponse = new GetE2EServiceInstanceResponse(); + + MsoRequest msoRequest = new MsoRequest(serviceId); + + long startTime = System.currentTimeMillis(); + + OperationStatus operationStatus = null; + + try { + operationStatus = requestsDB.getOperationStatus(serviceId, + operationId); + + } catch (Exception e) { + msoLogger + .error(MessageEnum.APIH_DB_ACCESS_EXC, + MSO_PROP_APIHANDLER_INFRA, + "", + "", + MsoLogger.ErrorCode.AvailabilityError, + "Exception while communciate with Request DB - Infra Request Lookup", + e); + msoRequest + .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); + Response response = msoRequest.buildServiceErrorResponse( + HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, + e.getMessage(), + ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null); + alarmLogger.sendAlarm("MsoDatabaseAccessError", + MsoAlarmLogger.CRITICAL, Messages.errors + .get(ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB)); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.DBAccessError, + "Exception while communciate with Request DB"); + msoLogger.debug("End of the transaction, the final response is: " + + (String) response.getEntity()); + return response; + + } + + if (operationStatus == null) { + Response resp = msoRequest.buildServiceErrorResponse( + HttpStatus.SC_NO_CONTENT, MsoException.ServiceException, + "E2E serviceId " + serviceId + " is not found in DB", + ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null); + msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, + MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.BusinessProcesssError, + "Null response from RequestDB when searching by serviceId"); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.DataNotFound, + "Null response from RequestDB when searching by serviceId"); + msoLogger.debug("End of the transaction, the final response is: " + + (String) resp.getEntity()); + return resp; + + } + + e2eServiceResponse.setOperationStatus(operationStatus); + + return Response.status(200).entity(e2eServiceResponse).build(); + } + + private Response deleteE2EserviceInstances(String requestJSON, + Action action, HashMap<String, String> instanceIdMap, String version) { + // TODO should be a new one or the same service instance Id + String requestId = instanceIdMap.get("serviceId"); + long startTime = System.currentTimeMillis(); + msoLogger.debug("requestId is: " + requestId); + E2EServiceInstanceDeleteRequest e2eDelReq = null; + + MsoRequest msoRequest = new MsoRequest(requestId); + + ObjectMapper mapper = new ObjectMapper(); + try { + e2eDelReq = mapper.readValue(requestJSON, + E2EServiceInstanceDeleteRequest.class); + + } catch (Exception e) { + + msoLogger.debug("Mapping of request to JSON object failed : ", e); + Response response = msoRequest.buildServiceErrorResponse( + HttpStatus.SC_BAD_REQUEST, + MsoException.ServiceException, + "Mapping of request to JSON object failed. " + + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, + null); + msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, + MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.SchemaError, requestJSON, e); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.SchemaError, + "Mapping of request to JSON object failed"); + msoLogger.debug("End of the transaction, the final response is: " + + (String) response.getEntity()); + createOperationStatusRecordForError(action, requestId); + return response; + } + + CatalogDatabase db = null; + RecipeLookupResult recipeLookupResult = null; + try { + db = CatalogDatabase.getInstance(); + //TODO Get the service template model version uuid from AAI. + recipeLookupResult = getServiceInstanceOrchestrationURI(db, null, action); + } catch (Exception e) { + msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC, + MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.AvailabilityError, + "Exception while communciate with Catalog DB", e); + msoRequest + .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); + Response response = msoRequest.buildServiceErrorResponse( + HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, + "No communication to catalog DB " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + alarmLogger.sendAlarm("MsoDatabaseAccessError", + MsoAlarmLogger.CRITICAL, Messages.errors + .get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB)); + msoRequest.createRequestRecord(Status.FAILED, action); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.DBAccessError, + "Exception while communciate with DB"); + msoLogger.debug(END_OF_THE_TRANSACTION + + (String) response.getEntity()); + return response; + } finally { + closeCatalogDB(db); + } + if (recipeLookupResult == null) { + msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, + MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.DataError, "No recipe found in DB"); + msoRequest + .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); + Response response = msoRequest.buildServiceErrorResponse( + HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, + "Recipe does not exist in catalog DB", + ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null); + msoRequest.createRequestRecord(Status.FAILED, action); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.DataNotFound, + "No recipe found in DB"); + msoLogger.debug(END_OF_THE_TRANSACTION + + (String) response.getEntity()); + createOperationStatusRecordForError(action, requestId); + return response; + } + + RequestClient requestClient = null; + HttpResponse response = null; + + long subStartTime = System.currentTimeMillis(); + // String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON); + + try { + requestClient = RequestClientFactory.getRequestClient( + recipeLookupResult.getOrchestrationURI(), + MsoPropertiesUtils.loadMsoProperties()); + + JSONObject jjo = new JSONObject(requestJSON); + jjo.put("operationId", UUIDChecker.generateUUID(msoLogger)); + + String bpmnRequest = jjo.toString(); + + // Capture audit event + msoLogger + .debug("MSO API Handler Posting call to BPEL engine for url: " + + requestClient.getUrl()); + String serviceId = instanceIdMap.get("serviceId"); + String serviceInstanceType = e2eDelReq.getServiceType(); + response = requestClient.post(requestId, false, + recipeLookupResult.getRecipeTimeout(), action.name(), + serviceId, null, null, null, null, null, serviceInstanceType, + null, null, null, bpmnRequest, recipeLookupResult.getRecipeParamXsd()); + + msoLogger.recordMetricEvent(subStartTime, + MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully received response from BPMN engine", "BPMN", + recipeLookupResult.getOrchestrationURI(), null); + } catch (Exception e) { + msoLogger.recordMetricEvent(subStartTime, + MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.CommunicationError, + "Exception while communicate with BPMN engine", "BPMN", + recipeLookupResult.getOrchestrationURI(), null); + Response resp = msoRequest.buildServiceErrorResponse( + HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, + "Failed calling bpmn " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + alarmLogger.sendAlarm("MsoConfigurationError", + MsoAlarmLogger.CRITICAL, + Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL)); + msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, + MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.AvailabilityError, + "Exception while communicate with BPMN engine"); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.CommunicationError, + "Exception while communicate with BPMN engine"); + msoLogger.debug("End of the transaction, the final response is: " + + (String) resp.getEntity()); + createOperationStatusRecordForError(action, requestId); + return resp; + } + + if (response == null) { + Response resp = msoRequest.buildServiceErrorResponse( + HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, + "bpelResponse is null", + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, + MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.BusinessProcesssError, + "Null response from BPEL"); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.InternalError, + "Null response from BPMN"); + msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity()); + createOperationStatusRecordForError(action, requestId); + return resp; + } + + ResponseHandler respHandler = new ResponseHandler(response, + requestClient.getType()); + int bpelStatus = respHandler.getStatus(); + + return beplStatusUpdate(requestId, startTime, msoRequest, + requestClient, respHandler, bpelStatus, action, instanceIdMap); + } + + private Response updateE2EserviceInstances(String requestJSON, Action action, + HashMap<String, String> instanceIdMap, String version) { + + String requestId = UUIDChecker.generateUUID(msoLogger); + long startTime = System.currentTimeMillis(); + msoLogger.debug("requestId is: " + requestId); + E2EServiceInstanceRequest e2eSir = null; + String serviceId = instanceIdMap.get("serviceId"); + + MsoRequest msoRequest = new MsoRequest(requestId); + ObjectMapper mapper = new ObjectMapper(); + try { + e2eSir = mapper.readValue(requestJSON, E2EServiceInstanceRequest.class); + + } catch (Exception e) { + + msoLogger.debug("Mapping of request to JSON object failed : ", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, + MsoException.ServiceException, "Mapping of request to JSON object failed. " + e.getMessage(), + ErrorNumbers.SVC_BAD_PARAMETER, null); + msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.SchemaError, requestJSON, e); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, + "Mapping of request to JSON object failed"); + msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity()); + return response; + } + + mapReqJsonToSvcInstReq(e2eSir, requestJSON); + sir.getRequestDetails().getRequestParameters().setaLaCarte(true); + try { + msoRequest.parse(sir, instanceIdMap, action, version, requestJSON); + } catch (Exception e) { + msoLogger.debug("Validation failed: ", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, + MsoException.ServiceException, "Error parsing request. " + e.getMessage(), + ErrorNumbers.SVC_BAD_PARAMETER, null); + if (msoRequest.getRequestId() != null) { + msoLogger.debug("Logging failed message to the database"); + } + msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.SchemaError, requestJSON, e); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, + "Validation of the input request failed"); + msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity()); + return response; + } + + //check for the current operation status +// Response resp = checkE2ESvcInstStatus(action, serviceId, startTime, msoRequest); +// if(resp != null && resp.getStatus() != 200) { +// return resp; +// } + + CatalogDatabase db = null; + RecipeLookupResult recipeLookupResult = null; + try { + db = CatalogDatabase.getInstance(); + recipeLookupResult = getServiceInstanceOrchestrationURI(db, e2eSir.getService().getServiceUuid(), action); + } catch (Exception e) { + msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.AvailabilityError, "Exception while communciate with Catalog DB", e); + msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + alarmLogger.sendAlarm("MsoDatabaseAccessError", MsoAlarmLogger.CRITICAL, + Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB)); + + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, + "Exception while communciate with DB"); + msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + + return response; + } finally { + closeCatalogDB(db); + } + + if (recipeLookupResult == null) { + msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.DataError, "No recipe found in DB"); + msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "Recipe does not exist in catalog DB", + ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null); + + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, + "No recipe found in DB"); + msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + + return response; + } + + String serviceInstanceType = e2eSir.getService().getServiceType(); + + RequestClient requestClient = null; + HttpResponse response = null; + + long subStartTime = System.currentTimeMillis(); + String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON); + + try { + requestClient = RequestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI(), + MsoPropertiesUtils.loadMsoProperties()); + + // Capture audit event + msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl()); + + response = requestClient.post(requestId, false, recipeLookupResult.getRecipeTimeout(), action.name(), + serviceId, null, null, null, null, null, serviceInstanceType, null, null, null, sirRequestJson, + recipeLookupResult.getRecipeParamXsd()); + + msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully received response from BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI(), + null); + } catch (Exception e) { + msoLogger.debug("Exception while communicate with BPMN engine", e); + msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN", + recipeLookupResult.getOrchestrationURI(), null); + Response getBPMNResp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, + MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + alarmLogger.sendAlarm("MsoConfigurationError", MsoAlarmLogger.CRITICAL, + Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL)); + msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine"); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, + "Exception while communicate with BPMN engine"); + msoLogger.debug("End of the transaction, the final response is: " + (String) getBPMNResp.getEntity()); + + return getBPMNResp; + } + + if (response == null) { + Response getBPMNResp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, + MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL"); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, + "Null response from BPMN"); + msoLogger.debug(END_OF_THE_TRANSACTION + (String) getBPMNResp.getEntity()); + + return getBPMNResp; + } + + ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType()); + int bpelStatus = respHandler.getStatus(); + + return beplStatusUpdate(serviceId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action, instanceIdMap); + } + + private Response checkE2ESvcInstStatus(Action action, String serviceId, long startTime, MsoRequest msoRequest) { + OperationStatus curStatus = null; +// String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName(); + String requestScope = sir.getRequestDetails().getModelInfo().getModelType().name(); + try { + if (!(serviceId == null && "service".equals(requestScope) && (action == Action.updateInstance))) { + curStatus = chkSvcInstOperStatusbySvcId(serviceId); + } + } catch (Exception e) { + msoLogger.error(MessageEnum.APIH_DUPLICATE_CHECK_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.DataError, "Error during current operation status check ", e); + + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, + MsoException.ServiceException, e.getMessage(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null); + + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, + "Error during current operation status check"); + msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity()); + return response; + } + + if (curStatus != null && curStatus.getResult() != null && curStatus.getResult().equalsIgnoreCase("processing")) { + String chkMessage = "Error: Locked instance - This " + requestScope + " (" + serviceId + ") " + + "now being worked with a status of " + curStatus.getResult() + + ". The latest workflow of instance must be finished or cleaned up."; + + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_CONFLICT, + MsoException.ServiceException, chkMessage, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null); + + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, + chkMessage); + + msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity()); + + return response; + } + + return Response.status(200).entity(null).build(); + } + + private Response processE2EserviceInstances(String requestJSON, Action action, + HashMap<String, String> instanceIdMap, String version) { + + String requestId = UUIDChecker.generateUUID(msoLogger); + long startTime = System.currentTimeMillis(); + msoLogger.debug("requestId is: " + requestId); + E2EServiceInstanceRequest e2eSir = null; + + MsoRequest msoRequest = new MsoRequest(requestId); + ObjectMapper mapper = new ObjectMapper(); + try { + e2eSir = mapper.readValue(requestJSON, E2EServiceInstanceRequest.class); + + } catch (Exception e) { + //TODO update the service name + this.createOperationStatusRecordForError(action, requestId); + + msoLogger.debug("Mapping of request to JSON object failed : ", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, + MsoException.ServiceException, "Mapping of request to JSON object failed. " + e.getMessage(), + ErrorNumbers.SVC_BAD_PARAMETER, null); + msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.SchemaError, requestJSON, e); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, + "Mapping of request to JSON object failed"); + msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity()); + return response; + } + + mapReqJsonToSvcInstReq(e2eSir, requestJSON); + sir.getRequestDetails().getRequestParameters().setaLaCarte(true); + try { + msoRequest.parse(sir, instanceIdMap, action, version, requestJSON); + } catch (Exception e) { + msoLogger.debug("Validation failed: ", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, + MsoException.ServiceException, "Error parsing request. " + e.getMessage(), + ErrorNumbers.SVC_BAD_PARAMETER, null); + if (msoRequest.getRequestId() != null) { + msoLogger.debug("Logging failed message to the database"); + //TODO update the service name + this.createOperationStatusRecordForError(action, requestId); + } + msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.SchemaError, requestJSON, e); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, + "Validation of the input request failed"); + msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity()); + return response; + } + + OperationStatus dup = null; + String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName(); + String requestScope = sir.getRequestDetails().getModelInfo().getModelType().name(); + try { + if (!(instanceName == null && "service".equals(requestScope) + && (action == Action.createInstance || action == Action.activateInstance))) { + //TODO : Need to check for the duplicate record from the operation status, + //TODO : commenting this check for unblocking current testing for now... induces dead code... + dup = chkDuplicateServiceNameInOperStatus( instanceName); + } + } catch (Exception e) { + msoLogger.error(MessageEnum.APIH_DUPLICATE_CHECK_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.DataError, "Error during duplicate check ", e); + + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, + MsoException.ServiceException, e.getMessage(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null); + + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, + "Error during duplicate check"); + msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity()); + return response; + } + + if (dup != null) { + // Found the duplicate record. Return the appropriate error. + String instance = null; + if (instanceName != null) { + instance = instanceName; + } else { + instance = instanceIdMap.get(requestScope + "InstanceId"); + } + String dupMessage = "Error: Locked instance - This " + requestScope + " (" + instance + ") " + + "already has a request being worked with a status of " + dup.getProgress() + " (ServiceId - " + + dup.getServiceId() + "). The existing request must finish or be cleaned up before proceeding."; + + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_CONFLICT, + MsoException.ServiceException, dupMessage, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null); + + msoLogger.warn(MessageEnum.APIH_DUPLICATE_FOUND, dupMessage, "", "", MsoLogger.ErrorCode.SchemaError, + "Duplicate request - Subscriber already has a request for this service"); + + + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, + dupMessage); + msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity()); + createOperationStatusRecordForError(action, requestId); + return response; + } + + CatalogDatabase db = null; + RecipeLookupResult recipeLookupResult = null; + try { + db = CatalogDatabase.getInstance(); + recipeLookupResult = getServiceInstanceOrchestrationURI(db, e2eSir.getService().getServiceUuid(), action); + } catch (Exception e) { + msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.AvailabilityError, "Exception while communciate with Catalog DB", e); + msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + alarmLogger.sendAlarm("MsoDatabaseAccessError", MsoAlarmLogger.CRITICAL, + Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB)); + + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, + "Exception while communciate with DB"); + msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + createOperationStatusRecordForError(action, requestId); + return response; + } finally { + closeCatalogDB(db); + } + + if (recipeLookupResult == null) { + msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.DataError, "No recipe found in DB"); + msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "Recipe does not exist in catalog DB", + ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null); + + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, + "No recipe found in DB"); + msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + createOperationStatusRecordForError(action, requestId); + return response; + } +// try { +// msoRequest.createRequestRecord(Status.PENDING, action); +// //createOperationStatusRecord(action, requestId); +// } catch (Exception e) { +// msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC_REASON, "Exception while creating record in DB", "", "", +// MsoLogger.ErrorCode.SchemaError, "Exception while creating record in DB", e); +// msoRequest.setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); +// Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, +// MsoException.ServiceException, "Exception while creating record in DB " + e.getMessage(), +// ErrorNumbers.SVC_BAD_PARAMETER, null); +// msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, +// "Exception while creating record in DB"); +// msoLogger.debug("End of the transaction, the final response is: " + (String) response.getEntity()); +// return response; +// } + + String serviceInstanceType = e2eSir.getService().getServiceType(); + + String serviceId = ""; + RequestClient requestClient = null; + HttpResponse response = null; + + long subStartTime = System.currentTimeMillis(); + String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON); + + try { + requestClient = RequestClientFactory.getRequestClient(recipeLookupResult.getOrchestrationURI(), + MsoPropertiesUtils.loadMsoProperties()); + + // Capture audit event + msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl()); + + response = requestClient.post(requestId, false, recipeLookupResult.getRecipeTimeout(), action.name(), + serviceId, null, null, null, null, null, serviceInstanceType, null, null, null, sirRequestJson, + recipeLookupResult.getRecipeParamXsd()); + + msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully received response from BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI(), + null); + } catch (Exception e) { + msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN", + recipeLookupResult.getOrchestrationURI(), null); + Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, + MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + alarmLogger.sendAlarm("MsoConfigurationError", MsoAlarmLogger.CRITICAL, + Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL)); + msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine"); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, + "Exception while communicate with BPMN engine"); + msoLogger.debug("End of the transaction, the final response is: " + (String) resp.getEntity()); + createOperationStatusRecordForError(action, requestId); + return resp; + } + + if (response == null) { + Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, + MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL"); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, + "Null response from BPMN"); + msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity()); + return resp; + } + + ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType()); + int bpelStatus = respHandler.getStatus(); + + return beplStatusUpdate(requestId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action, instanceIdMap); + } + + private Response scaleE2EserviceInstances(String requestJSON, + Action action, HashMap<String, String> instanceIdMap, String version) { + + String requestId = instanceIdMap.get("serviceId"); + long startTime = System.currentTimeMillis(); + msoLogger.debug("requestId is: " + requestId); + E2EServiceInstanceScaleRequest e2eScaleReq = null; + + MsoRequest msoRequest = new MsoRequest(requestId); + + ObjectMapper mapper = new ObjectMapper(); + try { + e2eScaleReq = mapper.readValue(requestJSON, + E2EServiceInstanceScaleRequest.class); + + } catch (Exception e) { + + msoLogger.debug("Mapping of request to JSON object failed : ", e); + Response response = msoRequest.buildServiceErrorResponse( + HttpStatus.SC_BAD_REQUEST, + MsoException.ServiceException, + "Mapping of request to JSON object failed. " + + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, + null); + msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, + MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.SchemaError, requestJSON, e); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.SchemaError, + "Mapping of request to JSON object failed"); + msoLogger.debug("End of the transaction, the final response is: " + + (String) response.getEntity()); + createOperationStatusRecordForError(action, requestId); + return response; + } + + CatalogDatabase db = null; + RecipeLookupResult recipeLookupResult = null; + try { + db = CatalogDatabase.getInstance(); + //TODO Get the service template model version uuid from AAI. + recipeLookupResult = getServiceInstanceOrchestrationURI(db, null, action); + } catch (Exception e) { + msoLogger.error(MessageEnum.APIH_DB_ACCESS_EXC, + MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.AvailabilityError, + "Exception while communciate with Catalog DB", e); + msoRequest + .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); + Response response = msoRequest.buildServiceErrorResponse( + HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, + "No communication to catalog DB " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + alarmLogger.sendAlarm("MsoDatabaseAccessError", + MsoAlarmLogger.CRITICAL, Messages.errors + .get(ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB)); + msoRequest.createRequestRecord(Status.FAILED, action); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.DBAccessError, + "Exception while communciate with DB"); + msoLogger.debug(END_OF_THE_TRANSACTION + + (String) response.getEntity()); + return response; + } finally { + closeCatalogDB(db); + } + if (recipeLookupResult == null) { + msoLogger.error(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, + MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.DataError, "No recipe found in DB"); + msoRequest + .setStatus(org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); + Response response = msoRequest.buildServiceErrorResponse( + HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, + "Recipe does not exist in catalog DB", + ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null); + msoRequest.createRequestRecord(Status.FAILED, action); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.DataNotFound, + "No recipe found in DB"); + msoLogger.debug(END_OF_THE_TRANSACTION + + (String) response.getEntity()); + createOperationStatusRecordForError(action, requestId); + return response; + } + + RequestClient requestClient = null; + HttpResponse response = null; + + long subStartTime = System.currentTimeMillis(); + // String sirRequestJson = mapReqJsonToSvcInstReq(e2eSir, requestJSON); + + try { + requestClient = RequestClientFactory.getRequestClient( + recipeLookupResult.getOrchestrationURI(), + MsoPropertiesUtils.loadMsoProperties()); + + JSONObject jjo = new JSONObject(requestJSON); + jjo.put("operationId", UUIDChecker.generateUUID(msoLogger)); + + String bpmnRequest = jjo.toString(); + + // Capture audit event + msoLogger + .debug("MSO API Handler Posting call to BPEL engine for url: " + + requestClient.getUrl()); + String serviceId = instanceIdMap.get("serviceId"); + String serviceInstanceType = e2eScaleReq.getService().getServiceType(); + response = requestClient.post(requestId, false, + recipeLookupResult.getRecipeTimeout(), action.name(), + serviceId, null, null, null, null, null, serviceInstanceType, + null, null, null, bpmnRequest, recipeLookupResult.getRecipeParamXsd()); + + msoLogger.recordMetricEvent(subStartTime, + MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully received response from BPMN engine", "BPMN", + recipeLookupResult.getOrchestrationURI(), null); + } catch (Exception e) { + msoLogger.recordMetricEvent(subStartTime, + MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.CommunicationError, + "Exception while communicate with BPMN engine", "BPMN", + recipeLookupResult.getOrchestrationURI(), null); + Response resp = msoRequest.buildServiceErrorResponse( + HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, + "Failed calling bpmn " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + alarmLogger.sendAlarm("MsoConfigurationError", + MsoAlarmLogger.CRITICAL, + Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL)); + msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, + MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.AvailabilityError, + "Exception while communicate with BPMN engine",e); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.CommunicationError, + "Exception while communicate with BPMN engine"); + msoLogger.debug("End of the transaction, the final response is: " + + (String) resp.getEntity()); + createOperationStatusRecordForError(action, requestId); + return resp; + } + + if (response == null) { + Response resp = msoRequest.buildServiceErrorResponse( + HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, + "bpelResponse is null", + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null); + msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, + MSO_PROP_APIHANDLER_INFRA, "", "", + MsoLogger.ErrorCode.BusinessProcesssError, + "Null response from BPEL"); + msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.InternalError, + "Null response from BPMN"); + msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity()); + createOperationStatusRecordForError(action, requestId); + return resp; + } + + ResponseHandler respHandler = new ResponseHandler(response, + requestClient.getType()); + int bpelStatus = respHandler.getStatus(); + + return beplStatusUpdate(requestId, startTime, msoRequest, + requestClient, respHandler, bpelStatus, action, instanceIdMap); + } + + private void closeCatalogDB(CatalogDatabase db) { + if (db != null) { + db.close(); + } + } + + private Response beplStatusUpdate(String serviceId, long startTime, + MsoRequest msoRequest, RequestClient requestClient, + ResponseHandler respHandler, int bpelStatus, Action action, + HashMap<String, String> instanceIdMap) { + // BPMN accepted the request, the request is in progress + if (bpelStatus == HttpStatus.SC_ACCEPTED) { + String camundaJSONResponseBody = respHandler.getResponseBody(); + msoLogger.debug("Received from Camunda: " + camundaJSONResponseBody); + + // currently only for delete case we update the status here + if (action == Action.deleteInstance) { + ObjectMapper mapper = new ObjectMapper(); + try { + DelE2ESvcResp jo = mapper.readValue( + camundaJSONResponseBody, DelE2ESvcResp.class); + String operationId = jo.getOperationId(); + this.createOperationStatusRecord("DELETE", serviceId, + operationId); + } catch (Exception ex) { + msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR, + requestClient.getUrl(), "", "", + MsoLogger.ErrorCode.BusinessProcesssError, + "Response from BPEL engine is failed with HTTP Status=" + + bpelStatus); + } + } + + msoLogger.recordAuditEvent(startTime, + MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "BPMN accepted the request, the request is in progress"); + msoLogger.debug(END_OF_THE_TRANSACTION + camundaJSONResponseBody); + return Response.status(HttpStatus.SC_ACCEPTED) + .entity(camundaJSONResponseBody).build(); + } else { + List<String> variables = new ArrayList<>(); + variables.add(bpelStatus + ""); + String camundaJSONResponseBody = respHandler.getResponseBody(); + if (camundaJSONResponseBody != null + && !camundaJSONResponseBody.isEmpty()) { + Response resp = msoRequest.buildServiceErrorResponse( + bpelStatus, MsoException.ServiceException, + "Request Failed due to BPEL error with HTTP Status= %1 " + + '\n' + camundaJSONResponseBody, + ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, variables); + msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR, + requestClient.getUrl(), "", "", + MsoLogger.ErrorCode.BusinessProcesssError, + "Response from BPEL engine is failed with HTTP Status=" + + bpelStatus); + msoLogger.recordAuditEvent(startTime, + MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.InternalError, + "Response from BPMN engine is failed"); + msoLogger.debug(END_OF_THE_TRANSACTION + + (String) resp.getEntity()); + return resp; + } else { + Response resp = msoRequest + .buildServiceErrorResponse( + bpelStatus, + MsoException.ServiceException, + "Request Failed due to BPEL error with HTTP Status= %1", + ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, + variables); + msoLogger.error(MessageEnum.APIH_BPEL_RESPONSE_ERROR, + requestClient.getUrl(), "", "", + MsoLogger.ErrorCode.BusinessProcesssError, + "Response from BPEL engine is empty"); + msoLogger.recordAuditEvent(startTime, + MsoLogger.StatusCode.ERROR, + MsoLogger.ResponseCode.InternalError, + "Response from BPEL engine is empty"); + msoLogger.debug(END_OF_THE_TRANSACTION + + (String) resp.getEntity()); + return resp; + } + } + } + + /** + * Getting recipes from catalogDb + * + * @param db the catalog db + * @param serviceModelUUID the service model version uuid + * @param action the action for the service + * @return the service recipe result + */ + private RecipeLookupResult getServiceInstanceOrchestrationURI( + CatalogDatabase db, String serviceModelUUID, Action action) { + + RecipeLookupResult recipeLookupResult = getServiceURI(db, serviceModelUUID, action); + + if (recipeLookupResult != null) { + msoLogger.debug("Orchestration URI is: " + + recipeLookupResult.getOrchestrationURI() + + ", recipe Timeout is: " + + Integer.toString(recipeLookupResult.getRecipeTimeout())); + } else { + msoLogger.debug("No matching recipe record found"); + } + return recipeLookupResult; + } + + /** + * Getting recipes from catalogDb + * If Service recipe is not set, use default recipe, if set , use special recipe. + * @param db the catalog db + * @param serviceModelUUID the service version uuid + * @param action the action of the service. + * @return the service recipe result. + */ + private RecipeLookupResult getServiceURI(CatalogDatabase db, String serviceModelUUID, Action action) { + + String defaultServiceModelName = "UUI_DEFAULT"; + + Service defaultServiceRecord = db + .getServiceByModelName(defaultServiceModelName); + ServiceRecipe defaultRecipe = db.getServiceRecipeByModelUUID( + defaultServiceRecord.getModelUUID(), action.name()); + //set recipe as default generic recipe + ServiceRecipe recipe = defaultRecipe; + //check the service special recipe + if(null != serviceModelUUID && ! serviceModelUUID.isEmpty()){ + ServiceRecipe serviceSpecialRecipe = db.getServiceRecipeByModelUUID( + serviceModelUUID, action.name()); + if(null != serviceSpecialRecipe){ + //set service special recipe. + recipe = serviceSpecialRecipe; + } + } + + if (recipe == null) { + return null; + } + return new RecipeLookupResult(recipe.getOrchestrationUri(), + recipe.getRecipeTimeout(), recipe.getServiceParamXSD()); + + } + + /** + * Converting E2EServiceInstanceRequest to ServiceInstanceRequest and + * passing it to camunda engine. + * + * @param e2eSir + * @return + */ + private String mapReqJsonToSvcInstReq(E2EServiceInstanceRequest e2eSir, + String requestJSON) { + + sir = new ServiceInstancesRequest(); + + String returnString = null; + RequestDetails requestDetails = new RequestDetails(); + ModelInfo modelInfo = new ModelInfo(); + + // ModelInvariantId + modelInfo.setModelInvariantId(e2eSir.getService().getServiceInvariantUuid()); + + // modelNameVersionId + modelInfo.setModelNameVersionId(e2eSir.getService().getServiceUuid()); + + // String modelInfoValue = + // e2eSir.getService().getParameters().getNodeTemplateName(); + // String[] arrayOfInfo = modelInfoValue.split(":"); + // String modelName = arrayOfInfo[0]; + // String modelVersion = arrayOfInfo[1]; + + // TODO: To ensure, if we dont get the values from the UUI + String modelName = "voLTE"; + String modelVersion = "1.0"; + // modelName + modelInfo.setModelName(modelName); + + // modelVersion + modelInfo.setModelVersion(modelVersion); + + // modelType + modelInfo.setModelType(ModelType.service); + + // setting modelInfo to requestDetails + requestDetails.setModelInfo(modelInfo); + + SubscriberInfo subscriberInfo = new SubscriberInfo(); + + // globalsubscriberId + subscriberInfo.setGlobalSubscriberId(e2eSir.getService().getGlobalSubscriberId()); + + // setting subscriberInfo to requestDetails + requestDetails.setSubscriberInfo(subscriberInfo); + + RequestInfo requestInfo = new RequestInfo(); + + // instanceName + requestInfo.setInstanceName(e2eSir.getService().getName()); + + // source + requestInfo.setSource("UUI"); + + // suppressRollback + requestInfo.setSuppressRollback(true); + + // setting requestInfo to requestDetails + requestDetails.setRequestInfo(requestInfo); + + RequestParameters requestParameters = new RequestParameters(); + + // subscriptionServiceType + requestParameters.setSubscriptionServiceType("MOG"); + + // Userparams + List<E2EUserParam> userParams; + // userParams = + // e2eSir.getService().getParameters().getRequestParameters().getUserParams(); + List<Map<String, Object>> userParamList = new ArrayList<>(); + Map<String, Object> userParamMap = new HashMap<>(); + // complete json request updated in the camunda + userParamMap.put("UUIRequest", requestJSON); + userParamMap.put("ServiceInstanceName", e2eSir.getService().getName()); + + // Map<String, String> userParamMap3 = null; + // for (E2EUserParam userp : userParams) { + // userParamMap.put(userp.getName(), userp.getValue()); + // + // } + userParamList.add(userParamMap); + requestParameters.setUserParams(userParamList); + + // setting requestParameters to requestDetails + requestDetails.setRequestParameters(requestParameters); + + sir.setRequestDetails(requestDetails); + + // converting to string + ObjectMapper mapper = new ObjectMapper(); + try { + returnString = mapper.writeValueAsString(sir); + } catch (IOException e) { + msoLogger + .debug("Exception while converting ServiceInstancesRequest object to string", + e); + } + + return returnString; + } + + private void createOperationStatusRecordForError(Action action, + String serviceId) throws MsoDatabaseException { + + AbstractSessionFactoryManager requestsDbSessionFactoryManager = new RequestsDbSessionFactoryManager(); + + Session session = null; + try { + + session = requestsDbSessionFactoryManager.getSessionFactory() + .openSession(); + session.beginTransaction(); + + OperationStatus os = new OperationStatus(); + os.setOperation(action.name()); + os.setOperationContent(""); + os.setOperationId(""); + os.setProgress("100"); + os.setReason(""); + os.setResult("error"); + os.setServiceId(serviceId); + os.setUserId(""); + Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis()); + Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis()); + os.setFinishedAt(endTimeStamp); + os.setOperateAt(startTimeStamp); + + session.save(os); + session.getTransaction().commit(); + + } catch (Exception e) { + msoLogger.error(MessageEnum.APIH_DB_INSERT_EXC, "", "", + MsoLogger.ErrorCode.DataError, + "Exception when creation record request in Operation", e); + throw new MsoDatabaseException( + "Data did inserted in Operatus Status Table for failure", e); + } finally { + if (null != session) { + session.close(); + } + } + } + + private void createOperationStatusRecord(String actionNm, String serviceId, + String operationId) throws MsoDatabaseException { + + AbstractSessionFactoryManager requestsDbSessionFactoryManager = new RequestsDbSessionFactoryManager(); + + Session session = null; + try { + + session = requestsDbSessionFactoryManager.getSessionFactory() + .openSession(); + session.beginTransaction(); + + OperationStatus os = new OperationStatus(); + os.setOperation(actionNm); + os.setOperationContent(""); + os.setOperationId(operationId); + os.setProgress("0"); + os.setReason(""); + os.setResult("processing"); + os.setServiceId(serviceId); + // TODO : to be updated... + os.setUserId(""); + Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis()); + Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis()); + os.setFinishedAt(endTimeStamp); + os.setOperateAt(startTimeStamp); + + session.save(os); + session.getTransaction().commit(); + + } catch (Exception e) { + msoLogger.error(MessageEnum.APIH_DB_INSERT_EXC, "", "", + MsoLogger.ErrorCode.DataError, + "Exception when creation record request in Operation", e); + throw new MsoDatabaseException( + "Data did inserted in Operatus Status Table", e); + } finally { + if (null != session) { + session.close(); + } + } + } + + private OperationStatus chkSvcInstOperStatusbySvcId(String serviceId) { + OperationStatus svcInstanceOperStatus = (RequestsDatabase.getInstance()) + .getOperationStatusByServiceId(serviceId); + + return svcInstanceOperStatus; + } + + private OperationStatus chkDuplicateServiceNameInOperStatus( + String serviceName) { + OperationStatus dupServiceName = (RequestsDatabase.getInstance()) + .getOperationStatusByServiceName(serviceName); + + return dupServiceName; + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java index 7be86fed9d..b809fc24c0 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java @@ -341,7 +341,7 @@ public class OrchestrationRequests { requestDetails = mapper.readValue(requestBody, RequestDetails.class); }catch(Exception e){ - msoLogger.debug("Exception caught mapping requestBody to RequestDetails"); + msoLogger.debug("Exception caught mapping requestBody to RequestDetails",e); } request.setRequestDetails(requestDetails); |