2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask;
23 import org.camunda.bpm.engine.delegate.DelegateExecution;
24 import org.openecomp.mso.bpmn.core.WorkflowException;
25 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.GenericResourceApi;
26 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.builder.NetworkRpcInputEntityBuilder;
27 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.RpcNetworkTopologyOperationInputEntity;
28 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.RpcNetworkTopologyOperationOutputEntity;
29 import org.openecomp.mso.requestsdb.RequestsDbConstant;
34 * Created by 10112215 on 2017/9/20.
36 public class SdncNetworkTopologyOperationTask extends AbstractSdncOperationTask {
38 public void sendRestrequestAndHandleResponse(DelegateExecution execution,
39 Map<String, String> inputs,
40 GenericResourceApi genericResourceApiClient) throws Exception {
41 updateProgress(execution, null, null, "40", "sendRestrequestAndHandleResponse begin!");
42 NetworkRpcInputEntityBuilder builder = new NetworkRpcInputEntityBuilder();
43 RpcNetworkTopologyOperationInputEntity inputEntity = builder.build(execution, inputs);
44 updateProgress(execution, null, null, "50", "RequestBody build finished!");
45 RpcNetworkTopologyOperationOutputEntity outputEntity = genericResourceApiClient.postNetworkTopologyOperation(inputEntity).execute().body();
46 updateProgress(execution, null, null, "90", "sendRestrequestAndHandleResponse finished!");
47 saveOutput(execution, outputEntity);
50 private void saveOutput(DelegateExecution execution, RpcNetworkTopologyOperationOutputEntity output) throws Exception {
51 String responseCode = output.getOutput().getResponseCode();
52 if (!"200".equals(responseCode)) {
53 String processKey = getProcessKey(execution);
54 int errorCode = Integer.valueOf(responseCode);
55 String errorMessage = output.getOutput().getResponseMessage();
56 WorkflowException workflowException = new WorkflowException(processKey, errorCode, errorMessage);
57 execution.setVariable("SDNCA_SuccessIndicator", workflowException);
58 updateProgress(execution, RequestsDbConstant.Status.ERROR, String.valueOf(errorCode), null, errorMessage);
59 throw new Exception("");
61 updateProgress(execution, RequestsDbConstant.Status.FINISHED, null, RequestsDbConstant.Progress.ONE_HUNDRED, "execute finished!");