aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-02-26 16:11:04 +0100
committerPatrick Brady <pb071s@att.com>2018-03-01 08:30:39 +0000
commit1e65cff150f78124da0a7d2df84d1e92fbd00ac3 (patch)
tree3ba2a3bf4a0a036ae44176e0af49dbe047b3ef00 /appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org
parentdd4f9dd3da8f74dd14c2eb92a138f90a47f3f079 (diff)
appc-dg-common sonar fixes part 2
Sonar fixes in whole module Change-Id: I9d2d7f092fc44217c794ea3a4d4b12b1ad641ff0 Issue-ID: APPC-673 Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Diffstat (limited to 'appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org')
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolver.java51
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/Constants.java60
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImpl.java36
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DataReaderException.java4
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DgResolverException.java12
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DgResolverPluginImpl.java31
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java26
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java69
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/LegacyUtilImpl.java26
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/OutputMessagePluginImpl.java28
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverDataReaderFactory.java20
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverFactory.java22
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolver.java37
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolver.java35
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java53
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionInternalException.java8
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/objects/ConnectionDetails.java1
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JAXBUtil.java3
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JSONUtil.java23
19 files changed, 294 insertions, 251 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolver.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolver.java
index 78dd780d4..2f1050fb8 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolver.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolver.java
@@ -32,21 +32,25 @@ import org.onap.appc.rankingframework.RankedAttributesResolver;
abstract class AbstractResolver {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(AbstractResolver.class);
+ private static final long INTERVAL_MULTIPLIER = 1000L;
private long interval;
-
- private volatile long lastUpdate = 0l;
+ private volatile long lastUpdate = 0L;
private volatile boolean isUpdateInProgress = false;
private volatile RankedAttributesResolver<FlowKey> dgResolver;
- private final ReentrantLock INIT_LOCK = new ReentrantLock();
+ private final ReentrantLock initLock = new ReentrantLock();
AbstractResolver(int interval) {
- this.interval = interval * 1000l;
+ this.interval = interval * INTERVAL_MULTIPLIER;
}
private RankedAttributesResolver<FlowKey> createResolver(String resolverType) {
AbstractResolverDataReader reader = ResolverDataReaderFactory.createResolverDataReader(resolverType);
+
+ if (reader == null) {
+ throw new DataReaderException("Cannot read data since reader is null");
+ }
return reader.read();
}
@@ -55,29 +59,25 @@ abstract class AbstractResolver {
}
protected RankedAttributesResolver<FlowKey> resolver(String resolverType) {
-
/*
* In general case, the method implementation is non-blocking. The first
* thread that identifies data expiration will be used to refresh it. In
* meanwhile, any other thread will get the old instance without waiting
* for the updated one. The only exception is the very first time when
* previous instance doesn't exist - in such a cases all the threads
- * will be waiting on INIT_LOCK while one of them initializes the
+ * will be waiting on initLock while one of them initializes the
* resolver instance. NOTE: The initialization is intentionally
* implemented in lazy manner to make sure the bundle is initialized
* properly on startup regardless whether or not the data is correct.
* Afterwards, the resolver may be instantiated as many times as needed.
*/
-
try {
-
if (dgResolver == null) {
- INIT_LOCK.lock();
+ initLock.lock();
if (dgResolver != null) {
- INIT_LOCK.unlock();
+ initLock.unlock();
}
}
-
if (!isUpdateInProgress && isExpired()) {
boolean doUpgrade = false;
@@ -88,30 +88,29 @@ abstract class AbstractResolver {
doUpgrade = true;
}
}
-
if (doUpgrade) {
-
logger.info("DG resolver configuration data has expired - initiating refresh");
-
- try {
- RankedAttributesResolver<FlowKey> temp = createResolver(resolverType);
- dgResolver = temp;
- lastUpdate = System.currentTimeMillis();
-
- logger.info("DG resolver configuration data has been refreshed successfully");
- } finally {
- isUpdateInProgress = false;
- }
+ tryRefreshConfig(resolverType);
}
}
} finally {
- if (INIT_LOCK.isHeldByCurrentThread()) {
- INIT_LOCK.unlock();
+ if (initLock.isHeldByCurrentThread()) {
+ initLock.unlock();
}
}
-
return dgResolver;
}
+ private void tryRefreshConfig(String resolverType) {
+ try {
+ dgResolver = createResolver(resolverType);
+ lastUpdate = System.currentTimeMillis();
+
+ logger.info("DG resolver configuration data has been refreshed successfully");
+ } finally {
+ isUpdateInProgress = false;
+ }
+ }
+
protected abstract FlowKey resolve(final String... args);
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/Constants.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/Constants.java
index 9009f3c62..1e62dcc66 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/Constants.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/Constants.java
@@ -52,12 +52,31 @@ class Constants {
public static final String CVAAS_FILE_NAME = "cvaas-file-name";
public static final String CVAAS_FILE_CONTENT = "cvaas-file-content";
+ // DG Resolver Constants
+ public static final String IN_PARAM_VNF_TYPE = "vnfType";
+ public static final String IN_PARAM_VNFC_TYPE = "vnfcType";
+ public static final String IN_PARAM_ACTION = "action";
+ public static final String IN_PARAM_API_VERSION = "api-ver";
+
+ public static final String OUT_PARAM_DG_NAME = "dg_name";
+ public static final String OUT_PARAM_DG_VERSION = "dg_version";
+ public static final String OUT_PARAM_DG_MODULE = "dg_module";
+
+ public static final String TABLE_NAME = "VNFC_DG_MAPPING";
+ public static final String TABLE_COLUMN_VNF_TYPE = "VNF_TYPE";
+ public static final String TABLE_COLUMN_VNFC_TYPE = "VNFC_TYPE";
+ public static final String TABLE_COLUMN_ACTION = "ACTION";
+ public static final String TABLE_COLUMN_API_VERSION = "API_VERSION";
+ public static final String TABLE_COLUMN_DG_NAME = "DG_NAME";
+ public static final String TABLE_COLUMN_DG_VERSION = "DG_VERSION";
+ public static final String TABLE_COLUMN_DG_MODULE = "DG_MODULE";
+
enum LegacyAttributes {
- Action("org.onap.appc.action"),
+ ACTION("org.onap.appc.action"),
VMID("org.onap.appc.vmid"),
- IdentityURL("org.onap.appc.identity.url"),
- TenantID("org.onap.appc.tenant.id"),
- SkipHypervisorCheck("org.onap.appc.skiphypervisorcheck");
+ IDENTITY_URL("org.onap.appc.identity.url"),
+ TENANT_ID("org.onap.appc.tenant.id"),
+ SKIP_HYPERVISOR_CHECK("org.onap.appc.skiphypervisorcheck");
private String value;
@@ -70,15 +89,13 @@ class Constants {
}
}
- ;
-
enum LCMAttributes {
- Action("input.action"),
- Payload("input.payload"),
+ ACTION("input.action"),
+ PAYLOAD("input.payload"),
VMID("vm-id"),
- IdentityURL("identity-url"),
- TenantID("tenant.id"),
- SkipHypervisorCheck("skip-hypervisor-check");
+ IDENTITY_URL("identity-url"),
+ TENANT_ID("tenant.id"),
+ SKIP_HYPERVISOR_CHECK("skip-hypervisor-check");
private String value;
@@ -90,25 +107,4 @@ class Constants {
return value;
}
}
-
- ;
-
- // DG Resolver Constants
- public static final String IN_PARAM_VNF_TYPE = "vnfType";
- public static final String IN_PARAM_VNFC_TYPE = "vnfcType";
- public static final String IN_PARAM_ACTION = "action";
- public static final String IN_PARAM_API_VERSION = "api-ver";
-
- public static final String OUT_PARAM_DG_NAME = "dg_name";
- public static final String OUT_PARAM_DG_VERSION = "dg_version";
- public static final String OUT_PARAM_DG_MODULE = "dg_module";
-
- public static final String TABLE_NAME = "VNFC_DG_MAPPING";
- public static final String TABLE_COLUMN_VNF_TYPE = "VNF_TYPE";
- public static final String TABLE_COLUMN_VNFC_TYPE = "VNFC_TYPE";
- public static final String TABLE_COLUMN_ACTION = "ACTION";
- public static final String TABLE_COLUMN_API_VERSION = "API_VERSION";
- public static final String TABLE_COLUMN_DG_NAME = "DG_NAME";
- public static final String TABLE_COLUMN_DG_VERSION = "DG_VERSION";
- public static final String TABLE_COLUMN_DG_MODULE = "DG_MODULE";
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImpl.java
index f0e7674ee..c66a54ad4 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImpl.java
@@ -37,6 +37,9 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
public class DCAEReporterPluginImpl implements DCAEReporterPlugin {
+ private static final String ATTR_API_VERSION = "input.common-header.api-ver";
+ private static final String ATTR_REQUEST_ID = "input.common-header.request-id";
+ private static final String PARAM_EVENT_TOPIC_NAME = "event-topic-name";
private EventSender eventSender;
public DCAEReporterPluginImpl() {
@@ -54,7 +57,9 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin {
@Override
public void report(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
- String errorDescription, apiVersion, eventId;
+ String errorDescription;
+ String apiVersion;
+ String eventId;
Integer errorCode = readErrorCode(params, ctx);
errorDescription = params.get(Constants.EVENT_MESSAGE);
@@ -62,13 +67,13 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin {
if (StringUtils.isEmpty(errorDescription)) {
reportLegacy(params, ctx);
} else {
- apiVersion = ctx.getAttribute("input.common-header.api-ver");
- eventId = ctx.getAttribute("input.common-header.request-id");
+ apiVersion = ctx.getAttribute(ATTR_API_VERSION);
+ eventId = ctx.getAttribute(ATTR_REQUEST_ID);
EventMessage eventMessage = new EventMessage(new EventHeader(
(new java.util.Date()).toString(), apiVersion, eventId),
new EventStatus(errorCode, errorDescription));
- String eventWriteTopic = params.get("event-topic-name");
+ String eventWriteTopic = params.get(PARAM_EVENT_TOPIC_NAME);
if (!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic != null) {
eventSender.sendEvent(MessageDestination.DCAE, eventMessage, eventWriteTopic);
} else {
@@ -93,15 +98,18 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin {
@Override
public void reportSuccess(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
Integer successReportCode = 500;
- String successDescription, apiVersion, eventId;
+ String successDescription;
+ String apiVersion;
+ String eventId;
+
successDescription = params.get(Constants.EVENT_MESSAGE);
if (StringUtils.isEmpty(successDescription)) {
successDescription = params.get(Constants.DG_OUTPUT_STATUS_MESSAGE);
}
- apiVersion = ctx.getAttribute("input.common-header.api-ver");
- eventId = ctx.getAttribute("input.common-header.request-id");
+ apiVersion = ctx.getAttribute(ATTR_API_VERSION);
+ eventId = ctx.getAttribute(ATTR_REQUEST_ID);
if (null == successDescription) {
successDescription = "Success";
@@ -109,7 +117,7 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin {
EventMessage eventMessage = new EventMessage(new EventHeader(
(new java.util.Date()).toString(), apiVersion, eventId),
new EventStatus(successReportCode, successDescription));
- String eventWriteTopic = params.get("event-topic-name");
+ String eventWriteTopic = params.get(PARAM_EVENT_TOPIC_NAME);
if (!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic != null) {
eventSender.sendEvent(MessageDestination.DCAE, eventMessage, eventWriteTopic);
} else {
@@ -118,18 +126,20 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin {
}
private void reportLegacy(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
- String errorDescription, apiVersion, eventId;
+ String errorDescription;
+ String apiVersion;
+ String eventId;
Integer errorCode = readErrorCode(params, ctx);
errorDescription = getErrorDescriptionAndAddToCtx(params, ctx);
- apiVersion = ctx.getAttribute("input.common-header.api-ver");
- eventId = ctx.getAttribute("input.common-header.request-id");
+ apiVersion = ctx.getAttribute(ATTR_API_VERSION);
+ eventId = ctx.getAttribute(ATTR_REQUEST_ID);
EventMessage eventMessage = new EventMessage(new EventHeader(
(new java.util.Date()).toString(), apiVersion, eventId),
new EventStatus(errorCode, errorDescription));
- String eventWriteTopic = params.get("event-topic-name");
+ String eventWriteTopic = params.get(PARAM_EVENT_TOPIC_NAME);
if (!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic != null) {
eventSender.sendEvent(MessageDestination.DCAE, eventMessage, eventWriteTopic);
} else {
@@ -140,6 +150,7 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin {
private String getErrorDescriptionAndAddToCtx(Map<String, String> params, SvcLogicContext ctx) {
String errorDescription;
errorDescription = params.get(Constants.DG_OUTPUT_STATUS_MESSAGE);
+
if (StringUtils.isEmpty(errorDescription)) {
errorDescription = ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE);
}
@@ -162,5 +173,4 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin {
ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorDescriptionFromCtx + " | " + errorDescription);
}
}
-
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DataReaderException.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DataReaderException.java
index f12a83b04..742ff123d 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DataReaderException.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DataReaderException.java
@@ -29,4 +29,8 @@ public class DataReaderException extends RuntimeException {
public DataReaderException(Throwable cause) {
super(cause);
}
+
+ public DataReaderException(String message) {
+ super(message);
+ }
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DgResolverException.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DgResolverException.java
new file mode 100644
index 000000000..260fd7752
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DgResolverException.java
@@ -0,0 +1,12 @@
+package org.onap.appc.dg.common.impl;
+
+public class DgResolverException extends RuntimeException{
+
+ public DgResolverException(String message) {
+ super(message);
+ }
+
+ public DgResolverException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DgResolverPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DgResolverPluginImpl.java
index 5b98dd941..ade2cbb16 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DgResolverPluginImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DgResolverPluginImpl.java
@@ -33,33 +33,40 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
public class DgResolverPluginImpl implements DgResolverPlugin {
+ private static final String PARAM_DG_RESOLUTION_TYPE = "DGResolutionType";
+
@Override
public void resolveDg(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
- String DGName, DGVersion, DGModule = null;
+ String dgName;
+ String dgVersion;
+ String dgModule;
+
String prefix = params.containsKey("prefix") ? params.get("prefix") + "." : "";
- AbstractResolver resolver = ResolverFactory.createResolver(params.get("DGResolutionType"));
+ AbstractResolver resolver = ResolverFactory.createResolver(params.get(PARAM_DG_RESOLUTION_TYPE));
FlowKey flowKey = null;
try {
+ if (resolver == null)
+ throw new DgResolverException("Couldn't create resolver of type: " + PARAM_DG_RESOLUTION_TYPE);
- if (params.get("DGResolutionType").equalsIgnoreCase("VNFC")) {
+ if ("VNFC".equalsIgnoreCase(params.get(PARAM_DG_RESOLUTION_TYPE))) {
flowKey = resolver
.resolve(params.get(Constants.IN_PARAM_ACTION), params.get(Constants.IN_PARAM_VNF_TYPE),
params.get(Constants.IN_PARAM_VNFC_TYPE), params.get(Constants.IN_PARAM_API_VERSION));
- } else if (params.get("DGResolutionType").equalsIgnoreCase("VNF")) {
+ } else if ("VNF".equalsIgnoreCase(params.get(PARAM_DG_RESOLUTION_TYPE))) {
flowKey = resolver
.resolve(params.get(Constants.IN_PARAM_ACTION), params.get(Constants.IN_PARAM_VNF_TYPE),
params.get("vnfVersion"), params.get(Constants.IN_PARAM_API_VERSION));
}
if (flowKey != null) {
- DGName = flowKey.name();
- ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_NAME, DGName);
- DGVersion = flowKey.version();
- ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_VERSION, DGVersion);
- DGModule = flowKey.module();
- ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_MODULE, DGModule);
+ dgName = flowKey.name();
+ ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_NAME, dgName);
+ dgVersion = flowKey.version();
+ ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_VERSION, dgVersion);
+ dgModule = flowKey.module();
+ ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_MODULE, dgModule);
} else {
- throw new RuntimeException(params.get("DGResolutionType") + " DG not found for vnf type :" + params
+ throw new DgResolverException(params.get(PARAM_DG_RESOLUTION_TYPE) + " DG not found for vnf type :" + params
.get(Constants.IN_PARAM_VNF_TYPE)
+ " vnfc type : " + params.get(Constants.IN_PARAM_VNFC_TYPE)
+ " action : " + params.get(Constants.IN_PARAM_ACTION)
@@ -69,7 +76,7 @@ public class DgResolverPluginImpl implements DgResolverPlugin {
String msg = EELFResourceManager
.format(Msg.FAILURE_RETRIEVE_VNFC_DG, params.get(Constants.IN_PARAM_VNFC_TYPE), e.getMessage());
ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
- throw new RuntimeException(e);
+ throw new DgResolverException(e);
}
}
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java
index d9caf8f19..4010fd758 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java
@@ -29,6 +29,7 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
@@ -47,12 +48,12 @@ import org.osgi.framework.ServiceReference;
public class IntermediateMessageSenderImpl implements IntermediateMessageSender {
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(IntermediateMessageSenderImpl.class);
- private Producer producer;
-
- private Configuration configuration;
+ private static final String PARAM_MESSAGE = "message";
+ private static final String ATTR_REQUEST_ID = "input.common-header.request-id";
- private final EELFLogger logger = EELFManager.getInstance().getLogger(IntermediateMessageSenderImpl.class);
+ private Producer producer;
private static final String STATUS = "STATUS";
private static final String FAILURE = "FAILURE";
@@ -63,8 +64,7 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender
private static final String MSO = "MSO";
public void init() {
- configuration = ConfigurationFactory.getConfiguration();
- Properties properties = configuration.getProperties();
+ Properties properties = ConfigurationFactory.getConfiguration().getProperties();
String writeTopic = properties.getProperty("appc.LCM.topic.write");
String apiKey = properties.getProperty("appc.LCM.client.key");
@@ -76,9 +76,7 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender
Set<String> pool = new HashSet<>();
if (!StringUtils.isEmpty(hostNames)) {
- for (String name : hostNames.split(",")) {
- pool.add(name);
- }
+ pool.addAll(Arrays.asList(hostNames.split(",")));
}
BundleContext ctx = FrameworkUtil.getBundle(IntermediateMessageSenderImpl.class).getBundleContext();
@@ -111,11 +109,11 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender
private void validateInputs(Map<String, String> params, SvcLogicContext context) throws APPCException {
String code = params.get("code");
- String message = params.get("message");
+ String message = params.get(PARAM_MESSAGE);
if (StringUtils.isEmpty(code) || StringUtils.isEmpty(message)) {
throw new APPCException("code or message is empty");
}
- String requestId = context.getAttribute("input.common-header.request-id");
+ String requestId = context.getAttribute(ATTR_REQUEST_ID);
if (StringUtils.isEmpty(requestId)) {
throw new APPCException("requestId is empty");
}
@@ -145,7 +143,7 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender
}
private String getCorrelationId(SvcLogicContext context) {
- String requestId = context.getAttribute("input.common-header.request-id");
+ String requestId = context.getAttribute(ATTR_REQUEST_ID);
String subRequestId = context.getAttribute("input.common-header.sub-request-id");
return requestId + (StringUtils.isEmpty(subRequestId) ? "" : ("-" + subRequestId));
}
@@ -154,7 +152,7 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode status = objectMapper.createObjectNode();
status.put("code", params.get("code"));
- status.put("message", params.get("message"));
+ status.put(PARAM_MESSAGE, params.get(PARAM_MESSAGE));
return status;
}
@@ -164,7 +162,7 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender
commonHeader.put("api-ver", context.getAttribute("input.common-header.api-ver"));
commonHeader.put("timestamp", context.getAttribute("input.common-header.timestamp"));
commonHeader.put("originator-id", context.getAttribute("input.common-header.originator-id"));
- commonHeader.put("request-id", context.getAttribute("input.common-header.request-id"));
+ commonHeader.put("request-id", context.getAttribute(ATTR_REQUEST_ID));
commonHeader.put("sub-request-id", context.getAttribute("input.common-header.sub-request-id"));
return commonHeader;
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java
index 3d43dc1cd..16488e242 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java
@@ -47,11 +47,8 @@ public class JsonDgUtilImpl implements JsonDgUtil {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(JsonDgUtilImpl.class);
- private static final ThreadLocal<SimpleDateFormat> DATE_TIME_PARSER_THREAD_LOCAL = new ThreadLocal<SimpleDateFormat>() {
- protected SimpleDateFormat initialValue() {
- return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- }
- };
+ private static final ThreadLocal<SimpleDateFormat> DATE_TIME_PARSER_THREAD_LOCAL = ThreadLocal
+ .withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
@Override
public void flatAndAddToContext(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
@@ -69,11 +66,7 @@ public class JsonDgUtilImpl implements JsonDgUtil {
}
if (!StringUtils.isEmpty(payload)) {
Map<String, String> flatMap = JsonUtil.convertJsonStringToFlatMap(payload);
- if (flatMap != null && flatMap.size() > 0) {
- for (Map.Entry<String, String> entry : flatMap.entrySet()) {
- ctx.setAttribute(entry.getKey(), entry.getValue());
- }
- }
+ tryUpdateContext(ctx, flatMap);
} else {
logger.warn("input payload param value is empty (\"\") or null");
}
@@ -85,6 +78,14 @@ public class JsonDgUtilImpl implements JsonDgUtil {
}
}
+ private void tryUpdateContext(SvcLogicContext ctx, Map<String, String> flatMap) {
+ if (flatMap != null && flatMap.size() > 0) {
+ for (Map.Entry<String, String> entry : flatMap.entrySet()) {
+ ctx.setAttribute(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
@Override
public void generateOutputPayloadFromContext(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
if (logger.isTraceEnabled()) {
@@ -95,30 +96,12 @@ public class JsonDgUtilImpl implements JsonDgUtil {
try {
Set<String> keys = ctx.getAttributeKeySet();
ObjectMapper objectMapper = new ObjectMapper();
- ObjectNode JsonNode = objectMapper.createObjectNode();
+ ObjectNode jsonNode = objectMapper.createObjectNode();
for (String key : keys) {
- if (key.startsWith(Constants.OUTPUT_PAYLOAD + ".")) {
- String objkey = key.replaceFirst(Constants.OUTPUT_PAYLOAD + ".", "");
- if (objkey.contains("[") && objkey.contains("]")) {
- ArrayNode arrayNode;
- String arrayKey = objkey.substring(0, objkey.indexOf('['));
- int arrayIndex = Integer
- .parseInt(objkey.substring(objkey.indexOf('[') + 1, objkey.indexOf(']')));
- if (JsonNode.has(arrayKey)) {
- arrayNode = (ArrayNode) JsonNode.get(arrayKey);
- arrayNode.insert(arrayIndex, ctx.getAttribute(key));
- } else {
- arrayNode = objectMapper.createArrayNode();
- arrayNode.insert(arrayIndex, ctx.getAttribute(key));
- JsonNode.put(arrayKey, arrayNode);
- }
- } else {
- JsonNode.put(objkey, ctx.getAttribute(key));
- }
- }
+ updateJsonNode(ctx, objectMapper, jsonNode, key);
}
- if (JsonNode.size() > 0) {
- ctx.setAttribute(Constants.OUTPUT_PAYLOAD, objectMapper.writeValueAsString(JsonNode));
+ if (jsonNode.size() > 0) {
+ ctx.setAttribute(Constants.OUTPUT_PAYLOAD, objectMapper.writeValueAsString(jsonNode));
}
} catch (Exception e) {
logger.error(e.toString());
@@ -128,6 +111,28 @@ public class JsonDgUtilImpl implements JsonDgUtil {
}
+ private void updateJsonNode(SvcLogicContext ctx, ObjectMapper objectMapper, ObjectNode jsonNode, String key) {
+ if (key.startsWith(Constants.OUTPUT_PAYLOAD + ".")) {
+ String objkey = key.replaceFirst(Constants.OUTPUT_PAYLOAD + ".", "");
+ if (objkey.contains("[") && objkey.contains("]")) {
+ ArrayNode arrayNode;
+ String arrayKey = objkey.substring(0, objkey.indexOf('['));
+ int arrayIndex = Integer
+ .parseInt(objkey.substring(objkey.indexOf('[') + 1, objkey.indexOf(']')));
+ if (jsonNode.has(arrayKey)) {
+ arrayNode = (ArrayNode) jsonNode.get(arrayKey);
+ arrayNode.insert(arrayIndex, ctx.getAttribute(key));
+ } else {
+ arrayNode = objectMapper.createArrayNode();
+ arrayNode.insert(arrayIndex, ctx.getAttribute(key));
+ jsonNode.put(arrayKey, arrayNode);
+ }
+ } else {
+ jsonNode.put(objkey, ctx.getAttribute(key));
+ }
+ }
+ }
+
@Override
public void cvaasFileNameAndFileContentToContext(Map<String, String> params, SvcLogicContext ctx)
throws APPCException {
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/LegacyUtilImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/LegacyUtilImpl.java
index 400dadb34..8da7d5d92 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/LegacyUtilImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/LegacyUtilImpl.java
@@ -35,31 +35,33 @@ public class LegacyUtilImpl implements LegacyUtil {
@Override
public void prepareRequest(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
- ctx.setAttribute(Constants.LegacyAttributes.Action.getValue(),
- ctx.getAttribute(Constants.LCMAttributes.Action.getValue()).toLowerCase());
+ ctx.setAttribute(Constants.LegacyAttributes.ACTION.getValue(),
+ ctx.getAttribute(Constants.LCMAttributes.ACTION.getValue()).toLowerCase());
- String payloadStr = ctx.getAttribute(Constants.LCMAttributes.Payload.getValue());
+ String payloadStr = ctx.getAttribute(Constants.LCMAttributes.PAYLOAD.getValue());
Map<String, String> payloads = JSONUtil.extractPlainValues(payloadStr,
- Constants.LCMAttributes.VMID.getValue(), Constants.LCMAttributes.IdentityURL.getValue(),
- Constants.LCMAttributes.TenantID.getValue(),
- Constants.LCMAttributes.SkipHypervisorCheck.getValue());
+ Constants.LCMAttributes.VMID.getValue(), Constants.LCMAttributes.IDENTITY_URL.getValue(),
+ Constants.LCMAttributes.TENANT_ID.getValue(),
+ Constants.LCMAttributes.SKIP_HYPERVISOR_CHECK.getValue());
ctx.setAttribute(Constants.LegacyAttributes.VMID.getValue(),
payloads.get(Constants.LCMAttributes.VMID.getValue()));
- ctx.setAttribute(Constants.LegacyAttributes.IdentityURL.getValue(),
- payloads.get(Constants.LCMAttributes.IdentityURL.getValue()));
- ctx.setAttribute(Constants.LegacyAttributes.TenantID.getValue(),
- payloads.get(Constants.LCMAttributes.TenantID.getValue()));
- ctx.setAttribute(Constants.LegacyAttributes.SkipHypervisorCheck.getValue(),
- payloads.get(Constants.LCMAttributes.SkipHypervisorCheck.getValue()));
+ ctx.setAttribute(Constants.LegacyAttributes.IDENTITY_URL.getValue(),
+ payloads.get(Constants.LCMAttributes.IDENTITY_URL.getValue()));
+ ctx.setAttribute(Constants.LegacyAttributes.TENANT_ID.getValue(),
+ payloads.get(Constants.LCMAttributes.TENANT_ID.getValue()));
+ ctx.setAttribute(Constants.LegacyAttributes.SKIP_HYPERVISOR_CHECK.getValue(),
+ payloads.get(Constants.LCMAttributes.SKIP_HYPERVISOR_CHECK.getValue()));
}
@Override
public void convertPositiveResponse(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+ /*TODO implement this method*/
}
@Override
public void convertNegativeResponse(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+ /*TODO implement this method*/
}
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/OutputMessagePluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/OutputMessagePluginImpl.java
index cd385c9d2..f6e24b5d9 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/OutputMessagePluginImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/OutputMessagePluginImpl.java
@@ -35,7 +35,8 @@ public class OutputMessagePluginImpl implements OutputMessagePlugin {
@Override
public void outputMessageBuilder(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
- String errorDescription, eventDescription;
+ String errorDescription;
+ String eventDescription;
//making output.status.message
errorDescription = params.get(Constants.ATTRIBUTE_ERROR_MESSAGE);
@@ -52,23 +53,22 @@ public class OutputMessagePluginImpl implements OutputMessagePlugin {
}
}
- public static void addToContextIfNotContains(String errorDescription, String eventDescription,
+ private static void addToContextIfNotContains(String errorDescription, String eventDescription,
SvcLogicContext ctx) {
if (!isEmpty(errorDescription)) {
- if (isEmpty(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE))) {
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorDescription);
- } else if (!ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE).contains(errorDescription)) {
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE,
- ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE) + " | " + errorDescription);
- }
+ updateContext(errorDescription, ctx);
}
if (!isEmpty(eventDescription)) {
- if (isEmpty(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE))) {
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, eventDescription);
- } else if (!ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE).contains(eventDescription)) {
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE,
- ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE) + " | " + eventDescription);
- }
+ updateContext(eventDescription, ctx);
+ }
+ }
+
+ private static void updateContext(String eventDescription, SvcLogicContext ctx) {
+ if (isEmpty(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE))) {
+ ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, eventDescription);
+ } else if (!ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE).contains(eventDescription)) {
+ ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE,
+ ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE) + " | " + eventDescription);
}
}
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverDataReaderFactory.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverDataReaderFactory.java
index 15e4ab681..c71614766 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverDataReaderFactory.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverDataReaderFactory.java
@@ -31,20 +31,24 @@ public class ResolverDataReaderFactory {
private static final Configuration configuration = ConfigurationFactory.getConfiguration();
- private static class ReferenceHolder {
-
- private static final AbstractResolverDataReader VNFC_RESOLVER_DATA_READER = new VNFCResolverDataReader();
-
- private static final AbstractResolverDataReader VNF_RESOLVER_DATA_READER = new VNFResolverDataReader();
- }
+ private ResolverDataReaderFactory() {}
public static AbstractResolverDataReader createResolverDataReader(String resolverType) {
- if (resolverType.equalsIgnoreCase("VNF")) {
+ if ("VNF".equalsIgnoreCase(resolverType)) {
return ReferenceHolder.VNF_RESOLVER_DATA_READER;
- } else if (resolverType.equalsIgnoreCase("VNFC")) {
+ } else if ("VNFC".equalsIgnoreCase(resolverType)) {
return ReferenceHolder.VNFC_RESOLVER_DATA_READER;
} else {
return null;
}
}
+
+ private static class ReferenceHolder {
+
+ private static final AbstractResolverDataReader VNFC_RESOLVER_DATA_READER = new VNFCResolverDataReader();
+
+ private static final AbstractResolverDataReader VNF_RESOLVER_DATA_READER = new VNFResolverDataReader();
+
+ private ReferenceHolder() {}
+ }
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverFactory.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverFactory.java
index be71dae8d..6474836dc 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverFactory.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverFactory.java
@@ -31,21 +31,25 @@ public class ResolverFactory {
private static final Configuration configuration = ConfigurationFactory.getConfiguration();
- private static class ReferenceHolder {
-
- private static final AbstractResolver VNFC_RESOLVER = new VNFCResolver(
- configuration.getIntegerProperty("org.onap.appc.workflow.resolver.refresh_interval", 300));
- private static final AbstractResolver VNF_RESOLVER = new VNFResolver(
- configuration.getIntegerProperty("org.onap.appc.workflow.resolver.refresh_interval", 300));
- }
+ private ResolverFactory() {}
public static AbstractResolver createResolver(String resolverType) {
- if (resolverType.equalsIgnoreCase("VNF")) {
+ if ("VNF".equalsIgnoreCase(resolverType)) {
return ReferenceHolder.VNF_RESOLVER;
- } else if (resolverType.equalsIgnoreCase("VNFC")) {
+ } else if ("VNFC".equalsIgnoreCase(resolverType)) {
return ReferenceHolder.VNFC_RESOLVER;
} else {
return null;
}
}
+
+ private static class ReferenceHolder {
+
+ private static final AbstractResolver VNFC_RESOLVER = new VNFCResolver(
+ configuration.getIntegerProperty("org.onap.appc.workflow.resolver.refresh_interval", 300));
+ private static final AbstractResolver VNF_RESOLVER = new VNFResolver(
+ configuration.getIntegerProperty("org.onap.appc.workflow.resolver.refresh_interval", 300));
+
+ private ReferenceHolder(){}
+ }
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolver.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolver.java
index a6b5e656f..5766e8de2 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolver.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolver.java
@@ -24,6 +24,7 @@
package org.onap.appc.dg.common.impl;
+import java.util.Arrays;
import org.onap.appc.rankingframework.RankedAttributesContext;
@@ -36,34 +37,28 @@ public class VNFCResolver extends AbstractResolver {
@Override
protected FlowKey resolve(String... args) {
if (args.length != 4) {
- throw new IllegalStateException(args.toString());
+ throw new IllegalStateException(Arrays.toString(args));
}
return resolve(args[0], args[1], args[2], args[3]);
}
- protected FlowKey resolve(final String action, final String vnfType, final String vnfcType,
+ private FlowKey resolve(final String action, final String vnfType, final String vnfcType,
final String apiVersion) {
- RankedAttributesContext context = new RankedAttributesContext() {
- @Override
- public Object getAttributeValue(String name) {
- switch (name) {
- case "action":
- return action;
- case "api_version":
- return apiVersion;
- case "vnf_type":
- return vnfType;
- case "vnfc_type":
- return vnfcType;
- default:
- throw new IllegalStateException(name);
- }
+ RankedAttributesContext context = name -> {
+ switch (name) {
+ case "action":
+ return action;
+ case "api_version":
+ return apiVersion;
+ case "vnf_type":
+ return vnfType;
+ case "vnfc_type":
+ return vnfcType;
+ default:
+ throw new IllegalStateException(name);
}
};
-
- FlowKey wfKey = resolver("VNFC").resolve(context);
-
- return wfKey;
+ return resolver("VNFC").resolve(context);
}
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolver.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolver.java
index 10d4fffc3..37033703f 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolver.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolver.java
@@ -37,29 +37,22 @@ public class VNFResolver extends AbstractResolver {
return resolve(args[0], args[1], args[2], args[3]);
}
-
- protected FlowKey resolve(final String action, final String vnfType, final String vnfVersion,
+ private FlowKey resolve(final String action, final String vnfType, final String vnfVersion,
final String apiVersion) {
- RankedAttributesContext context = new RankedAttributesContext() {
- @Override
- public Object getAttributeValue(String name) {
- switch (name) {
- case "action":
- return action;
- case "api_version":
- return apiVersion;
- case "vnf_type":
- return vnfType;
- case "vnf_version":
- return vnfVersion;
- default:
- throw new IllegalStateException(name);
- }
+ RankedAttributesContext context = name -> {
+ switch (name) {
+ case "action":
+ return action;
+ case "api_version":
+ return apiVersion;
+ case "vnf_type":
+ return vnfType;
+ case "vnf_version":
+ return vnfVersion;
+ default:
+ throw new IllegalStateException(name);
}
};
-
- FlowKey wfKey = resolver("VNF").resolve(context);
-
- return wfKey;
+ return resolver("VNF").resolve(context);
}
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java
index fe7545d0f..7be6f098c 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java
@@ -84,23 +84,24 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow {
DependencyManager dependencyManager = DependencyModelFactory.createDependencyManager();
dependencyModel = dependencyManager.getVnfcDependencyModel(
modelIdentifier, DependencyTypes.findByString(dependencyType));
+
} catch (DependencyModelNotFound e) {
String msg = EELFResourceManager
- .format(Msg.DEPENDENCY_MODEL_NOT_FOUND, params.get(Constants.VNF_TYPE), e.getMessage());
- logger.error(msg);
+ .format(Msg.DEPENDENCY_MODEL_NOT_FOUND, params.get(Constants.VNF_TYPE));
+ logger.error(msg, e);
context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
context.setAttribute("dependencyModelFound", "false");
return;
} catch (InvalidDependencyModelException e) {
String msg = EELFResourceManager
- .format(Msg.INVALID_DEPENDENCY_MODEL, params.get(Constants.VNF_TYPE), e.getMessage());
- logger.error(msg);
+ .format(Msg.INVALID_DEPENDENCY_MODEL, params.get(Constants.VNF_TYPE));
+ logger.error(msg, e);
context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
- throw new RuntimeException(e.getMessage(), e);
+ throw new VnfExecutionInternalException(e);
} catch (APPCException e) {
logger.error(e.getMessage());
context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, e.getMessage());
- throw new RuntimeException(e.getMessage(), e);
+ throw new VnfExecutionInternalException(e);
} catch (RuntimeException e) {
logger.error(e.getMessage());
context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, e.getMessage());
@@ -112,19 +113,16 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow {
logger.debug("Dependency Model = " + dependencyModel);
}
logger.info("Building Inventory Model from DG context");
- InventoryModel inventoryModel = null;
+ InventoryModel inventoryModel;
try {
inventoryModel = readInventoryModel(context);
} catch (APPCException e) {
logger.error(e.getMessage());
context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, e.getMessage());
- throw new RuntimeException(e.getMessage(), e);
+ throw new VnfExecutionInternalException(e);
}
if (logger.isDebugEnabled()) {
logger.debug("Inventory Model = " + inventoryModel);
- }
-
- if (logger.isDebugEnabled()) {
logger.debug("Validating inventory model with dependency model");
}
try {
@@ -132,7 +130,7 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow {
} catch (APPCException e) {
logger.error(e.getMessage());
context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, e.getMessage());
- throw new RuntimeException(e.getMessage(), e);
+ throw new VnfExecutionInternalException(e);
}
logger.info("Creating flow builder");
FlowBuilder flowBuilder = FlowBuilderFactory.getInstance().getFlowBuilder(
@@ -147,7 +145,7 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow {
.format(Msg.INVALID_DEPENDENCY_MODEL, params.get(Constants.VNF_TYPE), e.getMessage());
logger.error(msg);
context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
- throw new RuntimeException(e.getMessage(), e);
+ throw new VnfExecutionInternalException(e);
}
// remove VNFCs from the flow model where vserver list is empty
@@ -172,15 +170,19 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow {
throw new APPCException("Flow Strategy from the input : " + flowStrategy + " is invalid.");
}
String vnfType = params.get(Constants.VNF_TYPE);
- if (vnfType == null || vnfType.length() == 0) {
+ if (nullOrEmpty(vnfType)) {
throw new APPCException("Vnf Type is not passed in the input");
}
String vnfVersion = params.get(Constants.VNF_VERION);
- if (vnfVersion == null || vnfVersion.length() == 0) {
+ if (nullOrEmpty(vnfVersion)) {
throw new APPCException("Vnf Version not found");
}
}
+ private boolean nullOrEmpty(String vnfType) {
+ return vnfType == null || vnfType.isEmpty();
+ }
+
private void logContext(SvcLogicContext context) {
for (String key : context.getAttributeKeySet()) {
logger.debug(key + " = " + context.getAttribute(key) + "\n");
@@ -219,7 +221,7 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow {
String vnfcName = context.getAttribute(VNF_VNFC + i + "].name");
String vnfcType = context.getAttribute(VNF_VNFC + i + "].type");
String vmCountStr = context.getAttribute(VNF_VNFC + i + "].vm_count");
- if (vnfcType == null || vnfcType.length() == 0) {
+ if (nullOrEmpty(vnfcType)) {
throw new APPCException("Could not retrieve VNFC Type from DG Context for vnf.vnfc[" + i + "].type");
}
Integer vmCount = Integer.parseInt(vmCountStr);
@@ -288,7 +290,7 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow {
} else {
Set<String> difference = new HashSet<>(dependencyModelMandatoryVnfcSet);
difference.removeAll(inventoryModelVnfcsSet);
- if (difference.size() > 0) {
+ if (!difference.isEmpty()) {
logger.error("Inventory model is missing following mandatory vnfc type(s): " + difference);
throw new APPCException("Inventory model is missing following mandatory vnfc type(s): " + difference);
}
@@ -301,15 +303,18 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow {
Iterator<Vnfc> vnfcIterator = flowIterator.next().iterator();
while (vnfcIterator.hasNext()) {
Vnfc vnfc = vnfcIterator.next();
- if (vnfc.getVserverList().size() == 0) {
- if (logger.isDebugEnabled()) {
- logger.debug("No vservers present for Vnfc type: " + vnfc.getVnfcType()
- + ". Hence, removing it from the flow model.");
- }
- vnfcIterator.remove();
- }
+ tryRemoveInterator(vnfcIterator, vnfc);
}
}
}
+ private void tryRemoveInterator(Iterator<Vnfc> vnfcIterator, Vnfc vnfc) {
+ if (vnfc.getVserverList().isEmpty()) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("No vservers present for Vnfc type: " + vnfc.getVnfcType()
+ + ". Hence, removing it from the flow model.");
+ }
+ vnfcIterator.remove();
+ }
+ }
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionInternalException.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionInternalException.java
new file mode 100644
index 000000000..2b5ab7ab6
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionInternalException.java
@@ -0,0 +1,8 @@
+package org.onap.appc.dg.common.impl;
+
+public class VnfExecutionInternalException extends RuntimeException{
+
+ public VnfExecutionInternalException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/objects/ConnectionDetails.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/objects/ConnectionDetails.java
index 40f5cba11..e5e5c001e 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/objects/ConnectionDetails.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/objects/ConnectionDetails.java
@@ -63,5 +63,4 @@ public class ConnectionDetails {
public void setPassword(String password) {
this.password = password;
}
-
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JAXBUtil.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JAXBUtil.java
index 38012b1bd..7f3cf3927 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JAXBUtil.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JAXBUtil.java
@@ -36,6 +36,8 @@ import java.io.InputStreamReader;
public class JAXBUtil {
+ private JAXBUtil() {}
+
public static <T> T toObject(String xml, Class<T> type) throws JAXBException {
//create JAXB context
@@ -48,6 +50,5 @@ public class JAXBUtil {
BufferedReader reader = new BufferedReader(new InputStreamReader(xmlInputStream));
return type.cast(unmarshaller.unmarshal(reader));
-
}
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JSONUtil.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JSONUtil.java
index 388295a7d..6b77d6cd1 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JSONUtil.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JSONUtil.java
@@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.Reader;
+import java.io.UncheckedIOException;
import java.util.*;
@@ -36,12 +37,14 @@ public class JSONUtil {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+ private JSONUtil() {}
+
public static <T> T fromJson(String json, Class<T> clazz) {
try {
return OBJECT_MAPPER.readValue(json, clazz);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new UncheckedIOException(e);
}
}
@@ -50,7 +53,7 @@ public class JSONUtil {
try {
return OBJECT_MAPPER.readValue(reader, clazz);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new UncheckedIOException(e);
}
}
@@ -59,25 +62,23 @@ public class JSONUtil {
try {
return OBJECT_MAPPER.writeValueAsString(object);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new UncheckedIOException(e);
}
}
- public static Map<String,String> extractPlainValues(String json, String ... names) {
- if (null == names) return Collections.emptyMap();
- Map<String,String> values = new HashMap<>();
+ public static Map<String, String> extractPlainValues(String json, String... names) {
+ if (null == names) {
+ return Collections.emptyMap();
+ }
+ Map<String, String> values = new HashMap<>();
try {
final JsonNode jsonNode = OBJECT_MAPPER.readTree(json);
for (String name : names) {
values.put(name, jsonNode.path(name).asText());
}
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new UncheckedIOException(e);
}
return values;
}
-
-
-
-
}