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.apache.commons.lang3.StringUtils;
24 import org.onap.msb.sdk.httpclient.RestServiceCreater;
25 import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
26 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.GenericResourceApi;
27 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.HeaderUtil;
28 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.builder.NetworkRpcInputEntityBuilder;
29 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.RpcNetworkTopologyOperationInputEntity;
30 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.RpcNetworkTopologyOperationOutputEntity;
31 import org.openecomp.mso.logger.MsoLogger;
32 import org.openecomp.mso.requestsdb.RequestsDatabase;
33 import org.openecomp.mso.requestsdb.RequestsDbConstant;
34 import org.openecomp.mso.requestsdb.ResourceOperationStatus;
39 * Created by 10112215 on 2017/9/21.
41 public class SdncUnderlayVpnOperationClient {
43 private static final String DEFAULT_MSB_IP = "127.0.0.1";
44 private static final int DEFAULT_MSB_Port = 10081;
45 private RequestsDatabase requestsDB = RequestsDatabase.getInstance();
47 private String serviceId;
48 private String operationId;
49 private String resourceTemplateUUID;
52 private static MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL);
54 public boolean excute(String msbIp,
56 Map<String, String> inputs,
59 String resourceTemplateUUID_i){
60 serviceId = serviceId_i;
61 operationId = operationId_i;
62 resourceTemplateUUID = resourceTemplateUUID_i;
63 GenericResourceApi genericResourceApiClient = getGenericResourceApiClient(msbIp, msbPort);
64 updateProgress(RequestsDbConstant.Status.PROCESSING, null, "10", "execute begin!");
65 return sendRestrequestAndHandleResponse(inputs, genericResourceApiClient);
68 public boolean sendRestrequestAndHandleResponse(Map<String, String> inputs, GenericResourceApi genericResourceApiClient){
69 updateProgress(null, null, "40", "sendRestrequestAndHandleResponse begin!");
70 NetworkRpcInputEntityBuilder builder = new NetworkRpcInputEntityBuilder();
71 RpcNetworkTopologyOperationInputEntity body = builder.build(null, inputs);
72 updateProgress(null, null, "50", "RequestBody build finished!");
73 RpcNetworkTopologyOperationOutputEntity networkRpcOutputEntiy = null;
75 networkRpcOutputEntiy = genericResourceApiClient.postNetworkTopologyOperation
76 (HeaderUtil.DefaulAuth ,body).execute().body();
77 } catch (Exception e) {
78 logger.debug("Exception: ", e);
79 updateProgress(RequestsDbConstant.Status.ERROR, null, null, "sendRestrequestAndHandleResponse exception:" + e.getMessage());
82 updateProgress(null, null, "90", "sendRestrequestAndHandleResponse finished!");
83 saveOutput(networkRpcOutputEntiy);
84 updateProgress(RequestsDbConstant.Status.FINISHED, null, RequestsDbConstant.Progress.ONE_HUNDRED, "execute finished!");
88 private GenericResourceApi getGenericResourceApiClient(String msbIp, int msbPort) {
89 if (StringUtils.isBlank(msbIp)) {
90 msbIp = DEFAULT_MSB_IP;
93 msbPort = DEFAULT_MSB_Port;
95 MSBServiceClient msbClient = new MSBServiceClient(msbIp, msbPort);
96 RestServiceCreater restServiceCreater = new RestServiceCreater(msbClient);
97 return restServiceCreater.createService(GenericResourceApi.class);
100 public void updateProgress(String status,
103 String statusDescription) {
104 ResourceOperationStatus resourceOperationStatus = requestsDB.getResourceOperationStatus(serviceId, operationId, resourceTemplateUUID);
105 if (!StringUtils.isBlank(status)) {
106 resourceOperationStatus.setStatus(status);
108 if (!StringUtils.isBlank(errorCode)) {
109 resourceOperationStatus.setErrorCode(errorCode);
111 if (!StringUtils.isBlank(progress)) {
112 resourceOperationStatus.setProgress(progress);
114 if (!StringUtils.isBlank(statusDescription)) {
115 resourceOperationStatus.setStatusDescription(statusDescription);
117 requestsDB.updateResOperStatus(resourceOperationStatus);
120 private void saveOutput(RpcNetworkTopologyOperationOutputEntity output) {