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 {
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),
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),
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") ?
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);
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);
}
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() {
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;
}
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();
+ return ChronoUnit.MILLIS.between(Instant.now(), requestTimestamp.plusSeconds(ttl));
}
private CommandTask getMessageExecutor(String action){
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;
@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);
}
@Test
public void testRunGetConfig(){
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
LCMReadonlyCommandTask.setCommandRequest(request);
LCMReadonlyCommandTask.run();
}
@Test
public void testRun(){
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
executionTask.setCommandRequest(request);
executionTask.run();
}
@Test
public void testRunNegative(){
- RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", new Date(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
+ RuntimeContext request = pouplateCommandExecutorInput("FIREWALL", 30, "1.0", Instant.now(), API_VERSION, "11", ORIGINATOR_ID, "", VNFOperation.Sync, "1", "");
executionTask.setCommandRequest(request);
executionTask.run();
}
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;
}
@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", "");
}
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();
*/
+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;
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 {
@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) {
@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) {
}
- 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));
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;
this.flags = flags;
}
- public Date getTimeStamp() {
+ public Instant getTimeStamp() {
return timestamp;
}
- public void setTimestamp(Date timestamp) {
+ public void setTimestamp(Instant timestamp) {
this.timestamp = timestamp;
}
package org.openecomp.appc.domainmodel.lcm;
+import java.time.Instant;
import java.util.Date;
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;
this.rpcName = rpcName;
}
- public Date getTimeStart() {
+ public Instant getTimeStart() {
return timeStart;
}
this.isLockAcquired = isLockAcquired;
}
- public void setTimeStart(Date timeStart) {
+ public void setTimeStart(Instant timeStart) {
this.timeStart = timeStart;
}
package org.openecomp.appc.executionqueue.impl;
+import java.time.Instant;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;
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;
@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){
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;
}
}
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;
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());
return queue.offer(queueMessage);
}
- private boolean messageExpired(QueueMessage<? extends Runnable> queueMessage) {
- if(queueMessage.getExpirationTime() != null){
- return queueMessage.getExpirationTime().getTime() < System.currentTimeMillis();
- }
- return false;
- }
-
}
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());
}
}
}
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());
package org.openecomp.appc.transactionrecorder.objects;
-import java.util.Date;
+import java.time.Instant;
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;
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;
}
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;
}
}
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);
}
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;
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());
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());
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);
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());
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,
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;
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;
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 {
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");
}
- 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();
}
- 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())+")");
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,
import javax.ws.rs.container.AsyncResponse;
import java.text.ParseException;
+import java.time.Instant;
import java.util.Date;
import java.util.HashMap;
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;
}
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;
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;
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})
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());
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());
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());
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());
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());}
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());
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());
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());
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());
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);
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);
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));
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());
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());
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);
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);
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());
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());
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());
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));
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);
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();
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);
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);
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);
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());
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());
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;
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;
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)
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();
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
// 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 {
// 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 {
@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;
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);
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);
}
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);
}