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.bpmn.infrastructure.workflow.serviceTask.client.entity.RpcNetworkTopologyOperationOutputEntity;
33 import org.onap.so.db.request.beans.ResourceOperationStatus;
34 import org.onap.so.db.request.beans.ResourceOperationStatusId;
35 import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository;
36 import org.onap.so.logger.MsoLogger;
37 import org.onap.so.requestsdb.RequestsDbConstant;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.stereotype.Component;
42 public class SdncUnderlayVpnOperationClient {
44 private static final String DEFAULT_MSB_IP = "127.0.0.1";
45 private static final int DEFAULT_MSB_PORT = 10081;
47 private static MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, SdncUnderlayVpnOperationClient.class);
49 public boolean excute(String msbIp,
51 Map<String, String> inputs,
54 String resourceTemplateUUID_i){
55 ResourceOperationStatusId id = new ResourceOperationStatusId(iServiceID, iOperationID, resourceTemplateUUID_i);
56 GenericResourceApi genericResourceApiClient = getGenericResourceApiClient(msbIp, msbPort);
57 updateProgress(id, RequestsDbConstant.Status.PROCESSING, null, "10", "execute begin!");
58 return sendRestrequestAndHandleResponse(id, inputs, genericResourceApiClient);
61 public boolean sendRestrequestAndHandleResponse(ResourceOperationStatusId id, Map<String, String> inputs, GenericResourceApi genericResourceApiClient){
62 updateProgress(id, null, null, "40", "sendRestrequestAndHandleResponse begin!");
63 NetworkRpcInputEntityBuilder builder = new NetworkRpcInputEntityBuilder();
64 RpcNetworkTopologyOperationInputEntity body = builder.build(null, inputs);
65 updateProgress(id, null, null, "50", "RequestBody build finished!");
66 //RpcNetworkTopologyOperationOutputEntity networkRpcOutputEntiy = null;
68 genericResourceApiClient.postNetworkTopologyOperation(HeaderUtil.DefaulAuth ,body).execute().body();
69 } catch (Exception e) {
70 logger.debug("Exception: ", e);
71 updateProgress(id, RequestsDbConstant.Status.ERROR, null, null, "sendRestrequestAndHandleResponse exception:" + e.getMessage());
74 updateProgress(id, null, null, "90", "sendRestrequestAndHandleResponse finished!");
75 updateProgress(id, RequestsDbConstant.Status.FINISHED, null, RequestsDbConstant.Progress.ONE_HUNDRED, "execute finished!");
79 private GenericResourceApi getGenericResourceApiClient(String msbIp, int msbPort) {
80 if (StringUtils.isBlank(msbIp)) {
81 msbIp = DEFAULT_MSB_IP;
84 msbPort = DEFAULT_MSB_PORT;
86 MSBServiceClient msbClient = new MSBServiceClient(msbIp, msbPort);
87 RestServiceCreater restServiceCreater = new RestServiceCreater(msbClient);
88 return restServiceCreater.createService(GenericResourceApi.class);
91 public void updateProgress(ResourceOperationStatusId id, String status,
94 String statusDescription) {
97 ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus();//rosRepo.getOne(id);
98 if (!StringUtils.isBlank(status)) {
99 resourceOperationStatus.setStatus(status);
101 if (!StringUtils.isBlank(errorCode)) {
102 resourceOperationStatus.setErrorCode(errorCode);
104 if (!StringUtils.isBlank(progress)) {
105 resourceOperationStatus.setProgress(progress);
107 if (!StringUtils.isBlank(statusDescription)) {
108 resourceOperationStatus.setStatusDescription(statusDescription);
110 //rosRepo.save(resourceOperationStatus);
113 private void saveOutput() {