From 38f720752af4d4aad8c4e467a288d9048659f688 Mon Sep 17 00:00:00 2001 From: Rob Daugherty Date: Wed, 14 Mar 2018 02:07:32 -0400 Subject: AT&T 1712 and 1802 release code This is code from AT&T's 1712 and 1802 releases. Change-Id: Ie1e85851e94bc66c4d9514a0226c221939531a04 Issue-ID: SO-425 Signed-off-by: Rob Daugherty --- .../client/appc/ApplicationControllerClient.java | 133 ++++++++++----------- 1 file changed, 63 insertions(+), 70 deletions(-) (limited to 'bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerClient.java') diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerClient.java index f66034f5e9..c383408488 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerClient.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerClient.java @@ -20,88 +20,79 @@ package org.openecomp.mso.client.appc; -import java.beans.BeanInfo; - -import java.util.Map; - -import org.openecomp.mso.bpmn.core.PropertyConfiguration; - -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.time.Instant; +import java.util.Map; import java.util.Properties; import java.util.UUID; +import org.openecomp.mso.bpmn.core.PropertyConfiguration; import org.springframework.beans.factory.annotation.Autowired; -import org.openecomp.appc.client.lcm.api.AppcClientServiceFactoryProvider; -import org.openecomp.appc.client.lcm.api.AppcLifeCycleManagerServiceFactory; -import org.openecomp.appc.client.lcm.api.ApplicationContext; -import org.openecomp.appc.client.lcm.api.LifeCycleManagerStateful; -import org.openecomp.appc.client.lcm.api.ResponseHandler; -import org.openecomp.appc.client.lcm.exceptions.AppcClientException; -import org.openecomp.appc.client.lcm.model.Action; -import org.openecomp.appc.client.lcm.model.ActionIdentifiers; -import org.openecomp.appc.client.lcm.model.AuditOutput; -import org.openecomp.appc.client.lcm.model.CommonHeader; -import org.openecomp.appc.client.lcm.model.Flags; -import org.openecomp.appc.client.lcm.model.Flags.Force; -import org.openecomp.appc.client.lcm.model.Flags.Mode; -import org.openecomp.appc.client.lcm.model.Payload; -import org.openecomp.appc.client.lcm.model.Status; -import org.openecomp.appc.client.lcm.model.ZULU; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectWriter; -import org.openecomp.mso.logger.MsoLogger; +import org.onap.appc.client.lcm.api.AppcClientServiceFactoryProvider; +import org.onap.appc.client.lcm.api.AppcLifeCycleManagerServiceFactory; +import org.onap.appc.client.lcm.api.ApplicationContext; +import org.onap.appc.client.lcm.api.LifeCycleManagerStateful; +import org.onap.appc.client.lcm.exceptions.AppcClientException; +import org.onap.appc.client.lcm.model.Action; +import org.onap.appc.client.lcm.model.ActionIdentifiers; +import org.onap.appc.client.lcm.model.CommonHeader; +import org.onap.appc.client.lcm.model.Flags; +import org.onap.appc.client.lcm.model.Flags.Force; +import org.onap.appc.client.lcm.model.Flags.Mode; +import org.onap.appc.client.lcm.model.Payload; +import org.onap.appc.client.lcm.model.Status; +import org.onap.appc.client.lcm.model.ZULU; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFLogger.Level; +import com.att.eelf.configuration.EELFManager; public class ApplicationControllerClient { - private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); - - private static final int PARTIAL_SERIES = 500; + private static final String CLIENT_NAME = "MSO"; - private final String apiVer = "2.00"; - private final String originatorId = "MSO"; - private final int flagsTTL = 65000; - private final static String clientName = "MSO"; + private static final String API_VER = "2.00"; + private static final String ORIGINATOR_ID = "MSO"; + private static final int FLAGS_TTL = 65000; + protected final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); @Autowired public ApplicationControllerSupport appCSupport; - private LifeCycleManagerStateful client; + private static LifeCycleManagerStateful client; - public Status runCommand(Action action, ActionIdentifiers identifier, Flags flags, Payload payload, - String requestID) throws IllegalAccessException,NoSuchMethodException,AppcClientException,JsonProcessingException,InvocationTargetException { - Object requestObject = createRequest(action, identifier, flags, payload, requestID); - client = getAppCClient(); - Method lcmMethod = appCSupport.getAPIMethod(action.name(), client, false); - appCSupport.logLCMMessage(requestObject); - Object response = lcmMethod.invoke(client, requestObject); - return appCSupport.getStatusFromGenericResponse(response); + public ApplicationControllerClient() { + appCSupport = new ApplicationControllerSupport(); + client = this.getAppCClient(); } - public void shutdownclient() { - AppcClientServiceFactoryProvider.getFactory(AppcLifeCycleManagerServiceFactory.class) - .shutdownLifeCycleManager(false); + public Status runCommand(Action action, org.onap.appc.client.lcm.model.ActionIdentifiers actionIdentifiers, org.onap.appc.client.lcm.model.Payload payload, String requestID) + throws ApplicationControllerOrchestratorException { + Object requestObject; + requestObject = createRequest(action, actionIdentifiers, payload, requestID); + appCSupport.logLCMMessage(requestObject); + Method lcmMethod = appCSupport.getAPIMethod(action.name(), client, false); + try { + Object response = lcmMethod.invoke(client, requestObject); + return appCSupport.getStatusFromGenericResponse(response); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + throw new RuntimeException(String.format("%s : %s", "Unable to invoke action", action.toString()), e); + } } - public LifeCycleManagerStateful getAppCClient() throws AppcClientException { + public LifeCycleManagerStateful getAppCClient() { if (client == null) - client = AppcClientServiceFactoryProvider.getFactory(AppcLifeCycleManagerServiceFactory.class) - .createLifeCycleManagerStateful(new ApplicationContext(), getLCMProperties()); + try { + client = AppcClientServiceFactoryProvider.getFactory(AppcLifeCycleManagerServiceFactory.class) + .createLifeCycleManagerStateful(new ApplicationContext(), getLCMProperties()); + } catch (AppcClientException e) { + auditLogger.log(Level.ERROR, "Error in getting LifeCycleManagerStateful: ", e, e.getMessage()); + } return client; } - private Properties getLCMProperties() { - return getLCMPropertiesHelper(); - } - - protected Properties getLCMPropertiesHelper() { + protected Properties getLCMProperties() { Properties properties = new Properties(); Map globalProperties = PropertyConfiguration.getInstance() .getProperties("mso.bpmn.urn.properties"); @@ -110,44 +101,46 @@ public class ApplicationControllerClient { properties.put("topic.read.timeout", globalProperties.get("appc.topic.read.timeout")); properties.put("client.response.timeout", globalProperties.get("appc.client.response.timeout")); properties.put("topic.write", globalProperties.get("appc.topic.write")); - properties.put("poolMembers", globalProperties.get("appc.pool.members")); + properties.put("poolMembers", globalProperties.get("appc.poolMembers")); properties.put("client.key", globalProperties.get("appc.client.key")); properties.put("client.secret", globalProperties.get("appc.client.secret")); - properties.put("client.name", clientName); + properties.put("client.name", CLIENT_NAME); + properties.put("service", globalProperties.get("appc.service")); return properties; } - public Object createRequest(Action action, ActionIdentifiers identifier, Flags flags, Payload payload, - String requestId) throws IllegalAccessException,NoSuchMethodException,InvocationTargetException { + public Object createRequest(Action action, ActionIdentifiers identifier, Payload payload, String requestId) { Object requestObject = appCSupport.getInput(action.name()); try { - org.openecomp.appc.client.lcm.model.CommonHeader commonHeader = buildCommonHeader(requestId); + CommonHeader commonHeader = buildCommonHeader(requestId); requestObject.getClass().getDeclaredMethod("setCommonHeader", CommonHeader.class).invoke(requestObject, commonHeader); requestObject.getClass().getDeclaredMethod("setAction", Action.class).invoke(requestObject, action); requestObject.getClass().getDeclaredMethod("setActionIdentifiers", ActionIdentifiers.class) .invoke(requestObject, identifier); + if (payload != null) { + requestObject.getClass().getDeclaredMethod("setPayload", Payload.class).invoke(requestObject, payload); + } } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - LOGGER.debug("Exception:", e); - throw new IllegalAccessException("Error Building AppC Request: " + e.getMessage()); + auditLogger.log(Level.ERROR, "Error building Appc request: ", e, e.getMessage()); } return requestObject; } - private org.openecomp.appc.client.lcm.model.CommonHeader buildCommonHeader(String requestId) { - org.openecomp.appc.client.lcm.model.CommonHeader commonHeader = new org.openecomp.appc.client.lcm.model.CommonHeader(); - commonHeader.setApiVer(apiVer); - commonHeader.setOriginatorId(originatorId); + private CommonHeader buildCommonHeader(String requestId) { + CommonHeader commonHeader = new CommonHeader(); + commonHeader.setApiVer(API_VER); + commonHeader.setOriginatorId(ORIGINATOR_ID); commonHeader.setRequestId(requestId == null ? UUID.randomUUID().toString() : requestId); commonHeader.setSubRequestId(requestId); - org.openecomp.appc.client.lcm.model.Flags flags = new org.openecomp.appc.client.lcm.model.Flags(); + Flags flags = new Flags(); String flagsMode = "NORMAL"; Mode mode = Mode.valueOf(flagsMode); flags.setMode(mode); String flagsForce = "FALSE"; Force force = Force.valueOf(flagsForce); flags.setForce(force); - flags.setTtl(flagsTTL); + flags.setTtl(FLAGS_TTL); commonHeader.setFlags(flags); Instant timestamp = Instant.now(); ZULU zulu = new ZULU(timestamp.toString()); -- cgit 1.2.3-korg