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.builder.NetworkRpcInputEntityBuilder;
28 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.RpcNetworkTopologyOperationInputEntity;
29 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.RpcNetworkTopologyOperationOutputEntity;
30 import org.openecomp.mso.logger.MsoLogger;
31 import org.openecomp.mso.requestsdb.RequestsDatabase;
32 import org.openecomp.mso.requestsdb.RequestsDbConstant;
33 import org.openecomp.mso.requestsdb.ResourceOperationStatus;
38 * Created by 10112215 on 2017/9/21.
40 public class SdncUnderlayVpnOperationClient {
42 private static final String DEFAULT_MSB_IP = "127.0.0.1";
43 private static final int DEFAULT_MSB_Port = 10081;
44 private RequestsDatabase requestsDB = RequestsDatabase.getInstance();
46 private String serviceId;
47 private String operationId;
48 private String resourceTemplateUUID;
51 private static MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL);
53 public boolean excute(String msbIp,
55 Map<String, String> inputs,
58 String resourceTemplateUUID_i){
59 serviceId = serviceId_i;
60 operationId = operationId_i;
61 resourceTemplateUUID = resourceTemplateUUID_i;
62 GenericResourceApi genericResourceApiClient = getGenericResourceApiClient(msbIp, msbPort);
63 updateProgress(RequestsDbConstant.Status.PROCESSING, null, "10", "execute begin!");
64 return sendRestrequestAndHandleResponse(inputs, genericResourceApiClient);
67 public boolean sendRestrequestAndHandleResponse(Map<String, String> inputs, GenericResourceApi genericResourceApiClient){
68 updateProgress(null, null, "40", "sendRestrequestAndHandleResponse begin!");
69 NetworkRpcInputEntityBuilder builder = new NetworkRpcInputEntityBuilder();
70 RpcNetworkTopologyOperationInputEntity body = builder.build(null, inputs);
71 updateProgress(null, null, "50", "RequestBody build finished!");
72 RpcNetworkTopologyOperationOutputEntity networkRpcOutputEntiy = null;
74 networkRpcOutputEntiy = genericResourceApiClient.postNetworkTopologyOperation(body).execute().body();
75 } catch (Exception e) {
76 logger.debug("Exception: ", e);
77 updateProgress(RequestsDbConstant.Status.ERROR, null, null, "sendRestrequestAndHandleResponse exception:" + e.getMessage());
80 updateProgress(null, null, "90", "sendRestrequestAndHandleResponse finished!");
81 saveOutput(networkRpcOutputEntiy);
82 updateProgress(RequestsDbConstant.Status.FINISHED, null, RequestsDbConstant.Progress.ONE_HUNDRED, "execute finished!");
86 private GenericResourceApi getGenericResourceApiClient(String msbIp, int msbPort) {
87 if (StringUtils.isBlank(msbIp)) {
88 msbIp = DEFAULT_MSB_IP;
91 msbPort = DEFAULT_MSB_Port;
93 MSBServiceClient msbClient = new MSBServiceClient(msbIp, msbPort);
94 RestServiceCreater restServiceCreater = new RestServiceCreater(msbClient);
95 return restServiceCreater.createService(GenericResourceApi.class);
98 public void updateProgress(String status,
101 String statusDescription) {
102 ResourceOperationStatus resourceOperationStatus = requestsDB.getResourceOperationStatus(serviceId, operationId, resourceTemplateUUID);
103 if (!StringUtils.isBlank(status)) {
104 resourceOperationStatus.setStatus(status);
106 if (!StringUtils.isBlank(errorCode)) {
107 resourceOperationStatus.setErrorCode(errorCode);
109 if (!StringUtils.isBlank(progress)) {
110 resourceOperationStatus.setProgress(progress);
112 if (!StringUtils.isBlank(statusDescription)) {
113 resourceOperationStatus.setStatusDescription(statusDescription);
115 requestsDB.updateResOperStatus(resourceOperationStatus);
118 private void saveOutput(RpcNetworkTopologyOperationOutputEntity output) {