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.onap.so.bpmn.infrastructure.workflow.serviceTask;
25 import org.apache.commons.lang3.StringUtils;
26 import org.onap.msb.sdk.httpclient.RestServiceCreater;
27 import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
28 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.GenericResourceApi;
29 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.HeaderUtil;
30 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.NetworkRpcInputEntityBuilder;
31 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.entity.RpcNetworkTopologyOperationInputEntity;
32 import org.onap.so.db.request.beans.ResourceOperationStatus;
33 import org.onap.so.db.request.beans.ResourceOperationStatusId;
34 import org.onap.so.logger.MsoLogger;
35 import org.onap.so.requestsdb.RequestsDbConstant;
36 import org.springframework.stereotype.Component;
39 public class SdncUnderlayVpnOperationClient {
41 private static final String DEFAULT_MSB_IP = "127.0.0.1";
42 private static final int DEFAULT_MSB_PORT = 10081;
44 private static MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, SdncUnderlayVpnOperationClient.class);
46 public boolean excute(String msbIp,
48 Map<String, String> inputs,
51 String resourceTemplateUUID_i){
52 ResourceOperationStatusId id = new ResourceOperationStatusId(iServiceID, iOperationID, resourceTemplateUUID_i);
53 GenericResourceApi genericResourceApiClient = getGenericResourceApiClient(msbIp, msbPort);
54 updateProgress(id, RequestsDbConstant.Status.PROCESSING, null, "10", "execute begin!");
55 return sendRestrequestAndHandleResponse(id, inputs, genericResourceApiClient);
58 public boolean sendRestrequestAndHandleResponse(ResourceOperationStatusId id, Map<String, String> inputs, GenericResourceApi genericResourceApiClient){
59 updateProgress(id, null, null, "40", "sendRestrequestAndHandleResponse begin!");
60 NetworkRpcInputEntityBuilder builder = new NetworkRpcInputEntityBuilder();
61 RpcNetworkTopologyOperationInputEntity body = builder.build(null, inputs);
62 updateProgress(id, null, null, "50", "RequestBody build finished!");
63 //RpcNetworkTopologyOperationOutputEntity networkRpcOutputEntiy = null;
65 genericResourceApiClient.postNetworkTopologyOperation(HeaderUtil.DefaulAuth ,body).execute().body();
66 } catch (Exception e) {
67 logger.debug("Exception: ", e);
68 updateProgress(id, RequestsDbConstant.Status.ERROR, null, null, "sendRestrequestAndHandleResponse exception:" + e.getMessage());
71 updateProgress(id, null, null, "90", "sendRestrequestAndHandleResponse finished!");
72 updateProgress(id, RequestsDbConstant.Status.FINISHED, null, RequestsDbConstant.Progress.ONE_HUNDRED, "execute finished!");
76 private GenericResourceApi getGenericResourceApiClient(String msbIp, int msbPort) {
77 if (StringUtils.isBlank(msbIp)) {
78 msbIp = DEFAULT_MSB_IP;
81 msbPort = DEFAULT_MSB_PORT;
83 MSBServiceClient msbClient = new MSBServiceClient(msbIp, msbPort);
84 RestServiceCreater restServiceCreater = new RestServiceCreater(msbClient);
85 return restServiceCreater.createService(GenericResourceApi.class);
88 public void updateProgress(ResourceOperationStatusId id, String status,
91 String statusDescription) {
94 ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus();//rosRepo.getOne(id);
95 if (!StringUtils.isBlank(status)) {
96 resourceOperationStatus.setStatus(status);
98 if (!StringUtils.isBlank(errorCode)) {
99 resourceOperationStatus.setErrorCode(errorCode);
101 if (!StringUtils.isBlank(progress)) {
102 resourceOperationStatus.setProgress(progress);
104 if (!StringUtils.isBlank(statusDescription)) {
105 resourceOperationStatus.setStatusDescription(statusDescription);
107 //rosRepo.save(resourceOperationStatus);
110 private void saveOutput() {