From b2ee1e9c0b43722b3a573b08a0f60dd35cd2ef3f Mon Sep 17 00:00:00 2001 From: Enbo Wang Date: Thu, 19 Mar 2020 23:27:16 +0800 Subject: Fix PNF software upgrade workflow Fix the issue that API can not return when the workflow has ended. Issue-ID: SO-2751 Signed-off-by: Enbo Wang Change-Id: I7d140b2286ce3003a6efcd2c3891fc8142982477 --- .../bpmn/common/scripts/CompleteMsoProcess.groovy | 3 +- .../scripts/PNFSoftwareUpgrade.groovy | 124 +++++++++++ .../main/resources/process/PNFSWUPDownload.bpmn | 221 +++++++++++++++----- .../main/resources/process/PNFSoftwareUpgrade.bpmn | 230 +++++++++++++++------ .../process/PNFSoftwareUpgradeTest.java | 18 +- .../camunda/controller/sdnc/SdncControllerDE.java | 106 +++++----- 6 files changed, 539 insertions(+), 163 deletions(-) create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/PNFSoftwareUpgrade.groovy diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcess.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcess.groovy index 48a8e60095..37ad0d3a3e 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcess.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcess.groovy @@ -104,7 +104,8 @@ public class CompleteMsoProcess extends AbstractServiceTaskProcessor { infraRequest.setVfModuleId(utils.getNodeText(xml, "vfModuleId")) }else if(utils.nodeExists(xml, "volumeGroupId")){ infraRequest.setVolumeGroupId(utils.getNodeText(xml, "volumeGroupId")) - + }else if(utils.nodeExists(xml, "pnfName")){ + infraRequest.setPnfName(utils.getNodeText(xml, "pnfName")) } dbClient.updateInfraActiveRequests(infraRequest, UrnPropertiesReader.getVariable("mso.adapters.requestDb.auth"), UrnPropertiesReader.getVariable("mso.adapters.requestDb.endpoint")) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/PNFSoftwareUpgrade.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/PNFSoftwareUpgrade.groovy new file mode 100644 index 0000000000..8e7a4f727d --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/PNFSoftwareUpgrade.groovy @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 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.onap.so.bpmn.infrastructure.scripts + +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.MsoUtils +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.workflow.context.WorkflowContext +import org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder +import org.onap.so.bpmn.core.WorkflowException +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.* + +class PNFSoftwareUpgrade extends AbstractServiceTaskProcessor { + private static final Logger logger = LoggerFactory.getLogger(PNFSoftwareUpgrade.class) + + ExceptionUtil exceptionUtil = new ExceptionUtil() + String prefix = "PnfSwUpgrade_" + + @Override + void preProcessRequest(DelegateExecution execution) { + } + + void sendResponse(DelegateExecution execution) { + def requestId = execution.getVariable(REQUEST_ID) + def instanceId = execution.getVariable(PNF_CORRELATION_ID) + logger.debug("Send response for requestId: {}, instanceId: {}", requestId, instanceId) + + String response = """{"requestReferences":{"requestId":"${requestId}", "instanceId":"${instanceId}"}}""".trim() + sendWorkflowResponse(execution, 200, response) + } + + static WorkflowContext getWorkflowContext(DelegateExecution execution) { + String requestId = execution.getVariable(REQUEST_ID) + return WorkflowContextHolder.getInstance().getWorkflowContext(requestId) + } + + void prepareCompletion(DelegateExecution execution) { + try { + String requestId = execution.getVariable(REQUEST_ID) + logger.debug("Prepare Completion of PNF Software Upgrade for requestId: {}", requestId) + + String msoCompletionRequest = + """ + + ${MsoUtils.xmlEscape(requestId)} + UPDATE + VID + + PNF has been upgraded successfully. + PNF_SOFTWARE_UPGRADE + """ + String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest) + + execution.setVariable(prefix + "CompleteMsoProcessRequest", xmlMsoCompletionRequest) + + logger.debug("CompleteMsoProcessRequest of PNF Software Upgrade - " + "\n" + xmlMsoCompletionRequest) + } catch (Exception e) { + String msg = "Prepare Completion error for PNF software upgrade - " + e.getMessage() + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + } + } + + void prepareFalloutHandler(DelegateExecution execution) { + WorkflowContext workflowContext = getWorkflowContext(execution) + if (workflowContext == null) { + logger.debug("Error occurred before sending response to API handler, and send it now") + sendResponse(execution) + } + + try { + String requestId = execution.getVariable(REQUEST_ID) + logger.debug("Prepare FalloutHandler of PNF Software Upgrade for requestId: {}", requestId) + + WorkflowException workflowException = execution.getVariable("WorkflowException") + String errorCode = String.valueOf(workflowException.getErrorCode()) + String errorMessage = workflowException.getErrorMessage() + String falloutHandlerRequest = + """ + + ${MsoUtils.xmlEscape(requestId)} + UPDATE + VID + + + ${MsoUtils.xmlEscape(errorMessage)} + ${MsoUtils.xmlEscape(errorCode)} + + """ + String xmlFalloutHandlerRequest = utils.formatXml(falloutHandlerRequest) + + execution.setVariable(prefix + "FalloutHandlerRequest", xmlFalloutHandlerRequest) + + logger.debug("FalloutHandlerRequest of PNF Software Upgrade - " + "\n" + xmlFalloutHandlerRequest) + } catch (Exception e) { + String msg = "Prepare FalloutHandler error for PNF software upgrade - " + e.getMessage() + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg) + } + } +} diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/PNFSWUPDownload.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/PNFSWUPDownload.bpmn index 24ca7104a7..5d523194bb 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/PNFSWUPDownload.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/PNFSWUPDownload.bpmn @@ -1,15 +1,15 @@ - + SequenceFlow_1fdclh0 SequenceFlow_1fdclh0 - SequenceFlow_12155q6 + SequenceFlow_0kusy70 - SequenceFlow_1d2rfyx + SequenceFlow_0mjjdia @@ -32,8 +32,8 @@ SequenceFlow_1kaikh5 - SequenceFlow_1d2rfyx SequenceFlow_1gawssm + SequenceFlow_1d2rfyx SequenceFlow_1gawssm @@ -73,10 +73,7 @@ SequenceFlow_1ccldpp - - - #{execution.getVariable("ControllerStatus").equals("Success")} - + @@ -89,113 +86,229 @@ #{execution.getVariable("ControllerStatus").equals("Success")} + + + SequenceFlow_0swi04u + + + + SequenceFlow_0swi04u + SequenceFlow_1ppn4a8 + import org.onap.so.bpmn.infrastructure.scripts.* +def pnfSwUpgrade = new PNFSoftwareUpgrade() +pnfSwUpgrade.prepareFalloutHandler(execution) + + + + + + SequenceFlow_1ppn4a8 + SequenceFlow_1ahmdun + + + SequenceFlow_1ahmdun + + + + + + + + SequenceFlow_0kusy70 + SequenceFlow_12155q6 + import org.onap.so.bpmn.infrastructure.scripts.* +def pnfSwUpgrade = new PNFSoftwareUpgrade() +pnfSwUpgrade.sendResponse(execution) + + + + SequenceFlow_1d2rfyx + SequenceFlow_183s0wo + import org.onap.so.bpmn.infrastructure.scripts.* +def pnfSwUpgrade = new PNFSoftwareUpgrade() +pnfSwUpgrade.prepareCompletion(execution) + + + + + + SequenceFlow_183s0wo + SequenceFlow_0mjjdia + + + + #{execution.getVariable("ControllerStatus").equals("Success")} + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - - - - - - - - + + + + + + - - + + - - + + - + - - + + - - + + - + - - + + - + - - + + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/PNFSoftwareUpgrade.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/PNFSoftwareUpgrade.bpmn index 8d59dac8ac..4ff0af4549 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/PNFSoftwareUpgrade.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/PNFSoftwareUpgrade.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_1ng4b6l @@ -8,9 +8,9 @@ SequenceFlow_1ng4b6l SequenceFlow_12ejx4m - + - SequenceFlow_1atiydu + SequenceFlow_0tle5zb @@ -60,7 +60,7 @@ #{execution.getVariable("ControllerStatus").equals("Success")} - + #{execution.getVariable("ControllerStatus").equals("Success")} @@ -110,7 +110,7 @@ async - SequenceFlow_12ejx4m + SequenceFlow_0ks3p41 SequenceFlow_0j26xlx @@ -119,9 +119,59 @@ SequenceFlow_084orr1 + + SequenceFlow_12ejx4m + SequenceFlow_0ks3p41 + import org.onap.so.bpmn.infrastructure.scripts.* +def pnfSwUpgrade = new PNFSoftwareUpgrade() +pnfSwUpgrade.sendResponse(execution) + + + + SequenceFlow_1atiydu + SequenceFlow_0ipc3nt + import org.onap.so.bpmn.infrastructure.scripts.* +def pnfSwUpgrade = new PNFSoftwareUpgrade() +pnfSwUpgrade.prepareCompletion(execution) + + + + + + + SequenceFlow_0ipc3nt + SequenceFlow_0tle5zb + + + + + SequenceFlow_05haut5 + + + + SequenceFlow_05haut5 + SequenceFlow_09y0mpc + import org.onap.so.bpmn.infrastructure.scripts.* +def pnfSwUpgrade = new PNFSoftwareUpgrade() +pnfSwUpgrade.prepareFalloutHandler(execution) + + + + + + SequenceFlow_09y0mpc + SequenceFlow_1tcjlty + + + SequenceFlow_1tcjlty + + + + + + - @@ -131,142 +181,204 @@ - + - - + + - + - + - + - + - + - + - - + + - + - + - - + + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - - + + - + - - + + + + + + - + - - + + - + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/PNFSoftwareUpgradeTest.java b/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/PNFSoftwareUpgradeTest.java index a9bf4352bf..2993ed6724 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/PNFSoftwareUpgradeTest.java +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/PNFSoftwareUpgradeTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Huawei Technologies Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,6 +61,7 @@ public class PNFSoftwareUpgradeTest extends BaseBPMNTest { private static final String TEST_PROCESSINSTANCE_KEY = "PNFSoftwareUpgrade"; private static final AAIVersion VERSION = AAIVersion.LATEST; private static final Map executionVariables = new HashMap(); + private static final String REQUEST_ID = "50ae41ad-049c-4fe2-9950-539f111120f5"; private final String[] actionNames = new String[4]; private String requestObject; private String responseObject; @@ -80,6 +82,7 @@ public class PNFSoftwareUpgradeTest extends BaseBPMNTest { responseObject = FileUtil.readResourceFile("response/" + getClass().getSimpleName() + ".json"); executionVariables.put("bpmnRequest", requestObject); + executionVariables.put("requestId", REQUEST_ID); /** * This variable indicates that the flow was invoked asynchronously. It's injected by {@link WorkflowProcessor}. @@ -99,6 +102,7 @@ public class PNFSoftwareUpgradeTest extends BaseBPMNTest { public void workflow_validInput_expectedOutput() throws InterruptedException { mockCatalogDb(); + mockRequestDb(); mockAai(); final String msoRequestId = UUID.randomUUID().toString(); @@ -118,9 +122,9 @@ public class PNFSoftwareUpgradeTest extends BaseBPMNTest { // Layout is to reflect the bpmn visual layout assertThat(pi).isEnded().hasPassedInOrder("softwareUpgrade_startEvent", "ServiceTask_042uz7n", - "ServiceTask_0slpahe", "ExclusiveGateway_0x6h0ni", "ServiceTask_0x5cje8", "ExclusiveGateway_0v3l3wv", - "ServiceTask_02lxf48", "ExclusiveGateway_0ch3fef", "ServiceTask_0y2uysu", "ExclusiveGateway_1ny9b1z", - "softwareUpgrade_endEvent"); + "ScriptTask_10klpg8", "ServiceTask_0slpahe", "ExclusiveGateway_0x6h0ni", "ServiceTask_0x5cje8", + "ExclusiveGateway_0v3l3wv", "ServiceTask_02lxf48", "ExclusiveGateway_0ch3fef", "ServiceTask_0y2uysu", + "ExclusiveGateway_1ny9b1z", "ScriptTask_1igtc83", "CallActivity_0o1mi8u", "softwareUpgrade_endEvent"); List detailedMessages = grpcNettyServer.getDetailedMessages(); assertThat(detailedMessages.size() == 4); @@ -202,6 +206,14 @@ public class PNFSoftwareUpgradeTest extends BaseBPMNTest { wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo"))); } + private void mockRequestDb() { + /** + * Update Request DB + */ + wireMockServer.stubFor(put(urlEqualTo("/infraActiveRequests/" + REQUEST_ID))); + + } + /** * Mock the catalobdb rest interface. */ diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDE.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDE.java index 8499b6f7d1..ea3405d423 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDE.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDE.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix - * Modifications Copyright (C) 2020 Huawei + * Modifications Copyright (C) 2020 Huawei Technologies Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,8 @@ import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; import org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda.controller.common.SoPropertyConstants; import org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda.controller.LcmControllerDE; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.client.exception.PayloadGenerationException; import org.onap.so.client.sdnc.common.SDNCConstants; import org.onap.so.client.sdnc.lcm.*; import org.onap.so.client.sdnc.lcm.beans.*; @@ -59,26 +61,20 @@ public class SdncControllerDE extends LcmControllerDE { logger.debug("Running activity for id: {}, name: {}", execution.getCurrentActivityId(), execution.getCurrentActivityName()); - boolean result; try { LcmInput lcmInput = buildLcmInput(execution); - if (lcmInput != null) { - result = sendLcmRequest(execution, lcmInput); - } else { - logger.error("Build LCM Input error"); - result = false; - } - } catch (Exception e) { - logger.error("Call SDNC LCM Client failure: ", e); - result = false; - } + sendLcmRequest(execution, lcmInput); - if (result) { execution.setVariable(SoPropertyConstants.CONTROLLER_STATUS, "Success"); - } else { + } catch (Exception e) { execution.setVariable(SoPropertyConstants.CONTROLLER_STATUS, "Failure"); + + exceptionUtil.buildAndThrowWorkflowException(execution, SDNC_DELEGATE_EXECUTION_ERROR_CODE, e); } + logger.debug("Finish activity for id: {}, name: {}", execution.getCurrentActivityId(), + execution.getCurrentActivityName()); + return 0; } @@ -87,17 +83,24 @@ public class SdncControllerDE extends LcmControllerDE { return SDNC_DELEGATE_EXECUTION_ERROR_CODE; } - private LcmOutput sendSyncRequest(String operation, LcmInput lcmInput) { + private LcmOutput sendSyncRequest(String operation, LcmInput lcmInput) throws BadResponseException { SDNCLcmClientBuilder sdncLcmClientBuilder = new SDNCLcmClientBuilder(); SDNCLcmRestClient sdncLcmRestClient; try { sdncLcmRestClient = sdncLcmClientBuilder.newSDNCLcmRestClient(operation); } catch (SDNCLcmClientBuilderException e) { logger.error("Create SDNCLcmRestClient error: ", e); - return null; + throw new BadResponseException("Can not send request to SDNC."); } - return sdncLcmRestClient.sendRequest(lcmInput); + LcmOutput lcmOutput; + try { + lcmOutput = sdncLcmRestClient.sendRequest(lcmInput); + } catch (Exception e) { + logger.error("SDNCLcmRestClient sends request failure: ", e); + throw new BadResponseException("Send request to SDNC failure."); + } + return lcmOutput; } private LcmOutput selectLcmOutputFromDmaapResponses(List lcmDmaapResponses, LcmInput lcmInput) { @@ -115,22 +118,22 @@ public class SdncControllerDE extends LcmControllerDE { return null; } - private LcmOutput sendAsyncRequest(String operation, LcmInput lcmInput) { + private LcmOutput sendAsyncRequest(String operation, LcmInput lcmInput) throws BadResponseException { SDNCLcmClientBuilder sdncLcmClientBuilder = new SDNCLcmClientBuilder(); SDNCLcmDmaapClient sdncLcmDmaapClient; try { sdncLcmDmaapClient = sdncLcmClientBuilder.newSDNCLcmDmaapClient(); } catch (SDNCLcmClientBuilderException e) { logger.error("Create SDNCLcmDmaapClient error: ", e); - return null; + throw new BadResponseException("Can not send request to SDNC."); } LcmDmaapRequest lcmDmaapRequest = SDNCLcmMessageBuilder.buildLcmDmaapRequest(operation, lcmInput); try { sdncLcmDmaapClient.sendRequest(lcmDmaapRequest); } catch (Exception e) { - logger.error("SDNCLcmDmaapClient sends request error: ", e); - return null; + logger.error("SDNCLcmDmaapClient sends request failure: ", e); + throw new BadResponseException("Send request to SDNC failure."); } long timeout = sdncLcmClientBuilder.getSDNCLcmProperties().getActionTimeout(); @@ -146,8 +149,9 @@ public class SdncControllerDE extends LcmControllerDE { long stopTime = System.currentTimeMillis(); if ((stopTime - startTime) > timeout) { - logger.error("Timeout for SDNC LCM action {}", lcmInput.getAction()); - return null; + String msg = "Timeout for SDNC LCM action " + lcmInput.getAction(); + logger.error(msg); + throw new BadResponseException(msg); } } } @@ -158,7 +162,15 @@ public class SdncControllerDE extends LcmControllerDE { return lcmAction.replaceAll(regex, replacement).toLowerCase(); } - private LcmInput buildLcmInput(DelegateExecution execution) throws JsonProcessingException { + private String convertToSting(Object msgObject) throws PayloadGenerationException { + try { + return SDNCLcmPayloadBuilder.convertToSting(msgObject); + } catch (JsonProcessingException e) { + throw new PayloadGenerationException(e.getMessage()); + } + } + + private LcmInput buildLcmInput(DelegateExecution execution) throws PayloadGenerationException { String requestId = String.valueOf(execution.getVariable(REQUEST_ID)); String requestAction = String.valueOf(execution.getVariable(SoPropertyConstants.SO_ACTION)); String pnfName = String.valueOf(execution.getVariable(PNF_CORRELATION_ID)); @@ -176,32 +188,33 @@ public class SdncControllerDE extends LcmControllerDE { UpgradePreCheckPayload upgradePreCheckPayload; upgradePreCheckPayload = SDNCLcmPayloadBuilder.buildUpgradePreCheckPayload(execution); - lcmPayload = SDNCLcmPayloadBuilder.convertToSting(upgradePreCheckPayload); + lcmPayload = convertToSting(upgradePreCheckPayload); break; case SoPropertyConstants.ACTION_DOWNLOAD_N_E_SW: lcmAction = SDNCLcmActionConstants.DOWNLOAD_N_E_SW; DownloadNESwPayload downloadNESwPayload; downloadNESwPayload = SDNCLcmPayloadBuilder.buildDownloadNESwPayload(execution); - lcmPayload = SDNCLcmPayloadBuilder.convertToSting(downloadNESwPayload); + lcmPayload = convertToSting(downloadNESwPayload); break; case SoPropertyConstants.ACTION_ACTIVATE_N_E_SW: lcmAction = SDNCLcmActionConstants.ACTIVATE_N_E_SW; ActivateNESwPayload activateNESwPayload; activateNESwPayload = SDNCLcmPayloadBuilder.buildActivateNESwPayload(execution); - lcmPayload = SDNCLcmPayloadBuilder.convertToSting(activateNESwPayload); + lcmPayload = convertToSting(activateNESwPayload); break; case SoPropertyConstants.ACTION_POST_CHECK: lcmAction = SDNCLcmActionConstants.UPGRADE_POST_CHECK; UpgradePostCheckPayload upgradePostCheckPayload; upgradePostCheckPayload = SDNCLcmPayloadBuilder.buildUpgradePostCheckPayload(execution); - lcmPayload = SDNCLcmPayloadBuilder.convertToSting(upgradePostCheckPayload); + lcmPayload = convertToSting(upgradePostCheckPayload); break; default: - logger.error("Unsupported SO Action: " + requestAction); - return null; + String msg = "Unsupported SO Action: " + requestAction; + logger.error(msg); + throw new PayloadGenerationException(msg); } String subRequestId = UUID.randomUUID().toString(); @@ -209,32 +222,33 @@ public class SdncControllerDE extends LcmControllerDE { SDNCLcmMessageBuilder.buildLcmInputForPnf(requestId, subRequestId, pnfName, lcmAction, lcmPayload); ObjectMapper mapper = new ObjectMapper(); - String lcmInputMsg = mapper.writeValueAsString(lcmInput); - logger.debug("SDNC input message for {}: {}", lcmAction, lcmInputMsg); + try { + String lcmInputMsg = mapper.writeValueAsString(lcmInput); + logger.debug("SDNC input message for {}: {}", lcmAction, lcmInputMsg); + } catch (JsonProcessingException e) { + throw new PayloadGenerationException(e.getMessage()); + } return lcmInput; } - private boolean parseLcmOutput(LcmOutput lcmOutput, String lcmAction) { - if (lcmOutput == null) { - logger.error("Call SDNC LCM API failure"); - return false; - } - + private void parseLcmOutput(LcmOutput lcmOutput, String lcmAction) throws BadResponseException { LcmStatus lcmStatus = lcmOutput.getStatus(); + int lcmStatusCode = lcmStatus.getCode(); String outputPayload = lcmOutput.getPayload(); - logger.debug("SDNC LCM output payload of action {}: {}", lcmAction, outputPayload); - if (lcmStatus.getCode() == SDNCConstants.LCM_OUTPUT_SUCCESS_CODE) { - logger.debug("Call SDNC LCM API for {} success, message: {}", lcmAction, lcmStatus.getMessage()); - return true; + if (lcmStatusCode == SDNCConstants.LCM_OUTPUT_SUCCESS_CODE) { + logger.debug("Call SDNC LCM API for {} success, code: {}, message: {}, payload: {}", lcmAction, + lcmStatusCode, lcmStatus.getMessage(), outputPayload); } else { - logger.error("Call SDNC LCM API for {} failure, message: {}", lcmAction, lcmStatus.getMessage()); - return false; + String msg = String.format("Call SDNC LCM API for %s failure, code: %d, message: %s, payload: %s", + lcmAction, lcmStatusCode, lcmStatus.getMessage(), outputPayload); + logger.error(msg); + throw new BadResponseException(msg); } } - private boolean sendLcmRequest(DelegateExecution execution, LcmInput lcmInput) { + private void sendLcmRequest(DelegateExecution execution, LcmInput lcmInput) throws BadResponseException { String actionMode = String.valueOf(execution.getVariable(SoPropertyConstants.SO_ACTION_MODE)); String lcmOperation = toLowerHyphen(lcmInput.getAction()); @@ -245,6 +259,6 @@ public class SdncControllerDE extends LcmControllerDE { lcmOutput = sendSyncRequest(lcmOperation, lcmInput); } - return parseLcmOutput(lcmOutput, lcmInput.getAction()); + parseLcmOutput(lcmOutput, lcmInput.getAction()); } } -- cgit 1.2.3-korg