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 okhttp3.RequestBody;
24 import okhttp3.ResponseBody;
25 import org.camunda.bpm.engine.delegate.DelegateExecution;
26 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationOutput;
27 import org.openecomp.mso.bpmn.core.WorkflowException;
28 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.GenericResourceApi;
29 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.builder.NetworkTopologyRequestBodyBuilder;
30 import org.openecomp.mso.requestsdb.RequestsDbConstant;
31 import org.openecomp.mso.yangDecoder.transform.api.ITransformJava2StringService;
32 import org.openecomp.mso.yangDecoder.transform.impl.TransfromJava2StringFactory;
37 * Created by 10112215 on 2017/9/20.
39 public class SdncOperationTaskYangToolsImpl extends AbstractSdncOperationTask {
41 public void sendRestrequestAndHandleResponse(DelegateExecution execution,
42 Map<String, String> inputs,
43 GenericResourceApi genericResourceApiClient) throws Exception {
44 updateProgress(execution, null, null, "40", "sendRestrequestAndHandleResponse begin!");
45 NetworkTopologyRequestBodyBuilder builder = new NetworkTopologyRequestBodyBuilder();
46 RequestBody body = builder.build(execution, inputs);
47 updateProgress(execution, null, null, "50", "RequestBody build finished!");
48 ResponseBody responseBody = genericResourceApiClient.postNetworkTopologyOperation(body).execute().body();
49 updateProgress(execution, null, null, "90", "sendRestrequestAndHandleResponse finished!");
50 saveResponse(execution, responseBody);
53 private void saveResponse(DelegateExecution execution, ResponseBody responseBody) throws Exception {
54 ITransformJava2StringService java2jsonService = TransfromJava2StringFactory.getJava2jsonService();
55 NetworkTopologyOperationOutput output = (NetworkTopologyOperationOutput) java2jsonService.
56 transformRpcDataObjectFromString(NetworkTopologyRequestBodyBuilder.URI_PATH, responseBody.string());
57 String responseCode = output.getResponseCode();
58 if (!"200".equals(responseCode)) {
59 String processKey = getProcessKey(execution);
60 int errorCode = Integer.valueOf(responseCode);
61 String errorMessage = output.getResponseMessage();
62 WorkflowException workflowException = new WorkflowException(processKey, errorCode, errorMessage);
63 execution.setVariable("SDNCA_SuccessIndicator", workflowException);
64 updateProgress(execution, RequestsDbConstant.Status.ERROR, String.valueOf(errorCode), null, errorMessage);
65 throw new Exception("");