diff options
23 files changed, 293 insertions, 292 deletions
diff --git a/appc-common/src/main/java/org/openecomp/appc/logging/LoggingUtils.java b/appc-common/src/main/java/org/openecomp/appc/logging/LoggingUtils.java index 901ff3272..c186a4afa 100644 --- a/appc-common/src/main/java/org/openecomp/appc/logging/LoggingUtils.java +++ b/appc-common/src/main/java/org/openecomp/appc/logging/LoggingUtils.java @@ -21,20 +21,23 @@ package org.openecomp.appc.logging; -import org.openecomp.appc.i18n.Msg; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.att.eelf.i18n.EELFResourceManager; -import org.slf4j.MDC; - import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.Date; import java.util.TimeZone; +import org.openecomp.appc.i18n.Msg; +import org.slf4j.MDC; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.att.eelf.i18n.EELFResourceManager; + public class LoggingUtils { @@ -61,7 +64,7 @@ public class LoggingUtils { cleanErrorLogContext(); } - public static void logAuditMessage(Date beginTimeStamp, Date endTimeStamp, String code, String responseDescription, String className) { + public static void logAuditMessage(Instant beginTimeStamp, Instant endTimeStamp, String code, String responseDescription, String className) { populateAuditLogContext(beginTimeStamp, endTimeStamp, code, responseDescription, className); auditLogger.info(EELFResourceManager.format(Msg.APPC_AUDIT_MSG, MDC.get(MDC_SERVICE_NAME), @@ -74,7 +77,7 @@ public class LoggingUtils { cleanAuditErrorContext(); } - public static void logMetricsMessage(Date beginTimeStamp, Date endTimeStamp, String targetEntity, String targetServiceName, String statusCode, String responseCode, String responseDescription, String className) { + public static void logMetricsMessage(Instant beginTimeStamp, Instant endTimeStamp, String targetEntity, String targetServiceName, String statusCode, String responseCode, String responseDescription, String className) { populateMetricLogContext(beginTimeStamp, endTimeStamp, targetEntity, targetServiceName, statusCode, responseCode, responseDescription, className); metricLogger.info(EELFResourceManager.format(Msg.APPC_METRIC_MSG, MDC.get(MDC_SERVICE_NAME), @@ -88,7 +91,7 @@ public class LoggingUtils { cleanMetricContext(); } - private static void populateAuditLogContext(Date beginTimeStamp, Date endTimeStamp, String code, String responseDescription, String className) { + private static void populateAuditLogContext(Instant beginTimeStamp, Instant endTimeStamp, String code, String responseDescription, String className) { populateTimeContext(beginTimeStamp, endTimeStamp); MDC.put(LoggingConstants.MDCKeys.RESPONSE_CODE, code); MDC.put(LoggingConstants.MDCKeys.STATUS_CODE, code.equals("100") || code.equals("400") ? @@ -118,7 +121,7 @@ public class LoggingUtils { MDC.remove(LoggingConstants.MDCKeys.CLASS_NAME); } - private static void populateMetricLogContext(Date beginTimeStamp, Date endTimeStamp, String targetEntity, String targetServiceName, String statusCode, String responseCode, String responseDescription, String className) { + private static void populateMetricLogContext(Instant beginTimeStamp, Instant endTimeStamp, String targetEntity, String targetServiceName, String statusCode, String responseCode, String responseDescription, String className) { populateTimeContext(beginTimeStamp, endTimeStamp); populateTargetContext(targetEntity, targetServiceName); populateResponseContext(statusCode, responseCode, responseDescription); @@ -142,13 +145,13 @@ public class LoggingUtils { MDC.remove(LoggingConstants.MDCKeys.TARGET_SERVICE_NAME); } - private static void populateTimeContext(Date beginTimeStamp, Date endTimeStamp) { + private static void populateTimeContext(Instant beginTimeStamp, Instant endTimeStamp) { String beginTime = ""; String endTime = ""; String elapsedTime = ""; if (beginTimeStamp != null && endTimeStamp != null) { - elapsedTime = String.valueOf(endTimeStamp.getTime() - beginTimeStamp.getTime()); + elapsedTime = String.valueOf(ChronoUnit.MILLIS.between(beginTimeStamp, endTimeStamp)); beginTime = generateTimestampStr(beginTimeStamp); endTime = generateTimestampStr(endTimeStamp); } @@ -158,11 +161,11 @@ public class LoggingUtils { MDC.put(LoggingConstants.MDCKeys.ELAPSED_TIME, elapsedTime); } - private static String generateTimestampStr(Date timeStamp) { + private static String generateTimestampStr(Instant timeStamp) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX"); TimeZone tz = TimeZone.getTimeZone("UTC"); df.setTimeZone(tz); - return df.format(timeStamp); + return df.format(Date.from(timeStamp)); } private static void cleanTimeContext() { diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-api/src/main/java/org/openecomp/appc/executor/objects/CommandResponse.java b/appc-dispatcher/appc-command-executor/appc-command-executor-api/src/main/java/org/openecomp/appc/executor/objects/CommandResponse.java index c973fcde1..8009d72d5 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-api/src/main/java/org/openecomp/appc/executor/objects/CommandResponse.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-api/src/main/java/org/openecomp/appc/executor/objects/CommandResponse.java @@ -26,13 +26,14 @@ import org.openecomp.appc.domainmodel.lcm.RuntimeContext; public class CommandResponse { - private RuntimeContext runtimeContext; + private final RuntimeContext runtimeContext; - public RuntimeContext getRuntimeContext() { - return runtimeContext; + public CommandResponse(RuntimeContext runtimeContext) { + super(); + this.runtimeContext = runtimeContext; } - public void setRuntimeContext(RuntimeContext runtimeContext) { - this.runtimeContext = runtimeContext; + public RuntimeContext getRuntimeContext() { + return runtimeContext; } } diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandExecutorImpl.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandExecutorImpl.java index 0948b2b4d..fcc4f9156 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandExecutorImpl.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandExecutorImpl.java @@ -25,7 +25,8 @@ package org.openecomp.appc.executor.impl; -import java.util.Date; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.concurrent.TimeUnit; import org.apache.commons.lang.ObjectUtils; @@ -92,8 +93,8 @@ public class CommandExecutorImpl implements CommandExecutor { logger.trace("Entering to enqueRequest with CommandRequest = "+ ObjectUtils.toString(request)); } try { - CommandTask commandTask = getMessageExecutor(request.getRequestContext().getAction().name()); - commandTask.setCommandRequest(request); + String action = request.getRequestContext().getAction().name(); + CommandTask commandTask = executionTaskFactory.getExecutionTask(action, request); long remainingTTL = getRemainingTTL(request); executionQueueService.putMessage(commandTask,remainingTTL, TimeUnit.MILLISECONDS); } catch (Exception e) { @@ -107,20 +108,9 @@ public class CommandExecutorImpl implements CommandExecutor { } private long getRemainingTTL(RuntimeContext request) { - Date requestTimestamp = request.getRequestContext().getCommonHeader().getTimeStamp(); + Instant requestTimestamp = request.getRequestContext().getCommonHeader().getTimeStamp(); int ttl = request.getRequestContext().getCommonHeader().getFlags().getTtl(); - return ttl*1000 + requestTimestamp.getTime() - System.currentTimeMillis(); - } - - private CommandTask getMessageExecutor(String action){ - if (logger.isTraceEnabled()) { - logger.trace("Entering to getMessageExecutor with command = "+ action); - } - CommandTask executionTask = executionTaskFactory.getExecutionTask(action); - if (logger.isTraceEnabled()) { - logger.trace("Exiting from getMessageExecutor"); - } - return executionTask; + return ChronoUnit.MILLIS.between(Instant.now(), requestTimestamp.plusSeconds(ttl)); } diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTask.java index f34746b24..21a00861e 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTask.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTask.java @@ -51,44 +51,30 @@ import org.slf4j.MDC; public abstract class CommandTask implements Runnable { - protected RequestHandler requestHandler; - protected WorkFlowManager workflowManager; + protected final RequestHandler requestHandler; + protected final WorkFlowManager workflowManager; + protected final RuntimeContext commandRequest; - private RuntimeContext commandRequest; - - public RuntimeContext getCommandRequest() { - return commandRequest; - } - - public void setCommandRequest(RuntimeContext commandRequest) { + protected CommandTask(RuntimeContext commandRequest, RequestHandler requestHandler, + WorkFlowManager workflowManager) { + super(); this.commandRequest = commandRequest; - } - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(CommandTask.class); - - public void setWorkflowManager(WorkFlowManager workflowManager) { - this.workflowManager = workflowManager; - } - - public void setRequestHandler(RequestHandler requestHandler) { this.requestHandler = requestHandler; + this.workflowManager = workflowManager; } - CommandTask(){ - } + private static final EELFLogger logger = EELFManager.getInstance().getLogger(CommandTask.class); - public void onRequestCompletion(RuntimeContext request, CommandResponse response , boolean isAAIUpdated) { + public void onRequestCompletion(CommandResponse response, boolean isAAIUpdated) { logger.debug("Entry: onRequestCompletion()"); - requestHandler.onRequestExecutionEnd(request, isAAIUpdated); + requestHandler.onRequestExecutionEnd(commandRequest, isAAIUpdated); } - public abstract void onRequestCompletion(RuntimeContext request, CommandResponse response); + public abstract void onRequestCompletion(CommandResponse response); - protected CommandResponse buildCommandResponse(RuntimeContext request, WorkflowResponse response) { + protected CommandResponse buildCommandResponse(WorkflowResponse response) { - CommandResponse commandResponse = new CommandResponse(); - commandResponse.setRuntimeContext(request); - return commandResponse; + return new CommandResponse(commandRequest); } @@ -114,8 +100,8 @@ public abstract class CommandTask implements Runnable { WorkflowResponse response = workflowManager.executeWorkflow(workflowRequest); - CommandResponse commandResponse = buildCommandResponse(commandRequest, response); - this.onRequestCompletion(commandRequest,commandResponse); + CommandResponse commandResponse = buildCommandResponse(response); + this.onRequestCompletion(commandResponse); } } diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTaskFactory.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTaskFactory.java index 610f0bca3..e5ac79cfa 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTaskFactory.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTaskFactory.java @@ -22,6 +22,7 @@ package org.openecomp.appc.executor.impl; +import org.openecomp.appc.domainmodel.lcm.RuntimeContext; import org.openecomp.appc.domainmodel.lcm.VNFOperation; import org.openecomp.appc.lifecyclemanager.LifecycleManager; import org.openecomp.appc.requesthandler.RequestHandler; @@ -53,11 +54,11 @@ public class CommandTaskFactory { } - public synchronized CommandTask getExecutionTask(String action){ + public synchronized CommandTask getExecutionTask(String action, RuntimeContext commandRequest){ if (VNFOperation.Sync.toString().equals(action) || VNFOperation.Audit.toString().equals(action)){ - return new LCMReadonlyCommandTask(requestHandler,workflowManager); + return new LCMReadonlyCommandTask(commandRequest, requestHandler,workflowManager); }else { - return new LCMCommandTask(requestHandler,workflowManager, + return new LCMCommandTask(commandRequest, requestHandler,workflowManager, lifecyclemanager); } } diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMCommandTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMCommandTask.java index 889bd25da..ef25c67bc 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMCommandTask.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMCommandTask.java @@ -22,10 +22,12 @@ package org.openecomp.appc.executor.impl; +import java.util.HashMap; +import java.util.Map; + import org.apache.commons.lang3.StringUtils; import org.openecomp.appc.domainmodel.lcm.CommonHeader; import org.openecomp.appc.domainmodel.lcm.RuntimeContext; -import org.openecomp.appc.domainmodel.lcm.Status; import org.openecomp.appc.domainmodel.lcm.VNFOperation; import org.openecomp.appc.executor.UnstableVNFException; import org.openecomp.appc.executor.objects.CommandResponse; @@ -39,8 +41,6 @@ import org.openecomp.appc.lifecyclemanager.objects.VNFOperationOutcome; import org.openecomp.appc.requesthandler.RequestHandler; import org.openecomp.appc.workflow.WorkFlowManager; import org.openecomp.appc.workflow.objects.WorkflowResponse; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.openecomp.sdnc.sli.SvcLogicContext; import org.openecomp.sdnc.sli.SvcLogicException; import org.openecomp.sdnc.sli.SvcLogicResource; @@ -49,31 +49,22 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; -import java.util.HashMap; -import java.util.Map; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; public class LCMCommandTask extends CommandTask { - private AAIService aaiService; - private LifecycleManager lifecyclemanager; + private final AAIService aaiService; + private final LifecycleManager lifecyclemanager; private static final EELFLogger logger = EELFManager.getInstance().getLogger(LCMCommandTask.class); - public LCMCommandTask(RequestHandler requestHandler, WorkFlowManager workflowManager, - LifecycleManager lifecyclemanager){ - setRequestHandler(requestHandler); - setWorkflowManager(workflowManager); - setLifecyclemanager(lifecyclemanager); - getAAIservice(); - } - - public void setLifecyclemanager(LifecycleManager lifecyclemanager) { - this.lifecyclemanager = lifecyclemanager; - } + public LCMCommandTask(RuntimeContext commandRequest, RequestHandler requestHandler, WorkFlowManager workflowManager, + LifecycleManager lifecyclemanager) { + super(commandRequest, requestHandler, workflowManager); + this.lifecyclemanager = lifecyclemanager; - - private void getAAIservice() { BundleContext bctx = FrameworkUtil.getBundle(AAIService.class).getBundleContext(); // Get AAIadapter reference ServiceReference sref = bctx.getServiceReference(AAIService.class.getName()); @@ -84,15 +75,15 @@ public class LCMCommandTask extends CommandTask { } else { logger.info("AAIService error from bundlecontext"); logger.warn("Cannot find service reference for org.openecomp.sdnc.sli.aai.AAIService"); - + aaiService = null; } } @Override - public void onRequestCompletion(RuntimeContext request, CommandResponse response) { - - boolean isAAIUpdated = false; + public void onRequestCompletion(CommandResponse response) { + final RuntimeContext request = commandRequest; + boolean isAAIUpdated = false; try { final int statusCode = request.getResponseContext().getStatus().getCode(); @@ -118,14 +109,14 @@ public class LCMCommandTask extends CommandTask { throw new RuntimeException(e1); } finally { - super.onRequestCompletion(request, response , isAAIUpdated); + super.onRequestCompletion(response, isAAIUpdated); } } @Override public void run() { - RuntimeContext request = getCommandRequest(); - boolean isAAIUpdated; + final RuntimeContext request = commandRequest; + boolean isAAIUpdated = false; final String vnfId = request.getVnfContext().getId(); final String vnfType = request.getVnfContext().getType(); try { @@ -169,8 +160,8 @@ public class LCMCommandTask extends CommandTask { logger.error(errorMsg); WorkflowResponse response = new WorkflowResponse(); response.setResponseContext(request.getResponseContext()); - CommandResponse commandResponse = super.buildCommandResponse(request, response); - this.onRequestCompletion(request,commandResponse); + CommandResponse commandResponse = super.buildCommandResponse(response); + this.onRequestCompletion(commandResponse); } } diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMReadonlyCommandTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMReadonlyCommandTask.java index a351c4d36..dc61673d0 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMReadonlyCommandTask.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMReadonlyCommandTask.java @@ -25,7 +25,6 @@ package org.openecomp.appc.executor.impl; import org.apache.commons.lang3.StringUtils; import org.openecomp.appc.domainmodel.lcm.CommonHeader; import org.openecomp.appc.domainmodel.lcm.RuntimeContext; -import org.openecomp.appc.domainmodel.lcm.Status; import org.openecomp.appc.executor.UnstableVNFException; import org.openecomp.appc.executor.objects.CommandResponse; import org.openecomp.appc.executor.objects.LCMCommandStatus; @@ -33,6 +32,7 @@ import org.openecomp.appc.executor.objects.Params; import org.openecomp.appc.executor.objects.UniqueRequestIdentifier; import org.openecomp.appc.requesthandler.RequestHandler; import org.openecomp.appc.workflow.WorkFlowManager; + import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -40,21 +40,19 @@ public class LCMReadonlyCommandTask extends CommandTask { private static final EELFLogger logger = EELFManager.getInstance().getLogger(LCMReadonlyCommandTask.class); - public LCMReadonlyCommandTask(RequestHandler requestHandler, WorkFlowManager workflowManager){ - - setRequestHandler(requestHandler); - setWorkflowManager(workflowManager); + public LCMReadonlyCommandTask(RuntimeContext commandRequest, RequestHandler requestHandler, + WorkFlowManager workflowManager) { + super(commandRequest, requestHandler, workflowManager); } - @Override - public void onRequestCompletion(RuntimeContext request, CommandResponse response) { - super.onRequestCompletion(request, response, true); + public void onRequestCompletion(CommandResponse response) { + super.onRequestCompletion(response, true); } @Override public void run() { - RuntimeContext request = getCommandRequest(); + RuntimeContext request = commandRequest; final CommonHeader commonHeader = request.getRequestContext().getCommonHeader(); final boolean forceFlag = commonHeader.getFlags().isForce(); UniqueRequestIdentifier requestIdentifier = new UniqueRequestIdentifier(commonHeader.getOriginatorId(), commonHeader.getRequestId(), commonHeader.getSubRequestId()); diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java index 9757430d8..f2c30990e 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutionTask.java @@ -54,6 +54,7 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import java.time.Instant; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -71,8 +72,6 @@ public class TestCommandExecutionTask { private static final String TTL_FLAG= "TTL"; private static final String API_VERSION= "2.0.0"; private static final String ORIGINATOR_ID= "1"; - private LCMCommandTask executionTask; - private LCMReadonlyCommandTask LCMReadonlyCommandTask; private CommandTaskFactory factory ; private RequestHandler requestHandler; @@ -118,8 +117,6 @@ public class TestCommandExecutionTask { workflowManager = Mockito.mock(WorkFlowManager.class); lifecyclemanager = Mockito.mock(LifecycleManager.class ); - executionTask = new LCMCommandTask(requestHandler,workflowManager,lifecyclemanager); - LCMReadonlyCommandTask = new LCMReadonlyCommandTask(requestHandler,workflowManager); factory = new CommandTaskFactory(); factory.setLifecyclemanager(lifecyclemanager); factory.setWorkflowManager(workflowManager); @@ -130,9 +127,9 @@ public class TestCommandExecutionTask { @Test public void testFactory(){ - CommandTask task = factory.getExecutionTask("Configure"); + CommandTask task = factory.getExecutionTask("Configure", null); assertEquals(LCMCommandTask.class,task.getClass() ); - task = factory.getExecutionTask("Sync"); + task = factory.getExecutionTask("Sync", null); assertEquals(LCMReadonlyCommandTask.class,task.getClass() ); } @@ -142,37 +139,36 @@ public class TestCommandExecutionTask { @Test public void testOnRequestCompletion(){ Mockito.doNothing().when(requestHandler).onRequestTTLEnd((RuntimeContext) anyObject(),anyBoolean()); - RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Configure, "1", ""); + RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Configure, "1", ""); CommandResponse response = getCommandResponse(VNFOperation.Configure, true, "11", "","1"); - executionTask.onRequestCompletion(request, response); + LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager); + executionTask.onRequestCompletion(response); } @Test public void testRunGetConfig(){ - RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", ""); - LCMReadonlyCommandTask.setCommandRequest(request); - LCMReadonlyCommandTask.run(); + RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", ""); + LCMReadonlyCommandTask readonlyCommandTask = new LCMReadonlyCommandTask(request, requestHandler,workflowManager); + readonlyCommandTask.run(); } @Test public void testRun(){ - RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", ""); - executionTask.setCommandRequest(request); + RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", ""); + LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager); executionTask.run(); } @Test public void testRunNegative(){ - RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", ""); - executionTask.setCommandRequest(request); + RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", ""); + LCMCommandTask executionTask = new LCMCommandTask(request, requestHandler,workflowManager,lifecyclemanager); executionTask.run(); } CommandResponse getCommandResponse(VNFOperation action , boolean success, String responseId, String payload, String vnfId){ - CommandResponse commandResponse = new CommandResponse(); RuntimeContext runtimeContext = new RuntimeContext(); - commandResponse.setRuntimeContext(runtimeContext); ResponseContext responseContext = new ResponseContext(); runtimeContext.setResponseContext(responseContext); RequestContext requestContext = new RequestContext(); @@ -191,9 +187,9 @@ public class TestCommandExecutionTask { responseContext.setStatus(new Status(100, null)); commonHeader.setRequestId(responseId); responseContext.setPayload(payload); - commonHeader.setTimestamp(new Date()); + commonHeader.setTimestamp(Instant.now()); vnfContext.setId(vnfId); - return commandResponse; + return new CommandResponse(runtimeContext); } @@ -201,10 +197,9 @@ public class TestCommandExecutionTask { @Test public void testPositiveFlow_configure() { - Date timeStamp = new Date(); String requestId = "1"; - RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL",30, "1.0", timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "", VNFOperation.Configure, "33", ""); + RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL",30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "", VNFOperation.Configure, "33", ""); } @@ -226,7 +221,7 @@ public class TestCommandExecutionTask { return wfResponse; } - private RuntimeContext pouplateCommandExecutorInput(String vnfType, int ttl, String vnfVersion, Date timeStamp, String apiVersion, String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload){ + private RuntimeContext pouplateCommandExecutorInput(String vnfType, int ttl, String vnfVersion, Instant timeStamp, String apiVersion, String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload){ RuntimeContext commandExecutorInput = createCommandExecutorInputWithSubObjects(); RequestContext requestContext = commandExecutorInput.getRequestContext(); ResponseContext responseContext = createResponseContextWithSuObjects(); diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java index bb4e39109..cd33e8b2e 100644 --- a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java +++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/test/java/org/openecomp/appc/executor/TestCommandExecutor.java @@ -25,12 +25,19 @@ package org.openecomp.appc.executor; */ +import java.time.Instant; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -import org.openecomp.appc.domainmodel.lcm.*; -import org.openecomp.appc.domainmodel.lcm.Flags.Mode; +import org.openecomp.appc.domainmodel.lcm.ActionIdentifiers; +import org.openecomp.appc.domainmodel.lcm.CommonHeader; +import org.openecomp.appc.domainmodel.lcm.Flags; +import org.openecomp.appc.domainmodel.lcm.RequestContext; +import org.openecomp.appc.domainmodel.lcm.RuntimeContext; +import org.openecomp.appc.domainmodel.lcm.VNFContext; +import org.openecomp.appc.domainmodel.lcm.VNFOperation; import org.openecomp.appc.exceptions.APPCException; import org.openecomp.appc.executionqueue.ExecutionQueueService; import org.openecomp.appc.executor.impl.CommandExecutorImpl; @@ -41,11 +48,6 @@ import org.openecomp.appc.lifecyclemanager.LifecycleManager; import org.openecomp.appc.requesthandler.RequestHandler; import org.openecomp.appc.workflow.WorkFlowManager; -import java.util.Date; -import java.util.concurrent.TimeUnit; - -import static junit.framework.Assert.assertTrue; - @SuppressWarnings("deprecation") public class TestCommandExecutor { @@ -78,8 +80,8 @@ public class TestCommandExecutor { commandExecutor.setExecutionQueueService(executionQueueService); LCMCommandTask lcmCommandTask = Mockito.mock(LCMCommandTask.class); LCMReadonlyCommandTask LCMReadonlyCommandTask = Mockito.mock(LCMReadonlyCommandTask.class); - Mockito.doReturn(lcmCommandTask).when(executionTaskFactory).getExecutionTask("Configure"); - Mockito.doReturn(LCMReadonlyCommandTask).when(executionTaskFactory).getExecutionTask("Sync"); + Mockito.doReturn(lcmCommandTask).when(executionTaskFactory).getExecutionTask("Configure", null); + Mockito.doReturn(LCMReadonlyCommandTask).when(executionTaskFactory).getExecutionTask("Sync", null); // Mockito.when(executionQueueService.putMessage((Runnable) Mockito.anyObject(),Mockito.anyLong(),(TimeUnit)Mockito.anyObject())).thenReturn(true); } @@ -88,9 +90,8 @@ public class TestCommandExecutor { @Test public void testPositiveFlow_LCM(){ //Map <String,Object> flags = setTTLInFlags("30"); - Date timeStamp = new Date(); String requestId = "1"; - RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure, "15", "") ; + RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Configure, "15", "") ; try { commandExecutor.executeCommand(commandExecutorInput); } catch (APPCException e) { @@ -101,10 +102,9 @@ public class TestCommandExecutor { @Test public void testPositiveFlow_GetConfig(){ - Date timeStamp = new Date(); String requestId = "1"; - RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", timeStamp, API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ; + RuntimeContext commandExecutorInput = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, requestId, ORIGINATOR_ID, "2", VNFOperation.Sync,"15","") ; try { commandExecutor.executeCommand(commandExecutorInput); } catch (APPCException e) { @@ -114,7 +114,7 @@ public class TestCommandExecutor { } - private RuntimeContext pouplateCommandExecutorInput(String vnfType, int ttl, String vnfVersion, Date timeStamp, String apiVersion, String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload){ + private RuntimeContext pouplateCommandExecutorInput(String vnfType, int ttl, String vnfVersion, Instant timeStamp, String apiVersion, String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload){ RuntimeContext commandExecutorInput = createCommandExecutorInputWithSubObjects(); RequestContext requestContext = commandExecutorInput.getRequestContext(); requestContext.getCommonHeader().setFlags(new Flags(null, false, ttl)); diff --git a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/CommonHeader.java b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/CommonHeader.java index 0819a58d5..30459465f 100644 --- a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/CommonHeader.java +++ b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/CommonHeader.java @@ -21,13 +21,13 @@ package org.openecomp.appc.domainmodel.lcm; -import java.util.Date; +import java.time.Instant; public class CommonHeader { private Flags flags; - private Date timestamp; + private Instant timestamp; private String apiVer; private String originatorId; private String requestId; @@ -41,11 +41,11 @@ public class CommonHeader { this.flags = flags; } - public Date getTimeStamp() { + public Instant getTimeStamp() { return timestamp; } - public void setTimestamp(Date timestamp) { + public void setTimestamp(Instant timestamp) { this.timestamp = timestamp; } diff --git a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/RuntimeContext.java b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/RuntimeContext.java index fd2bcffbf..e47f5469a 100644 --- a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/RuntimeContext.java +++ b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/RuntimeContext.java @@ -21,6 +21,7 @@ package org.openecomp.appc.domainmodel.lcm; +import java.time.Instant; import java.util.Date; @@ -31,7 +32,7 @@ public class RuntimeContext { private VNFContext vnfContext; //TODO move fields timeStart abd isLockAcquired to a better place - private Date timeStart; + private Instant timeStart; private boolean isLockAcquired; private String rpcName; @@ -43,7 +44,7 @@ public class RuntimeContext { this.rpcName = rpcName; } - public Date getTimeStart() { + public Instant getTimeStart() { return timeStart; } @@ -55,7 +56,7 @@ public class RuntimeContext { this.isLockAcquired = isLockAcquired; } - public void setTimeStart(Date timeStart) { + public void setTimeStart(Instant timeStart) { this.timeStart = timeStart; } diff --git a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/ExecutionQueueServiceImpl.java b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/ExecutionQueueServiceImpl.java index 2ac383696..672f4aa9b 100644 --- a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/ExecutionQueueServiceImpl.java +++ b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/ExecutionQueueServiceImpl.java @@ -21,6 +21,7 @@ package org.openecomp.appc.executionqueue.impl; +import java.time.Instant; import java.util.Calendar; import java.util.Date; import java.util.concurrent.TimeUnit; @@ -29,6 +30,7 @@ import org.openecomp.appc.exceptions.APPCException; import org.openecomp.appc.executionqueue.ExecutionQueueService; import org.openecomp.appc.executionqueue.MessageExpirationListener; import org.openecomp.appc.executionqueue.impl.object.QueueMessage; + import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -49,7 +51,7 @@ public class ExecutionQueueServiceImpl<M extends Runnable> implements ExecutionQ @Override public void putMessage(M message, long timeout, TimeUnit unit) throws APPCException{ try { - Date expirationTime = calculateExpirationTime(timeout,unit); + Instant expirationTime = calculateExpirationTime(timeout,unit); QueueManager queueManager = QueueManager.getInstance(); boolean enqueueTask = queueManager.enqueueTask(new QueueMessage<M>(message,expirationTime)); if(!enqueueTask){ @@ -66,15 +68,15 @@ public class ExecutionQueueServiceImpl<M extends Runnable> implements ExecutionQ QueueManager.getInstance().setListener(listener); } - private Date calculateExpirationTime(long timeToLive, TimeUnit unit) { - Date expirationTime = null; - if(timeToLive > 0){ - long currentTime = System.currentTimeMillis(); - Calendar cal = Calendar.getInstance(); - cal.setTimeInMillis(currentTime + unit.toMillis(timeToLive)); - expirationTime = cal.getTime(); + private Instant calculateExpirationTime(long timeToLive, TimeUnit unit) { + if (timeToLive > 0 && unit != null) { + // as of Java 8, there is no built-in conversion method from + // TimeUnit to ChronoUnit; do it manually + return Instant.now().plusMillis(unit.toMillis(timeToLive)); + } else { + // never expires + return Instant.MAX; } - return expirationTime; } } diff --git a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java index cf625b4d5..056bfda29 100644 --- a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java +++ b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java @@ -28,6 +28,7 @@ import java.util.concurrent.LinkedBlockingQueue; import org.openecomp.appc.executionqueue.MessageExpirationListener; import org.openecomp.appc.executionqueue.helper.Util; import org.openecomp.appc.executionqueue.impl.object.QueueMessage; + import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -69,7 +70,7 @@ public class QueueManager { while (true){ try{ QueueMessage<? extends Runnable> queueMessage = queue.take(); - if(messageExpired(queueMessage)){ + if (queueMessage.isExpired()) { logger.debug("Message expired "+ queueMessage.getMessage()); if(listener != null){ listener.onMessageExpiration(queueMessage.getMessage()); @@ -98,11 +99,4 @@ public class QueueManager { return queue.offer(queueMessage); } - private boolean messageExpired(QueueMessage<? extends Runnable> queueMessage) { - if(queueMessage.getExpirationTime() != null){ - return queueMessage.getExpirationTime().getTime() < System.currentTimeMillis(); - } - return false; - } - } diff --git a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/object/QueueMessage.java b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/object/QueueMessage.java index bbf805871..d3097e650 100644 --- a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/object/QueueMessage.java +++ b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/object/QueueMessage.java @@ -21,22 +21,23 @@ package org.openecomp.appc.executionqueue.impl.object; -import java.util.Date; +import java.time.Instant; +import java.util.Objects; public class QueueMessage<M extends Runnable> { - M message; - Date expirationTime; - public QueueMessage(M message, Date expirationTime){ + private final M message; + private final Instant expirationTime; + public QueueMessage(M message, Instant expirationTime){ this.message = message; - this.expirationTime = expirationTime; + this.expirationTime = Objects.requireNonNull(expirationTime); } public M getMessage() { return message; } - public Date getExpirationTime() { - return expirationTime; + public boolean isExpired() { + return expirationTime.isBefore(Instant.now()); } } diff --git a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/impl/TransactionRecorderImpl.java b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/impl/TransactionRecorderImpl.java index 74040d3e4..c5278e57c 100644 --- a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/impl/TransactionRecorderImpl.java +++ b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/impl/TransactionRecorderImpl.java @@ -54,10 +54,10 @@ public class TransactionRecorderImpl implements TransactionRecorder { } connection = DBUtils.getConnection(APPCCTL_SCHEMA); stmt = connection.prepareStatement(queryString); - stmt.setTimestamp(1, new java.sql.Timestamp(record.getTimeStamp().getTime())); + stmt.setTimestamp(1, new java.sql.Timestamp(record.getTimeStamp().toEpochMilli())); stmt.setString(2, record.getRequestID()); - stmt.setTimestamp(3, new java.sql.Timestamp(record.getStartTime().getTime())); - stmt.setTimestamp(4, new java.sql.Timestamp(record.getEndTime().getTime())); + stmt.setTimestamp(3, new java.sql.Timestamp(record.getStartTime().toEpochMilli())); + stmt.setTimestamp(4, new java.sql.Timestamp(record.getEndTime().toEpochMilli())); stmt.setString(5, record.getTargetID()); stmt.setString(6, record.getTargetType()); stmt.setString(7, record.getSubComponent()); diff --git a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/objects/TransactionRecord.java b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/objects/TransactionRecord.java index 4807aed0a..c2c662703 100644 --- a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/objects/TransactionRecord.java +++ b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/objects/TransactionRecord.java @@ -21,7 +21,7 @@ package org.openecomp.appc.transactionrecorder.objects; -import java.util.Date; +import java.time.Instant; public class TransactionRecord { @@ -38,10 +38,10 @@ public class TransactionRecord { - Result - Success/Error code + description,as published to the initiator RequestHandlerResponse.ACCEPTED/RequestHandlerResponse.REJECTED + String (description) */ - private Date timeStamp; + private Instant timeStamp; private String requestID; - private Date startTime; - private Date endTime; + private Instant startTime; + private Instant endTime; private String targetID; private String targetType; private String subComponent; @@ -49,11 +49,11 @@ public class TransactionRecord { private String resultCode; private String description; - public Date getTimeStamp() { + public Instant getTimeStamp() { return timeStamp; } - public void setTimeStamp(Date timeStamp) { + public void setTimeStamp(Instant timeStamp) { this.timeStamp = timeStamp; } @@ -65,19 +65,19 @@ public class TransactionRecord { this.requestID = requestID; } - public Date getStartTime() { + public Instant getStartTime() { return startTime; } - public void setStartTime(Date startTime) { + public void setStartTime(Instant startTime) { this.startTime = startTime; } - public Date getEndTime() { + public Instant getEndTime() { return endTime; } - public void setEndTime(Date endTime) { + public void setEndTime(Instant endTime) { this.endTime = endTime; } diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/conv/Converter.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/conv/Converter.java index 50c18d661..e72eb89a7 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/conv/Converter.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/conv/Converter.java @@ -227,7 +227,7 @@ public class Converter { } if(inObj.getCommonHeader().getTimeStamp() != null){ - String zuluTimestampStr = Converter.convDateToZuluString(inObj.getCommonHeader().getTimeStamp()); + String zuluTimestampStr = Converter.convDateToZuluString(Date.from(inObj.getCommonHeader().getTimeStamp())); ZULU zuluTimestamp = new ZULU(zuluTimestampStr); commonHeaderBuilder.setTimestamp(zuluTimestamp); } diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestHandlerImpl.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestHandlerImpl.java index 07a430671..0273c7957 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestHandlerImpl.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestHandlerImpl.java @@ -73,6 +73,8 @@ import org.slf4j.MDC; import static com.att.eelf.configuration.Configuration.*; import java.net.InetAddress; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -164,7 +166,7 @@ public class RequestHandlerImpl implements RequestHandler { logger.trace("Entering to handleRequest with RequestHandlerInput = " + ObjectUtils.toString(input) + ")"); Params params = null; String vnfId = null, vnfType = null, errorMessage = null; - Date startTime = new Date(System.currentTimeMillis()); + Instant startTime = Instant.now(); RequestHandlerOutput output = null; setInitialLogProperties(input.getRequestContext()); @@ -291,7 +293,7 @@ public class RequestHandlerImpl implements RequestHandler { transactionRecord.setTimeStamp(runtimeContext.getResponseContext().getCommonHeader().getTimeStamp()); transactionRecord.setRequestID(runtimeContext.getResponseContext().getCommonHeader().getRequestId()); transactionRecord.setStartTime(runtimeContext.getTimeStart()); - transactionRecord.setEndTime(new Date(System.currentTimeMillis())); + transactionRecord.setEndTime(Instant.now()); transactionRecord.setTargetID(runtimeContext.getVnfContext().getId()); transactionRecord.setTargetType(runtimeContext.getVnfContext().getType()); transactionRecord.setOperation(runtimeContext.getRequestContext().getAction().name()); @@ -509,7 +511,7 @@ public class RequestHandlerImpl implements RequestHandler { if (logger.isTraceEnabled()) { logger.trace("Entering to calculateRemainingTTL with RequestHeader = " + ObjectUtils.toString(commonHeader)); } - long usedTimeInMillis = (System.currentTimeMillis() - commonHeader.getTimeStamp().getTime()); + long usedTimeInMillis = ChronoUnit.MILLIS.between(commonHeader.getTimeStamp(), Instant.now()); logger.debug("usedTimeInMillis = " + usedTimeInMillis); int usedTimeInSeconds = Math.round(usedTimeInMillis / 1000); logger.debug("usedTimeInSeconds = " + usedTimeInSeconds); @@ -640,7 +642,7 @@ public class RequestHandlerImpl implements RequestHandler { private void storeAuditLogRecord(RuntimeContext runtimeContext) { LoggingUtils.logAuditMessage(runtimeContext.getTimeStart(), - new Date(System.currentTimeMillis()), + Instant.now(), String.valueOf(runtimeContext.getResponseContext().getStatus().getCode()), runtimeContext.getResponseContext().getStatus().getMessage(), this.getClass().getCanonicalName()); @@ -648,7 +650,7 @@ public class RequestHandlerImpl implements RequestHandler { private void storeMetricLogRecord(RuntimeContext runtimeContext) { LoggingUtils.logMetricsMessage(runtimeContext.getTimeStart(), - new Date(System.currentTimeMillis()), + Instant.now(), LoggingConstants.TargetNames.APPC, runtimeContext.getRequestContext().getAction().name(), runtimeContext.getResponseContext().getStatus().getCode() == LCMCommandStatus.ACCEPTED.getResponseCode() ? LoggingConstants.StatusCodes.COMPLETE : LoggingConstants.StatusCodes.ERROR, diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestValidatorImpl.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestValidatorImpl.java index 0871a8f97..509c351ea 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestValidatorImpl.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestValidatorImpl.java @@ -21,11 +21,17 @@ package org.openecomp.appc.requesthandler.impl; +import java.time.Instant; + import org.apache.commons.lang.ObjectUtils; import org.openecomp.appc.common.constant.Constants; import org.openecomp.appc.configuration.Configuration; import org.openecomp.appc.configuration.ConfigurationFactory; -import org.openecomp.appc.domainmodel.lcm.*; +import org.openecomp.appc.domainmodel.lcm.CommonHeader; +import org.openecomp.appc.domainmodel.lcm.RequestContext; +import org.openecomp.appc.domainmodel.lcm.RuntimeContext; +import org.openecomp.appc.domainmodel.lcm.VNFContext; +import org.openecomp.appc.domainmodel.lcm.VNFOperation; import org.openecomp.appc.executor.UnstableVNFException; import org.openecomp.appc.executor.objects.UniqueRequestIdentifier; import org.openecomp.appc.i18n.Msg; @@ -34,16 +40,18 @@ import org.openecomp.appc.lifecyclemanager.objects.LifecycleException; import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException; import org.openecomp.appc.logging.LoggingConstants; import org.openecomp.appc.logging.LoggingUtils; -import org.openecomp.appc.requesthandler.exceptions.*; +import org.openecomp.appc.requesthandler.exceptions.DGWorkflowNotFoundException; +import org.openecomp.appc.requesthandler.exceptions.DuplicateRequestException; +import org.openecomp.appc.requesthandler.exceptions.InvalidInputException; +import org.openecomp.appc.requesthandler.exceptions.RequestExpiredException; +import org.openecomp.appc.requesthandler.exceptions.VNFNotFoundException; +import org.openecomp.appc.requesthandler.exceptions.WorkflowNotFoundException; import org.openecomp.appc.requesthandler.helper.RequestRegistry; import org.openecomp.appc.requesthandler.helper.RequestValidator; import org.openecomp.appc.workflow.WorkFlowManager; import org.openecomp.appc.workflow.objects.WorkflowExistsOutput; import org.openecomp.appc.workflow.objects.WorkflowRequest; import org.openecomp.appc.workingstatemanager.WorkingStateManager; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.att.eelf.i18n.EELFResourceManager; import org.openecomp.sdnc.sli.SvcLogicContext; import org.openecomp.sdnc.sli.SvcLogicException; import org.openecomp.sdnc.sli.SvcLogicResource; @@ -52,8 +60,9 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; -import java.util.Calendar; -import java.util.Date; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.att.eelf.i18n.EELFResourceManager; public class RequestValidatorImpl implements RequestValidator { @@ -153,24 +162,24 @@ public class RequestValidatorImpl implements RequestValidator { checkForDuplicateRequest(commonHeader); - Calendar inputTimeStamp = DateToCalendar(commonHeader.getTimeStamp()); - Calendar currentTime = Calendar.getInstance(); + Instant inputTimeStamp = commonHeader.getTimeStamp(); + Instant currentTime = Instant.now(); // If input timestamp is of future, we reject the request - if (inputTimeStamp.getTime().getTime() > currentTime.getTime().getTime()) { + if (inputTimeStamp.isAfter(currentTime)) { if (logger.isDebugEnabled()) { - logger.debug("Input Timestamp is of future = " + inputTimeStamp.getTime()); + logger.debug("Input Timestamp is of future = " + inputTimeStamp); } - throw new InvalidInputException("Input Timestamp is of future = " + inputTimeStamp.getTime()); + throw new InvalidInputException("Input Timestamp is of future = " + inputTimeStamp); } - Integer ttl = readTTL(commonHeader); + int ttl = readTTL(commonHeader); logger.debug("TTL value set to (seconds) : " + ttl); - inputTimeStamp.add(Calendar.SECOND, ttl); - if (currentTime.getTime().getTime() >= inputTimeStamp.getTime().getTime()) { + Instant expirationTime = inputTimeStamp.plusSeconds(ttl); + if (currentTime.isAfter(expirationTime)) { LoggingUtils.logErrorMessage( LoggingConstants.TargetNames.REQUEST_VALIDATOR, - "TTL Expired: Current time - " + currentTime.getTime().getTime() + " Request time: " + inputTimeStamp.getTime().getTime() + " with TTL value: " + ttl, + "TTL Expired: Current time - " + currentTime + " Request time: " + expirationTime + " with TTL value: " + ttl, this.getClass().getCanonicalName()); throw new RequestExpiredException("TTL Expired"); @@ -181,12 +190,6 @@ public class RequestValidatorImpl implements RequestValidator { } - private static Calendar DateToCalendar(Date date) { - Calendar cal = Calendar.getInstance(); - cal.setTime(date); - return cal; - } - // TODO: Get reference once via Blueprint and get rid of this method private void getAAIservice() { BundleContext bctx = FrameworkUtil.getBundle(AAIService.class).getBundleContext(); @@ -321,14 +324,13 @@ public class RequestValidatorImpl implements RequestValidator { } - private Integer readTTL(CommonHeader header) { + private int readTTL(CommonHeader header) { if (logger.isTraceEnabled()) { logger.trace("Entering to readTTL with RequestHandlerInput = "+ ObjectUtils.toString(header)); } if (header.getFlags()== null || !isValidTTL(String.valueOf(header.getFlags().getTtl()))) { String defaultTTLStr = configuration.getProperty("org.openecomp.appc.workflow.default.ttl", String.valueOf(Constants.DEFAULT_TTL)); - Integer defaultTTL = Integer.parseInt(defaultTTLStr); - return defaultTTL; + return Integer.parseInt(defaultTTLStr); } if (logger.isTraceEnabled()) { logger.trace("Exiting from readTTL with (TTL = "+ ObjectUtils.toString(header.getFlags().getTtl())+")"); @@ -345,9 +347,9 @@ public class RequestValidatorImpl implements RequestValidator { String key = "vnf-id = '" + vnf_id + "'"; logger.debug("inside getVnfdata=== " + key); try { - Date beginTimestamp = new Date(); + Instant beginTimestamp = Instant.now(); SvcLogicResource.QueryStatus response = aaiService.query("generic-vnf", false, null, key, prefix, null, ctx); - Date endTimestamp = new Date(); + Instant endTimestamp = Instant.now(); String status = SvcLogicResource.QueryStatus.SUCCESS.equals(response) ? LoggingConstants.StatusCodes.COMPLETE : LoggingConstants.StatusCodes.ERROR; LoggingUtils.logMetricsMessage( beginTimestamp, diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestConverter.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestConverter.java index 87fda3930..c54f94750 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestConverter.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestConverter.java @@ -30,6 +30,7 @@ import org.openecomp.appc.requesthandler.conv.Converter; import javax.ws.rs.container.AsyncResponse; import java.text.ParseException; +import java.time.Instant; import java.util.Date; import java.util.HashMap; @@ -328,7 +329,7 @@ public class TestConverter { asyncResponse.getCommonHeader().setOriginatorId("oid"); asyncResponse.getCommonHeader().setApiVer("2.0.0"); asyncResponse.getCommonHeader().setRequestId("reqid"); - asyncResponse.getCommonHeader().setTimestamp(new Date(1000L)); + asyncResponse.getCommonHeader().setTimestamp(Instant.ofEpochMilli(1000L)); asyncResponse.setPayload("any valid JSON string value. Json escape characters need to be added to make it a valid json string value"); return asyncResponse; } diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestRequestHandler.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestRequestHandler.java index 0c7ded71a..1af658f0a 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestRequestHandler.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestRequestHandler.java @@ -21,14 +21,32 @@ package org.openecomp.appc.requesthandler; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.powermock.api.mockito.PowerMockito.when; + +import java.time.Instant; +import java.util.HashMap; +import java.util.UUID; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Matchers; import org.mockito.Mockito; -import org.openecomp.appc.domainmodel.lcm.*; -import org.openecomp.appc.domainmodel.lcm.Flags.Mode; +import org.openecomp.appc.domainmodel.lcm.ActionIdentifiers; +import org.openecomp.appc.domainmodel.lcm.CommonHeader; +import org.openecomp.appc.domainmodel.lcm.Flags; +import org.openecomp.appc.domainmodel.lcm.RequestContext; +import org.openecomp.appc.domainmodel.lcm.ResponseContext; +import org.openecomp.appc.domainmodel.lcm.RuntimeContext; +import org.openecomp.appc.domainmodel.lcm.Status; +import org.openecomp.appc.domainmodel.lcm.VNFContext; +import org.openecomp.appc.domainmodel.lcm.VNFOperation; import org.openecomp.appc.executor.CommandExecutor; import org.openecomp.appc.executor.UnstableVNFException; import org.openecomp.appc.executor.objects.LCMCommandStatus; @@ -38,7 +56,12 @@ import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException; import org.openecomp.appc.lockmanager.api.LockException; import org.openecomp.appc.lockmanager.api.LockManager; import org.openecomp.appc.messageadapter.MessageAdapter; -import org.openecomp.appc.requesthandler.exceptions.*; +import org.openecomp.appc.requesthandler.exceptions.DGWorkflowNotFoundException; +import org.openecomp.appc.requesthandler.exceptions.DuplicateRequestException; +import org.openecomp.appc.requesthandler.exceptions.InvalidInputException; +import org.openecomp.appc.requesthandler.exceptions.RequestExpiredException; +import org.openecomp.appc.requesthandler.exceptions.VNFNotFoundException; +import org.openecomp.appc.requesthandler.exceptions.WorkflowNotFoundException; import org.openecomp.appc.requesthandler.impl.RequestHandlerImpl; import org.openecomp.appc.requesthandler.impl.RequestValidatorImpl; import org.openecomp.appc.requesthandler.objects.RequestHandlerInput; @@ -50,18 +73,13 @@ import org.openecomp.appc.workflow.objects.WorkflowExistsOutput; import org.openecomp.appc.workflow.objects.WorkflowRequest; import org.openecomp.appc.workingstatemanager.WorkingStateManager; import org.openecomp.appc.workingstatemanager.objects.VNFWorkingState; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.osgi.framework.FrameworkUtil; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import java.util.*; -import static org.mockito.Matchers.*; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; @RunWith(PowerMockRunner.class) @PrepareForTest( {WorkingStateManager.class,FrameworkUtil.class, TransactionRecorder.class, RequestHandlerImpl.class,RequestValidatorImpl.class, TransactionRecorder.class}) @@ -131,7 +149,7 @@ public class TestRequestHandler { logger.debug("=====================testNegativeFlowWithRequestingUsedVnfId============================="); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); RequestHandlerInput input1 = this.getRequestHandlerInput("131", VNFOperation.Configure, 1200, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); mockRuntimeContextAndVnfContext(input1); PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); PowerMockito.doThrow(new LockException(" ")).when(lockManager).acquireLock(Matchers.anyString(), Matchers.anyString(), Matchers.anyByte()); @@ -149,7 +167,7 @@ public class TestRequestHandler { String subRequestID = UUID.randomUUID().toString(); PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); - RequestHandlerInput input = this.getRequestHandlerInput("3009", VNFOperation.Configure, 0,false,originatorID, requestID, subRequestID,new Date()); + RequestHandlerInput input = this.getRequestHandlerInput("3009", VNFOperation.Configure, 0,false,originatorID, requestID, subRequestID, Instant.now()); PowerMockito.doThrow(new VNFNotFoundException(" ")).when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); RequestHandlerOutput output = requestHandler.handleRequest(input); Assert.assertEquals(LCMCommandStatus.VNF_NOT_FOUND.getResponseCode(), output.getResponseContext().getStatus().getCode()); @@ -162,7 +180,7 @@ public class TestRequestHandler { String subRequestID = UUID.randomUUID().toString(); PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); - RequestHandlerInput input = this.getRequestHandlerInput("3009", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date()); + RequestHandlerInput input = this.getRequestHandlerInput("3009", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now()); PowerMockito.doThrow(new LifecycleException(new Exception(),"Configured","test event")).when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); RequestHandlerOutput output = requestHandler.handleRequest(input); Assert.assertEquals(LCMCommandStatus.ACTION_NOT_SUPPORTED.getResponseCode(), output.getResponseContext().getStatus().getCode()); @@ -175,7 +193,7 @@ public class TestRequestHandler { String requestID = UUID.randomUUID().toString(); String subRequestID = UUID.randomUUID().toString(); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); - RequestHandlerInput input = this.getRequestHandlerInput("3009", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date()); + RequestHandlerInput input = this.getRequestHandlerInput("3009", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now()); PowerMockito.doThrow(new RequestExpiredException("")).when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); RequestHandlerOutput output = requestHandler.handleRequest(input); Assert.assertEquals(LCMCommandStatus.EXPIRED_REQUEST.getResponseCode(), output.getResponseContext().getStatus().getCode()); @@ -188,7 +206,7 @@ public class TestRequestHandler { String subRequestID = UUID.randomUUID().toString(); PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); - RequestHandlerInput input = this.getRequestHandlerInput("3009", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date()); + RequestHandlerInput input = this.getRequestHandlerInput("3009", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now()); PowerMockito.doThrow(new WorkflowNotFoundException("Unable to find the DG","VNF-2.0.0.0", "Test")).when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); RequestHandlerOutput output = requestHandler.handleRequest(input); Assert.assertEquals(LCMCommandStatus.WORKFLOW_NOT_FOUND.getResponseCode(), output.getResponseContext().getStatus().getCode());} @@ -199,7 +217,7 @@ public class TestRequestHandler { String requestID = UUID.randomUUID().toString(); String subRequestID = UUID.randomUUID().toString(); Mockito.when(workflowManager.workflowExists((WorkflowRequest) anyObject())).thenReturn(new WorkflowExistsOutput(true, true)); - RequestHandlerInput input = this.getRequestHandlerInput("3009", VNFOperation.Configure, 0, false, originatorID, requestID, subRequestID, new Date()); + RequestHandlerInput input = this.getRequestHandlerInput("3009", VNFOperation.Configure, 0, false, originatorID, requestID, subRequestID, Instant.now()); PowerMockito.doThrow(new DGWorkflowNotFoundException("Unable to find the DG", "VNF-2.0.0.0", "temp", "Test")).when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); RequestHandlerOutput output = requestHandler.handleRequest(input); Assert.assertEquals(LCMCommandStatus.DG_WORKFLOW_NOT_FOUND.getResponseCode(), output.getResponseContext().getStatus().getCode()); @@ -211,7 +229,7 @@ public class TestRequestHandler { String requestID1 = UUID.randomUUID().toString(); String subRequestID1 = UUID.randomUUID().toString(); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); - RequestHandlerInput input1 = this.getRequestHandlerInput("3009", VNFOperation.Configure,0,false,originatorID1, requestID1, subRequestID1,new Date()); + RequestHandlerInput input1 = this.getRequestHandlerInput("3009", VNFOperation.Configure,0,false,originatorID1, requestID1, subRequestID1, Instant.now()); PowerMockito.doThrow(new InvalidInputException(" ")).when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); RequestHandlerOutput output1 = requestHandler.handleRequest(input1); Assert.assertEquals(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode(), output1.getResponseContext().getStatus().getCode()); @@ -224,7 +242,7 @@ public class TestRequestHandler { String subRequestID = UUID.randomUUID().toString(); PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); - RequestHandlerInput input = this.getRequestHandlerInput("3010", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date()); + RequestHandlerInput input = this.getRequestHandlerInput("3010", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now()); PowerMockito.doThrow(new NoTransitionDefinedException("Invalid VNF State","Unstable","Test event")).when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); RequestHandlerOutput output = requestHandler.handleRequest(input); Assert.assertEquals(LCMCommandStatus.NO_TRANSITION_DEFINE.getResponseCode(), output.getResponseContext().getStatus().getCode()); @@ -237,7 +255,7 @@ public class TestRequestHandler { String subRequestID = UUID.randomUUID().toString(); PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); - RequestHandlerInput input = this.getRequestHandlerInput("3009", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date()); + RequestHandlerInput input = this.getRequestHandlerInput("3009", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now()); PowerMockito.doThrow(new VNFNotFoundException(" ")).when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); RequestHandlerOutput output = requestHandler.handleRequest(input); Assert.assertEquals(LCMCommandStatus.VNF_NOT_FOUND.getResponseCode(), output.getResponseContext().getStatus().getCode()); @@ -249,7 +267,7 @@ public class TestRequestHandler { Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); Mockito.when(workingStateManager.isVNFStable("37")).thenReturn(true,false); RequestHandlerInput input = this.getRequestHandlerInput("37", VNFOperation.Configure, 1200, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); mockRuntimeContextAndVnfContext(input); RequestHandlerOutput output = requestHandler.handleRequest(input); @@ -257,7 +275,7 @@ public class TestRequestHandler { Assert.assertEquals(LCMCommandStatus.ACCEPTED.getResponseCode(), output.getResponseContext().getStatus().getCode()); RequestHandlerInput input1 = this.getRequestHandlerInput("37", VNFOperation.Configure,1200, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); PowerMockito.doThrow(new LockException(" ")).when(lockManager).acquireLock(Matchers.anyString(), Matchers.anyString(), Matchers.anyByte()); mockRuntimeContextAndVnfContext(input1); RequestHandlerOutput output1 = requestHandler.handleRequest(input1); @@ -271,7 +289,7 @@ public class TestRequestHandler { logger.debug("=====================testOnRequestExecutionEndSuccessForWorkingState============================="); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); RequestHandlerInput input1 = this.getRequestHandlerInput("137", VNFOperation.Configure, 1200, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); mockRuntimeContextAndVnfContext(input1); PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); @@ -284,7 +302,7 @@ public class TestRequestHandler { requestHandler.onRequestExecutionEnd(this.getAsyncResponse(true,LCMCommandStatus.SUCCESS,"137", "", "", ""),true); input1 = this.getRequestHandlerInput("137", VNFOperation.Configure, 1200, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); mockRuntimeContextAndVnfContext(input1); output = requestHandler.handleRequest(input1); Assert.assertEquals(LCMCommandStatus.ACCEPTED.getResponseCode(),output.getResponseContext().getStatus().getCode()); @@ -322,7 +340,7 @@ public class TestRequestHandler { PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); RequestHandlerInput input1 = this.getRequestHandlerInput("38", VNFOperation.Configure, 1200, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); mockRuntimeContextAndVnfContext(input1); RequestHandlerOutput output = requestHandler.handleRequest(input1); Assert.assertEquals(LCMCommandStatus.ACCEPTED.getResponseCode(),output.getResponseContext().getStatus().getCode()); @@ -330,7 +348,7 @@ public class TestRequestHandler { requestHandler.onRequestExecutionEnd(this.getAsyncResponse(false,LCMCommandStatus.NO_TRANSITION_DEFINE,"38", "", "", ""),true); input1 = this.getRequestHandlerInput("38", VNFOperation.Configure, 1200, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); PowerMockito.doThrow(new UnstableVNFException(" ")).when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); mockRuntimeContextAndVnfContext(input1); output = requestHandler.handleRequest(input1); @@ -345,7 +363,7 @@ public class TestRequestHandler { Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); RequestHandlerInput input1 = this.getRequestHandlerInput("39", VNFOperation.Configure, 1, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); mockRuntimeContextAndVnfContext(input1); @@ -354,7 +372,7 @@ public class TestRequestHandler { Assert.assertEquals(LCMCommandStatus.ACCEPTED.getResponseCode(),output.getResponseContext().getStatus().getCode()); threadSleep(); input1 = this.getRequestHandlerInput("39", VNFOperation.Configure, 1200, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); PowerMockito.doThrow(new LockException(" ")).when(lockManager).acquireLock(Matchers.anyString(), Matchers.anyString(), Matchers.anyByte()); output = requestHandler.handleRequest(input1); Assert.assertEquals(LCMCommandStatus.LOCKING_FAILURE.getResponseCode(),output.getResponseContext().getStatus().getCode()); @@ -369,7 +387,7 @@ public class TestRequestHandler { PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); RequestHandlerInput input1 = this.getRequestHandlerInput("40", VNFOperation.Configure, 1200, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); mockRuntimeContextAndVnfContext(input1); RequestHandlerOutput output = requestHandler.handleRequest(input1); Assert.assertEquals(LCMCommandStatus.ACCEPTED.getResponseCode(),output.getResponseContext().getStatus().getCode()); @@ -377,7 +395,7 @@ public class TestRequestHandler { RuntimeContext response = this.getAsyncResponse(false,LCMCommandStatus.EXPIRED_REQUEST_FAILURE,"40", "", "", ""); requestHandler.onRequestTTLEnd(response,true); input1 = this.getRequestHandlerInput("40", VNFOperation.Configure, 1200, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); PowerMockito.doThrow(new UnstableVNFException(" ")).when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); output = requestHandler.handleRequest(input1); Assert.assertEquals(LCMCommandStatus.UNSTABLE_VNF.getResponseCode(),output.getResponseContext().getStatus().getCode()); @@ -389,7 +407,7 @@ public class TestRequestHandler { logger.debug("=====================testForceCommandExecution============================="); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); RequestHandlerInput input1 = this.getRequestHandlerInput("138", VNFOperation.Configure, 1200, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); mockRuntimeContextAndVnfContext(input1); PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); @@ -399,7 +417,7 @@ public class TestRequestHandler { RuntimeContext response = this.getAsyncResponse(false,LCMCommandStatus.ACCEPTED,"138", "", "", ""); requestHandler.onRequestTTLEnd(response,true); input1 = this.getRequestHandlerInput("138", VNFOperation.Configure, 1200, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); input1.getRequestContext().getCommonHeader().setFlags(new Flags(null, true, 1200)); mockRuntimeContextAndVnfContext(input1); output = requestHandler.handleRequest(input1); @@ -423,7 +441,7 @@ public class TestRequestHandler { logger.debug("=====================Positive TEST - On Request Execution End FAILURE- Ends ============================="); } - private RequestHandlerInput getRequestHandlerInput(String vnfID, VNFOperation action, int ttl, boolean force,String originatorId, String requestId, String subRequestId,Date timeStamp){ + private RequestHandlerInput getRequestHandlerInput(String vnfID, VNFOperation action, int ttl, boolean force,String originatorId, String requestId, String subRequestId, Instant timeStamp){ String API_VERSION= "2.0.0"; RequestHandlerInput input = new RequestHandlerInput(); RuntimeContext runtimeContext = createRuntimeContextWithSubObjects(); @@ -449,9 +467,9 @@ public class TestRequestHandler { output.getRequestContext().getActionIdentifiers().setVnfId(vnfId); output.getVnfContext().setId(vnfId); output.getResponseContext().getCommonHeader().setApiVer("2.0.0"); - output.getResponseContext().getCommonHeader().setTimestamp(new Date()); + output.getResponseContext().getCommonHeader().setTimestamp( Instant.now()); output.getResponseContext().setStatus(LCMCommandStatus.SUCCESS.toStatus(null)); - output.setTimeStart(new Date()); + output.setTimeStart( Instant.now()); output.getResponseContext().getCommonHeader().setOriginatorId(originatorId); output.getResponseContext().getCommonHeader().setRequestId(requestId); output.getResponseContext().getCommonHeader().setSubRequestId(subRequestId); @@ -471,13 +489,13 @@ public class TestRequestHandler { PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); - RequestHandlerInput input = this.getRequestHandlerInput("301", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date()); + RequestHandlerInput input = this.getRequestHandlerInput("301", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now()); mockRuntimeContextAndVnfContext(input); RequestHandlerOutput output = requestHandler.handleRequest(input); Assert.assertEquals(LCMCommandStatus.ACCEPTED.getResponseCode(), output.getResponseContext().getStatus().getCode()); - input = this.getRequestHandlerInput("309", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date()); + input = this.getRequestHandlerInput("309", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now()); PowerMockito.doThrow(new DuplicateRequestException(" ")).when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); output = requestHandler.handleRequest(input); @@ -492,7 +510,7 @@ public class TestRequestHandler { PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); - RequestHandlerInput input = this.getRequestHandlerInput("302", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date()); + RequestHandlerInput input = this.getRequestHandlerInput("302", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now()); mockRuntimeContextAndVnfContext(input); RequestHandlerOutput output = requestHandler.handleRequest(input); @@ -501,7 +519,7 @@ public class TestRequestHandler { RuntimeContext asyncResponse = this.getAsyncResponse(true,LCMCommandStatus.SUCCESS,"302",originatorID,requestID,subRequestID); requestHandler.onRequestExecutionEnd(asyncResponse,true); - input = this.getRequestHandlerInput("310", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date()); + input = this.getRequestHandlerInput("310", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now()); mockRuntimeContextAndVnfContext(input); output = requestHandler.handleRequest(input); Assert.assertEquals(LCMCommandStatus.ACCEPTED.getResponseCode(), output.getResponseContext().getStatus().getCode()); @@ -516,7 +534,7 @@ public class TestRequestHandler { PowerMockito.doNothing().when(requestValidator).validateRequest(Matchers.any(RuntimeContext.class)); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); - RequestHandlerInput input = this.getRequestHandlerInput("303", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date()); + RequestHandlerInput input = this.getRequestHandlerInput("303", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now()); mockRuntimeContextAndVnfContext(input); RequestHandlerOutput output = requestHandler.handleRequest(input); Assert.assertEquals(LCMCommandStatus.ACCEPTED.getResponseCode(), output.getResponseContext().getStatus().getCode()); diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestRequestValidator.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestRequestValidator.java index 1298aa542..f4d703756 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestRequestValidator.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/openecomp/appc/requesthandler/TestRequestValidator.java @@ -22,20 +22,43 @@ package org.openecomp.appc.requesthandler; +import static junit.framework.TestCase.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; + +import java.time.Instant; +import java.util.Map; +import java.util.UUID; + import org.junit.Before; -import org.junit.Test; import org.junit.Ignore; +import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import org.openecomp.appc.domainmodel.lcm.*; -import org.openecomp.appc.domainmodel.lcm.Flags.Mode; +import org.openecomp.appc.domainmodel.lcm.ActionIdentifiers; +import org.openecomp.appc.domainmodel.lcm.CommonHeader; +import org.openecomp.appc.domainmodel.lcm.Flags; +import org.openecomp.appc.domainmodel.lcm.RequestContext; +import org.openecomp.appc.domainmodel.lcm.ResponseContext; +import org.openecomp.appc.domainmodel.lcm.RuntimeContext; +import org.openecomp.appc.domainmodel.lcm.Status; +import org.openecomp.appc.domainmodel.lcm.VNFContext; +import org.openecomp.appc.domainmodel.lcm.VNFOperation; import org.openecomp.appc.executor.UnstableVNFException; import org.openecomp.appc.lifecyclemanager.LifecycleManager; import org.openecomp.appc.lifecyclemanager.objects.LifecycleException; import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException; -import org.openecomp.appc.requesthandler.exceptions.*; +import org.openecomp.appc.requesthandler.exceptions.DGWorkflowNotFoundException; +import org.openecomp.appc.requesthandler.exceptions.DuplicateRequestException; +import org.openecomp.appc.requesthandler.exceptions.InvalidInputException; +import org.openecomp.appc.requesthandler.exceptions.RequestExpiredException; +import org.openecomp.appc.requesthandler.exceptions.VNFNotFoundException; +import org.openecomp.appc.requesthandler.exceptions.WorkflowNotFoundException; import org.openecomp.appc.requesthandler.impl.RequestHandlerImpl; import org.openecomp.appc.requesthandler.impl.RequestValidatorImpl; import org.openecomp.appc.requesthandler.objects.RequestHandlerInput; @@ -44,8 +67,6 @@ import org.openecomp.appc.workflow.WorkFlowManager; import org.openecomp.appc.workflow.objects.WorkflowExistsOutput; import org.openecomp.appc.workflow.objects.WorkflowRequest; import org.openecomp.appc.workingstatemanager.WorkingStateManager; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.openecomp.sdnc.sli.SvcLogicContext; import org.openecomp.sdnc.sli.SvcLogicResource; import org.openecomp.sdnc.sli.aai.AAIService; @@ -57,13 +78,8 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import java.util.Date; -import java.util.Map; -import java.util.UUID; - -import static junit.framework.TestCase.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.*; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; @RunWith(PowerMockRunner.class) @@ -214,7 +230,7 @@ public class TestRequestValidator { genericVnf.setOrchestrationStatus(operationalState); return genericVnf; }*/ - private RequestHandlerInput getRequestHandlerInput(String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Date timeStamp){ + private RequestHandlerInput getRequestHandlerInput(String vnfID, VNFOperation action, int ttl, boolean force, String originatorId, String requestId, String subRequestId, Instant timeStamp){ String API_VERSION= "2.0.0"; RequestHandlerInput input = new RequestHandlerInput(); RuntimeContext runtimeContext = createRuntimeContextWithSubObjects(); @@ -242,7 +258,7 @@ public class TestRequestValidator { logger.debug("=====================testNullVnfID============================="); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); RequestHandlerInput input = this.getRequestHandlerInput(null, VNFOperation.Configure, 30, - false, UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false, UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); try { @@ -261,7 +277,7 @@ public class TestRequestValidator { Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); Mockito.when(workingStateManager.isVNFStable("1")).thenReturn(true); RequestHandlerInput input = this.getRequestHandlerInput("1", VNFOperation.Configure, 30, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); try { @@ -279,7 +295,7 @@ public class TestRequestValidator { logger.debug("=====================testVnfNotFound============================="); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); RequestHandlerInput input = this.getRequestHandlerInput("8", VNFOperation.Configure, 30, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); try { @@ -298,7 +314,7 @@ public class TestRequestValidator { logger.debug("=====================testNullCommand============================="); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); RequestHandlerInput input = this.getRequestHandlerInput("7", null,30, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); try { @@ -315,7 +331,7 @@ public class TestRequestValidator { logger.debug("=====================testNullVnfIDAndCommand============================="); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); RequestHandlerInput input = this.getRequestHandlerInput(null, null,30, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); try { @@ -332,7 +348,7 @@ public class TestRequestValidator { logger.debug("=====================testWorkflowNotFound============================="); Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(false,false)); RequestHandlerInput input = this.getRequestHandlerInput("10", VNFOperation.Configure, 30, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); try { @@ -351,7 +367,7 @@ public class TestRequestValidator { Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","","")); RequestHandlerInput input = this.getRequestHandlerInput("11", VNFOperation.Configure, 30, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); try { @@ -369,7 +385,7 @@ public class TestRequestValidator { Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","","")); RequestHandlerInput input = this.getRequestHandlerInput("12", VNFOperation.Test,30, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); try { @@ -387,7 +403,7 @@ public class TestRequestValidator { Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","","")); RequestHandlerInput input = this.getRequestHandlerInput("13", VNFOperation.Start,30, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); try { @@ -404,7 +420,7 @@ public class TestRequestValidator { logger.debug("=====================testUnstableVnfWithTerminate============================="); Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","","")); RequestHandlerInput input = this.getRequestHandlerInput("14", VNFOperation.Terminate,30, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); try { @@ -422,7 +438,7 @@ public class TestRequestValidator { Mockito.when(lifecyclemanager.getNextState(anyString(), anyString(),anyString())).thenThrow( new NoTransitionDefinedException("","","")); RequestHandlerInput input = this.getRequestHandlerInput("26", VNFOperation.Restart,30, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); try { @@ -441,7 +457,7 @@ public class TestRequestValidator { // Mockito.doReturn(this.getGenericVnf("Firewall", "NOT_INSTANTIATED")).when(getAaiadapter()).requestGenericVnfData("8"); RequestHandlerInput input = this.getRequestHandlerInput("27", VNFOperation.Rebuild,30, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); try { @@ -463,7 +479,7 @@ public class TestRequestValidator { // RequestHandler requestHandler=RequestHandlerSingleton.getRequestHandler(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl()); // RequestHandler requestHandler = new RequestHandlerImpl(new WorkFlowManagerImpl(),aaiAdapter,new LifecycleManagerImpl()); RequestHandlerInput input = this.getRequestHandlerInput("28", VNFOperation.Configure, 30, - false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),new Date()); + false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(), Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); try { @@ -479,9 +495,8 @@ public class TestRequestValidator { @Test public void testNegativeFlowWithTimeStamp() throws NoTransitionDefinedException, LifecycleException, InvalidInputException, RequestExpiredException, UnstableVNFException, DuplicateRequestException, VNFNotFoundException, WorkflowNotFoundException,DGWorkflowNotFoundException { logger.debug("=====================testNegativeFlowWithTimeStamp============================="); - Date now = new Date(); - Date past = new Date(); - past.setTime(now.getTime() -1000000 ); + Instant now = Instant.now(); + Instant past = now.minusMillis(1000000); RequestHandlerInput input = this.getRequestHandlerInput("35", VNFOperation.Configure, 30, false,UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString(),past); Exception ex =null; @@ -507,9 +522,9 @@ public class TestRequestValidator { Mockito.when(workflowManager.workflowExists((WorkflowRequest)anyObject())).thenReturn(new WorkflowExistsOutput(true,true)); Mockito.when(workingStateManager.isVNFStable("301")).thenReturn(true); Mockito.when(workingStateManager.isVNFStable("309")).thenReturn(true); - RequestHandlerInput input = this.getRequestHandlerInput("301", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date()); + RequestHandlerInput input = this.getRequestHandlerInput("301", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now()); - RequestHandlerInput input1 = this.getRequestHandlerInput("309", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID,new Date()); + RequestHandlerInput input1 = this.getRequestHandlerInput("309", VNFOperation.Configure,0,false,originatorID, requestID, subRequestID, Instant.now()); Exception ex =null; RuntimeContext runtimeContext = putInputToRuntimeContext(input); RuntimeContext runtimeContext1 = putInputToRuntimeContext(input1); @@ -573,7 +588,7 @@ public class TestRequestValidator { String requestID = UUID.randomUUID().toString(); String subRequestID = UUID.randomUUID().toString(); - RequestHandlerInput input = this.getRequestHandlerInput(resource, operation, 0, false, originatorID, requestID, subRequestID, new Date()); + RequestHandlerInput input = this.getRequestHandlerInput(resource, operation, 0, false, originatorID, requestID, subRequestID, Instant.now()); RuntimeContext runtimeContext = putInputToRuntimeContext(input); requestValidator.validateRequest(runtimeContext); } diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/lcm/util/RequestInputBuilder.java b/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/lcm/util/RequestInputBuilder.java index f45748de2..248492df8 100644 --- a/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/lcm/util/RequestInputBuilder.java +++ b/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/lcm/util/RequestInputBuilder.java @@ -92,7 +92,7 @@ public class RequestInputBuilder { if(null != commonHeader.getTimestamp()) { SimpleDateFormat format = new SimpleDateFormat(FORMAT); format.setLenient(false); - header.setTimestamp(format.parse(commonHeader.getTimestamp().getValue())); + header.setTimestamp(format.parse(commonHeader.getTimestamp().getValue()).toInstant()); }else{ throw new ParseException("Missing mandatory parameter : timestamp " , 0); } |