diff options
author | 2017-08-16 14:16:50 -0400 | |
---|---|---|
committer | 2017-08-16 21:30:21 +0000 | |
commit | 6b4baf891625c8b5f7635c8c2a1d9f599f57950c (patch) | |
tree | e000e825003e2b11c030b87476d010ec957303cd /appc-oam/appc-oam-bundle/src/main/java/org/openecomp | |
parent | db75c0a0b305c86429a6940de4d56870d3daf5bf (diff) |
[APPC-144] OAM operation abort messages
Provide abort audit log as well as notification when OAM operation is
interrupted by a new OAM operation request.
Fix missing ID in audit log for reject message.
Issue-Id: APPC-144
Change-Id: Ie87e19949be85c085444c753fdf061f4fc45e48f
Signed-off-by: beili.zhou <beili.zhou@amdocs.com>
Diffstat (limited to 'appc-oam/appc-oam-bundle/src/main/java/org/openecomp')
5 files changed, 103 insertions, 34 deletions
diff --git a/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/OAMCommandStatus.java b/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/OAMCommandStatus.java index 378fa032d..b8a4e3e86 100644 --- a/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/OAMCommandStatus.java +++ b/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/OAMCommandStatus.java @@ -24,7 +24,6 @@ package org.openecomp.appc.oam; - import org.openecomp.appc.executor.objects.Params; import org.openecomp.appc.util.MessageFormatter; @@ -32,24 +31,19 @@ import java.util.Map; public enum OAMCommandStatus { - ACCEPTED(100,"ACCEPTED - request accepted"), - - //ERROR(2xx) - request can't be handled due to some technical error - UNEXPECTED_ERROR(200,"UNEXPECTED ERROR - ${errorMsg}"), - - REJECTED(300,"REJECTED - ${errorMsg}"), - INVALID_PARAMETER(302,"INVALID PARAMETER - ${errorMsg}" ), - TIMEOUT(303, "OPERATION TIMEOUT REACHED - ${errorMsg}"), + ACCEPTED(100, "ACCEPTED - request accepted"), + UNEXPECTED_ERROR(200, "UNEXPECTED ERROR - ${errorMsg}"), + REJECTED(300, "REJECTED - ${errorMsg}"), + INVALID_PARAMETER(302, "INVALID PARAMETER - ${errorMsg}" ), + TIMEOUT(303, "OPERATION TIMEOUT REACHED - ${errorMsg}"), + ABORT(304, "OPERATION ABORT - ${errorMsg}"), + SUCCESS(400, "SUCCESS - request has been processed successfully"); - SUCCESS(400,"SUCCESS - request has been processed successfully"), - ; + final String TO_STRING_FORMAT = "OAMCommandStatus{responseCode=%d, responseMessage='%s'}"; private int responseCode; private String responseMessage; - - - OAMCommandStatus(int responseCode, String responseMessage) { this.responseCode = responseCode; this.responseMessage = responseMessage; @@ -63,22 +57,18 @@ public enum OAMCommandStatus { return responseCode; } - /** + * Get formated message of passed in params * - * @return messageTemplate + * @param params of Params object with name value pairs for message + * @return message string */ - public String getFormattedMessage(Params params){ + public String getFormattedMessage(Params params) { Map<String,Object> paramsMap = params != null ? params.getParams() : null; - return MessageFormatter.format(getResponseMessage(),paramsMap); - + return MessageFormatter.format(getResponseMessage(), paramsMap); } @Override public String toString() { - return "OAMCommandStatus{" + - "responseCode=" + responseCode + - ", responseMessage='" + responseMessage + '\'' + - '}'; - } -} + return String.format(TO_STRING_FORMAT, responseCode, responseMessage); + }} diff --git a/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseActionRunnable.java b/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseActionRunnable.java index 2ffad6993..542e53d63 100644 --- a/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseActionRunnable.java +++ b/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseActionRunnable.java @@ -25,6 +25,7 @@ package org.openecomp.appc.oam.processor; import org.openecomp.appc.i18n.Msg; +import org.openecomp.appc.oam.AppcOam; import org.openecomp.appc.oam.OAMCommandStatus; import org.openecomp.appc.statemachine.impl.readers.AppcOamStates; @@ -43,16 +44,18 @@ import java.util.concurrent.Future; * <br> - auditMsg * <br> - finalState */ -abstract class BaseActionRunnable extends BaseCommon implements Runnable { +public abstract class BaseActionRunnable extends BaseCommon implements Runnable { final String OAM_OPERATION_TIMEOUT_SECOND = "appc.OAM.api.timeout"; /** Default operation tiemout set to 1 minute */ final int DEFAULT_OAM_OPERATION_TIMEOUT = 60; - /** Abort message format with flexible operation name */ - final String ABORT_MESSAGE_FORMAT = "Aborting %s operation."; + /** Abort due to rejection message format with flexible operation name */ + final String ABORT_MESSAGE_FORMAT = "Aborting %s operation due to %s."; /** Timeout message format with flexible operation name */ final String TIMEOUT_MESSAGE_FORMAT = "%s operation has reached timeout %d milliseconds."; /** Failure message format with flexible number of bundles */ final String BUNDLE_OPERATION_FAILED_FORMAT = "%d bundle(s) failed, see logs for details."; + final String NEW_RPC_OPERATION_REQUEST = "new %s operation request"; + final String DUE_TO_EXECUTION_ERROR = "due to execution error."; private boolean isWaiting = false; private AppcOamStates currentState; @@ -103,6 +106,26 @@ abstract class BaseActionRunnable extends BaseCommon implements Runnable { rpc.name(), Boolean.toString(doTimeoutChecking), timeoutMs, startTimeMs); } + /** + * Abort operation handling due to outside interruption, does<br> + * - set ABORT status<br> + * - send notification message<br> + * - add audit log + * + * @param newRpc of the new AppcOam.RPC operation. + */ + public void abortRunnable(final AppcOam.RPC newRpc) { + resetLogProperties(false); + + String additionalMsg = String.format(NEW_RPC_OPERATION_REQUEST, newRpc); + logDebug("%s action aborted due to %s", rpc.name(), additionalMsg); + setStatus(OAMCommandStatus.ABORT, String.format(ABORT_MESSAGE_FORMAT, rpc.name(), additionalMsg)); + operationHelper.sendNotificationMessage(rpc, commonHeader, status); + auditInfoLog(auditMsg); + + resetLogProperties(true); + } + @Override public void run() { try { @@ -179,10 +202,10 @@ abstract class BaseActionRunnable extends BaseCommon implements Runnable { } /** - * Set class <b>status</b> to REJECTED with abort message. + * Set class <b>status</b> to ABORT with abort message. */ void setAbortStatus() { - setStatus(OAMCommandStatus.REJECTED, String.format(ABORT_MESSAGE_FORMAT, rpc.name())); + setStatus(OAMCommandStatus.ABORT, String.format(ABORT_MESSAGE_FORMAT, rpc.name(), DUE_TO_EXECUTION_ERROR)); } /** diff --git a/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseCommon.java b/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseCommon.java index cc725e7b9..ccb57305a 100644 --- a/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseCommon.java +++ b/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseCommon.java @@ -43,7 +43,11 @@ import org.openecomp.appc.oam.util.StateHelper; import org.slf4j.MDC; import java.net.InetAddress; +import java.util.Arrays; import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID; import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; @@ -69,6 +73,18 @@ abstract class BaseCommon { AppcOam.RPC rpc; CommonHeader commonHeader; + private final List<String> MDC_KEYS = Arrays.asList( + LoggingConstants.MDCKeys.PARTNER_NAME, + LoggingConstants.MDCKeys.SERVER_NAME, + MDC_INSTANCE_UUID, + MDC_KEY_REQUEST_ID, + MDC_SERVER_FQDN, + MDC_SERVER_IP_ADDRESS, + MDC_SERVICE_NAME + ); + + private Map<String, String> oldMdcContent = new HashMap<>(); + /** * Constructor * @@ -138,6 +154,32 @@ abstract class BaseCommon { } /** + * Reset MDC log properties based on passed in condition. does:<br> + * - persist existing MDC setting and set my MDC log properties <br> + * - or re-apply persisted MDC log properties + * @param useMdcMap boolean to indicate whether to persist the existing MDC setting and set my MDC log properties, + * or to re-apply the persisted MDC log properties. + */ + void resetLogProperties(boolean useMdcMap) { + if (useMdcMap) { + for (Map.Entry<String, String> aEntry : oldMdcContent.entrySet()) { + MDC.put(aEntry.getKey(), aEntry.getValue()); + } + return; + } + + // persist existing log properties and set my log properties + oldMdcContent.clear(); + for (String key : MDC_KEYS) { + String value = MDC.get(key); + if (value != null) { + oldMdcContent.put(key, value); + } + } + setInitialLogProperties(); + } + + /** * Set class <b>status</b> by calling setStatus(OAMCommandStatus, Params) with null paramter. * @see #setStatus(OAMCommandStatus, String) * @@ -170,9 +212,11 @@ abstract class BaseCommon { /** * Set class <b>status</b> with error status calculated from the passed in paremeter * and audit log the error message. - * @param t of the erro Throwable. + * @param t of the error Throwable. */ void setErrorStatus(Throwable t) { + resetLogProperties(false); + final String appName = configurationHelper.getAppcName(); String exceptionMessage = t.getMessage() != null ? t.getMessage() : t.toString(); @@ -201,6 +245,8 @@ abstract class BaseCommon { LoggingConstants.TargetNames.APPC_OAM_PROVIDER, errorMessage, AppcOam.class.getCanonicalName()); + + resetLogProperties(true); } /** diff --git a/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseProcessor.java b/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseProcessor.java index 6c7011111..c9ba0efa7 100644 --- a/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseProcessor.java +++ b/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/processor/BaseProcessor.java @@ -54,7 +54,7 @@ public abstract class BaseProcessor extends BaseCommon { Integer timeoutSeconds; Msg auditMsg; - Runnable runnable; + BaseActionRunnable runnable; private Future<?> scheduledRunnable = null; /** diff --git a/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/util/AsyncTaskHelper.java b/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/util/AsyncTaskHelper.java index ff28e995a..25467da04 100644 --- a/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/util/AsyncTaskHelper.java +++ b/appc-oam/appc-oam-bundle/src/main/java/org/openecomp/appc/oam/util/AsyncTaskHelper.java @@ -26,6 +26,7 @@ package org.openecomp.appc.oam.util; import com.att.eelf.configuration.EELFLogger; import org.openecomp.appc.oam.AppcOam; +import org.openecomp.appc.oam.processor.BaseActionRunnable; import org.osgi.framework.Bundle; import org.osgi.framework.FrameworkUtil; @@ -52,6 +53,8 @@ public class AsyncTaskHelper { /** Reference to the Async task */ private volatile Future<?> backgroundOamTask; + /** Reference to the runnable of Async task */ + private volatile BaseActionRunnable taskRunnable; /** * Constructor @@ -107,9 +110,9 @@ public class AsyncTaskHelper { * Schedule a service for async task with the passed in parameters * @param rpc of the REST API call, decides how to schedule the service * @param runnable of the to be scheduled service. - * @return the refernce of the scheduled task + * @return the reference of the scheduled task */ - public Future<?> scheduleAsyncTask(final AppcOam.RPC rpc, final Runnable runnable) { + public Future<?> scheduleAsyncTask(final AppcOam.RPC rpc, final BaseActionRunnable runnable) { int initialDelay, interval; switch (rpc) { case maintenance_mode: @@ -129,8 +132,14 @@ public class AsyncTaskHelper { // Always cancel existing async task if (backgroundOamTask != null) { + logDebug("Cancelling background task in schedule task."); backgroundOamTask.cancel(true); + if (taskRunnable != null) { + taskRunnable.abortRunnable(rpc); + } } + + taskRunnable = runnable; backgroundOamTask = scheduledExecutorService.scheduleWithFixedDelay( runnable, initialDelay, interval, TimeUnit.MILLISECONDS); @@ -149,6 +158,7 @@ public class AsyncTaskHelper { task.cancel(false); if (task == backgroundOamTask) { backgroundOamTask = null; + logDebug("Cancelling background task in cancel task."); } } |