From b45d2ce251d5e93b26298dbe352ea01c171aad92 Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Mon, 26 Feb 2018 14:33:58 +0100 Subject: appc-dg-common sonar fixes part 1 Initial code refactor and imports rearrangement Change-Id: I4b96f82a4ebc30539872d9678cd5c2badc994256 Issue-ID: APPC-673 Signed-off-by: Jakub Dudycz --- .../onap/appc/dg/common/DCAEReporterPlugin.java | 3 +- .../org/onap/appc/dg/common/DgResolverPlugin.java | 4 +- .../appc/dg/common/IntermediateMessageSender.java | 3 +- .../java/org/onap/appc/dg/common/JsonDgUtil.java | 1 - .../java/org/onap/appc/dg/common/LegacyUtil.java | 2 - .../onap/appc/dg/common/OutputMessagePlugin.java | 8 +- .../onap/appc/dg/common/VNFCDgResolverPlugin.java | 7 +- .../org/onap/appc/dg/common/VNFConfigurator.java | 3 +- .../org/onap/appc/dg/common/VnfExecutionFlow.java | 6 +- .../onap/appc/dg/common/impl/AbstractResolver.java | 6 +- .../dg/common/impl/AbstractResolverDataReader.java | 19 ++- .../org/onap/appc/dg/common/impl/Constants.java | 37 +++-- .../dg/common/impl/DCAEReporterPluginImpl.java | 80 +++++---- .../appc/dg/common/impl/DataReaderException.java | 2 +- .../appc/dg/common/impl/DgResolverPluginImpl.java | 34 ++-- .../java/org/onap/appc/dg/common/impl/FlowKey.java | 1 + .../common/impl/IntermediateMessageSenderImpl.java | 73 ++++----- .../onap/appc/dg/common/impl/JsonDgUtilImpl.java | 66 ++++---- .../onap/appc/dg/common/impl/LegacyUtilImpl.java | 29 ++-- .../dg/common/impl/OutputMessagePluginImpl.java | 25 +-- .../dg/common/impl/ResolverDataReaderFactory.java | 13 +- .../onap/appc/dg/common/impl/ResolverFactory.java | 19 ++- .../dg/common/impl/VNFCDgResolverPluginImpl.java | 8 +- .../org/onap/appc/dg/common/impl/VNFCResolver.java | 8 +- .../dg/common/impl/VNFCResolverDataReader.java | 3 +- .../appc/dg/common/impl/VNFConfiguratorImpl.java | 58 +++---- .../org/onap/appc/dg/common/impl/VNFResolver.java | 6 +- .../appc/dg/common/impl/VNFResolverDataReader.java | 3 +- .../appc/dg/common/impl/VnfExecutionFlowImpl.java | 181 +++++++++++---------- .../appc/dg/common/objects/ConnectionDetails.java | 1 - 30 files changed, 377 insertions(+), 332 deletions(-) (limited to 'appc-dg/appc-dg-shared') diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DCAEReporterPlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DCAEReporterPlugin.java index 17bb56f66..eb844baf4 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DCAEReporterPlugin.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DCAEReporterPlugin.java @@ -25,13 +25,14 @@ package org.onap.appc.dg.common; import java.util.Map; - import org.onap.appc.exceptions.APPCException; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; public interface DCAEReporterPlugin extends SvcLogicJavaPlugin { + void report(Map params, SvcLogicContext ctx) throws APPCException; + void reportSuccess(Map params, SvcLogicContext ctx) throws APPCException; } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DgResolverPlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DgResolverPlugin.java index 397e3de3d..d38a91187 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DgResolverPlugin.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DgResolverPlugin.java @@ -24,13 +24,13 @@ package org.onap.appc.dg.common; +import java.util.Map; import org.onap.appc.exceptions.APPCException; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; -import java.util.Map; - @FunctionalInterface public interface DgResolverPlugin extends SvcLogicJavaPlugin { + void resolveDg(Map params, SvcLogicContext ctx) throws APPCException; } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/IntermediateMessageSender.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/IntermediateMessageSender.java index dcb516453..a7c4d968f 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/IntermediateMessageSender.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/IntermediateMessageSender.java @@ -24,11 +24,10 @@ package org.onap.appc.dg.common; +import java.util.Map; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; -import java.util.Map; - /** * This interface provides api for sending intermediate messages from DG to initiator */ diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/JsonDgUtil.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/JsonDgUtil.java index 95143e145..06ceb1412 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/JsonDgUtil.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/JsonDgUtil.java @@ -25,7 +25,6 @@ package org.onap.appc.dg.common; import java.util.Map; - import org.onap.appc.exceptions.APPCException; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/LegacyUtil.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/LegacyUtil.java index 54456b385..93b7bc793 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/LegacyUtil.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/LegacyUtil.java @@ -25,13 +25,11 @@ package org.onap.appc.dg.common; import java.util.Map; - import org.onap.appc.exceptions.APPCException; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - public interface LegacyUtil extends SvcLogicJavaPlugin { void prepareRequest(Map params, SvcLogicContext ctx) throws APPCException; diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/OutputMessagePlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/OutputMessagePlugin.java index f0ba0c57e..ca746a5f6 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/OutputMessagePlugin.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/OutputMessagePlugin.java @@ -24,15 +24,13 @@ package org.onap.appc.dg.common; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - import java.util.Map; - import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; @FunctionalInterface public interface OutputMessagePlugin extends SvcLogicJavaPlugin { - void outputMessageBuilder(Map params, SvcLogicContext ctx) throws APPCException; + void outputMessageBuilder(Map params, SvcLogicContext ctx) throws APPCException; } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFCDgResolverPlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFCDgResolverPlugin.java index 6352fccf1..3e0c10b05 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFCDgResolverPlugin.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFCDgResolverPlugin.java @@ -24,14 +24,13 @@ package org.onap.appc.dg.common; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - import java.util.Map; - import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; @FunctionalInterface public interface VNFCDgResolverPlugin extends SvcLogicJavaPlugin { + void resolveVNFCDg(Map params, SvcLogicContext ctx) throws APPCException; } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFConfigurator.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFConfigurator.java index 65e2324f8..c32015676 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFConfigurator.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFConfigurator.java @@ -24,11 +24,10 @@ package org.onap.appc.dg.common; +import java.util.Map; import org.onap.appc.exceptions.APPCException; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -import java.util.Map; /** * DG plugin created for VNF configuration operation to store data in MD-SAL store **/ diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VnfExecutionFlow.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VnfExecutionFlow.java index 8c28e4412..760f4b159 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VnfExecutionFlow.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VnfExecutionFlow.java @@ -24,12 +24,12 @@ package org.onap.appc.dg.common; +import java.util.Map; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; -import java.util.Map; - @FunctionalInterface public interface VnfExecutionFlow extends SvcLogicJavaPlugin { - void getVnfExecutionFlowData(Map params, SvcLogicContext context); + + void getVnfExecutionFlowData(Map params, SvcLogicContext context); } 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 30ba0808f..78dd780d4 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 @@ -24,11 +24,10 @@ package org.onap.appc.dg.common.impl; -import org.onap.appc.rankingframework.RankedAttributesResolver; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; - import java.util.concurrent.locks.ReentrantLock; +import org.onap.appc.rankingframework.RankedAttributesResolver; abstract class AbstractResolver { @@ -113,5 +112,6 @@ abstract class AbstractResolver { return dgResolver; } - protected abstract FlowKey resolve(final String...args); + + 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/AbstractResolverDataReader.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolverDataReader.java index 19e2a5c37..a2b1c007c 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolverDataReader.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolverDataReader.java @@ -24,26 +24,26 @@ package org.onap.appc.dg.common.impl; -import org.onap.appc.dao.util.DBUtils; -import org.onap.appc.rankingframework.AbstractRankedAttributesResolverFactory; -import org.onap.appc.rankingframework.ConfigurationEntry; -import org.onap.appc.rankingframework.ConfigurationSet; -import org.onap.appc.rankingframework.RankedAttributesResolver; - import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Collection; import java.util.Iterator; +import org.onap.appc.dao.util.DBUtils; +import org.onap.appc.rankingframework.AbstractRankedAttributesResolverFactory; +import org.onap.appc.rankingframework.ConfigurationEntry; +import org.onap.appc.rankingframework.ConfigurationSet; +import org.onap.appc.rankingframework.RankedAttributesResolver; abstract class AbstractResolverDataReader { - private class ConfigurationSetAdaptor implements ConfigurationSet { + private class ConfigurationSetAdaptor implements ConfigurationSet { private final ResultSet resultSet; private class ResultSetIterator implements Iterator>, ConfigurationEntry { + @Override public boolean hasNext() { try { @@ -75,7 +75,8 @@ abstract class AbstractResolverDataReader { @Override public FlowKey getResult() { try { - return new FlowKey(resultSet.getString("dg_name"), resultSet.getString("dg_version"), resultSet.getString("dg_module")); + return new FlowKey(resultSet.getString("dg_name"), resultSet.getString("dg_version"), + resultSet.getString("dg_module")); } catch (SQLException e) { throw new DataReaderException(e); } @@ -99,8 +100,8 @@ abstract class AbstractResolverDataReader { } protected abstract Collection getAttributeNames(); - protected abstract String getQueryStmt(); + protected abstract String getQueryStmt(); RankedAttributesResolver read() { 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 603b65a19..9009f3c62 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 @@ -25,7 +25,6 @@ package org.onap.appc.dg.common.impl; - class Constants { public static final String DG_ERROR_FIELD_NAME = "org.onap.appc.dg.error"; @@ -40,13 +39,13 @@ class Constants { public static final String OUTPUT_PAYLOAD = "output.payload"; //Added for VnfExecution Flow - public static final String FLOW_STRATEGY = "FlowStrategy" ; + public static final String FLOW_STRATEGY = "FlowStrategy"; public static final String DEPENDENCY_TYPE = "DependencyType"; public static final String VNF_TYPE = "vnfType"; public static final String VNF_VERION = "vnfVersion"; - public static final String APPC_INSTANCE_ID= "appc-instance-id"; + public static final String APPC_INSTANCE_ID = "appc-instance-id"; //Added for Cvaas public static final String CVAAS_DIRECTORY_PATH = "cvaas-directory-path"; @@ -61,9 +60,17 @@ class Constants { SkipHypervisorCheck("org.onap.appc.skiphypervisorcheck"); private String value; - LegacyAttributes(String value) {this.value = value;} - String getValue() {return value;} - }; + + LegacyAttributes(String value) { + this.value = value; + } + + String getValue() { + return value; + } + } + + ; enum LCMAttributes { Action("input.action"), @@ -74,9 +81,17 @@ class Constants { SkipHypervisorCheck("skip-hypervisor-check"); private String value; - LCMAttributes(String value) {this.value = value;} - String getValue() {return value;} - }; + + LCMAttributes(String value) { + this.value = value; + } + + String getValue() { + return value; + } + } + + ; // DG Resolver Constants public static final String IN_PARAM_VNF_TYPE = "vnfType"; @@ -85,7 +100,7 @@ class Constants { 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_VERSION = "dg_version"; public static final String OUT_PARAM_DG_MODULE = "dg_module"; public static final String TABLE_NAME = "VNFC_DG_MAPPING"; @@ -94,6 +109,6 @@ class Constants { 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_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 68f3cdc68..f0e7674ee 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 @@ -24,6 +24,7 @@ package org.onap.appc.dg.common.impl; +import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.onap.appc.adapter.message.EventSender; import org.onap.appc.adapter.message.MessageDestination; @@ -34,8 +35,6 @@ import org.onap.appc.dg.common.DCAEReporterPlugin; import org.onap.appc.exceptions.APPCException; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import java.util.Map; - public class DCAEReporterPluginImpl implements DCAEReporterPlugin { private EventSender eventSender; @@ -55,24 +54,24 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin { @Override public void report(Map params, SvcLogicContext ctx) throws APPCException { - String errorDescription,apiVersion,eventId ; + String errorDescription, apiVersion, eventId; - Integer errorCode = readErrorCode(params,ctx); + Integer errorCode = readErrorCode(params, ctx); errorDescription = params.get(Constants.EVENT_MESSAGE); - if(StringUtils.isEmpty(errorDescription)) { - reportLegacy(params , ctx); - }else{ - apiVersion = ctx.getAttribute("input.common-header.api-ver"); - eventId = ctx.getAttribute("input.common-header.request-id"); + if (StringUtils.isEmpty(errorDescription)) { + reportLegacy(params, ctx); + } else { + apiVersion = ctx.getAttribute("input.common-header.api-ver"); + eventId = ctx.getAttribute("input.common-header.request-id"); EventMessage eventMessage = new EventMessage(new EventHeader( - (new java.util.Date()).toString(), apiVersion, eventId), - new EventStatus(errorCode, errorDescription)); + (new java.util.Date()).toString(), apiVersion, eventId), + new EventStatus(errorCode, errorDescription)); String eventWriteTopic = params.get("event-topic-name"); - if(!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic!=null){ - eventSender.sendEvent(MessageDestination.DCAE, eventMessage,eventWriteTopic); - }else { + if (!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic != null) { + eventSender.sendEvent(MessageDestination.DCAE, eventMessage, eventWriteTopic); + } else { eventSender.sendEvent(MessageDestination.DCAE, eventMessage); } } @@ -81,12 +80,11 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin { private Integer readErrorCode(Map params, SvcLogicContext ctx) { Integer errorReportCode = 501; String errorCodeStr = params.get(Constants.DG_ERROR_CODE); - errorCodeStr = StringUtils.isEmpty(errorCodeStr)? - ctx.getAttribute(Constants.DG_ERROR_CODE):errorCodeStr; - try{ - errorReportCode = Integer.parseInt(errorCodeStr); - } - catch (NumberFormatException e){ + errorCodeStr = StringUtils.isEmpty(errorCodeStr) ? + ctx.getAttribute(Constants.DG_ERROR_CODE) : errorCodeStr; + try { + errorReportCode = Integer.parseInt(errorCodeStr); + } catch (NumberFormatException e) { // Ignore Exception } return errorReportCode; @@ -98,7 +96,7 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin { String successDescription, apiVersion, eventId; successDescription = params.get(Constants.EVENT_MESSAGE); - if(StringUtils.isEmpty(successDescription)) { + if (StringUtils.isEmpty(successDescription)) { successDescription = params.get(Constants.DG_OUTPUT_STATUS_MESSAGE); } @@ -109,32 +107,32 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin { successDescription = "Success"; } EventMessage eventMessage = new EventMessage(new EventHeader( - (new java.util.Date()).toString(), apiVersion, eventId), - new EventStatus(successReportCode, successDescription)); + (new java.util.Date()).toString(), apiVersion, eventId), + new EventStatus(successReportCode, successDescription)); String eventWriteTopic = params.get("event-topic-name"); - if(!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic!=null){ - eventSender.sendEvent(MessageDestination.DCAE, eventMessage,eventWriteTopic); - }else { + if (!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic != null) { + eventSender.sendEvent(MessageDestination.DCAE, eventMessage, eventWriteTopic); + } else { eventSender.sendEvent(MessageDestination.DCAE, eventMessage); } } private void reportLegacy(Map params, SvcLogicContext ctx) throws APPCException { - String errorDescription,apiVersion,eventId ; + String errorDescription, apiVersion, eventId; - Integer errorCode = readErrorCode(params,ctx); - errorDescription = getErrorDescriptionAndAddToCtx(params,ctx); + 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"); EventMessage eventMessage = new EventMessage(new EventHeader( - (new java.util.Date()).toString(), apiVersion, eventId), - new EventStatus(errorCode, errorDescription)); + (new java.util.Date()).toString(), apiVersion, eventId), + new EventStatus(errorCode, errorDescription)); String eventWriteTopic = params.get("event-topic-name"); - if(!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic!=null){ - eventSender.sendEvent(MessageDestination.DCAE, eventMessage,eventWriteTopic); - }else { + if (!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic != null) { + eventSender.sendEvent(MessageDestination.DCAE, eventMessage, eventWriteTopic); + } else { eventSender.sendEvent(MessageDestination.DCAE, eventMessage); } } @@ -142,26 +140,26 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin { private String getErrorDescriptionAndAddToCtx(Map params, SvcLogicContext ctx) { String errorDescription; errorDescription = params.get(Constants.DG_OUTPUT_STATUS_MESSAGE); - if(StringUtils.isEmpty(errorDescription)) { + if (StringUtils.isEmpty(errorDescription)) { errorDescription = ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE); } - if(StringUtils.isEmpty(errorDescription)) { + if (StringUtils.isEmpty(errorDescription)) { errorDescription = "Unknown"; } - addToContextIfNotContains(errorDescription,ctx); + addToContextIfNotContains(errorDescription, ctx); return errorDescription; } private void addToContextIfNotContains(String errorDescription, SvcLogicContext ctx) { String errorDescriptionFromCtx; errorDescriptionFromCtx = ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE); - if(StringUtils.isEmpty(errorDescriptionFromCtx)){ + if (StringUtils.isEmpty(errorDescriptionFromCtx)) { errorDescriptionFromCtx = ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE); } - if(StringUtils.isEmpty(errorDescriptionFromCtx)){ + if (StringUtils.isEmpty(errorDescriptionFromCtx)) { ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorDescription); - }else if (!errorDescriptionFromCtx.contains(errorDescription)){ - ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorDescriptionFromCtx+ " | "+ errorDescription); + } else if (!errorDescriptionFromCtx.contains(errorDescription)) { + 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 8c97092b3..f12a83b04 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 @@ -24,7 +24,7 @@ package org.onap.appc.dg.common.impl; -public class DataReaderException extends RuntimeException{ +public class DataReaderException extends RuntimeException { public DataReaderException(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 c68fde5a2..5b98dd941 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 @@ -24,14 +24,12 @@ package org.onap.appc.dg.common.impl; -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.i18n.Msg; import com.att.eelf.i18n.EELFResourceManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - import java.util.Map; - import org.onap.appc.dg.common.DgResolverPlugin; +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.i18n.Msg; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class DgResolverPluginImpl implements DgResolverPlugin { @@ -44,10 +42,14 @@ public class DgResolverPluginImpl implements DgResolverPlugin { FlowKey flowKey = null; try { - if(params.get("DGResolutionType").equalsIgnoreCase("VNFC")) { - 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")){ - 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 (params.get("DGResolutionType").equalsIgnoreCase("VNFC")) { + 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")) { + 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(); @@ -57,14 +59,16 @@ public class DgResolverPluginImpl implements DgResolverPlugin { 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.get(Constants.IN_PARAM_VNF_TYPE) - + " vnfc type : " + params.get(Constants.IN_PARAM_VNFC_TYPE) - + " action : " + params.get(Constants.IN_PARAM_ACTION) - + " api version : " + params.get(Constants.IN_PARAM_API_VERSION)); + throw new RuntimeException(params.get("DGResolutionType") + " 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) + + " api version : " + params.get(Constants.IN_PARAM_API_VERSION)); } } catch (Exception e) { - 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); + 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); } } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/FlowKey.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/FlowKey.java index 68f596f5d..a5c0cbb41 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/FlowKey.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/FlowKey.java @@ -25,6 +25,7 @@ package org.onap.appc.dg.common.impl; class FlowKey { + private final String name; private final String version; private final String module; 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 026fa2841..d9caf8f19 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,10 @@ 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.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; import org.apache.commons.lang3.StringUtils; import org.onap.appc.adapter.message.MessageAdapterFactory; import org.onap.appc.adapter.message.Producer; @@ -41,11 +45,6 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; -import java.util.HashSet; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - public class IntermediateMessageSenderImpl implements IntermediateMessageSender { @@ -63,17 +62,17 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender private static final String RESPONSE = "response"; private static final String MSO = "MSO"; - public void init(){ + public void init() { configuration = ConfigurationFactory.getConfiguration(); - Properties properties=configuration.getProperties(); + Properties properties = configuration.getProperties(); String writeTopic = properties.getProperty("appc.LCM.topic.write"); String apiKey = properties.getProperty("appc.LCM.client.key"); String apiSecret = properties.getProperty("appc.LCM.client.secret"); String hostNames = properties.getProperty("appc.LCM.poolMembers"); - logger.debug("Configuration Read : writeTopic = " + writeTopic +", " + - "hostNames = " + hostNames); + logger.debug("Configuration Read : writeTopic = " + writeTopic + ", " + + "hostNames = " + hostNames); Set pool = new HashSet<>(); if (!StringUtils.isEmpty(hostNames)) { @@ -86,7 +85,8 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender if (ctx != null) { ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName()); if (svcRef != null) { - producer = ((MessageAdapterFactory) ctx.getService(svcRef)).createProducer(pool, writeTopic,apiKey, apiSecret); + producer = ((MessageAdapterFactory) ctx.getService(svcRef)) + .createProducer(pool, writeTopic, apiKey, apiSecret); } } } @@ -94,30 +94,29 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender @Override public void sendMessage(Map params, SvcLogicContext context) { String prefix = params.get("prefix"); - prefix = StringUtils.isEmpty(prefix)? "":prefix+"."; - try{ - validateInputs(params,context); + prefix = StringUtils.isEmpty(prefix) ? "" : prefix + "."; + try { + validateInputs(params, context); String jsonMessage = getJsonMessage(params, context); logger.debug("Constructed JSON Message : " + jsonMessage); - producer.post("",jsonMessage); + producer.post("", jsonMessage); context.setAttribute(prefix + STATUS, SUCCESS); - } - catch(Exception e){ + } catch (Exception e) { String errorMessage = "Error sending intermediate message to initiator " + e.getMessage(); context.setAttribute(prefix + STATUS, FAILURE); context.setAttribute(prefix + ERROR_MESSAGE, errorMessage); - logger.error(errorMessage,e); + logger.error(errorMessage, e); } } private void validateInputs(Map params, SvcLogicContext context) throws APPCException { String code = params.get("code"); String message = params.get("message"); - if(StringUtils.isEmpty(code) || StringUtils.isEmpty(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"); - if(StringUtils.isEmpty(requestId)){ + if (StringUtils.isEmpty(requestId)) { throw new APPCException("requestId is empty"); } } @@ -129,18 +128,18 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender ObjectNode status = getStatus(params); ObjectNode output = objectMapper.createObjectNode(); - output.put("common-header",commonHeader); - output.put("status",status); + output.put("common-header", commonHeader); + output.put("status", status); - ObjectNode body = objectMapper.createObjectNode(); - body.put("output",output); + ObjectNode body = objectMapper.createObjectNode(); + body.put("output", output); ObjectNode root = objectMapper.createObjectNode(); root.put("type", RESPONSE); - root.put("rpc-name",context.getAttribute("input.action")); + root.put("rpc-name", context.getAttribute("input.action")); root.put("cambria.partition", MSO); - root.put("correlation-id",getCorrelationId(context)); - root.put("body",body); + root.put("correlation-id", getCorrelationId(context)); + root.put("body", body); return root.toString(); } @@ -148,25 +147,25 @@ public class IntermediateMessageSenderImpl implements IntermediateMessageSender private String getCorrelationId(SvcLogicContext context) { String requestId = context.getAttribute("input.common-header.request-id"); String subRequestId = context.getAttribute("input.common-header.sub-request-id"); - return requestId + (StringUtils.isEmpty(subRequestId)?"":("-"+subRequestId)); + return requestId + (StringUtils.isEmpty(subRequestId) ? "" : ("-" + subRequestId)); } - private ObjectNode getStatus(Map params) { + private ObjectNode getStatus(Map params) { ObjectMapper objectMapper = new ObjectMapper(); - ObjectNode status = objectMapper.createObjectNode(); - status.put("code",params.get("code")); - status.put("message",params.get("message")); + ObjectNode status = objectMapper.createObjectNode(); + status.put("code", params.get("code")); + status.put("message", params.get("message")); return status; } private ObjectNode getCommonHeader(SvcLogicContext context) { ObjectMapper objectMapper = new ObjectMapper(); - ObjectNode commonHeader = objectMapper.createObjectNode(); - 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("sub-request-id",context.getAttribute("input.common-header.sub-request-id")); + ObjectNode commonHeader = objectMapper.createObjectNode(); + 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("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 caad8b809..3d43dc1cd 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 @@ -24,11 +24,16 @@ package org.onap.appc.dg.common.impl; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.att.eelf.i18n.EELFResourceManager; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.File; import java.text.SimpleDateFormat; import java.util.Map; import java.util.Set; - import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.onap.appc.dg.common.JsonDgUtil; @@ -37,15 +42,9 @@ import org.onap.appc.i18n.Msg; import org.onap.appc.util.JsonUtil; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.att.eelf.i18n.EELFResourceManager; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - public class JsonDgUtilImpl implements JsonDgUtil { + private static final EELFLogger logger = EELFManager.getInstance().getLogger(JsonDgUtilImpl.class); private static final ThreadLocal DATE_TIME_PARSER_THREAD_LOCAL = new ThreadLocal() { @@ -58,13 +57,16 @@ public class JsonDgUtilImpl implements JsonDgUtil { public void flatAndAddToContext(Map params, SvcLogicContext ctx) throws APPCException { if (logger.isTraceEnabled()) { - logger.trace("Entering to flatAndAddToContext with params = "+ ObjectUtils.toString(params)+", SvcLogicContext = "+ObjectUtils.toString(ctx)); + logger.trace( + "Entering to flatAndAddToContext with params = " + ObjectUtils.toString(params) + ", SvcLogicContext = " + + ObjectUtils.toString(ctx)); } try { String paramName = Constants.PAYLOAD; String payload = params.get(paramName); - if (payload == null || payload.isEmpty()) + if (payload == null || payload.isEmpty()) { payload = ctx.getAttribute("input.payload"); + } if (!StringUtils.isEmpty(payload)) { Map flatMap = JsonUtil.convertJsonStringToFlatMap(payload); if (flatMap != null && flatMap.size() > 0) { @@ -77,16 +79,17 @@ public class JsonDgUtilImpl implements JsonDgUtil { } } catch (Exception e) { logger.error(e.toString()); - String msg = EELFResourceManager.format(Msg.INPUT_PAYLOAD_PARSING_FAILED,params.get(Constants.PAYLOAD)); + String msg = EELFResourceManager.format(Msg.INPUT_PAYLOAD_PARSING_FAILED, params.get(Constants.PAYLOAD)); ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg); throw new APPCException(e); } } @Override - public void generateOutputPayloadFromContext(Map params, SvcLogicContext ctx) throws APPCException{ + public void generateOutputPayloadFromContext(Map params, SvcLogicContext ctx) throws APPCException { if (logger.isTraceEnabled()) { - logger.trace("Entering to generateOutputPayloadFromContext with SvcLogicContext = "+ObjectUtils.toString(ctx)); + logger.trace( + "Entering to generateOutputPayloadFromContext with SvcLogicContext = " + ObjectUtils.toString(ctx)); } try { @@ -94,26 +97,27 @@ public class JsonDgUtilImpl implements JsonDgUtil { ObjectMapper objectMapper = new ObjectMapper(); 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("]")){ + 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 { + 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); + arrayNode.insert(arrayIndex, ctx.getAttribute(key)); + JsonNode.put(arrayKey, arrayNode); } - }else { + } else { JsonNode.put(objkey, ctx.getAttribute(key)); } } } - if(JsonNode.size()>0) { + if (JsonNode.size() > 0) { ctx.setAttribute(Constants.OUTPUT_PAYLOAD, objectMapper.writeValueAsString(JsonNode)); } } catch (Exception e) { @@ -126,11 +130,11 @@ public class JsonDgUtilImpl implements JsonDgUtil { @Override public void cvaasFileNameAndFileContentToContext(Map params, SvcLogicContext ctx) - throws APPCException { + throws APPCException { if (logger.isTraceEnabled()) { logger.trace("Entering to caasFileNameAndFileContentToContext with SvcLogicContext = " - + ObjectUtils.toString(ctx)); + + ObjectUtils.toString(ctx)); } String vnfId = null; @@ -139,13 +143,13 @@ public class JsonDgUtilImpl implements JsonDgUtil { String appcInstanceId = params.get(Constants.APPC_INSTANCE_ID); /* - * File name + * File name */ vnfId = params.get("vnf-id"); long timestampAsLongRepresentingFileCreationTime = System.currentTimeMillis(); ctx.setAttribute(Constants.CVAAS_FILE_NAME, cvassDirectoryPath + File.separator + vnfId + "_" - + timestampAsLongRepresentingFileCreationTime + "_" + appcInstanceId + ".json"); + + timestampAsLongRepresentingFileCreationTime + "_" + appcInstanceId + ".json"); /* * File content @@ -174,7 +178,7 @@ public class JsonDgUtilImpl implements JsonDgUtil { jsonNode.put("CONTENT", ctx.getAttribute("running-config.content")); ctx.setAttribute(Constants.CVAAS_FILE_CONTENT, - objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode)); + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode)); } catch (Exception e) { String errorMessage = "Failed to parse create cvass file for vnf with id : " + vnfId; 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 ad0884b94..400dadb34 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 @@ -25,28 +25,33 @@ package org.onap.appc.dg.common.impl; import java.util.Map; - import org.onap.appc.dg.common.LegacyUtil; import org.onap.appc.dg.common.utils.JSONUtil; import org.onap.appc.exceptions.APPCException; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - public class LegacyUtilImpl implements LegacyUtil { - @Override public void prepareRequest(Map params, SvcLogicContext ctx) throws APPCException { - ctx.setAttribute(Constants.LegacyAttributes.Action.getValue(), ctx.getAttribute(Constants.LCMAttributes.Action.getValue()).toLowerCase()); + @Override + public void prepareRequest(Map params, SvcLogicContext ctx) throws APPCException { + ctx.setAttribute(Constants.LegacyAttributes.Action.getValue(), + ctx.getAttribute(Constants.LCMAttributes.Action.getValue()).toLowerCase()); String payloadStr = ctx.getAttribute(Constants.LCMAttributes.Payload.getValue()); - Map payloads = JSONUtil.extractPlainValues(payloadStr, - Constants.LCMAttributes.VMID.getValue(), Constants.LCMAttributes.IdentityURL.getValue(), Constants.LCMAttributes.TenantID.getValue(), - Constants.LCMAttributes.SkipHypervisorCheck.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())); + Map payloads = JSONUtil.extractPlainValues(payloadStr, + Constants.LCMAttributes.VMID.getValue(), Constants.LCMAttributes.IdentityURL.getValue(), + Constants.LCMAttributes.TenantID.getValue(), + Constants.LCMAttributes.SkipHypervisorCheck.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())); } 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 66ac82fcb..cd385c9d2 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 @@ -24,14 +24,12 @@ package org.onap.appc.dg.common.impl; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import static org.apache.commons.lang3.StringUtils.isEmpty; import java.util.Map; - import org.onap.appc.dg.common.OutputMessagePlugin; import org.onap.appc.exceptions.APPCException; - -import static org.apache.commons.lang3.StringUtils.isEmpty; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class OutputMessagePluginImpl implements OutputMessagePlugin { @@ -43,7 +41,7 @@ public class OutputMessagePluginImpl implements OutputMessagePlugin { errorDescription = params.get(Constants.ATTRIBUTE_ERROR_MESSAGE); eventDescription = params.get(Constants.EVENT_MESSAGE); - addToContextIfNotContains(errorDescription , eventDescription, ctx); + addToContextIfNotContains(errorDescription, eventDescription, ctx); //making event-message @@ -54,19 +52,22 @@ public class OutputMessagePluginImpl implements OutputMessagePlugin { } } - public static void addToContextIfNotContains(String errorDescription, String eventDescription, SvcLogicContext ctx) { - if (!isEmpty(errorDescription)){ + public 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); + } 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); } } - if (!isEmpty(eventDescription)){ + 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); + } 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 790547f37..15e4ab681 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 @@ -28,19 +28,22 @@ import org.onap.appc.configuration.Configuration; import org.onap.appc.configuration.ConfigurationFactory; public class ResolverDataReaderFactory { + private static final Configuration configuration = ConfigurationFactory.getConfiguration(); - private static class ReferenceHolder{ + + private static class ReferenceHolder { + private static final AbstractResolverDataReader VNFC_RESOLVER_DATA_READER = new VNFCResolverDataReader(); private static final AbstractResolverDataReader VNF_RESOLVER_DATA_READER = new VNFResolverDataReader(); } - public static AbstractResolverDataReader createResolverDataReader(String resolverType){ - if(resolverType.equalsIgnoreCase("VNF")){ + public static AbstractResolverDataReader createResolverDataReader(String resolverType) { + if (resolverType.equalsIgnoreCase("VNF")) { return ReferenceHolder.VNF_RESOLVER_DATA_READER; - }else if(resolverType.equalsIgnoreCase("VNFC")){ + } else if (resolverType.equalsIgnoreCase("VNFC")) { return ReferenceHolder.VNFC_RESOLVER_DATA_READER; - }else { + } else { return null; } } 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 e39546846..be71dae8d 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 @@ -28,18 +28,23 @@ import org.onap.appc.configuration.Configuration; import org.onap.appc.configuration.ConfigurationFactory; 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 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)); } - public static AbstractResolver createResolver(String resolverType){ - if(resolverType.equalsIgnoreCase("VNF")){ + public static AbstractResolver createResolver(String resolverType) { + if (resolverType.equalsIgnoreCase("VNF")) { return ReferenceHolder.VNF_RESOLVER; - }else if(resolverType.equalsIgnoreCase("VNFC")){ + } else if (resolverType.equalsIgnoreCase("VNFC")) { return ReferenceHolder.VNFC_RESOLVER; - }else { + } else { return null; } } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCDgResolverPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCDgResolverPluginImpl.java index 304bdf882..4a7911658 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCDgResolverPluginImpl.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCDgResolverPluginImpl.java @@ -24,16 +24,16 @@ package org.onap.appc.dg.common.impl; +import java.util.Map; import org.onap.appc.exceptions.APPCException; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import java.util.Map; - public class VNFCDgResolverPluginImpl implements org.onap.appc.dg.common.VNFCDgResolverPlugin { + @Override public void resolveVNFCDg(Map params, SvcLogicContext ctx) throws APPCException { DgResolverPluginImpl dgResolverPlugin = new DgResolverPluginImpl(); - params.put("DGResolutionType" , "VNFC"); - dgResolverPlugin.resolveDg(params,ctx); + params.put("DGResolutionType", "VNFC"); + dgResolverPlugin.resolveDg(params, ctx); } } 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 e2893951b..a6b5e656f 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 @@ -28,19 +28,21 @@ import org.onap.appc.rankingframework.RankedAttributesContext; public class VNFCResolver extends AbstractResolver { + VNFCResolver(int interval) { super(interval); } @Override protected FlowKey resolve(String... args) { - if(args.length !=4){ + if (args.length != 4) { throw new IllegalStateException(args.toString()); } - return resolve(args[0],args[1],args[2],args[3]); + return resolve(args[0], args[1], args[2], args[3]); } - protected FlowKey resolve(final String action, final String vnfType, final String vnfcType, final String apiVersion) { + protected FlowKey resolve(final String action, final String vnfType, final String vnfcType, + final String apiVersion) { RankedAttributesContext context = new RankedAttributesContext() { @Override public Object getAttributeValue(String name) { diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolverDataReader.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolverDataReader.java index c78da685c..544f2a30b 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolverDataReader.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolverDataReader.java @@ -28,9 +28,10 @@ import java.util.Arrays; import java.util.Collection; public class VNFCResolverDataReader extends AbstractResolverDataReader { + @Override protected Collection getAttributeNames() { - return Arrays.asList("action","api_version", "vnf_type", "vnfc_type"); + return Arrays.asList("action", "api_version", "vnf_type", "vnfc_type"); } @Override diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFConfiguratorImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFConfiguratorImpl.java index c46a9c227..d2499313d 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFConfiguratorImpl.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFConfiguratorImpl.java @@ -24,6 +24,13 @@ package org.onap.appc.dg.common.impl; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; import org.onap.appc.Constants; import org.onap.appc.dg.common.VNFConfigurator; import org.onap.appc.exceptions.APPCException; @@ -31,15 +38,7 @@ import org.onap.appc.mdsal.MDSALStore; import org.onap.appc.mdsal.exception.MDSALStoreException; import org.onap.appc.mdsal.impl.MDSALStoreFactory; import org.onap.appc.mdsal.objects.BundleInfo; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.apache.commons.lang3.StringUtils; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Map; public class VNFConfiguratorImpl implements VNFConfigurator { @@ -57,48 +56,49 @@ public class VNFConfiguratorImpl implements VNFConfigurator { String configJSON = params.get("configJSON"); String requestId = params.get("requestId"); String prefix = params.get("prefix"); - prefix = StringUtils.isEmpty(prefix)? "":prefix+"."; + prefix = StringUtils.isEmpty(prefix) ? "" : prefix + "."; MDSALStore store = MDSALStoreFactory.createMDSALStore(); logger.debug("Inputs Received : uniqueId = " + uniqueId + - " , yang = " + yang + - " , configJSON = " + configJSON + - " , requestId = " + requestId + - " , prefix = " +prefix); + " , yang = " + yang + + " , configJSON = " + configJSON + + " , requestId = " + requestId + + " , prefix = " + prefix); try { - if(StringUtils.isEmpty(uniqueId) - ||StringUtils.isEmpty(yang) - || StringUtils.isEmpty(configJSON) - || StringUtils.isEmpty(requestId)){ + if (StringUtils.isEmpty(uniqueId) + || StringUtils.isEmpty(yang) + || StringUtils.isEmpty(configJSON) + || StringUtils.isEmpty(requestId)) { throw new APPCException("One or more input parameters are empty : uniqueId = " + uniqueId + " " + - ", yang = " + yang + - " , configJSON = " + configJSON + - " , requestId = " + requestId); + ", yang = " + yang + + " , configJSON = " + configJSON + + " , requestId = " + requestId); } Date revision = new SimpleDateFormat(Constants.YANG_REVISION_FORMAT).parse(Constants.YANG_REVISION); - boolean isYangAlreadyLoaded = store.isModulePresent(uniqueId,revision); + boolean isYangAlreadyLoaded = store.isModulePresent(uniqueId, revision); - if(!isYangAlreadyLoaded){ + if (!isYangAlreadyLoaded) { BundleInfo bundleInfo = getBundleInfo(uniqueId); - store.storeYangModule(yang,bundleInfo); + store.storeYangModule(yang, bundleInfo); } - store.storeJson(uniqueId, requestId , configJSON); + store.storeJson(uniqueId, requestId, configJSON); context.setAttribute(prefix + STATUS, SUCCESS); } catch (ParseException e) { - String errorMessage ="Error parsing the date : " + Constants.YANG_REVISION + " into format " + Constants.YANG_REVISION_FORMAT; - logger.error(errorMessage,e); + String errorMessage = "Error parsing the date : " + Constants.YANG_REVISION + " into format " + + Constants.YANG_REVISION_FORMAT; + logger.error(errorMessage, e); context.setAttribute(prefix + STATUS, FAILURE); context.setAttribute(prefix + ERROR_MESSAGE, errorMessage); throw new APPCException(e.getMessage()); - }catch (MDSALStoreException e){ + } catch (MDSALStoreException e) { String errorMessage = "Error while adding yang to MD-SAL store." + e.getMessage(); - logger.error(errorMessage,e); - context.setAttribute(prefix + STATUS,FAILURE); + logger.error(errorMessage, e); + context.setAttribute(prefix + STATUS, FAILURE); context.setAttribute(prefix + ERROR_MESSAGE, errorMessage); throw new APPCException(e.getMessage()); } 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 501ad0713..10d4fffc3 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 @@ -27,17 +27,19 @@ package org.onap.appc.dg.common.impl; import org.onap.appc.rankingframework.RankedAttributesContext; public class VNFResolver extends AbstractResolver { + VNFResolver(int interval) { super(interval); } @Override protected FlowKey resolve(String... args) { - return resolve(args[0],args[1],args[2],args[3]); + return resolve(args[0], args[1], args[2], args[3]); } - protected FlowKey resolve(final String action, final String vnfType, final String vnfVersion, final String apiVersion) { + protected FlowKey resolve(final String action, final String vnfType, final String vnfVersion, + final String apiVersion) { RankedAttributesContext context = new RankedAttributesContext() { @Override public Object getAttributeValue(String name) { diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolverDataReader.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolverDataReader.java index 3c4cf837e..8b30230d4 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolverDataReader.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolverDataReader.java @@ -31,9 +31,10 @@ import java.util.Collection; * @since January 19,2017 */ public class VNFResolverDataReader extends AbstractResolverDataReader { + @Override protected Collection getAttributeNames() { - return Arrays.asList("action","api_version", "vnf_type", "vnf_version"); + return Arrays.asList("action", "api_version", "vnf_type", "vnf_version"); } @Override 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 8129e2e02..fe7545d0f 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 @@ -27,11 +27,11 @@ package org.onap.appc.dg.common.impl; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.att.eelf.i18n.EELFResourceManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.appc.exceptions.APPCException; - -import java.util.*; - +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.onap.appc.dg.common.VnfExecutionFlow; import org.onap.appc.dg.dependencymanager.DependencyManager; import org.onap.appc.dg.dependencymanager.exception.DependencyModelNotFound; @@ -39,23 +39,30 @@ import org.onap.appc.dg.dependencymanager.impl.DependencyModelFactory; import org.onap.appc.dg.flowbuilder.FlowBuilder; import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModelException; import org.onap.appc.dg.flowbuilder.impl.FlowBuilderFactory; -import org.onap.appc.dg.objects.*; +import org.onap.appc.dg.objects.DependencyTypes; +import org.onap.appc.dg.objects.FlowStrategies; +import org.onap.appc.dg.objects.InventoryModel; +import org.onap.appc.dg.objects.Node; +import org.onap.appc.dg.objects.VnfcDependencyModel; +import org.onap.appc.dg.objects.VnfcFlowModel; import org.onap.appc.domainmodel.Vnf; import org.onap.appc.domainmodel.Vnfc; import org.onap.appc.domainmodel.Vserver; +import org.onap.appc.exceptions.APPCException; import org.onap.appc.i18n.Msg; import org.onap.appc.metadata.objects.DependencyModelIdentifier; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class VnfExecutionFlowImpl implements VnfExecutionFlow { private final EELFLogger logger = EELFManager.getInstance().getLogger(VnfExecutionFlowImpl.class); - private static final String VNFC_FLOW="vnfcFlow["; - private static final String VNF_VNFC="vnf.vnfc["; + private static final String VNFC_FLOW = "vnfcFlow["; + private static final String VNF_VNFC = "vnf.vnfc["; + /** - * Constructor - *

Used through blueprint + * Constructor

Used through blueprint */ - public VnfExecutionFlowImpl(){ + public VnfExecutionFlowImpl() { // do nothing } @@ -70,133 +77,135 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { if (logger.isTraceEnabled()) { logger.trace("Input received from DG Node : dependencyType = " + dependencyType + - " , flowStrategy = " + flowStrategy + - ", DependencyModelIdentifier = " + modelIdentifier.toString()); + " , flowStrategy = " + flowStrategy + + ", DependencyModelIdentifier = " + modelIdentifier.toString()); } DependencyManager dependencyManager = DependencyModelFactory.createDependencyManager(); dependencyModel = dependencyManager.getVnfcDependencyModel( - modelIdentifier, DependencyTypes.findByString(dependencyType)); + modelIdentifier, DependencyTypes.findByString(dependencyType)); } catch (DependencyModelNotFound e) { - String msg = EELFResourceManager.format(Msg.DEPENDENCY_MODEL_NOT_FOUND,params.get(Constants.VNF_TYPE), e.getMessage()); + String msg = EELFResourceManager + .format(Msg.DEPENDENCY_MODEL_NOT_FOUND, params.get(Constants.VNF_TYPE), e.getMessage()); logger.error(msg); - context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg); - context.setAttribute("dependencyModelFound","false"); + 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()); + } catch (InvalidDependencyModelException e) { + String msg = EELFResourceManager + .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); - } catch (APPCException e){ + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg); + throw new RuntimeException(e.getMessage(), e); + } catch (APPCException e) { logger.error(e.getMessage()); - context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); - throw new RuntimeException(e.getMessage(),e); - } - catch (RuntimeException e){ + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, e.getMessage()); + throw new RuntimeException(e.getMessage(), e); + } catch (RuntimeException e) { logger.error(e.getMessage()); - context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, e.getMessage()); throw e; } - - context.setAttribute("dependencyModelFound","true"); - if(logger.isDebugEnabled()){ - logger.debug("Dependency Model = " +dependencyModel); + context.setAttribute("dependencyModelFound", "true"); + if (logger.isDebugEnabled()) { + logger.debug("Dependency Model = " + dependencyModel); } logger.info("Building Inventory Model from DG context"); InventoryModel inventoryModel = null; try { - inventoryModel = readInventoryModel(context); + inventoryModel = readInventoryModel(context); } catch (APPCException e) { logger.error(e.getMessage()); - context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); - throw new RuntimeException(e.getMessage(),e); + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, e.getMessage()); + throw new RuntimeException(e.getMessage(), e); } - if(logger.isDebugEnabled()){ - logger.debug("Inventory Model = " +inventoryModel); + if (logger.isDebugEnabled()) { + logger.debug("Inventory Model = " + inventoryModel); } - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug("Validating inventory model with dependency model"); } try { validateInventoryModelWithDependencyModel(dependencyModel, inventoryModel); - } - catch (APPCException e){ + } catch (APPCException e) { logger.error(e.getMessage()); - context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); - throw new RuntimeException(e.getMessage(),e); + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, e.getMessage()); + throw new RuntimeException(e.getMessage(), e); } logger.info("Creating flow builder"); FlowBuilder flowBuilder = FlowBuilderFactory.getInstance().getFlowBuilder( - FlowStrategies.findByString(flowStrategy)); + FlowStrategies.findByString(flowStrategy)); logger.info("Building Vnf flow model"); VnfcFlowModel flowModel; - try{ - flowModel = flowBuilder.buildFlowModel(dependencyModel,inventoryModel); - } - catch (InvalidDependencyModelException e){ - String msg = EELFResourceManager.format(Msg.INVALID_DEPENDENCY_MODEL,params.get(Constants.VNF_TYPE), e.getMessage()); + try { + flowModel = flowBuilder.buildFlowModel(dependencyModel, inventoryModel); + } catch (InvalidDependencyModelException e) { + String msg = EELFResourceManager + .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); + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg); + throw new RuntimeException(e.getMessage(), e); } // remove VNFCs from the flow model where vserver list is empty reconcileFlowModel(flowModel); - populateContext(flowModel,context); - if(logger.isDebugEnabled()){ + populateContext(flowModel, context); + if (logger.isDebugEnabled()) { logContext(context); } - String msg = EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "GetVnfExecutionFlowData","VNF ID " + params.get(Constants.VNF_TYPE)); + String msg = EELFResourceManager + .format(Msg.SUCCESS_EVENT_MESSAGE, "GetVnfExecutionFlowData", "VNF ID " + params.get(Constants.VNF_TYPE)); context.setAttribute(org.onap.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg); } - private void validateInput(String dependencyType, String flowStrategy, Map params) throws APPCException { + private void validateInput(String dependencyType, String flowStrategy, Map params) + throws APPCException { DependencyTypes dependencyTypes = DependencyTypes.findByString(dependencyType); - if(dependencyTypes == null){ - throw new APPCException("Dependency type from the input : " + dependencyType +" is invalid."); + if (dependencyTypes == null) { + throw new APPCException("Dependency type from the input : " + dependencyType + " is invalid."); } FlowStrategies flowStrategies = FlowStrategies.findByString(flowStrategy); - if(flowStrategies == null){ - throw new APPCException("Flow Strategy from the input : " + flowStrategy +" is invalid."); + if (flowStrategies == null) { + 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 (vnfType == null || vnfType.length() == 0) { 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 (vnfVersion == null || vnfVersion.length() == 0) { throw new APPCException("Vnf Version not found"); } } private void logContext(SvcLogicContext context) { - for(String key:context.getAttributeKeySet()){ - logger.debug(key + " = " + context.getAttribute(key) + "\n" ); + for (String key : context.getAttributeKeySet()) { + logger.debug(key + " = " + context.getAttribute(key) + "\n"); } } private void populateContext(VnfcFlowModel flowModel, SvcLogicContext context) { - int flowIndex=0; + int flowIndex = 0; Iterator> iterator = flowModel.getModelIterator(); - while (iterator.hasNext()){ - for(Vnfc vnfc:iterator.next()){ - context.setAttribute(VNFC_FLOW+flowIndex+"].vnfcName",vnfc.getVnfcName()); - context.setAttribute(VNFC_FLOW+flowIndex+"].vnfcType",vnfc.getVnfcType()); - context.setAttribute(VNFC_FLOW+flowIndex+"].resilienceType",vnfc.getResilienceType()); - context.setAttribute(VNFC_FLOW+flowIndex+"].vmCount",Integer.toString(vnfc.getVserverList().size())); - int vmIndex =0; - for(Vserver vm :vnfc.getVserverList()){ - context.setAttribute(VNFC_FLOW+flowIndex+"].vm["+vmIndex+"].url",vm.getUrl()); + while (iterator.hasNext()) { + for (Vnfc vnfc : iterator.next()) { + context.setAttribute(VNFC_FLOW + flowIndex + "].vnfcName", vnfc.getVnfcName()); + context.setAttribute(VNFC_FLOW + flowIndex + "].vnfcType", vnfc.getVnfcType()); + context.setAttribute(VNFC_FLOW + flowIndex + "].resilienceType", vnfc.getResilienceType()); + context + .setAttribute(VNFC_FLOW + flowIndex + "].vmCount", Integer.toString(vnfc.getVserverList().size())); + int vmIndex = 0; + for (Vserver vm : vnfc.getVserverList()) { + context.setAttribute(VNFC_FLOW + flowIndex + "].vm[" + vmIndex + "].url", vm.getUrl()); vmIndex++; } flowIndex++; } } - context.setAttribute("vnfcFlowCount",Integer.toString(flowIndex)); + context.setAttribute("vnfcFlowCount", Integer.toString(flowIndex)); } private InventoryModel readInventoryModel(SvcLogicContext context) throws APPCException { @@ -206,17 +215,17 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { String vnfcCountStr = context.getAttribute("vnf.vnfcCount"); Integer vnfcCount = Integer.parseInt(vnfcCountStr); Vnf vnf = createVnf(vnfId, vnfType, vnfVersion); - for(Integer i=0;i params) { String vnfType = params.get(Constants.VNF_TYPE); String catalogVersion = params.get(Constants.VNF_VERION); - return new DependencyModelIdentifier(vnfType,catalogVersion); + return new DependencyModelIdentifier(vnfType, catalogVersion); } - private void validateInventoryModelWithDependencyModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) throws APPCException { + private void validateInventoryModelWithDependencyModel(VnfcDependencyModel dependencyModel, + InventoryModel inventoryModel) throws APPCException { Set dependencyModelVnfcSet = new HashSet<>(); Set dependencyModelMandatoryVnfcSet = new HashSet<>(); Set inventoryModelVnfcsSet = new HashSet<>(); @@ -293,7 +303,8 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { 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."); + 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/objects/ConnectionDetails.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/objects/ConnectionDetails.java index 1572e726b..40f5cba11 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 @@ -25,7 +25,6 @@ package org.onap.appc.dg.common.objects; - public class ConnectionDetails { private String host; -- cgit 1.2.3-korg