diff options
author | Chuanyu Chen <chenchuanyu@huawei.com> | 2020-03-26 01:41:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-03-26 01:41:27 +0000 |
commit | 79d1e0244ce1f01f76640491dd6fca23420212cd (patch) | |
tree | 19828b0f2d3d1e039094f50a3e8f90dd26606b8f /bpmn/so-bpmn-tasks/src/main | |
parent | f5420060c758308df18a0e316d6ae214ef9eb5c6 (diff) | |
parent | b2ee1e9c0b43722b3a573b08a0f60dd35cd2ef3f (diff) |
Merge "Fix PNF software upgrade workflow"
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main')
-rw-r--r-- | bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDE.java | 106 |
1 files changed, 60 insertions, 46 deletions
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<LcmDmaapResponse> 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()); } } |