1 package org.openecomp.mso.client.appc;
3 import java.beans.BeanInfo;
7 import org.openecomp.mso.bpmn.core.PropertyConfiguration;
9 import java.beans.IntrospectionException;
10 import java.beans.Introspector;
11 import java.beans.PropertyDescriptor;
12 import java.lang.reflect.InvocationTargetException;
13 import java.lang.reflect.Method;
14 import java.time.Instant;
15 import java.util.Properties;
16 import java.util.UUID;
18 import org.springframework.beans.factory.annotation.Autowired;
20 import org.openecomp.appc.client.lcm.api.AppcClientServiceFactoryProvider;
21 import org.openecomp.appc.client.lcm.api.AppcLifeCycleManagerServiceFactory;
22 import org.openecomp.appc.client.lcm.api.ApplicationContext;
23 import org.openecomp.appc.client.lcm.api.LifeCycleManagerStateful;
24 import org.openecomp.appc.client.lcm.api.ResponseHandler;
25 import org.openecomp.appc.client.lcm.exceptions.AppcClientException;
26 import org.openecomp.appc.client.lcm.model.Action;
27 import org.openecomp.appc.client.lcm.model.ActionIdentifiers;
28 import org.openecomp.appc.client.lcm.model.AuditOutput;
29 import org.openecomp.appc.client.lcm.model.CommonHeader;
30 import org.openecomp.appc.client.lcm.model.Flags;
31 import org.openecomp.appc.client.lcm.model.Flags.Force;
32 import org.openecomp.appc.client.lcm.model.Flags.Mode;
33 import org.openecomp.appc.client.lcm.model.Payload;
34 import org.openecomp.appc.client.lcm.model.Status;
35 import org.openecomp.appc.client.lcm.model.ZULU;
36 import com.fasterxml.jackson.annotation.JsonInclude.Include;
37 import com.fasterxml.jackson.core.JsonProcessingException;
38 import com.fasterxml.jackson.databind.ObjectMapper;
39 import com.fasterxml.jackson.databind.ObjectWriter;
40 import org.openecomp.mso.logger.MsoLogger;
42 public class ApplicationControllerClient {
44 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
46 private static final int ACCEPT_SERIES = 100;
47 private static final int ERROR_SERIES = 200;
48 private static final int REJECT_SERIES = 300;
49 private static final int SUCCESS_SERIES = 400;
50 private static final int SUCCESS_STATUS = SUCCESS_SERIES + 0;
51 private static final int PARTIAL_SERIES = 500;
52 private static final int PARTIAL_SUCCESS_STATUS = PARTIAL_SERIES + 0;
54 private final boolean useLCMBypass = false;
56 private final String apiVer = "2.00";
57 private final String originatorId = "MSO";
58 private final int flagsTTL = 65000;
59 private final static String clientName = "MSO";
62 public ApplicationControllerSupport appCSupport;
64 private LifeCycleManagerStateful client;
66 public Status runCommand(Action action, ActionIdentifiers identifier, Flags flags, Payload payload,
67 String requestID) throws Exception {
68 Object requestObject = createRequest(action, identifier, flags, payload, requestID);
69 client = getAppCClient();
70 Method lcmMethod = appCSupport.getAPIMethod(action.name(), client, false);
71 appCSupport.logLCMMessage(requestObject);
72 Object response = lcmMethod.invoke(client, requestObject);
73 return appCSupport.getStatusFromGenericResponse(response);
76 public void shutdownclient() {
77 AppcClientServiceFactoryProvider.getFactory(AppcLifeCycleManagerServiceFactory.class)
78 .shutdownLifeCycleManager(false);
81 public LifeCycleManagerStateful getAppCClient() throws AppcClientException {
83 client = AppcClientServiceFactoryProvider.getFactory(AppcLifeCycleManagerServiceFactory.class)
84 .createLifeCycleManagerStateful(new ApplicationContext(), getLCMProperties());
88 private Properties getLCMProperties() {
89 return getLCMPropertiesHelper();
92 protected Properties getLCMPropertiesHelper() {
93 Properties properties = new Properties();
94 Map<String, String> globalProperties = PropertyConfiguration.getInstance()
95 .getProperties("mso.bpmn.urn.properties");
97 properties.put("topic.read", globalProperties.get("appc.topic.read"));
98 properties.put("topic.read.timeout", globalProperties.get("appc.topic.read.timeout"));
99 properties.put("client.response.timeout", globalProperties.get("appc.client.response.timeout"));
100 properties.put("topic.write", globalProperties.get("appc.topic.write"));
101 properties.put("poolMembers", globalProperties.get("appc.pool.members"));
102 properties.put("client.key", globalProperties.get("appc.client.key"));
103 properties.put("client.secret", globalProperties.get("appc.client.secret"));
104 properties.put("client.name", clientName);
108 public Object createRequest(Action action, ActionIdentifiers identifier, Flags flags, Payload payload,
109 String requestId) throws Exception {
110 Object requestObject = appCSupport.getInput(action.name());
112 org.openecomp.appc.client.lcm.model.CommonHeader commonHeader = buildCommonHeader(requestId);
113 requestObject.getClass().getDeclaredMethod("setCommonHeader", CommonHeader.class).invoke(requestObject,
115 requestObject.getClass().getDeclaredMethod("setAction", Action.class).invoke(requestObject, action);
116 requestObject.getClass().getDeclaredMethod("setActionIdentifiers", ActionIdentifiers.class)
117 .invoke(requestObject, identifier);
118 } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
119 LOGGER.debug("Exception:", e);
120 throw new Exception("Error Building AppC Request: " + e.getMessage());
122 return requestObject;
125 private org.openecomp.appc.client.lcm.model.CommonHeader buildCommonHeader(String requestId) {
126 org.openecomp.appc.client.lcm.model.CommonHeader commonHeader = new org.openecomp.appc.client.lcm.model.CommonHeader();
127 commonHeader.setApiVer(apiVer);
128 commonHeader.setOriginatorId(originatorId);
129 commonHeader.setRequestId(requestId == null ? UUID.randomUUID().toString() : requestId);
130 commonHeader.setSubRequestId(requestId);
131 org.openecomp.appc.client.lcm.model.Flags flags = new org.openecomp.appc.client.lcm.model.Flags();
132 String flagsMode = "NORMAL";
133 Mode mode = Mode.valueOf(flagsMode);
135 String flagsForce = "FALSE";
136 Force force = Force.valueOf(flagsForce);
137 flags.setForce(force);
138 flags.setTtl(flagsTTL);
139 commonHeader.setFlags(flags);
140 Instant timestamp = Instant.now();
141 ZULU zulu = new ZULU(timestamp.toString());
142 commonHeader.setTimestamp(zulu);
146 public Flags createRequestFlags() {
147 Flags flags = new Flags();