2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.workflow.serviceTask;
26 import org.apache.commons.lang3.StringUtils;
27 import org.onap.msb.sdk.httpclient.RestServiceCreater;
28 import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
29 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.GenericResourceApi;
30 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.HeaderUtil;
31 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.NetworkRpcInputEntityBuilder;
32 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.entity.RpcNetworkTopologyOperationInputEntity;
33 import org.onap.so.db.request.beans.ResourceOperationStatus;
34 import org.onap.so.db.request.beans.ResourceOperationStatusId;
35 import org.onap.so.requestsdb.RequestsDbConstant;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.stereotype.Component;
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;
46 private static Logger logger = LoggerFactory.getLogger(SdncUnderlayVpnOperationClient.class);
48 public boolean excute(String msbIp, int msbPort, Map<String, String> inputs, String iServiceID, String iOperationID,
49 String resourceTemplateUUID_i) {
50 ResourceOperationStatusId id = new ResourceOperationStatusId(iServiceID, iOperationID, resourceTemplateUUID_i);
51 GenericResourceApi genericResourceApiClient = getGenericResourceApiClient(msbIp, msbPort);
52 updateProgress(id, RequestsDbConstant.Status.PROCESSING, null, "10", "execute begin!");
53 return sendRestrequestAndHandleResponse(id, inputs, genericResourceApiClient);
56 public boolean sendRestrequestAndHandleResponse(ResourceOperationStatusId id, Map<String, String> inputs,
57 GenericResourceApi genericResourceApiClient) {
58 updateProgress(id, null, null, "40", "sendRestrequestAndHandleResponse begin!");
59 NetworkRpcInputEntityBuilder builder = new NetworkRpcInputEntityBuilder();
60 RpcNetworkTopologyOperationInputEntity body = builder.build(null, inputs);
61 updateProgress(id, null, null, "50", "RequestBody build finished!");
62 // RpcNetworkTopologyOperationOutputEntity networkRpcOutputEntiy = null;
64 genericResourceApiClient.postNetworkTopologyOperation(HeaderUtil.DefaulAuth, body).execute().body();
65 } catch (Exception e) {
66 logger.debug("Exception: ", e);
67 updateProgress(id, RequestsDbConstant.Status.ERROR, null, null,
68 "sendRestrequestAndHandleResponse exception:" + e.getMessage());
71 updateProgress(id, null, null, "90", "sendRestrequestAndHandleResponse finished!");
72 updateProgress(id, RequestsDbConstant.Status.FINISHED, null, RequestsDbConstant.Progress.ONE_HUNDRED,
77 private GenericResourceApi getGenericResourceApiClient(String msbIp, int msbPort) {
78 if (StringUtils.isBlank(msbIp)) {
79 msbIp = DEFAULT_MSB_IP;
82 msbPort = DEFAULT_MSB_PORT;
84 MSBServiceClient msbClient = new MSBServiceClient(msbIp, msbPort);
85 RestServiceCreater restServiceCreater = new RestServiceCreater(msbClient);
86 return restServiceCreater.createService(GenericResourceApi.class);
89 public void updateProgress(ResourceOperationStatusId id, String status, String errorCode, String progress,
90 String statusDescription) {
93 ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus();// rosRepo.getOne(id);
94 if (!StringUtils.isBlank(status)) {
95 resourceOperationStatus.setStatus(status);
97 if (!StringUtils.isBlank(errorCode)) {
98 resourceOperationStatus.setErrorCode(errorCode);
100 if (!StringUtils.isBlank(progress)) {
101 resourceOperationStatus.setProgress(progress);
103 if (!StringUtils.isBlank(statusDescription)) {
104 resourceOperationStatus.setStatusDescription(statusDescription);
106 // rosRepo.save(resourceOperationStatus);
109 private void saveOutput() {