1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
package org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask;
import org.apache.commons.lang3.StringUtils;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.onap.msb.sdk.httpclient.RestServiceCreater;
import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.GenericResourceApi;
import org.openecomp.mso.bpmn.core.BaseTask;
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoLogger;
import org.openecomp.mso.requestsdb.RequestsDatabase;
import org.openecomp.mso.requestsdb.RequestsDbConstant;
import org.openecomp.mso.requestsdb.ResourceOperationStatus;
import java.util.Map;
/**
* Created by 10112215 on 2017/9/16.
*/
public abstract class AbstractSdncVlOperationTask extends BaseTask {
private static final String DEFAULT_MSB_IP = "127.0.0.1";
private static final int DEFAULT_MSB_Port = 10081;
private static final String SDCADAPTOR_INPUTS = "SDCADAPTOR_INPUTS";
private RequestsDatabase requestsDB = RequestsDatabase.getInstance();
private static MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL);
@Override
public void execute(DelegateExecution execution) {
GenericResourceApi genericResourceApiClient = getGenericResourceApiClient(execution);
updateProgress(execution, RequestsDbConstant.Status.PROCESSING, null, "10", "execute begin!");
Map<String, String> inputs = (Map<String, String>) execution.getVariable(SDCADAPTOR_INPUTS);
updateProgress(execution, null, null, "30", "getGenericResourceApiClient finished!");
try {
sendRestrequestAndHandleResponse(execution, inputs, genericResourceApiClient);
execution.setVariable("SDNCA_SuccessIndicator", true);
updateProgress(execution, RequestsDbConstant.Status.FINISHED, null, RequestsDbConstant.Progress.ONE_HUNDRED, "execute finished!");
} catch (Exception e) {
e.printStackTrace();
execution.setVariable("SDNCA_SuccessIndicator", false);
}
}
public abstract void sendRestrequestAndHandleResponse(DelegateExecution execution,
Map<String, String> inputs,
GenericResourceApi genericResourceApiClient) throws Exception;
public void updateProgress(DelegateExecution execution,
String status,
String errorCode,
String progress,
String statusDescription) {
String serviceId = (String) execution.getVariable("serviceId");
String operationId = (String) execution.getVariable("operationId");
String resourceTemplateUUID = (String) execution.getVariable("resourceTemplateUUID");
ResourceOperationStatus resourceOperationStatus = requestsDB.getResourceOperationStatus(serviceId, operationId, resourceTemplateUUID);
if (!StringUtils.isBlank(status)) {
resourceOperationStatus.setStatus(status);
}
if (!StringUtils.isBlank(errorCode)) {
resourceOperationStatus.setErrorCode(errorCode);
}
if (!StringUtils.isBlank(progress)) {
resourceOperationStatus.setProgress(progress);
}
if (!StringUtils.isBlank(statusDescription)) {
resourceOperationStatus.setStatusDescription(statusDescription);
}
requestsDB.updateResOperStatus(resourceOperationStatus);
}
private GenericResourceApi getGenericResourceApiClient(DelegateExecution execution) {
updateProgress(execution, null, null, "20", "getGenericResourceApiClient begin!");
String msbIp = getString(execution, "MSB_IP", DEFAULT_MSB_IP);
int msbPort = getInteger(execution, "MSB_Port", DEFAULT_MSB_Port);
MSBServiceClient msbClient = new MSBServiceClient(msbIp, msbPort);
RestServiceCreater restServiceCreater = new RestServiceCreater(msbClient);
return restServiceCreater.createService(GenericResourceApi.class);
}
private String getString(DelegateExecution execution, String name, String defaultValue) {
String vlaue = (String) execution.getVariable(name);
try {
if (!StringUtils.isBlank(vlaue)) {
return vlaue;
}
} catch (Exception e) {
System.out.println(e);
logger.error(MessageEnum.GENERAL_EXCEPTION, " getMsbIp catch exception: ", "", this.getTaskName(), MsoLogger.ErrorCode.UnknownError, e.getClass().toString());
}
return defaultValue;
}
private Integer getInteger(DelegateExecution execution, String name, Integer defaultValue) {
Integer vlaue = (Integer) execution.getVariable(name);
try {
if (vlaue != null) {
return vlaue;
}
} catch (Exception e) {
System.out.println(e);
logger.error(MessageEnum.GENERAL_EXCEPTION, " getMsbIp catch exception: ", "", this.getTaskName(), MsoLogger.ErrorCode.UnknownError, e.getClass().toString());
}
return defaultValue;
}
public String getProcessKey(DelegateExecution execution) {
return execution.getProcessEngineServices().getRepositoryService().getProcessDefinition(execution.getProcessDefinitionId()).getKey();
}
}
|