diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc')
6 files changed, 365 insertions, 138 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerAction.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerAction.java new file mode 100644 index 0000000000..8b870889ac --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerAction.java @@ -0,0 +1,178 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.appc;
+
+import java.util.HashMap;
+import java.util.List;
+
+import org.openecomp.mso.client.appc.ApplicationControllerSupport.StatusCategory;
+import org.openecomp.mso.bpmn.appc.payload.PayloadClient;
+import org.openecomp.mso.bpmn.core.json.JsonUtils;
+import org.openecomp.mso.client.appc.ApplicationControllerOrchestrator;
+import java.util.Optional;
+import org.onap.appc.client.lcm.model.Action;
+import org.onap.appc.client.lcm.model.Status;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.configuration.EELFLogger.Level;
+import java.lang.NoSuchMethodError;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+
+public class ApplicationControllerAction {
+ protected ApplicationControllerOrchestrator client = new ApplicationControllerOrchestrator();
+ private String errorCode = "1002";
+ private String errorMessage = "Unable to reach App C Servers";
+ protected final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
+
+ public void runAppCCommand(Action action, String msoRequestId, String vnfId, Optional<String> payload, HashMap<String, String> payloadInfo){
+ Status appCStatus = null;
+ try{
+ String vnfName = payloadInfo.getOrDefault("vnfName", "");
+ String aicIdentity = payloadInfo.getOrDefault("vnfName","");
+ String vnfHostIpAddress = payloadInfo.getOrDefault("vnfHostIpAddress","");
+ String vmIdList = payloadInfo.getOrDefault("vmIdList", "");
+ String identityUrl = payloadInfo.getOrDefault("identityUrl", "");
+ switch(action){
+ case ResumeTraffic:
+ appCStatus = resumeTrafficAction(msoRequestId, vnfId, vnfName);
+ break;
+ case Start:
+ case Stop:
+ appCStatus = startStopAction(action, msoRequestId, vnfId, aicIdentity);
+ break;
+ case Unlock:
+ case Lock:
+ appCStatus = client.vnfCommand(action, msoRequestId, vnfId, Optional.empty());
+ break;
+ case QuiesceTraffic:
+ appCStatus = quiesceTrafficAction(msoRequestId, vnfId, payload, vnfName);
+ break;
+ case HealthCheck:
+ appCStatus = healthCheckAction(msoRequestId, vnfId, vnfName, vnfHostIpAddress);
+ break;
+ case Snapshot:
+ String vmIds = JsonUtils.getJsonValue(vmIdList, "vmIds");
+ String vmId = "";
+ ObjectMapper mapper = new ObjectMapper();
+ List<String> vmIdJsonList = mapper.readValue(vmIds, new TypeReference<List<String>>(){});
+ int i = 0;
+ while(i < vmIdJsonList.size()){
+ vmId = vmIdJsonList.get(i);
+ appCStatus = snapshotAction(msoRequestId, vnfId, vmId, identityUrl);
+ i++;
+ }
+ break;
+ case ConfigModify:
+ appCStatus = payloadAction(action, msoRequestId, vnfId, payload);
+ break;
+ case UpgradePreCheck:
+ case UpgradePostCheck:
+ case UpgradeSoftware:
+ case UpgradeBackup:
+ appCStatus = upgradeAction(action,msoRequestId, vnfId, payload, vnfName);
+ break;
+ default:
+ errorMessage = "Unable to idenify Action request for AppCClient";
+ break;
+ }
+ if(appCStatus != null){
+ errorCode = Integer.toString(appCStatus.getCode());
+ errorMessage = appCStatus.getMessage();
+
+ }
+ if(ApplicationControllerSupport.getCategoryOf(appCStatus).equals(StatusCategory.NORMAL)){
+ errorCode = "0";
+ }
+ }
+ catch(JsonProcessingException e){
+ auditLogger.log(Level.ERROR, "Incorrect Payload format for action request" + action.toString(),e, e.getMessage());
+ errorMessage = e.getMessage();
+ }
+ catch(ApplicationControllerOrchestratorException e){
+ auditLogger.log(Level.ERROR, "Error building Appc request: ", e, e.getMessage());
+ errorCode = "1002";
+ errorMessage = e.getMessage();
+ }
+ catch (NoSuchMethodError e) {
+ auditLogger.log(Level.ERROR, "Error building Appc request: ", e, e.getMessage());
+ errorMessage = e.getMessage();
+ }
+ catch(Exception e){
+ auditLogger.log(Level.ERROR, "Error building Appc request: ", e, e.getMessage());
+ errorMessage = e.getMessage();
+ }
+ }
+
+ private Status payloadAction(Action action, String msoRequestId, String vnfId, Optional<String> payload) throws JsonProcessingException, Exception{
+ if(!(payload.isPresent())){
+ throw new IllegalArgumentException("Payload is not present for " + action.toString());
+ }
+ return client.vnfCommand(action, msoRequestId, vnfId, payload);
+ }
+
+ private Status quiesceTrafficAction(String msoRequestId, String vnfId, Optional<String> payload, String vnfName) throws JsonProcessingException, Exception{
+ if(!(payload.isPresent())){
+ throw new IllegalArgumentException("Payload is not present for " + Action.QuiesceTraffic.toString());
+ }
+ payload = PayloadClient.quiesceTrafficFormat(payload, vnfName);
+ return client.vnfCommand(Action.QuiesceTraffic, msoRequestId, vnfId, payload);
+ }
+
+ private Status upgradeAction(Action action, String msoRequestId, String vnfId, Optional<String> payload, String vnfName) throws JsonProcessingException, Exception{
+ if(!(payload.isPresent())){
+ throw new IllegalArgumentException("Payload is not present for " + action.toString());
+ }
+ payload = PayloadClient.upgradeFormat(payload, vnfName);
+ return client.vnfCommand(action, msoRequestId, vnfId, payload);
+ }
+
+ private Status resumeTrafficAction(String msoRequestId, String vnfId, String vnfName)throws JsonProcessingException, Exception{
+ Optional<String> payload = PayloadClient.resumeTrafficFormat(vnfName);
+ return client.vnfCommand(Action.ResumeTraffic, msoRequestId, vnfId, payload);
+ }
+
+ private Status startStopAction(Action action, String msoRequestId, String vnfId, String aicIdentity)throws JsonProcessingException, Exception{
+ Optional<String> payload = PayloadClient.startStopFormat(aicIdentity);
+ return client.vnfCommand(action, msoRequestId, vnfId, payload);
+ }
+
+ private Status healthCheckAction(String msoRequestId, String vnfId, String vnfName, String vnfHostIpAddress)throws JsonProcessingException, Exception{
+ Optional<String> payload = PayloadClient.healthCheckFormat(vnfName, vnfHostIpAddress);
+ return client.vnfCommand(Action.HealthCheck, msoRequestId, vnfId, payload);
+ }
+
+ private Status snapshotAction(String msoRequestId, String vnfId, String vmId, String identityUrl) throws JsonProcessingException, Exception{
+ Optional<String> payload = PayloadClient.snapshotFormat(vmId, identityUrl);
+ return client.vnfCommand(Action.Snapshot, msoRequestId, vnfId, payload);
+ }
+
+ public String getErrorMessage(){
+ return errorMessage;
+ }
+
+ public String getErrorCode(){
+ return errorCode;
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerCallback.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerCallback.java index c84e5903c5..1bb4dc7eed 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerCallback.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerCallback.java @@ -19,8 +19,9 @@ */ package org.openecomp.mso.client.appc; -import org.openecomp.appc.client.lcm.api.ResponseHandler; -import org.openecomp.appc.client.lcm.exceptions.AppcClientException; + +import org.onap.appc.client.lcm.api.ResponseHandler; +import org.onap.appc.client.lcm.exceptions.AppcClientException; public class ApplicationControllerCallback<T> implements ResponseHandler<T> { 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<String, String> 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()); diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerOrchestrator.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerOrchestrator.java new file mode 100644 index 0000000000..217525e56a --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerOrchestrator.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.appc; + +import java.util.Optional; + +import org.openecomp.mso.client.appc.ApplicationControllerSupport.StatusCategory; + +import org.onap.appc.client.lcm.model.Action; +import org.onap.appc.client.lcm.model.ActionIdentifiers; +import org.onap.appc.client.lcm.model.Payload; +import org.onap.appc.client.lcm.model.Status; + +public class ApplicationControllerOrchestrator { + + public Status vnfCommand(Action action, String requestId, String vnfId, Optional<String> request) throws ApplicationControllerOrchestratorException { + ApplicationControllerClient client = new ApplicationControllerClient(); + Status status; + ActionIdentifiers actionIdentifiers = new ActionIdentifiers(); + actionIdentifiers.setVnfId(vnfId); + Payload payload = null; + if (request.isPresent()) { + payload = new Payload(request.get()); + } + status = client.runCommand(action, actionIdentifiers, payload, requestId); + if (ApplicationControllerSupport.getCategoryOf(status).equals(StatusCategory.ERROR)) { + throw new ApplicationControllerOrchestratorException(status.getMessage(), status.getCode()); + } else { + return status; + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerOrchestratorException.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerOrchestratorException.java new file mode 100644 index 0000000000..4692f1dcc2 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerOrchestratorException.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.appc;
+
+public class ApplicationControllerOrchestratorException extends Exception {
+
+ private final int appcCode;
+
+ public ApplicationControllerOrchestratorException(String message, int code) {
+ super(message);
+ appcCode = code;
+ }
+
+ public int getAppcCode()
+ {
+ return appcCode;
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerSupport.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerSupport.java index f7db52b1c0..e3ed432dfc 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerSupport.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerSupport.java @@ -20,35 +20,26 @@ package org.openecomp.mso.client.appc; - import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; -import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Properties; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.stereotype.Component; -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.Status; +import org.onap.appc.client.lcm.api.LifeCycleManagerStateful; +import org.onap.appc.client.lcm.api.ResponseHandler; +import org.onap.appc.client.lcm.model.Status; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.att.eelf.configuration.EELFLogger.Level; 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; - @Component public class ApplicationControllerSupport { @@ -61,14 +52,8 @@ public class ApplicationControllerSupport { private static final int PARTIAL_SUCCESS_STATUS = PARTIAL_SERIES; private static final int PARTIAL_FAILURE_STATUS = PARTIAL_SERIES + 1; - @Value("${lcm.model.package:org.openecomp.appc.client.lcm.model}") - private String lcmModelPackage; - - public LifeCycleManagerStateful createService() throws AppcClientException, IOException { - AppcLifeCycleManagerServiceFactory factory = AppcClientServiceFactoryProvider - .getFactory(AppcLifeCycleManagerServiceFactory.class); - return factory.createLifeCycleManagerStateful(new ApplicationContext(), getLCMProperties()); - } + protected final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); + private String lcmModelPackage = "org.onap.appc.client.lcm.model"; /** * @param action @@ -114,26 +99,18 @@ public class ApplicationControllerSupport { "Unable to derive viable LCM Kit API method for action", action, async)); } - public Method getCommonHeaderSetterMethod(String action) { - return getBeanPropertyMethodFor(getInputClass(action), "commonHeader", true); - } - - public Method getPayloadSetterMethod(String action) { - return getBeanPropertyMethodFor(getInputClass(action), "payload", true); - } - public Status getStatusFromGenericResponse(Object response) { Method statusReader = getBeanPropertyMethodFor(response.getClass(), "status", false); if (statusReader != null) { try { return (Status) statusReader.invoke(response); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - throw new RuntimeException("Unable to obtain status from LCM Kit response", e); + auditLogger.log(Level.ERROR, "Unable to obtain status from LCM Kit response", e, e.getMessage()); } } return new Status(); } - + public static StatusCategory getCategoryOf(Status status) { int codeSeries = status.getCode() - (status.getCode() % 100); switch (codeSeries) { @@ -157,7 +134,7 @@ public class ApplicationControllerSupport { return StatusCategory.WARNING; } } - + public static boolean getFinalityOf(Status status) { int codeSeries = status.getCode() - (status.getCode() % 100); switch (codeSeries) { @@ -173,16 +150,6 @@ public class ApplicationControllerSupport { } } - /** - * @return - * @throws IOException - */ - private Properties getLCMProperties() throws IOException { - Resource resource = new ClassPathResource("/lcm.properties"); - Properties properties = PropertiesLoaderUtils.loadProperties(resource); - return properties; - } - private Method getBeanPropertyMethodFor(Class<?> clazz, String propertyName, boolean isWriter) { BeanInfo beanInfo; try { @@ -213,34 +180,36 @@ public class ApplicationControllerSupport { try { return Class.forName(lcmModelPackage + '.' + action + "Input"); } catch (ClassNotFoundException e) { - throw new RuntimeException(String.format("%s : %s using package : ", + throw new RuntimeException(String.format("%s : %s using package : %s", "Unable to identify viable LCM Kit input class for action", action, lcmModelPackage), e); } } - - public static enum StatusCategory { - NORMAL("normal"), - WARNING("warning"), - ERROR("error"); - - private final String category; - - private StatusCategory(final String category) { - this.category = category; - } - - @Override - public String toString() { - return category; - } + + public enum StatusCategory { + NORMAL("normal"), WARNING("warning"), ERROR("error"); + + private final String category; + + private StatusCategory(final String category) { + this.category = category; + } + + @Override + public String toString() { + return category; + } } - - public void logLCMMessage(Object message) throws JsonProcessingException { + + public void logLCMMessage(Object message) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(Include.NON_NULL); ObjectWriter writer = objectMapper.writerWithDefaultPrettyPrinter(); - String inputAsJSON = writer.writeValueAsString(message); - System.out.println("LCM Kit input message follows."); - System.out.println(inputAsJSON); + String inputAsJSON; + try { + inputAsJSON = writer.writeValueAsString(message); + auditLogger.log(Level.INFO, "\nLCM Kit input message follows: \n" + inputAsJSON, null); + } catch (JsonProcessingException e) { + auditLogger.log(Level.ERROR, "Error in logging LCM Message: ", e, e.getMessage()); + } } } |