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.opendaylight.yangtools.yang.binding.DataObject;
28 import org.openecomp.mso.bpmn.core.WorkflowException;
29 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.GenericResourceApi;
30 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.builder.NetworkTopologyRequestBodyBuilder;
31 import org.openecomp.mso.requestsdb.RequestsDbConstant;
32 import org.openecomp.mso.yangDecoder.transform.api.ITransformJava2StringService;
33 import org.openecomp.mso.yangDecoder.transform.impl.TransfromJava2StringFactory;
38 * Created by 10112215 on 2017/9/20.
40 public class SdncVlOperationTaskYangToolsImpl extends AbstractSdncVlOperationTask {
42 public void sendRestrequestAndHandleResponse(DelegateExecution execution,
43 Map<String, String> inputs,
44 GenericResourceApi genericResourceApiClient) throws Exception {
45 updateProgress(execution, null, null, "40", "sendRestrequestAndHandleResponse begin!");
46 NetworkTopologyRequestBodyBuilder builder = new NetworkTopologyRequestBodyBuilder();
47 RequestBody body = builder.build(inputs);
48 updateProgress(execution, null, null, "50", "RequestBody build finished!");
49 ResponseBody responseBody = genericResourceApiClient.postNetworkTopologyPeration(body).execute().body();
50 updateProgress(execution, null, null, "90", "sendRestrequestAndHandleResponse finished!");
51 saveResponse(execution, responseBody);
54 private void saveResponse(DelegateExecution execution, ResponseBody responseBody) throws Exception {
55 ITransformJava2StringService java2jsonService = TransfromJava2StringFactory.getJava2jsonService();
56 NetworkTopologyOperationOutput output = (NetworkTopologyOperationOutput) java2jsonService.
57 transformRpcDataObjectFromString(NetworkTopologyRequestBodyBuilder.URI_PATH, responseBody.string());
58 String responseCode = output.getResponseCode();
59 if (!responseCode.equals("200")) {
60 String processKey = getProcessKey(execution);
61 int errorCode = Integer.valueOf(responseCode);
62 String errorMessage = output.getResponseMessage();
63 WorkflowException workflowException = new WorkflowException(processKey, errorCode, errorMessage);
64 execution.setVariable("SDNCA_SuccessIndicator", workflowException);
65 updateProgress(execution, RequestsDbConstant.Status.ERROR, String.valueOf(errorCode), null, errorMessage);
66 throw new Exception("");