summaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main
diff options
context:
space:
mode:
authorGary Wu <gary.i.wu@huawei.com>2017-05-08 12:59:44 -0700
committerPatrick Brady <pb071s@att.com>2017-05-16 18:13:41 +0000
commit753cb638fcb58f355f2c979e9e0a43cba2832984 (patch)
tree55526dce196663d6c5c4265e504882e3deec2cc2 /appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main
parentf16391cacb2e91063bbe9ad66cb2310855c93695 (diff)
Migrate to Java 8 Time API
Migrate the uses of the old Date class in CommonHeader, RuntimeContext, QueueMessage, and TransactionRecord to Java 8 Time API. Change-Id: I3b0c18b2e63cdab06e37587d2010cb7f626a0396 Signed-off-by: Gary Wu <gary.i.wu@huawei.com>
Diffstat (limited to 'appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main')
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/conv/Converter.java2
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestHandlerImpl.java12
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestValidatorImpl.java56
3 files changed, 37 insertions, 33 deletions
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,