aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dg/appc-dg-shared
diff options
context:
space:
mode:
Diffstat (limited to 'appc-dg/appc-dg-shared')
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-aai/pom.xml16
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/AAIPlugin.java10
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/exception/AAIQueryException.java29
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/impl/AAIPluginImpl.java302
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/impl/Constants.java2
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/objects/AAIQueryResult.java49
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/objects/Relationship.java66
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-aai/src/main/test/java/org/openecomp/appc/dg/aai/impl/AAIPluginImplTest.java16
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/pom.xml47
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/DgResolverPlugin.java32
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/IntermediateMessageSender.java48
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/JsonDgUtil.java18
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/OutputMessagePlugin.java35
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFCDgResolverPlugin.java34
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFConfigurator.java43
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VnfExecutionFlow.java31
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolver.java114
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolverDataReader.java127
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/Constants.java43
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java134
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DgResolverPluginImpl.java68
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/FlowKey.java59
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/IntermediateMessageSenderImpl.java169
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImpl.java136
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/LegacyUtilImpl.java4
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/OutputMessagePluginImpl.java70
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverDataReaderFactory.java44
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverFactory.java43
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCDgResolverPluginImpl.java36
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolver.java64
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolverDataReader.java37
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFConfiguratorImpl.java112
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolver.java60
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolverDataReader.java40
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VnfExecutionFlowImpl.java268
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml25
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java40
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/EventSenderMock.java19
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java28
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVNFConfiguratorImpl.java105
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVnfExecutionFlowImpl.java417
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/.gitignore1
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/.settings/org.eclipse.core.resources.prefs5
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/.settings/org.eclipse.m2e.core.prefs4
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/.settings/org.eclipse.wst.common.project.facet.core.xml4
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/pom.xml78
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyManager.java33
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyType.java32
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/exception/DependencyModelNotFound.java29
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/helper/DependencyModelParser.java183
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyManagerImpl.java71
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyModelFactory.java37
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/ResourceDependency.java83
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowBuilder.java31
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowStrategy.java32
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/exception/InvalidDependencyModel.java29
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/helper/Graph.java64
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/AbstractFlowStrategy.java133
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderFactory.java48
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderImpl.java49
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ForwardFlowStrategy.java114
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ReverseFlowStrategy.java115
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/DependencyTypes.java36
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/FlowStrategies.java36
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/InventoryModel.java43
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/Node.java74
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcDependencyModel.java48
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcFlowModel.java89
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/openecomp/appc/dg/flowbuilder/TestFlowBuilder.java329
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.gitignore1
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.settings/org.eclipse.core.resources.prefs3
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.settings/org.eclipse.m2e.core.prefs4
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.settings/org.eclipse.wst.common.project.facet.core.xml4
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-domain-model-lib/pom.xml29
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/Vnf.java69
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/Vnfc.java145
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/Vserver.java75
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-license-manager/pom.xml8
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-license-manager/src/main/java/org/openecomp/appc/dg/licmgr/LicenseManagerPlugin.java1
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-mdsal-store/pom.xml45
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/MDSALStore.java62
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/exception/MDSALStoreException.java69
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/Constants.java108
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/MDSALStoreFactory.java47
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/MDSALStoreImpl.java137
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/objects/BundleInfo.java71
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperation.java289
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperationRequestFormatter.java51
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-netconf/pom.xml6
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-netconf/src/main/java/org/openecomp/appc/dg/netconf/NetconfClientPlugin.java1
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/openecomp/appc/dg/netconf/impl/NetconfClientPluginImplTest.java679
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-shared-features/src/main/resources/features.xml4
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-ssh/pom.xml6
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-ssh/src/main/java/org/openecomp/appc/dg/ssh/impl/SshDBPluginImpl.java26
-rw-r--r--appc-dg/appc-dg-shared/pom.xml5
95 files changed, 5971 insertions, 844 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-aai/pom.xml b/appc-dg/appc-dg-shared/appc-dg-aai/pom.xml
index 814386788..db5dcf390 100644
--- a/appc-dg/appc-dg-shared/appc-dg-aai/pom.xml
+++ b/appc-dg/appc-dg-shared/appc-dg-aai/pom.xml
@@ -30,6 +30,11 @@
<groupId>org.openecomp.sdnc.adaptors</groupId>
<artifactId>aai-service-provider</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-dg-dependency-model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>junit</groupId>
@@ -56,6 +61,11 @@
<version>1.6.2</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-dg-domain-model-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
@@ -69,12 +79,12 @@
<instructions>
<Bundle-SymbolicName>appc-dg-aai</Bundle-SymbolicName>
<Export-Package>org.openecomp.appc.dg.aai</Export-Package>
- <Private-Package>org.openecomp.appc.dg.aai.impl.*</Private-Package>
+ <Private-Package>org.openecomp.appc.dg.aai.exception,org.openecomp.appc.dg.aai.objects,org.openecomp.appc.dg.aai.impl.*</Private-Package>
<Import-Package>
- !org.apache.log,!org.apache.commons.logging,!groovy.lang,!javax.jms,!org.codehaus.commons.compiler,!org.codehaus.groovy.*,!org.codehaus.janino,!com.ibm.icu.*,!com.sun.faces.*,!org.jasypt.*,*;resolution:=optional
+ *;resolution:=optional
</Import-Package>
<Embed-Dependency>
- appc-common,eelf-core,logback-core,logback-classic;scope=compile|runtime;inline=false
+ appc-dg-domain-model-lib;scope=compile|runtime;inline=false
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
diff --git a/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/AAIPlugin.java b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/AAIPlugin.java
index e220182f2..7985dc454 100644
--- a/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/AAIPlugin.java
+++ b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/AAIPlugin.java
@@ -27,9 +27,17 @@ import org.openecomp.appc.exceptions.APPCException;
import org.openecomp.sdnc.sli.SvcLogicContext;
import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
-
public interface AAIPlugin extends SvcLogicJavaPlugin {
void postGenericVnfData(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
void getGenericVnfData(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
+
+ void getVnfHierarchy(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
+
+ void getResource(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
+
+ void postResource(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
+
+ void deleteResource(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
+
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/exception/AAIQueryException.java b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/exception/AAIQueryException.java
new file mode 100644
index 000000000..f9f781b50
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/exception/AAIQueryException.java
@@ -0,0 +1,29 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.aai.exception;
+
+
+public class AAIQueryException extends Exception{
+ public AAIQueryException(String message){
+ super(message);
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/impl/AAIPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/impl/AAIPluginImpl.java
index 6eae559e8..830147ca2 100644
--- a/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/impl/AAIPluginImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/impl/AAIPluginImpl.java
@@ -20,10 +20,17 @@
*/
package org.openecomp.appc.dg.aai.impl;
+import org.openecomp.appc.domainmodel.Vnf;
+import org.openecomp.appc.domainmodel.Vnfc;
+import org.openecomp.appc.domainmodel.Vserver;
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.i18n.Msg;
+import com.att.eelf.i18n.EELFResourceManager;
import org.openecomp.appc.dg.aai.AAIPlugin;
-import org.openecomp.appc.dg.aai.impl.Constants;
-import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.dg.aai.exception.AAIQueryException;
+import org.openecomp.appc.dg.aai.objects.AAIQueryResult;
+import org.openecomp.appc.dg.aai.objects.Relationship;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import org.openecomp.sdnc.sli.SvcLogicContext;
@@ -35,8 +42,7 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
public class AAIPluginImpl implements AAIPlugin {
@@ -68,20 +74,23 @@ public class AAIPluginImpl implements AAIPlugin {
try {
SvcLogicResource.QueryStatus response = aaiClient.update("generic-vnf", key, data, prefix, ctx);
if (SvcLogicResource.QueryStatus.NOT_FOUND.equals(response)) {
- String errorMessage = String.format("VNF not found for vnf_id = %s", vnf_id);
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorMessage);
- throw new APPCException(errorMessage);
+ String msg = EELFResourceManager.format(Msg.VNF_NOT_FOUND, vnf_id);
+ ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
+ throw new APPCException(msg);
}
logger.info("AAIResponse: " + response.toString());
if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
- String errorMessage = String.format("Error Querying AAI with vnfID = %s", vnf_id);
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorMessage);
- throw new APPCException(errorMessage);
+ String msg = EELFResourceManager.format(Msg.AAI_QUERY_FAILED, vnf_id);
+ ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
+ throw new APPCException(msg);
}
+ String msg = EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "PostGenericVnfData", "VNF ID " + vnf_id);
+ ctx.setAttribute(org.openecomp.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg);
+
} catch (SvcLogicException e) {
- String errorMessage = String.format("Error in postVnfdata %s", e);
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorMessage);
- logger.error(errorMessage);
+ String msg = EELFResourceManager.format(Msg.AAI_QUERY_FAILED, vnf_id);
+ ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
+ logger.error(msg);
throw new APPCException(e);
}
}
@@ -95,13 +104,14 @@ public class AAIPluginImpl implements AAIPlugin {
try {
SvcLogicResource.QueryStatus response = aaiClient.query("generic-vnf", false, null, key, prefix, null, ctx);
if (SvcLogicResource.QueryStatus.NOT_FOUND.equals(response)) {
- String errorMessage = String.format("VNF not found for vnf_id = %s", vnf_id);
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorMessage);
- throw new APPCException(errorMessage);
+ String msg = EELFResourceManager.format(Msg.VNF_NOT_FOUND, vnf_id);
+// String errorMessage = String.format("VNF not found for vnf_id = %s", vnf_id);
+ ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
+ throw new APPCException(msg);
} else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
- String errorMessage = String.format("Error Querying AAI with vnfID = %s", vnf_id);
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorMessage);
- throw new APPCException(errorMessage);
+ String msg = EELFResourceManager.format(Msg.AAI_QUERY_FAILED, vnf_id);
+ ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
+ throw new APPCException(msg);
}
String aaiEntitlementPoolUuid = ctx.getAttribute(Constants.AAI_ENTITLMENT_POOL_UUID_NAME);
if (null == aaiEntitlementPoolUuid) aaiEntitlementPoolUuid = "";
@@ -110,13 +120,261 @@ public class AAIPluginImpl implements AAIPlugin {
ctx.setAttribute(Constants.IS_RELEASE_ENTITLEMENT_REQUIRE, Boolean.toString(!aaiEntitlementPoolUuid.isEmpty()));
ctx.setAttribute(Constants.IS_RELEASE_LICENSE_REQUIRE, Boolean.toString(!aaiLicenseKeyGroupUuid.isEmpty()));
+ String msg = EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "GetGenericVnfData","VNF ID " + vnf_id);
+ ctx.setAttribute(org.openecomp.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg);
logger.info("AAIResponse: " + response.toString());
} catch (SvcLogicException e) {
- String errorMessage = String.format("Error in getVnfdata %s", e);
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorMessage);
- logger.error(errorMessage);
+ String msg = EELFResourceManager.format(Msg.AAI_QUERY_FAILED, vnf_id);
+ ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
+ logger.error(msg);
throw new APPCException(e);
}
}
+
+ @Override
+ public void getVnfHierarchy(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+
+ Map<Vnfc,Set<Vserver>> vnfcMap = new HashMap<>();
+ String vnfType,vnfVersion = null;
+ String vnfId = params.get("resourceKey");
+ AAIQueryResult vnfQueryResult = null;
+ int vmCount =0;
+ try {
+ vnfQueryResult = readVnf(vnfId);
+
+ vnfType = vnfQueryResult.getAdditionProperties().get("vnf-type");
+ vnfVersion = vnfQueryResult.getAdditionProperties().get("persona-model-version");
+
+ for(Relationship vnfRelationship:vnfQueryResult.getRelationshipList()){
+ if("vserver".equalsIgnoreCase(vnfRelationship.getRelatedTo())){
+ vmCount++;
+ String tenantId = vnfRelationship.getRelationShipDataMap().get("tenant.tenant-id");
+ String vmId = vnfRelationship.getRelationShipDataMap().get("vserver.vserver-id");
+ String vmRelatedLink = vnfRelationship.getRelatedLink();
+ String vmName = vnfRelationship.getRelatedProperties().get("vserver.vserver-name");
+ String cloudOwner = vnfRelationship.getRelationShipDataMap().get("cloud-region.cloud-owner");
+ String cloudRegionId = vnfRelationship.getRelationShipDataMap().get("cloud-region.cloud-region-id");
+
+ AAIQueryResult vmQueryResult = readVM(vmId,tenantId,cloudOwner,cloudRegionId);
+ String vmURL = vmQueryResult.getAdditionProperties().get("vserver-selflink");
+
+ Vserver vm = new Vserver(vmURL,tenantId,vmId,vmRelatedLink,vmName);
+ for(Relationship vmRelation:vmQueryResult.getRelationshipList()){
+
+ if("vnfc".equalsIgnoreCase(vmRelation.getRelatedTo())){
+ String vnfcName = vmRelation.getRelationShipDataMap().get("vnfc.vnfc-name");
+ AAIQueryResult vnfcQueryResult = readVnfc(vnfcName);
+ String vnfcType = vnfcQueryResult.getAdditionProperties().get("vnfc-type");
+
+ Vnfc vnfc = new Vnfc(vnfcType,null,vnfcName);
+ Set<Vserver> vmSet = vnfcMap.get(vnfc);
+ if(vmSet == null){
+ vmSet = new HashSet<>();
+ vnfcMap.put(vnfc,vmSet);
+ }
+ vmSet.add(vm);
+ }
+ }
+ }
+ }
+ ctx.setAttribute("VNF.VMCount",String.valueOf(vmCount));
+ } catch (AAIQueryException e) {
+ ctx.setAttribute("getVnfHierarchy_result", "FAILURE");
+ String msg = EELFResourceManager.format(Msg.AAI_QUERY_FAILED, vnfId);
+ ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
+ logger.error("Failed in getVnfHierarchy, Error retrieving VNF details. Error message: " + ctx
+ .getAttribute("getResource_result"));
+ logger.warn("Incorrect or Incomplete VNF Hierarchy");
+ throw new APPCException("Error Retrieving VNF hierarchy");
+ }
+
+ Vnf vnf = new Vnf(vnfId,vnfType,vnfVersion);
+ for(Vnfc vnfc:vnfcMap.keySet()){
+ for(Vserver vm:vnfcMap.get(vnfc)){
+ vnfc.addVm(vm);
+ }
+ vnf.addVnfc(vnfc);
+ }
+
+ populateContext(vnf,ctx);
+ ctx.setAttribute("getVnfHierarchy_result", "SUCCESS");
+ String msg = EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "GetVNFHierarchy","VNF ID " + vnfId);
+ ctx.setAttribute(org.openecomp.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg);
+
+ }
+
+ private void populateContext(Vnf vnf ,SvcLogicContext ctx) {
+ ctx.setAttribute("vnf.type",vnf.getVnfType());
+ ctx.setAttribute("vnf.version",vnf.getVnfVersion());
+ ctx.setAttribute("vnf.vnfcCount",String.valueOf(vnf.getVnfcs().size()));
+ int vnfcCount =0;
+ for(Vnfc vnfc:vnf.getVnfcs()){
+ ctx.setAttribute("vnf.vnfc["+vnfcCount+"].name",vnfc.getVnfcName());
+ ctx.setAttribute("vnf.vnfc["+vnfcCount+"].type",vnfc.getVnfcType());
+ ctx.setAttribute("vnf.vnfc["+vnfcCount+"].vm_count",String.valueOf(vnfc.getVserverList().size()));
+ int vmCount =0;
+ for(Vserver vm:vnfc.getVserverList()){
+ ctx.setAttribute("vnf.vnfc["+vnfcCount+"].vm["+ vmCount++ +"].url",vm.getUrl());
+ }
+ vnfcCount++;
+ }
+ }
+
+ private AAIQueryResult readVnfc(String vnfcName) throws AAIQueryException {
+ String query = "vnfc.vnfc-name = '" + vnfcName + "'";
+ String prefix = "VNFC";
+ String resourceType = "vnfc";
+ SvcLogicContext vnfContext = readResource(query,prefix,resourceType);
+ String[] additionalProperties = new String[]{"vnfc-type","vnfc-name",
+ "vnfc-function-code","in-maint","prov-status",
+ "is-closed-loop-disabled","orchestration-status","resource-version"};
+ AAIQueryResult result = readRelationDataAndProperties(prefix, vnfContext,additionalProperties);
+ return result;
+ }
+
+ private AAIQueryResult readVM(String vmId,String tenantId,String cloudOwner,String cloudRegionId) throws AAIQueryException {
+ String query = "vserver.vserver-id = '" + vmId + "' AND tenant.tenant_id = '" + tenantId + "' AND cloud-region.cloud-owner = '"
+ + cloudOwner + "' AND cloud-region.cloud-region-id = '" + cloudRegionId + "'";
+ String prefix = "VM";
+ String resourceType = "vserver";
+ SvcLogicContext vnfContext = readResource(query,prefix,resourceType);
+ String[] additionalProperties = new String[]{"vserver-id","vserver-selflink",
+ "vserver-name","in-maint","prov-status","is-closed-loop-disabled",
+ "vserver-name2","resource-version",};
+ AAIQueryResult result = readRelationDataAndProperties(prefix, vnfContext,additionalProperties);
+
+ return result;
+ }
+
+ private AAIQueryResult readVnf(String vnfId) throws AAIQueryException {
+ String query = "generic-vnf.vnf-id = '" + vnfId + "'";
+ String prefix = "VNF";
+ String resourceType = "generic-vnf";
+ SvcLogicContext vnfContext = readResource(query,prefix,resourceType);
+
+ String[] additionalProperties = new String[]{"vnf-type","vnf-name",
+ "in-maint","prov-status","heat-stack-id",
+ "is-closed-loop-disabled","orchestration-status","resource-version","persona-model-version"};
+
+ AAIQueryResult result = readRelationDataAndProperties(prefix, vnfContext,additionalProperties);
+
+ return result;
+ }
+
+ private AAIQueryResult readRelationDataAndProperties(String prefix, SvcLogicContext context,String[] additionalProperties) {
+ AAIQueryResult result = new AAIQueryResult();
+
+ Integer relationsCount = Integer.parseInt(context.getAttribute(prefix + ".relationship-list.relationship_length"));
+ for(int i=0;i<relationsCount;i++){
+ Relationship relationShip = new Relationship();
+ relationShip.setRelatedLink(context.getAttribute(prefix + ".relationship-list.relationship["+i+"].related-link"));
+ relationShip.setRelatedTo(context.getAttribute(prefix + ".relationship-list.relationship["+i+"].related-to"));
+ Integer relationDataCount = Integer.parseInt(context.getAttribute(prefix + ".relationship-list.relationship["+i+"].relationship-data_length"));
+ for(int j=0;j<relationDataCount;j++){
+ String key = context.getAttribute(prefix+".relationship-list.relationship["+i+"].relationship-data["+j+"].relationship-key");
+ String value = context.getAttribute(prefix+".relationship-list.relationship["+i+"].relationship-data["+j+"].relationship-value");
+ relationShip.getRelationShipDataMap().put(key,value);
+ }
+ Integer relatedPropertyCount = 0;
+ String relatedPropertyCountStr = null;
+ try{
+ relatedPropertyCountStr =context.getAttribute(prefix + ".relationship-list.relationship["+i+"].related-to-property_length");
+ relatedPropertyCount = Integer.parseInt(relatedPropertyCountStr);
+ }
+ catch (NumberFormatException e){
+ logger.debug("Invalid value in the context for Related Property Count " + relatedPropertyCountStr);
+ }
+
+ for(int j=0;j<relatedPropertyCount;j++){
+ String key = context.getAttribute(prefix+".relationship-list.relationship["+i+"].related-to-property["+j+"].property-key");
+ String value = context.getAttribute(prefix+".relationship-list.relationship["+i+"].related-to-property["+j+"].property-value");
+ relationShip.getRelatedProperties().put(key,value);
+ }
+ result.getRelationshipList().add(relationShip);
+ }
+
+ for(String key:additionalProperties){
+ result.getAdditionProperties().put(key,context.getAttribute(prefix+"."+key));
+ }
+ return result;
+ }
+
+ private SvcLogicContext readResource(String query, String prefix, String resourceType) throws AAIQueryException {
+ SvcLogicContext resourceContext = new SvcLogicContext();
+ try {
+ SvcLogicResource.QueryStatus response = aaiClient.query(resourceType,false,null,query,prefix,null,resourceContext);
+ logger.info("AAIResponse: " + response.toString());
+ if(!SvcLogicResource.QueryStatus.SUCCESS.equals(response)){
+ throw new AAIQueryException("Error Retrieving VNF hierarchy from A&AI");
+ }
+ } catch (SvcLogicException e) {
+ logger.error(EELFResourceManager.format(Msg.AAI_GET_DATA_FAILED, query, "", e.getMessage()));
+ throw new AAIQueryException("Error Retrieving VNF hierarchy from A&AI");
+ }
+ return resourceContext;
+ }
+
+ @Override public void getResource(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+ String resourceType = params.get("resourceType"), ctx_prefix = params.get("prefix"), resourceKey =
+ params.get("resourceKey");
+ if (logger.isDebugEnabled()) {
+ logger.debug("inside getResorce");
+ logger.debug("Retrieving " + resourceType + " details from A&AI for Key : " + resourceKey);
+ }
+ try {
+ SvcLogicResource.QueryStatus response =
+ aaiClient.query(resourceType, false, null, resourceKey, ctx_prefix, null, ctx);
+ logger.info("AAIResponse: " + response.toString());
+ ctx.setAttribute("getResource_result", response.toString());
+ } catch (SvcLogicException e) {
+ logger.error(EELFResourceManager.format(Msg.AAI_GET_DATA_FAILED, resourceKey, "", e.getMessage()));
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("exiting getResource======");
+ }
+ }
+
+ @Override public void postResource(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+ String resourceType = params.get("resourceType"), ctx_prefix = params.get("prefix"), resourceKey =
+ params.get("resourceKey"), att_name = params.get("attributeName"), att_value =
+ params.get("attributeValue");
+ if (logger.isDebugEnabled()) {
+ logger.debug("inside postResource");
+ logger.debug("Updating " + resourceType + " details in A&AI for Key : " + resourceKey);
+ logger.debug("Updating " + att_name + " to : " + att_value);
+ }
+ Map<String, String> data = new HashMap<String, String>();
+ data.put(att_name, att_value);
+
+ try {
+ SvcLogicResource.QueryStatus response = aaiClient.update(resourceType, resourceKey, data, ctx_prefix, ctx);
+ logger.info("AAIResponse: " + response.toString());
+ ctx.setAttribute("postResource_result", response.toString());
+ } catch (SvcLogicException e) {
+ logger.error(EELFResourceManager.format(Msg.AAI_UPDATE_FAILED, resourceKey, att_value, e.getMessage()));
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("exiting postResource======");
+ }
+ }
+
+ @Override public void deleteResource(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+ String resourceType = params.get("resourceType"), resourceKey = params.get("resourceKey");
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("inside deleteResource");
+ logger.debug("Deleting " + resourceType + " details From A&AI for Key : " + resourceKey);
+ }
+ try {
+ SvcLogicResource.QueryStatus response = aaiClient.delete(resourceType, resourceKey, ctx);
+ logger.info("AAIResponse: " + response.toString());
+ ctx.setAttribute("deleteResource_result", response.toString());
+ } catch (SvcLogicException e) {
+ logger.error(EELFResourceManager.format(Msg.AAI_DELETE_FAILED, resourceKey, e.getMessage()));
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("exiting deleteResource======");
+ }
+ }
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/impl/Constants.java b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/impl/Constants.java
index 3feab4795..8957d3a8f 100644
--- a/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/impl/Constants.java
+++ b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/impl/Constants.java
@@ -71,7 +71,7 @@ public class Constants {
public static final String VNF_HOST_IP_ADDRESS_FIELD_NAME = "vnf-host-ip-address";
public static final String UPGRADE_VERSION = "upgrade-version";
public static final String DG_ERROR_FIELD_NAME = "org.openecomp.appc.dg.error";
- public static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message";
+ public static final String ATTRIBUTE_ERROR_MESSAGE = "error-message";
public static final String RESOURCEKEY = "resourceKey";
public static final String REQ_ID_FIELD_NAME = "org.openecomp.appc.reqid";
public static final String API_VERSION_FIELD_NAME = "org.openecomp.appc.apiversion";
diff --git a/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/objects/AAIQueryResult.java b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/objects/AAIQueryResult.java
new file mode 100644
index 000000000..0ad6292f9
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/objects/AAIQueryResult.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.aai.objects;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+public class AAIQueryResult {
+ private List<Relationship> relationshipList;
+
+ private Map<String,String> additionProperties;
+
+
+ public AAIQueryResult(){
+ relationshipList = new ArrayList<>();
+ additionProperties = new HashMap<>();
+ }
+
+
+ public List<Relationship> getRelationshipList() {
+ return relationshipList;
+ }
+
+ public Map<String, String> getAdditionProperties() {
+ return additionProperties;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/objects/Relationship.java b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/objects/Relationship.java
new file mode 100644
index 000000000..63e6392a5
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/java/org/openecomp/appc/dg/aai/objects/Relationship.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.aai.objects;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class Relationship {
+
+ private String relatedTo;
+
+ private String relatedLink;
+
+ private Map<String,String> relationShipDataMap;
+
+ private Map<String,String> relatedProperties;
+
+ public Relationship(){
+ relationShipDataMap = new HashMap<>();
+ relatedProperties = new HashMap<>();
+ }
+
+ public String getRelatedTo() {
+ return relatedTo;
+ }
+
+ public String getRelatedLink() {
+ return relatedLink;
+ }
+
+ public Map<String, String> getRelationShipDataMap() {
+ return relationShipDataMap;
+ }
+
+ public Map<String, String> getRelatedProperties() {
+ return relatedProperties;
+ }
+
+ public void setRelatedTo(String relatedTo) {
+ this.relatedTo = relatedTo;
+ }
+
+ public void setRelatedLink(String relatedLink) {
+ this.relatedLink = relatedLink;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-aai/src/main/test/java/org/openecomp/appc/dg/aai/impl/AAIPluginImplTest.java b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/test/java/org/openecomp/appc/dg/aai/impl/AAIPluginImplTest.java
index 8d6fea0cf..eae221bc4 100644
--- a/appc-dg/appc-dg-shared/appc-dg-aai/src/main/test/java/org/openecomp/appc/dg/aai/impl/AAIPluginImplTest.java
+++ b/appc-dg/appc-dg-shared/appc-dg-aai/src/main/test/java/org/openecomp/appc/dg/aai/impl/AAIPluginImplTest.java
@@ -21,9 +21,7 @@
package org.openecomp.appc.dg.aai.impl;
-import org.junit.*;
import org.junit.runner.RunWith;
-import org.mockito.*;
import org.openecomp.appc.dg.aai.Constants;
import org.openecomp.appc.dg.aai.impl.AAIPluginImpl;
import org.openecomp.appc.dg.common.dao.DAOService;
@@ -40,12 +38,10 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
-import static org.powermock.api.support.SuppressCode.suppressConstructor;
@RunWith(PowerMockRunner.class)
@@ -119,7 +115,7 @@ public class AAIPluginImplTest {
aaiPlugin.postGenericVnfData(params, ctx);
Assert.assertTrue(false);
} catch (APPCException e) {
- Assert.assertNotNull(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE));
+ Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
}
}
@@ -143,7 +139,7 @@ public class AAIPluginImplTest {
aaiPlugin.postGenericVnfData(params, ctx);
Assert.assertTrue(false);
} catch (APPCException e) {
- Assert.assertNotNull(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE));
+ Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
}
}
@@ -167,7 +163,7 @@ public class AAIPluginImplTest {
aaiPlugin.postGenericVnfData(params, ctx);
Assert.assertTrue(false);
} catch (APPCException e) {
- Assert.assertNotNull(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE));
+ Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
}
}
@@ -219,7 +215,7 @@ public class AAIPluginImplTest {
aaiPlugin.getGenericVnfData(params, ctx);
Assert.assertTrue(false);
} catch (APPCException e) {
- Assert.assertNotNull(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE));
+ Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
}
}
@@ -236,7 +232,7 @@ public class AAIPluginImplTest {
aaiPlugin.getGenericVnfData(params, ctx);
Assert.assertTrue(false);
} catch (APPCException e) {
- Assert.assertNotNull(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE));
+ Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
}
}
@@ -253,7 +249,7 @@ public class AAIPluginImplTest {
aaiPlugin.getGenericVnfData(params, ctx);
Assert.assertTrue(false);
} catch (APPCException e) {
- Assert.assertNotNull(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE));
+ Assert.assertNotNull(ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
}
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/pom.xml b/appc-dg/appc-dg-shared/appc-dg-common/pom.xml
index 6ad459162..ae59b07dc 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/pom.xml
+++ b/appc-dg/appc-dg-shared/appc-dg-common/pom.xml
@@ -17,18 +17,25 @@
</dependency>
<dependency>
<groupId>org.openecomp.appc</groupId>
- <artifactId>appc-dmaap-adapter-bundle</artifactId>
+ <artifactId>appc-message-adapter-api</artifactId>
<version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-message-adapter-factory</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openecomp.sdnc.core</groupId>
<artifactId>sli-common</artifactId>
- <scope>compile</scope>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openecomp.sdnc.core</groupId>
<artifactId>sli-provider</artifactId>
- <scope>compile</scope>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
@@ -43,13 +50,11 @@
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
- <version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
- <version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -57,6 +62,31 @@
<artifactId>powermock-api-easymock</artifactId>
<version>1.6.2</version>
</dependency>
+ <dependency>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-dg-dependency-model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-ranking-framework-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-data-access-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>equinoxSDK381</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-dg-mdsal-store</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
<build>
@@ -70,8 +100,11 @@
<Bundle-SymbolicName>appc-dg-common</Bundle-SymbolicName>
<Export-Package>org.openecomp.appc.dg.common,org.openecomp.appc.dg.common.objects,org.openecomp.appc.dg.common.utils</Export-Package>
<Private-Package>org.openecomp.appc.dg.common.impl.*</Private-Package>
- <Import-Package>!org.apache.log,!org.apache.commons.logging,!groovy.lang,!javax.jms,!org.codehaus.commons.compiler,!org.codehaus.groovy.*,!org.codehaus.janino,!com.ibm.icu.*,!com.sun.faces.*,!org.jasypt.*,*;resolution:=optional</Import-Package>
- <Embed-Dependency>appc-common,eelf-core,logback-core,logback-classic;scope=compile|runtime;inline=false</Embed-Dependency>
+ <Import-Package>org.openecomp.appc.adapter.message.*,org.openecomp.appc.adapter.factory.*,org.openecomp.appc.adapter.messaging.*,
+ *;resolution:=optional</Import-Package>
+ <Embed-Dependency>appc-dg-mdsal-store,appc-dg-domain-model-lib,appc-dg-dependency-model,jackson-dataformat-yaml,jackson-databind;scope=compile|runtime;inline=false;artifactId=!org.eclipse.osgi</Embed-Dependency>
+
+ <!--Embed-Dependency>eelf-core,logback-core,logback-classic;scope=compile|runtime;inline=false</Embed-Dependency-->
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/DgResolverPlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/DgResolverPlugin.java
new file mode 100644
index 000000000..e2fabaa20
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/DgResolverPlugin.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common;
+
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
+
+import java.util.Map;
+
+public interface DgResolverPlugin extends SvcLogicJavaPlugin {
+ void resolveDg(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/IntermediateMessageSender.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/IntermediateMessageSender.java
new file mode 100644
index 000000000..f391c36ec
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/IntermediateMessageSender.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
+
+import java.util.Map;
+
+/**
+ * This interface provides api for sending intermediate messages from DG to initiator
+ */
+public interface IntermediateMessageSender extends SvcLogicJavaPlugin{
+
+ /**
+ * DG plugin which sends intermediate messages generated from DG to the initiator
+ * @param params expects 1. code, (mandatory)
+ * 2. message, (mandatory)
+ * 3. payload,
+ * 4. prefix
+ * @param context expects 1. input.common-header.timestamp,
+ * 2. input.common-header.api-ver,
+ * 3. input.common-header.originator-id,
+ * 4. input.common-header.request-id, (mandatory)
+ * 5. input.common-header.sub-request-id,
+ * 6. input.action
+ */
+ void sendMessage(Map<String, String> params, SvcLogicContext context);
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/JsonDgUtil.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/JsonDgUtil.java
index 2b3fbf793..ecdaea0dd 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/JsonDgUtil.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/JsonDgUtil.java
@@ -30,4 +30,22 @@ import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
public interface JsonDgUtil extends SvcLogicJavaPlugin {
void flatAndAddToContext(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
+
+ void generateOutputPayloadFromContext(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
+
+ /**
+ * Creates filename and content in Json format.
+ * @param params
+ * @param ctx
+ * @throws APPCException
+ */
+ void cvaasFileNameAndFileContentToContext(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
+
+ /**
+ * Checks if a file is created.
+ * @param params
+ * @param ctx
+ * @throws APPCException
+ */
+ void checkFileCreated(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/OutputMessagePlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/OutputMessagePlugin.java
new file mode 100644
index 000000000..35e7b2263
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/OutputMessagePlugin.java
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
+
+import java.util.Map;
+
+import org.openecomp.appc.exceptions.APPCException;
+
+public interface OutputMessagePlugin extends SvcLogicJavaPlugin {
+
+ void outputMessageBuilder(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFCDgResolverPlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFCDgResolverPlugin.java
new file mode 100644
index 000000000..0dd79998f
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFCDgResolverPlugin.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
+
+import java.util.Map;
+
+import org.openecomp.appc.exceptions.APPCException;
+
+
+public interface VNFCDgResolverPlugin extends SvcLogicJavaPlugin {
+ void resolveVNFCDg(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFConfigurator.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFConfigurator.java
new file mode 100644
index 000000000..57acf5223
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFConfigurator.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common;
+
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
+
+import java.util.Map;
+/**
+ * DG plugin created for VNF configuration operation to store data in MD-SAL store
+ **/
+public interface VNFConfigurator extends SvcLogicJavaPlugin{
+ /**
+ * it is invoked from the DG, and it performs following operations
+ * 1. checks whether given yang module is present in the MD-SAL store
+ * 2. if it is absent, loads it into MD-SAL store
+ * 3. Stores the VNF configuration into MD-SAL store
+ * @param params should have 1. uniqueId, 2. yang, 3.configJSON, 4.requestId
+ * @param context - DG context
+ * @throws APPCException
+ */
+ void storeConfig(Map<String, String> params, SvcLogicContext context) throws APPCException;
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VnfExecutionFlow.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VnfExecutionFlow.java
new file mode 100644
index 000000000..f69985f03
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VnfExecutionFlow.java
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
+
+import java.util.Map;
+
+public interface VnfExecutionFlow extends SvcLogicJavaPlugin {
+ void getVnfExecutionFlowData(Map<String,String> params, SvcLogicContext context);
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolver.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolver.java
new file mode 100644
index 000000000..1d7766fb2
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolver.java
@@ -0,0 +1,114 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import org.openecomp.appc.rankingframework.RankedAttributesResolver;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import java.util.concurrent.locks.ReentrantLock;
+
+abstract class AbstractResolver {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(AbstractResolver.class);
+
+ private long interval;
+
+ private volatile long lastUpdate = 0l;
+ private volatile boolean isUpdateInProgress = false;
+ private volatile RankedAttributesResolver<FlowKey> dgResolver;
+
+ private final ReentrantLock INIT_LOCK = new ReentrantLock();
+
+ AbstractResolver(int interval) {
+ this.interval = interval * 1000;
+ }
+
+ private RankedAttributesResolver<FlowKey> createResolver(String resolverType) {
+ AbstractResolverDataReader reader = ResolverDataReaderFactory.createResolverDataReader(resolverType);
+ return reader.read();
+ }
+
+ private boolean isExpired() {
+ return (System.currentTimeMillis() - lastUpdate) > interval;
+ }
+
+ 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
+ * 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();
+ if (dgResolver != null) {
+ INIT_LOCK.unlock();
+ }
+ }
+
+ if (!isUpdateInProgress && isExpired()) {
+
+ boolean doUpgrade = false;
+
+ synchronized (this) {
+ if (!isUpdateInProgress) {
+ isUpdateInProgress = true;
+ 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;
+ }
+ }
+ }
+ } finally {
+ if (INIT_LOCK.isHeldByCurrentThread()) {
+ INIT_LOCK.unlock();
+ }
+ }
+
+ return dgResolver;
+ }
+ protected abstract FlowKey resolve(final String...args);
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolverDataReader.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolverDataReader.java
new file mode 100644
index 000000000..edfc8f4b8
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolverDataReader.java
@@ -0,0 +1,127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import org.openecomp.appc.dao.util.DBUtils;
+import org.openecomp.appc.rankingframework.AbstractRankedAttributesResolverFactory;
+import org.openecomp.appc.rankingframework.ConfigurationEntry;
+import org.openecomp.appc.rankingframework.ConfigurationSet;
+import org.openecomp.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;
+
+abstract class AbstractResolverDataReader {
+
+ private class ConfigurationSetAdaptor implements ConfigurationSet<FlowKey> {
+
+ private final ResultSet resultSet;
+
+ private class ResultSetIterator implements Iterator<ConfigurationEntry<FlowKey>>, ConfigurationEntry<FlowKey> {
+ @Override
+ public boolean hasNext() {
+ try {
+ return resultSet.next();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public ConfigurationEntry<FlowKey> next() {
+ return this;
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Object getAttributeValue(String name) {
+ try {
+ return resultSet.getObject(name);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public FlowKey getResult() {
+ try {
+ return new FlowKey(resultSet.getString("dg_name"), resultSet.getString("dg_version"), resultSet.getString("dg_module"));
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ ConfigurationSetAdaptor(ResultSet resultSet) {
+ this.resultSet = resultSet;
+ }
+
+ @Override
+ public Iterable<ConfigurationEntry<FlowKey>> getEntries() {
+ return new Iterable<ConfigurationEntry<FlowKey>>() {
+
+ @Override
+ public Iterator<ConfigurationEntry<FlowKey>> iterator() {
+ return new ResultSetIterator();
+ }
+ };
+ }
+
+ @Override
+ public Collection<String> getRankedAttributeNames() {
+ return getAttributeNames();
+ }
+ }
+
+ protected abstract Collection<String> getAttributeNames();
+ protected abstract String getQueryStmt();
+
+
+
+ RankedAttributesResolver<FlowKey> read() {
+ try {
+ try (Connection conn = DBUtils.getConnection("sdnctl")) {
+ try (PreparedStatement stmt = conn.prepareStatement(getQueryStmt())) {
+ try (ResultSet res = stmt.executeQuery()) {
+ if (res.next()) {
+ res.beforeFirst();
+ ConfigurationSet<FlowKey> resolverConfig = new ConfigurationSetAdaptor(res);
+ return AbstractRankedAttributesResolverFactory.getInstance().create(resolverConfig);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+ }
+ }
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/Constants.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/Constants.java
index 92d23e3a6..3a5bb91ac 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/Constants.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/Constants.java
@@ -27,15 +27,35 @@ class Constants {
public static final String DG_ERROR_FIELD_NAME = "org.openecomp.appc.dg.error";
public static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message";
+ public static final String EVENT_MESSAGE = "event-message";
+ public static final String ATTRIBUTE_ERROR_MESSAGE = "error-message";
+ public static final String ATTRIBUTE_SUCCESS_MESSAGE = "success-message";
+ public static final String DG_ERROR_CODE = "output.status.dgerror.code";
public static final String API_VERSION_FIELD_NAME = "org.openecomp.appc.apiversion";
public static final String REQ_ID_FIELD_NAME = "org.openecomp.appc.reqid";
public static final String PAYLOAD = "payload";
+ public static final String OUTPUT_PAYLOAD = "output.payload";
+
+ //Added for VnfExecution Flow
+ 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";
+
+ //Added for Cvaas
+ public static final String CVAAS_DIRECTORY_PATH = "cvaas-directory-path";
+ public static final String CVAAS_FILE_NAME = "cvaas-file-name";
+ public static final String CVAAS_FILE_CONTENT = "cvaas-file-content";
enum LegacyAttributes {
Action("org.openecomp.appc.action"),
VMID("org.openecomp.appc.vmid"),
IdentityURL("org.openecomp.appc.identity.url"),
- TenantID("org.openecomp.appc.tenant.id");
+ TenantID("org.openecomp.appc.tenant.id"),
+ SkipHypervisorCheck("org.openecomp.appc.skiphypervisorcheck");
private String value;
LegacyAttributes(String value) {this.value = value;}
@@ -47,11 +67,30 @@ class Constants {
Payload("input.payload"),
VMID("vm-id"),
IdentityURL("identity-url"),
- TenantID("tenant.id");
+ TenantID("tenant.id"),
+ SkipHypervisorCheck("skip-hypervisor-check");
private String value;
LCMAttributes(String value) {this.value = value;}
String getValue() {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/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java
index 4458de10b..8081a6ff3 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java
@@ -22,11 +22,11 @@
package org.openecomp.appc.dg.common.impl;
import org.apache.commons.lang3.StringUtils;
-import org.openecomp.appc.adapter.dmaap.EventSender;
-import org.openecomp.appc.adapter.dmaap.DmaapDestination;
-import org.openecomp.appc.adapter.dmaap.event.EventHeader;
-import org.openecomp.appc.adapter.dmaap.event.EventMessage;
-import org.openecomp.appc.adapter.dmaap.event.EventStatus;
+import org.openecomp.appc.adapter.message.EventSender;
+import org.openecomp.appc.adapter.message.MessageDestination;
+import org.openecomp.appc.adapter.message.event.EventHeader;
+import org.openecomp.appc.adapter.message.event.EventMessage;
+import org.openecomp.appc.adapter.message.event.EventStatus;
import org.openecomp.appc.dg.common.DCAEReporterPlugin;
import org.openecomp.appc.exceptions.APPCException;
import org.openecomp.sdnc.sli.SvcLogicContext;
@@ -48,74 +48,108 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin {
@Override
public void report(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
- Integer errorReportCode = 501;
- boolean bwcMode = Boolean.parseBoolean(ctx.getAttribute("isBwcMode"));
String errorDescription,apiVersion,eventId ;
- errorDescription = getErrorDescriptionAndAddToCtx(bwcMode,params,ctx);
- if(!bwcMode){
- apiVersion = ctx.getAttribute("input.common-header.api-ver");
- eventId = ctx.getAttribute("input.common-header.request-id");
- }else {
- apiVersion = ctx.getAttribute(Constants.API_VERSION_FIELD_NAME);
- eventId = ctx.getAttribute(Constants.REQ_ID_FIELD_NAME);
- }
- EventMessage eventMessage = new EventMessage(new EventHeader((new java.util.Date()).toString(), apiVersion, eventId), new EventStatus(errorReportCode, errorDescription));
- eventSender.sendEvent(DmaapDestination.DCAE, eventMessage);
- }
+ Integer errorCode = readErrorCode(params,ctx);
+ errorDescription = params.get(Constants.EVENT_MESSAGE);
- private String getErrorDescriptionAndAddToCtx(boolean bwcMode, Map<String, String> params, SvcLogicContext ctx) {
- String errorDescription;
- if(!bwcMode) {
- errorDescription = params.get(Constants.DG_OUTPUT_STATUS_MESSAGE);
- if(StringUtils.isEmpty(errorDescription)) {
- errorDescription = ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE);
- }else {
- addToContextIfNotContains(bwcMode,errorDescription,ctx);
- }
+ if(StringUtils.isEmpty(errorDescription)) {
+ reportLegacy(params , ctx);
}else{
- errorDescription = params.get(Constants.DG_ERROR_FIELD_NAME);
- if(StringUtils.isEmpty(errorDescription)) {
- errorDescription = ctx.getAttribute("org.openecomp.appc.dg.error");
+ 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));
+ String eventWriteTopic = params.get("event-topic-name");
+ if(!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic!=null){
+ eventSender.sendEvent(MessageDestination.DCAE, eventMessage,eventWriteTopic);
}else {
- addToContextIfNotContains(bwcMode, errorDescription,ctx);
+ eventSender.sendEvent(MessageDestination.DCAE, eventMessage);
}
}
-
- if(StringUtils.isEmpty(errorDescription)) {
- errorDescription = "Unknown";
- }
- return errorDescription;
}
- private void addToContextIfNotContains(boolean bwcMode, String errorDescription, SvcLogicContext ctx) {
- String errorDescriptionFromCtx;
- if(!StringUtils.isEmpty(errorDescription)) {
- String outputStatusMessageProperty = bwcMode ? "org.openecomp.appc.dg.error" : Constants.DG_OUTPUT_STATUS_MESSAGE;
- errorDescriptionFromCtx = ctx.getAttribute(outputStatusMessageProperty);
- if(StringUtils.isEmpty(errorDescriptionFromCtx)){
- ctx.setAttribute(outputStatusMessageProperty, errorDescription);
- }else if (!errorDescriptionFromCtx.contains(errorDescription)){
- ctx.setAttribute(outputStatusMessageProperty, errorDescriptionFromCtx+ " | "+ errorDescription);
- }
+ private Integer readErrorCode(Map<String, String> 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){
+ // Ignore Exception
+ }
+ return errorReportCode;
}
-
@Override
public void reportSuccess(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
Integer successReportCode = 500;
String successDescription, apiVersion, eventId;
- successDescription = params.get(Constants.DG_OUTPUT_STATUS_MESSAGE);
+ 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");
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, successDescription);
if (null == successDescription) {
successDescription = "Success";
}
EventMessage eventMessage = new EventMessage(new EventHeader((new java.util.Date()).toString(), apiVersion, eventId), new EventStatus(successReportCode, successDescription));
- eventSender.sendEvent(DmaapDestination.DCAE, eventMessage);
+ String eventWriteTopic = params.get("event-topic-name");
+ if(!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic!=null){
+ eventSender.sendEvent(MessageDestination.DCAE, eventMessage,eventWriteTopic);
+ }else {
+ eventSender.sendEvent(MessageDestination.DCAE, eventMessage);
+ }
+ }
+
+ private void reportLegacy(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+ String errorDescription,apiVersion,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");
+
+ EventMessage eventMessage = new EventMessage(new EventHeader((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 {
+ eventSender.sendEvent(MessageDestination.DCAE, eventMessage);
+ }
+ }
+
+ 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);
+ }
+ if(StringUtils.isEmpty(errorDescription)) {
+ errorDescription = "Unknown";
+ }
+ 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)){
+ errorDescriptionFromCtx = ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE);
+ }
+ 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);
+ }
}
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DgResolverPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DgResolverPluginImpl.java
new file mode 100644
index 000000000..497cb7f66
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DgResolverPluginImpl.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.i18n.Msg;
+import com.att.eelf.i18n.EELFResourceManager;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+
+import java.util.Map;
+
+import org.openecomp.appc.dg.common.DgResolverPlugin;
+
+public class DgResolverPluginImpl implements DgResolverPlugin {
+
+ @Override
+ public void resolveDg(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+
+ String DGName, DGVersion, DGModule = null;
+ String prefix = params.containsKey("prefix") ? params.get("prefix") + "." : "";
+ AbstractResolver resolver = ResolverFactory.createResolver(params.get("DGResolutionType"));
+ 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 (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);
+ } 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));
+ }
+ } 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);
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/FlowKey.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/FlowKey.java
new file mode 100644
index 000000000..416f90786
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/FlowKey.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+class FlowKey {
+ private final String name;
+ private final String version;
+ private final String module;
+
+ FlowKey(String name, String version, String module) {
+ this.name = name;
+ this.version = version;
+ this.module = module;
+ }
+
+ String name() {
+ return name;
+ }
+
+ String version() {
+ return version;
+ }
+
+ String module() {
+ return module;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buff = new StringBuilder(128);
+ buff.append("{");
+ buff.append("module = ").append(module);
+ buff.append(", ");
+ buff.append("name = ").append(name);
+ buff.append(", ");
+ buff.append("version = ").append(version);
+ buff.append("}");
+ return buff.toString();
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/IntermediateMessageSenderImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/IntermediateMessageSenderImpl.java
new file mode 100644
index 000000000..3732ded04
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/IntermediateMessageSenderImpl.java
@@ -0,0 +1,169 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+
+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 org.apache.commons.lang.StringUtils;
+import org.openecomp.appc.adapter.message.MessageAdapterFactory;
+import org.openecomp.appc.adapter.message.Producer;
+import org.openecomp.appc.configuration.Configuration;
+import org.openecomp.appc.configuration.ConfigurationFactory;
+import org.openecomp.appc.dg.common.IntermediateMessageSender;
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+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 {
+
+
+ private Producer producer;
+
+ private Configuration configuration;
+
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(IntermediateMessageSenderImpl.class);
+
+ private static final String STATUS = "STATUS";
+ private static final String FAILURE = "FAILURE";
+ private static final String SUCCESS = "SUCCESS";
+ private static final String ERROR_MESSAGE = "ERROR_MESSAGE";
+
+ private static final String RESPONSE = "response";
+ private static final String MSO = "MSO";
+
+ public void init(){
+ configuration = ConfigurationFactory.getConfiguration();
+ 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);
+
+ Set<String> pool = new HashSet<>();
+ if (!StringUtils.isEmpty(hostNames)) {
+ for (String name : hostNames.split(",")) {
+ pool.add(name);
+ }
+ }
+
+ BundleContext ctx = FrameworkUtil.getBundle(IntermediateMessageSenderImpl.class).getBundleContext();
+ if (ctx != null) {
+ ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName());
+ if (svcRef != null) {
+ producer = ((MessageAdapterFactory) ctx.getService(svcRef)).createProducer(pool, writeTopic,apiKey, apiSecret);
+ }
+ }
+ }
+
+ @Override
+ public void sendMessage(Map<String, String> params, SvcLogicContext context) {
+ String prefix = params.get("prefix");
+ prefix = StringUtils.isEmpty(prefix)? "":prefix+".";
+ try{
+ validateInputs(params,context);
+ String jsonMessage = getJsonMessage(params, context);
+ logger.debug("Constructed JSON Message : " + jsonMessage);
+ producer.post("",jsonMessage);
+ context.setAttribute(prefix + STATUS, SUCCESS);
+ }
+ 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);
+ }
+ }
+
+ private void validateInputs(Map<String, String> params, SvcLogicContext context) throws APPCException {
+ String code = params.get("code");
+ String message = params.get("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)){
+ throw new APPCException("requestId is empty");
+ }
+ }
+
+ private String getJsonMessage(Map<String, String> params, SvcLogicContext context) {
+ ObjectMapper objectMapper = new ObjectMapper();
+
+ ObjectNode commonHeader = getCommonHeader(context);
+ ObjectNode status = getStatus(params);
+
+ ObjectNode output = objectMapper.createObjectNode();
+ output.put("common-header",commonHeader);
+ output.put("status",status);
+
+ 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("cambria.partition", MSO);
+ root.put("correlation-id",getCorrelationId(context));
+ root.put("body",body);
+
+ return root.toString();
+ }
+
+ 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));
+ }
+
+ private ObjectNode getStatus(Map<String,String> params) {
+ ObjectMapper objectMapper = new ObjectMapper();
+ 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"));
+ return commonHeader;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImpl.java
index 95191132a..1ba2b5b07 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImpl.java
@@ -21,21 +21,36 @@
package org.openecomp.appc.dg.common.impl;
+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.openecomp.appc.dg.common.JsonDgUtil;
import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.i18n.Msg;
import org.openecomp.appc.util.JsonUtil;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
import org.openecomp.sdnc.sli.SvcLogicContext;
-import java.util.Map;
+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<SimpleDateFormat> DATE_TIME_PARSER_THREAD_LOCAL = new ThreadLocal<SimpleDateFormat>() {
+ protected SimpleDateFormat initialValue() {
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ }
+ };
+
@Override
public void flatAndAddToContext(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
@@ -59,8 +74,123 @@ 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));
+ ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
+ throw new APPCException(e);
+ }
+ }
+
+ @Override
+ public void generateOutputPayloadFromContext(Map<String, String> params, SvcLogicContext ctx) throws APPCException{
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering to generateOutputPayloadFromContext with SvcLogicContext = "+ObjectUtils.toString(ctx));
+ }
+
+ try {
+ Set<String> keys = ctx.getAttributeKeySet();
+ 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("]")){
+ 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));
+ }
+ }
+ }
+ if(JsonNode.size()>0) {
+ ctx.setAttribute(Constants.OUTPUT_PAYLOAD, objectMapper.writeValueAsString(JsonNode));
+ }
+ } catch (Exception e) {
+ logger.error(e.toString());
ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.toString());
throw new APPCException(e);
}
+
+ }
+
+ @Override
+ public void cvaasFileNameAndFileContentToContext(Map<String, String> params, SvcLogicContext ctx)
+ throws APPCException {
+
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering to caasFileNameAndFileContentToContext with SvcLogicContext = "
+ + ObjectUtils.toString(ctx));
+ }
+
+ String vnfId = null;
+ try {
+ String cvassDirectoryPath = params.get(Constants.CVAAS_DIRECTORY_PATH);
+ String appcInstanceId = params.get(Constants.APPC_INSTANCE_ID);
+
+ /*
+ * File name
+ */
+ vnfId = params.get("vnf-id");
+ long timestampAsLongRepresentingFileCreationTime = System.currentTimeMillis();
+
+ ctx.setAttribute(Constants.CVAAS_FILE_NAME, cvassDirectoryPath + File.separator + vnfId + "_"
+ + timestampAsLongRepresentingFileCreationTime + "_" + appcInstanceId + ".json");
+
+ /*
+ * File content
+ */
+
+ String uploadDate = ctx.getAttribute("running-config.upload-date");
+ long epochUploadTimestamp = DATE_TIME_PARSER_THREAD_LOCAL.get().parse(uploadDate).getTime();
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ ObjectNode jsonNode = objectMapper.createObjectNode();
+ jsonNode.put("UPLOAD_CONFIG_ID", ctx.getAttribute("running-config.upload-config-id"));
+ jsonNode.put("REQUEST_ID", ctx.getAttribute("running-config.request-id"));
+ jsonNode.put("ORIGINATOR_ID", ctx.getAttribute("running-config.originator-id"));
+ jsonNode.put("SERVICE_DESCRIPTION", ctx.getAttribute("running-config.service-description"));
+ jsonNode.put("ACTION", ctx.getAttribute("running-config.action"));
+ jsonNode.put("UPLOAD_TIMESTAMP", epochUploadTimestamp);
+ jsonNode.put("UPLOAD_DATE", uploadDate);
+ jsonNode.put("VNF_ID", vnfId);
+ jsonNode.put("VNF_NAME", ctx.getAttribute("running-config.vnf-name"));
+ jsonNode.put("VM_NAME", ctx.getAttribute("running-config.vm-name"));
+ jsonNode.put("VNF_TYPE", ctx.getAttribute("running-config.vnf-type"));
+ jsonNode.put("VNFC_TYPE", ctx.getAttribute("running-config.vnfc-type"));
+ jsonNode.put("HOST_IP_ADDRESS", ctx.getAttribute("running-config.host-ip-address"));
+ jsonNode.put("CONFIG_INDICATOR", ctx.getAttribute("running-config.config-indicator"));
+ jsonNode.put("PENDING_DELETE", ctx.getAttribute("running-config.pending-delete"));
+ jsonNode.put("CONTENT", ctx.getAttribute("running-config.content"));
+
+ ctx.setAttribute(Constants.CVAAS_FILE_CONTENT,
+ objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode));
+
+ } catch (Exception e) {
+ String errorMessage = "Failed to parse create cvass file for vnf with id : " + vnfId;
+ logger.error(errorMessage, e);
+ ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, errorMessage);
+ throw new APPCException(e);
+ }
+ }
+
+ @Override
+ public void checkFileCreated(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+ String filePath = ctx.getAttribute(Constants.CVAAS_FILE_NAME);
+ File file = new File(filePath);
+
+ if (!file.exists()) {
+ String vnfId = params.get("vnf-id");
+ String errorMessage = "Cvass file could not be created for vnf with id : " + vnfId;
+ ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, errorMessage);
+ throw new APPCException(errorMessage);
+ }
}
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/LegacyUtilImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/LegacyUtilImpl.java
index 6354b2044..3ab8ee28f 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/LegacyUtilImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/LegacyUtilImpl.java
@@ -37,11 +37,13 @@ public class LegacyUtilImpl implements LegacyUtil {
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.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/openecomp/appc/dg/common/impl/OutputMessagePluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/OutputMessagePluginImpl.java
new file mode 100644
index 000000000..c70c754ca
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/OutputMessagePluginImpl.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+
+import java.util.Map;
+
+import org.openecomp.appc.dg.common.OutputMessagePlugin;
+import org.openecomp.appc.exceptions.APPCException;
+
+import static org.apache.commons.lang3.StringUtils.isEmpty;
+
+public class OutputMessagePluginImpl implements OutputMessagePlugin {
+
+ @Override
+ public void outputMessageBuilder(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+ String errorDescription, eventDescription;
+
+ //making output.status.message
+ errorDescription = params.get(Constants.ATTRIBUTE_ERROR_MESSAGE);
+ eventDescription = params.get(Constants.EVENT_MESSAGE);
+
+ addToContextIfNotContains(errorDescription , eventDescription, ctx);
+
+ //making event-message
+
+ if (!isEmpty(eventDescription)) {
+ ctx.setAttribute(Constants.EVENT_MESSAGE, eventDescription);
+ } else {
+ ctx.setAttribute(Constants.EVENT_MESSAGE, ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE));
+ }
+ }
+
+ 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);
+ }
+ }
+ 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);
+ }
+ }
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverDataReaderFactory.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverDataReaderFactory.java
new file mode 100644
index 000000000..9dc43abee
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverDataReaderFactory.java
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import org.openecomp.appc.configuration.Configuration;
+import org.openecomp.appc.configuration.ConfigurationFactory;
+
+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();
+ }
+
+ public static AbstractResolverDataReader createResolverDataReader(String resolverType){
+ if(resolverType.equalsIgnoreCase("VNF")){
+ return ReferenceHolder.VNF_RESOLVER_DATA_READER;
+ }else if(resolverType.equalsIgnoreCase("VNFC")){
+ return ReferenceHolder.VNFC_RESOLVER_DATA_READER;
+ }else {
+ return null;
+ }
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverFactory.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverFactory.java
new file mode 100644
index 000000000..afc7907db
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverFactory.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import org.openecomp.appc.configuration.Configuration;
+import org.openecomp.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.openecomp.appc.workflow.resolver.refresh_interval", 300));
+ private static final AbstractResolver VNF_RESOLVER = new VNFResolver(configuration.getIntegerProperty("org.openecomp.appc.workflow.resolver.refresh_interval", 300));
+ }
+
+ public static AbstractResolver createResolver(String resolverType){
+ if(resolverType.equalsIgnoreCase("VNF")){
+ return ReferenceHolder.VNF_RESOLVER;
+ }else if(resolverType.equalsIgnoreCase("VNFC")){
+ return ReferenceHolder.VNFC_RESOLVER;
+ }else {
+ return null;
+ }
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCDgResolverPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCDgResolverPluginImpl.java
new file mode 100644
index 000000000..404d9087b
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCDgResolverPluginImpl.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+
+import java.util.Map;
+
+public class VNFCDgResolverPluginImpl implements org.openecomp.appc.dg.common.VNFCDgResolverPlugin {
+ @Override
+ public void resolveVNFCDg(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+ DgResolverPluginImpl dgResolverPlugin = new DgResolverPluginImpl();
+ params.put("DGResolutionType" , "VNFC");
+ dgResolverPlugin.resolveDg(params,ctx);
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolver.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolver.java
new file mode 100644
index 000000000..7c90b57f9
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolver.java
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import org.openecomp.appc.rankingframework.RankedAttributesContext;
+
+
+public class VNFCResolver extends AbstractResolver {
+ VNFCResolver(int interval) {
+ super(interval);
+ }
+
+ @Override
+ protected FlowKey resolve(String... args) {
+ if(args.length !=4){
+ throw new IllegalStateException(args.toString());
+ }
+ 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) {
+ 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);
+ }
+ }
+ };
+
+ FlowKey wfKey = resolver("VNFC").resolve(context);
+
+ return wfKey;
+ }
+}
+
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolverDataReader.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolverDataReader.java
new file mode 100644
index 000000000..b49d1fa54
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolverDataReader.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+public class VNFCResolverDataReader extends AbstractResolverDataReader {
+ @Override
+ protected Collection<String> getAttributeNames() {
+ return Arrays.asList("action","api_version", "vnf_type", "vnfc_type");
+ }
+
+ @Override
+ protected String getQueryStmt() {
+ return "select vnf_type,vnfc_type,api_version,action,dg_name,dg_version,dg_module FROM VNFC_DG_MAPPING";
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFConfiguratorImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFConfiguratorImpl.java
new file mode 100644
index 000000000..169114330
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFConfiguratorImpl.java
@@ -0,0 +1,112 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import org.openecomp.appc.Constants;
+import org.openecomp.appc.dg.common.VNFConfigurator;
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.mdsal.MDSALStore;
+import org.openecomp.appc.mdsal.exception.MDSALStoreException;
+import org.openecomp.appc.mdsal.impl.MDSALStoreFactory;
+import org.openecomp.appc.mdsal.objects.BundleInfo;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.apache.commons.lang.StringUtils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map;
+
+
+public class VNFConfiguratorImpl implements VNFConfigurator {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(VNFConfiguratorImpl.class);
+ private static final String STATUS = "STATUS";
+ private static final String FAILURE = "FAILURE";
+ private static final String SUCCESS = "SUCCESS";
+ private static final String ERROR_MESSAGE = "ERROR_MESSAGE";
+
+ @Override
+ public void storeConfig(Map<String, String> params, SvcLogicContext context) throws APPCException {
+ String uniqueId = params.get("uniqueId");
+ String yang = params.get("yang");
+ String configJSON = params.get("configJSON");
+ String requestId = params.get("requestId");
+ String prefix = params.get("prefix");
+ prefix = StringUtils.isEmpty(prefix)? "":prefix+".";
+
+ MDSALStore store = MDSALStoreFactory.createMDSALStore();
+
+ logger.debug("Inputs Received : uniqueId = " + uniqueId +
+ " , yang = " + yang +
+ " , configJSON = " + configJSON +
+ " , requestId = " + requestId +
+ " , prefix = " +prefix);
+
+ try {
+
+ 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);
+ }
+
+ Date revision = new SimpleDateFormat(Constants.YANG_REVISION_FORMAT).parse(Constants.YANG_REVISION);
+
+ boolean isYangAlreadyLoaded = store.isModulePresent(uniqueId,revision);
+
+ if(!isYangAlreadyLoaded){
+ BundleInfo bundleInfo = getBundleInfo(uniqueId);
+ store.storeYangModule(yang,bundleInfo);
+ }
+ 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);
+ context.setAttribute(prefix + STATUS, FAILURE);
+ context.setAttribute(prefix + ERROR_MESSAGE, errorMessage);
+ throw new APPCException(e.getMessage());
+ }catch (MDSALStoreException e){
+ String errorMessage = "Error while adding yang to MD-SAL store." + e.getMessage();
+ logger.error(errorMessage,e);
+ context.setAttribute(prefix + STATUS,FAILURE);
+ context.setAttribute(prefix + ERROR_MESSAGE, errorMessage);
+ throw new APPCException(e.getMessage());
+ }
+
+ }
+
+ private BundleInfo getBundleInfo(String uniqueId) {
+ BundleInfo bundleInfo = new BundleInfo();
+ bundleInfo.setDescription(uniqueId);
+ bundleInfo.setName(uniqueId);
+ bundleInfo.setLocation(uniqueId);
+ return bundleInfo;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolver.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolver.java
new file mode 100644
index 000000000..b6002c65e
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolver.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import org.openecomp.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]);
+ }
+
+
+ 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) {
+ 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;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolverDataReader.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolverDataReader.java
new file mode 100644
index 000000000..7d91bee15
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolverDataReader.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+/**
+ * @since January 19,2017
+ */
+public class VNFResolverDataReader extends AbstractResolverDataReader {
+ @Override
+ protected Collection<String> getAttributeNames() {
+ return Arrays.asList("action","api_version", "vnf_type", "vnf_version");
+ }
+
+ @Override
+ protected String getQueryStmt() {
+ return "select vnf_type,vnf_version,api_version,action,dg_name,dg_version,dg_module FROM VNF_DG_MAPPING";
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VnfExecutionFlowImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VnfExecutionFlowImpl.java
new file mode 100644
index 000000000..e8975da0f
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VnfExecutionFlowImpl.java
@@ -0,0 +1,268 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+
+import java.util.*;
+
+import org.openecomp.appc.dg.common.VnfExecutionFlow;
+import org.openecomp.appc.dg.dependencymanager.DependencyManager;
+import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound;
+import org.openecomp.appc.dg.dependencymanager.impl.DependencyModelFactory;
+import org.openecomp.appc.dg.flowbuilder.FlowBuilder;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.flowbuilder.impl.FlowBuilderFactory;
+import org.openecomp.appc.dg.objects.*;
+import org.openecomp.appc.domainmodel.Vnf;
+import org.openecomp.appc.domainmodel.Vnfc;
+import org.openecomp.appc.domainmodel.Vserver;
+import org.openecomp.appc.i18n.Msg;
+import org.openecomp.appc.metadata.objects.DependencyModelIdentifier;
+
+public class VnfExecutionFlowImpl implements VnfExecutionFlow {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(VnfExecutionFlowImpl.class);
+
+ public VnfExecutionFlowImpl(){
+
+ }
+
+ @Override
+ public void getVnfExecutionFlowData(Map<String, String> params, SvcLogicContext context) {
+ String dependencyType = params.get(Constants.DEPENDENCY_TYPE);
+ String flowStrategy = params.get(Constants.FLOW_STRATEGY);
+ DependencyModelIdentifier modelIdentifier = readDependencyModelIdentifier(params);
+ VnfcDependencyModel dependencyModel = null;
+ try {
+ validateInput(dependencyType, flowStrategy, params);
+
+ if (logger.isTraceEnabled()) {
+ logger.trace("Input received from DG Node : dependencyType = " + dependencyType +
+ " , flowStrategy = " + flowStrategy +
+ ", DependencyModelIdentifier = " + modelIdentifier.toString());
+ }
+
+ 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);
+ context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg);
+ context.setAttribute("dependencyModelFound","false");
+ return;
+ } catch (InvalidDependencyModel 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 e;
+ }catch (RuntimeException e){
+ logger.error(e.getMessage());
+ context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage());
+ throw e;
+ }
+
+
+ context.setAttribute("dependencyModelFound","true");
+ if(logger.isDebugEnabled()){
+ logger.debug("Dependency Model = " +dependencyModel);
+ }
+ logger.info("Building Inventory Model from DG context");
+ InventoryModel inventoryModel = readInventoryModel(context);
+ if(logger.isDebugEnabled()){
+ logger.debug("Inventory Model = " +inventoryModel);
+ }
+
+ if(logger.isDebugEnabled()){
+ logger.debug("Validating inventory model with dependency model");
+ }
+ try {
+ validateInventoryModelWithDependencyModel(dependencyModel, inventoryModel);
+ }catch (RuntimeException e){
+ logger.error(e.getMessage());
+ context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage());
+ throw e;
+ }
+ logger.info("Creating flow builder");
+ FlowBuilder flowBuilder = FlowBuilderFactory.getInstance().getFlowBuilder(
+ FlowStrategies.findByString(flowStrategy));
+
+ logger.info("Building Vnf flow model");
+ VnfcFlowModel flowModel = null;
+ try{
+ flowModel = flowBuilder.buildFlowModel(dependencyModel,inventoryModel);
+ }
+ catch (InvalidDependencyModel 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 e;
+ }
+
+ // remove VNFCs from the flow model where vserver list is empty
+ reconcileFlowModel(flowModel);
+ populateContext(flowModel,context);
+ if(logger.isDebugEnabled()){
+ logContext(context);
+ }
+ String msg = EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "GetVnfExecutionFlowData","VNF ID " + params.get(Constants.VNF_TYPE));
+ context.setAttribute(org.openecomp.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg);
+ }
+
+ private void validateInput(String dependencyType, String flowStrategy, Map<String, String> params) {
+ DependencyTypes dependencyTypes = DependencyTypes.findByString(dependencyType);
+ if(dependencyTypes == null){
+ throw new RuntimeException("Dependency type from the input : " + dependencyType +" is invalid.");
+ }
+ FlowStrategies flowStrategies = FlowStrategies.findByString(flowStrategy);
+ if(flowStrategies == null){
+ throw new RuntimeException("Flow Strategy from the input : " + flowStrategy +" is invalid.");
+ }
+ String vnfType = params.get(Constants.VNF_TYPE);
+ if(vnfType ==null || vnfType.length() ==0){
+ throw new RuntimeException("Vnf Type is not passed in the input");
+ }
+ String vnfVersion = params.get(Constants.VNF_VERION);
+ if(vnfVersion == null || vnfVersion.length() ==0){
+ throw new RuntimeException("Vnf Version not found");
+ }
+ }
+
+ private void logContext(SvcLogicContext context) {
+ for(String key:context.getAttributeKeySet()){
+ logger.debug(key + " = " + context.getAttribute(key) + "\n" );
+ }
+ }
+
+ private void populateContext(VnfcFlowModel flowModel, SvcLogicContext context) {
+ int flowIndex=0;
+ Iterator<List<Vnfc>> iterator = flowModel.getModelIterator();
+ while (iterator.hasNext()){
+ for(Vnfc vnfc:iterator.next()){
+ context.setAttribute("vnfcFlow["+flowIndex+"].vnfcName",vnfc.getVnfcName());
+ context.setAttribute("vnfcFlow["+flowIndex+"].vnfcType",vnfc.getVnfcType());
+ context.setAttribute("vnfcFlow["+flowIndex+"].resilienceType",vnfc.getResilienceType());
+ context.setAttribute("vnfcFlow["+flowIndex+"].vmCount",Integer.toString(vnfc.getVserverList().size()));
+ int vmIndex =0;
+ for(Vserver vm :vnfc.getVserverList()){
+ context.setAttribute("vnfcFlow["+flowIndex+"].vm["+vmIndex+"].url",vm.getUrl());
+ vmIndex++;
+ }
+ flowIndex++;
+ }
+ }
+ context.setAttribute("vnfcFlowCount",Integer.toString(flowIndex));
+ }
+
+ private InventoryModel readInventoryModel(SvcLogicContext context) {
+ String vnfId = context.getAttribute("input.action-identifiers.vnf-id");
+ String vnfType = context.getAttribute("vnf.type");
+ String vnfVersion = context.getAttribute("vnf.version");
+ String vnfcCountStr = context.getAttribute("vnf.vnfcCount");
+ Integer vnfcCount = Integer.parseInt(vnfcCountStr);
+
+ Vnf vnf = new Vnf(vnfId,vnfType,vnfVersion);
+
+ for(Integer i=0;i<vnfcCount;i++){
+ 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){
+ throw new RuntimeException("Could not retrieve VNFC Type from DG Context for vnf.vnfc["+ i+"].type");
+ }
+ Integer vmCount = Integer.parseInt(vmCountStr);
+ Vnfc vnfc = new Vnfc(vnfcType,null,vnfcName);
+ for(Integer j=0;j<vmCount;j++){
+ String vmURL = context.getAttribute("vnf.vnfc["+i+"].vm["+j+"].url");
+ Vserver vm = new Vserver(vmURL);
+ vnfc.addVm(vm);
+ }
+ vnf.addVnfc(vnfc);
+ }
+ return new InventoryModel(vnf);
+ }
+
+ private DependencyModelIdentifier readDependencyModelIdentifier(Map<String, String> params) {
+ String vnfType = params.get(Constants.VNF_TYPE);
+ String catalogVersion = params.get(Constants.VNF_VERION);
+ return new DependencyModelIdentifier(vnfType,catalogVersion);
+ }
+
+ private void validateInventoryModelWithDependencyModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) {
+ Set<String> dependencyModelVnfcSet = new HashSet<String>();
+ Set<String> dependencyModelMandatoryVnfcSet = new HashSet<String>();
+ Set<String> inventoryModelVnfcsSet = new HashSet<String>();
+
+ for (Node<Vnfc> node : dependencyModel.getDependencies()) {
+ dependencyModelVnfcSet.add(node.getChild().getVnfcType().toLowerCase());
+ if (node.getChild().isMandatory()) {
+ dependencyModelMandatoryVnfcSet.add(node.getChild().getVnfcType().toLowerCase());
+ }
+ }
+
+ for (Vnfc vnfc : inventoryModel.getVnf().getVnfcs()) {
+ inventoryModelVnfcsSet.add(vnfc.getVnfcType().toLowerCase());
+ }
+
+ // if dependency model and inventory model contains same set of VNFCs, validation succeed and hence return
+ if (dependencyModelVnfcSet.equals(inventoryModelVnfcsSet)) {
+ return;
+ }
+
+ if (inventoryModelVnfcsSet.size() >= dependencyModelVnfcSet.size()) {
+ Set<String> difference = new HashSet<String>(inventoryModelVnfcsSet);
+ difference.removeAll(dependencyModelVnfcSet);
+ logger.error("Dependency model is missing following vnfc type(s): " + difference);
+ throw new RuntimeException("Dependency model is missing following vnfc type(s): " + difference);
+ } else {
+ Set<String> difference = new HashSet<String>(dependencyModelVnfcSet);
+ difference.removeAll(inventoryModelVnfcsSet);
+ difference.retainAll(dependencyModelMandatoryVnfcSet);
+ if (difference.size() > 0) {
+ logger.error("Inventory model is missing following mandatory vnfc type(s): " + difference);
+ throw new RuntimeException("Inventory model is missing following mandatory vnfc type(s): " + difference);
+ }
+ }
+ }
+
+ private void reconcileFlowModel(VnfcFlowModel flowModel) {
+ Iterator<List<Vnfc>> flowIterator = flowModel.getModelIterator();
+ while (flowIterator.hasNext()) {
+ 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();
+ }
+ }
+ }
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 53b5367e4..fcbaaf776 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -30,12 +30,35 @@
<bean id="JsonDgUtilBean" class="org.openecomp.appc.dg.common.impl.JsonDgUtilImpl"/>
<service id="JsonDgUtil" interface="org.openecomp.appc.dg.common.JsonDgUtil" ref="JsonDgUtilBean"/>
- <reference id="eventSenderRef" availability="mandatory" activation="eager" interface="org.openecomp.appc.adapter.dmaap.EventSender" />
+ <!-- <reference id="eventSenderRef" availability="mandatory" activation="eager" interface="org.openecomp.appc.adapter.message.EventSender" /> -->
<bean id="DCAEReporterPluginBean" class="org.openecomp.appc.dg.common.impl.DCAEReporterPluginImpl" scope="singleton"/>
<service id="DCAEReporterPlugin" interface="org.openecomp.appc.dg.common.DCAEReporterPlugin" ref="DCAEReporterPluginBean"/>
+ <bean id="OutputMessagePluginBean" class="org.openecomp.appc.dg.common.impl.OutputMessagePluginImpl" scope="singleton"/>
+ <service id="OutputMessagePlugin" interface="org.openecomp.appc.dg.common.OutputMessagePlugin" ref="OutputMessagePluginBean"/>
+
<bean id="legacyUtilBean" class="org.openecomp.appc.dg.common.impl.LegacyUtilImpl" scope="singleton"/>
<service id="legacyUtil" interface="org.openecomp.appc.dg.common.LegacyUtil" ref="legacyUtilBean"/>
+ <bean id="DgResolverPluginBean" class="org.openecomp.appc.dg.common.impl.DgResolverPluginImpl" scope="singleton">
+ </bean>
+
+ <service id="DgResolverPlugin" interface="org.openecomp.appc.dg.common.DgResolverPlugin" ref="DgResolverPluginBean"/>
+
+ <bean id="vnfExecutionFlowBean" class="org.openecomp.appc.dg.common.impl.VnfExecutionFlowImpl" scope="singleton"/>
+ <service id="vnfExecutionFlowService" interface="org.openecomp.appc.dg.common.VnfExecutionFlow" ref="vnfExecutionFlowBean"/>
+
+ <bean id="VNFCDgResolverPluginBean" class="org.openecomp.appc.dg.common.impl.VNFCDgResolverPluginImpl" scope="singleton">
+ </bean>
+
+ <service id="VNFCDgResolverPlugin" interface="org.openecomp.appc.dg.common.VNFCDgResolverPlugin" ref="VNFCDgResolverPluginBean"/>
+
+ <bean id="vnfConfiguratorBean" class="org.openecomp.appc.dg.common.impl.VNFConfiguratorImpl" scope="singleton"/>
+
+ <service id="vnfConfigurationService" interface="org.openecomp.appc.dg.common.VNFConfigurator" ref="vnfConfiguratorBean"/>
+
+ <bean id="interimMessageSender" class="org.openecomp.appc.dg.common.impl.IntermediateMessageSenderImpl" init-method="init" scope="singleton"/>
+ <service id="interimMessageSenderService" ref="interimMessageSender" interface="org.openecomp.appc.dg.common.IntermediateMessageSender"/>
+
</blueprint>
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java
index 834bd8655..44b71fb4d 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java
@@ -24,10 +24,9 @@ package org.openecomp.appc.dg.common.impl;
import org.junit.*;
import org.junit.runner.RunWith;
import org.mockito.*;
-import org.openecomp.appc.adapter.dmaap.EventSender;
-import org.openecomp.appc.adapter.dmaap.DmaapDestination;
-import org.openecomp.appc.adapter.dmaap.event.EventMessage;
-import org.openecomp.appc.dg.common.impl.Constants;
+import org.openecomp.appc.adapter.message.EventSender;
+import org.openecomp.appc.adapter.message.MessageDestination;
+import org.openecomp.appc.adapter.message.event.EventMessage;
import org.openecomp.appc.dg.common.impl.DCAEReporterPluginImpl;
import org.openecomp.appc.exceptions.APPCException;
import org.openecomp.sdnc.sli.SvcLogicContext;
@@ -44,7 +43,6 @@ import java.util.Map;
@RunWith(PowerMockRunner.class)
@PrepareForTest({DCAEReporterPluginImpl.class, FrameworkUtil.class})
-@Ignore
public class DCAEReporterPluginImplTest {
private SvcLogicContext ctx;
private Map<String, String> params;
@@ -75,39 +73,11 @@ public class DCAEReporterPluginImplTest {
-
- @Test
- public void testReportBwcTrue() throws Exception {
-
- ctx = new SvcLogicContext();
- params = new HashMap<>();
- ctx.setAttribute("isBwcMode", "true");
- params.put(Constants.DG_ERROR_FIELD_NAME, error);
- ctx.setAttribute(Constants.API_VERSION_FIELD_NAME, apiVer);
- ctx.setAttribute(Constants.REQ_ID_FIELD_NAME, requestId);
-
- positiveAssert();
- }
-
- @Test
- public void testReportErrorDescriptionNullBwcModeTrue() throws Exception {
-
- ctx = new SvcLogicContext();
- params = new HashMap<>();
- ctx.setAttribute("isBwcMode", "true");
- params.put(Constants.DG_ERROR_FIELD_NAME, null);
- ctx.setAttribute(Constants.API_VERSION_FIELD_NAME, apiVer);
- ctx.setAttribute(Constants.REQ_ID_FIELD_NAME, requestId);
-
- errorReasonNullAssert();
- }
-
@Test
public void testReportErrorDescriptionNullBwcModeFalse() throws Exception {
ctx = new SvcLogicContext();
params = new HashMap<>();
- ctx.setAttribute("isBwcMode", "false");
params.put("output.status.message", null);
ctx.setAttribute("input.common-header.api-ver", apiVer);
ctx.setAttribute("input.common-header.request-id", requestId);
@@ -118,7 +88,7 @@ public class DCAEReporterPluginImplTest {
private void errorReasonNullAssert() throws APPCException {
dcaeReporterPlugin.report(params, ctx);
- DmaapDestination destination = eventSender.getDestination();
+ MessageDestination destination = eventSender.getDestination();
EventMessage msg = eventSender.getMsg();
Assert.assertEquals("wrong API version", apiVer, msg.getEventHeader().getApiVer());
Assert.assertEquals("wrong requestId", requestId, msg.getEventHeader().getEventId());
@@ -130,7 +100,7 @@ public class DCAEReporterPluginImplTest {
private void positiveAssert() throws APPCException {
dcaeReporterPlugin.report(params, ctx);
- DmaapDestination destination = eventSender.getDestination();
+ MessageDestination destination = eventSender.getDestination();
EventMessage msg = eventSender.getMsg();
Assert.assertEquals("wrong API version", apiVer, msg.getEventHeader().getApiVer());
Assert.assertEquals("wrong requestId", requestId, msg.getEventHeader().getEventId());
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/EventSenderMock.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/EventSenderMock.java
index 0e6b1651b..86532922d 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/EventSenderMock.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/EventSenderMock.java
@@ -23,19 +23,19 @@ package org.openecomp.appc.dg.common.impl;
import java.util.Map;
-import org.openecomp.appc.adapter.dmaap.EventSender;
-import org.openecomp.appc.adapter.dmaap.DmaapDestination;
-import org.openecomp.appc.adapter.dmaap.event.EventMessage;
+import org.openecomp.appc.adapter.message.EventSender;
+import org.openecomp.appc.adapter.message.MessageDestination;
+import org.openecomp.appc.adapter.message.event.EventMessage;
import org.openecomp.appc.exceptions.APPCException;
import org.openecomp.sdnc.sli.SvcLogicContext;
public class EventSenderMock implements EventSender {
EventMessage msg;
- DmaapDestination destination;
+ MessageDestination destination;
@Override
- public boolean sendEvent(DmaapDestination destination, EventMessage msg) {
+ public boolean sendEvent(MessageDestination destination, EventMessage msg) {
if (destination != null && msg != null){
this.msg = msg;
this.destination = destination;
@@ -47,7 +47,12 @@ public class EventSenderMock implements EventSender {
}
@Override
- public boolean sendEvent(DmaapDestination destination, Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+ public boolean sendEvent(MessageDestination destination, EventMessage msg, String eventTopicName) {
+ return false;
+ }
+
+ @Override
+ public boolean sendEvent(MessageDestination destination, Map<String, String> params, SvcLogicContext ctx) throws APPCException {
return false;
}
@@ -55,7 +60,7 @@ public class EventSenderMock implements EventSender {
return msg;
}
- public DmaapDestination getDestination() {
+ public MessageDestination getDestination() {
return destination;
}
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java
index 70534872d..0a49d5326 100644
--- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java
@@ -32,7 +32,6 @@ import org.openecomp.sdnc.sli.SvcLogicContext;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
public class JsonDgUtilImplTest {
@@ -83,7 +82,7 @@ public class JsonDgUtilImplTest {
} catch (APPCException e) {
Assert.assertNull(ctx.getAttribute(testValueKey));
Assert.assertNull(ctx.getAttribute(testValueKey2));
- Assert.assertNotNull(ctx.getAttribute("output.status.message"));
+ Assert.assertNotNull(ctx.getAttribute("error-message"));
}
@@ -142,4 +141,29 @@ public class JsonDgUtilImplTest {
Assert.assertNull(ctx.getAttribute(testValueKey));
Assert.assertNull(ctx.getAttribute(testValueKey2));
}
+
+
+ @Test
+ public void testGenerateOutputPayloadFromContext() throws Exception {
+
+ JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl();
+ String key = "output.payload";
+ String key1 = "output.payload.test-key[0]";
+ String key2 = "output.payload.test-key[1]";
+ String testValueKey1 = "value1";
+ String testValueKey2 = "value2";
+
+ String key3 = "output.payload.test-key3";
+ String testValueKey3 = "value3";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> params = new HashMap<>();
+ ctx.setAttribute(key1, testValueKey1);
+ ctx.setAttribute(key2, testValueKey2);
+ ctx.setAttribute(key3, testValueKey3);
+ jsonDgUtil.generateOutputPayloadFromContext(params, ctx);
+
+ Assert.assertNotNull(ctx.getAttribute(key));
+
+ }
}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVNFConfiguratorImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVNFConfiguratorImpl.java
new file mode 100644
index 000000000..0ee06362e
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVNFConfiguratorImpl.java
@@ -0,0 +1,105 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import org.openecomp.appc.dg.common.VNFConfigurator;
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.mdsal.MDSALStore;
+import org.openecomp.appc.mdsal.impl.MDSALStoreFactory;
+import org.openecomp.appc.mdsal.impl.MDSALStoreImpl;
+import org.openecomp.appc.mdsal.objects.BundleInfo;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({MDSALStoreImpl.class,MDSALStoreFactory.class})
+public class TestVNFConfiguratorImpl {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVNFConfiguratorImpl.class);
+
+ @Before
+ public void setUp() {
+ logger.setLevel(EELFLogger.Level.DEBUG);
+ }
+
+ @Test(expected = APPCException.class)
+ public void testValidations() throws APPCException {
+ VNFConfigurator configurator = new VNFConfiguratorImpl();
+ Map<String,String> params = new HashMap<String, String>();
+ params.put("uniqueId","uniqueId");
+ params.put("yang","yang");
+ params.put("configJSON","configJSON");
+ configurator.storeConfig(params,new SvcLogicContext());
+ }
+
+ @Test
+ public void testYangPresentScenario() throws APPCException {
+
+ VNFConfigurator configurator = new VNFConfiguratorImpl();
+ PowerMockito.mockStatic(MDSALStoreFactory.class);
+ MDSALStore mdsalStore = PowerMockito.mock(MDSALStoreImpl.class);
+ PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore);
+ PowerMockito.when(mdsalStore.isModulePresent(Matchers.anyString(),(Date) Matchers.anyObject())).thenReturn(true);
+
+ Map<String,String> params = new HashMap<String, String>();
+ params.put("uniqueId","uniqueId");
+ params.put("yang","yang");
+ params.put("configJSON","configJSON");
+ params.put("requestId","requestId");
+ configurator.storeConfig(params,new SvcLogicContext());
+ }
+
+ @Test
+ public void testYangAbsentScenario() throws Exception {
+
+ VNFConfigurator configurator = new VNFConfiguratorImpl();
+ PowerMockito.mockStatic(MDSALStoreFactory.class);
+
+ MDSALStore mdsalStore = PowerMockito.mock(MDSALStoreImpl.class);
+
+ PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore);
+
+ PowerMockito.when(mdsalStore.isModulePresent(Matchers.anyString(),(Date) Matchers.anyObject())).thenReturn(false);
+
+ PowerMockito.doNothing().when(mdsalStore).storeYangModule(Matchers.anyString(),(BundleInfo)Matchers.anyObject());
+
+ Map<String,String> params = new HashMap<>();
+ params.put("uniqueId","uniqueId");
+ params.put("yang","yang");
+ params.put("configJSON","configJSON");
+ params.put("requestId","requestId");
+ configurator.storeConfig(params,new SvcLogicContext());
+
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVnfExecutionFlowImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVnfExecutionFlowImpl.java
new file mode 100644
index 000000000..773b6b61a
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVnfExecutionFlowImpl.java
@@ -0,0 +1,417 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.common.impl;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.openecomp.appc.dg.common.VnfExecutionFlow;
+import org.openecomp.appc.dg.common.impl.Constants;
+import org.openecomp.appc.dg.common.impl.VnfExecutionFlowImpl;
+import org.openecomp.appc.dg.dependencymanager.DependencyManager;
+import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound;
+import org.openecomp.appc.dg.dependencymanager.impl.DependencyModelFactory;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.objects.DependencyTypes;
+import org.openecomp.appc.dg.objects.Node;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+import org.openecomp.appc.domainmodel.Vnfc;
+import org.openecomp.appc.metadata.objects.DependencyModelIdentifier;
+import org.osgi.framework.FrameworkUtil;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TestVnfExecutionFlowImpl.class, FrameworkUtil.class,DependencyManager.class,DependencyModelFactory.class})
+public class TestVnfExecutionFlowImpl {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVnfExecutionFlowImpl.class);
+
+ @Before
+ public void setUp() {
+ logger.setLevel(EELFLogger.Level.DEBUG);
+ }
+
+ @Test
+ public void testPositiveFlow() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContext();
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+
+ @Test
+ public void testComplexFlow() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContextForComplexDependency();
+ VnfcDependencyModel dependencyModel = readComplexDependencyModel();
+
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+
+ @Test(expected = InvalidDependencyModel.class)
+ public void testCycleFlow() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContextForComplexDependency();
+ VnfcDependencyModel dependencyModel = readCyclicDependencyModel();
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+
+ private VnfcDependencyModel readCyclicDependencyModel() {
+
+ Vnfc a = new Vnfc("A","Active-Passive",null);
+ Vnfc b = new Vnfc("B","Active-Active",null);
+ Vnfc c = new Vnfc("C","Active-Active",null);
+ Vnfc d = new Vnfc("D","Active-Active",null);
+ Vnfc e = new Vnfc("E","Active-Active",null);
+ Vnfc f = new Vnfc("F","Active-Active",null);
+ Vnfc g = new Vnfc("G","Active-Active",null);
+
+ Node aNode = new Node(a);
+ Node bNode = new Node(b);
+ Node cNode = new Node(c);
+ Node dNode = new Node(d);
+ Node eNode = new Node(e);
+ Node fNode = new Node(f);
+ Node gNode = new Node(g);
+
+ bNode.addParent(a);
+ cNode.addParent(a);
+ cNode.addParent(b);
+
+ bNode.addParent(d);
+ dNode.addParent(c);
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(aNode);
+ dependencies.add(bNode);
+ dependencies.add(cNode);
+ dependencies.add(dNode);
+ dependencies.add(eNode);
+ dependencies.add(fNode);
+ dependencies.add(gNode);
+
+ return new VnfcDependencyModel(dependencies);
+
+ }
+
+ private SvcLogicContext prepareContextForComplexDependency() {
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute("input.action-identifiers.vnf-id","1");
+ context.setAttribute("vnf.type","vSCP");
+ context.setAttribute("vnf.vnfcCount","7");
+
+ context.setAttribute("vnf.vnfc[0].name","A");
+ context.setAttribute("vnf.vnfc[0].type","A");
+ context.setAttribute("vnf.vnfc[0].vm_count","2");
+ context.setAttribute("vnf.vnfc[0].vm[0].url","A1");
+ context.setAttribute("vnf.vnfc[0].vm[1].url","A2");
+
+ context.setAttribute("vnf.vnfc[1].name","B");
+ context.setAttribute("vnf.vnfc[1].type","B");
+ context.setAttribute("vnf.vnfc[1].vm_count","5");
+ context.setAttribute("vnf.vnfc[1].vm[0].url","B1");
+ context.setAttribute("vnf.vnfc[1].vm[1].url","B2");
+ context.setAttribute("vnf.vnfc[1].vm[2].url","B3");
+ context.setAttribute("vnf.vnfc[1].vm[3].url","B4");
+ context.setAttribute("vnf.vnfc[1].vm[4].url","B5");
+
+ context.setAttribute("vnf.vnfc[2].name","C");
+ context.setAttribute("vnf.vnfc[2].type","C");
+ context.setAttribute("vnf.vnfc[2].vm_count","4");
+ context.setAttribute("vnf.vnfc[2].vm[0].url","C1");
+ context.setAttribute("vnf.vnfc[2].vm[1].url","C2");
+ context.setAttribute("vnf.vnfc[2].vm[2].url","C3");
+ context.setAttribute("vnf.vnfc[2].vm[3].url","C4");
+
+ context.setAttribute("vnf.vnfc[3].name","D");
+ context.setAttribute("vnf.vnfc[3].type","D");
+ context.setAttribute("vnf.vnfc[3].vm_count","3");
+ context.setAttribute("vnf.vnfc[3].vm[0].url","D1");
+ context.setAttribute("vnf.vnfc[3].vm[1].url","D2");
+ context.setAttribute("vnf.vnfc[3].vm[2].url","D3");
+
+ context.setAttribute("vnf.vnfc[4].name","E");
+ context.setAttribute("vnf.vnfc[4].type","E");
+ context.setAttribute("vnf.vnfc[4].vm_count","2");
+ context.setAttribute("vnf.vnfc[4].vm[0].url","E1");
+ context.setAttribute("vnf.vnfc[4].vm[1].url","E2");
+
+ context.setAttribute("vnf.vnfc[5].name","F");
+ context.setAttribute("vnf.vnfc[5].type","F");
+ context.setAttribute("vnf.vnfc[5].vm_count","1");
+ context.setAttribute("vnf.vnfc[5].vm[0].url","F1");
+
+ context.setAttribute("vnf.vnfc[6].name","G");
+ context.setAttribute("vnf.vnfc[6].type","G");
+ context.setAttribute("vnf.vnfc[6].vm_count","1");
+ context.setAttribute("vnf.vnfc[6].vm[0].url","G1");
+
+
+ return context;
+ }
+
+ private VnfcDependencyModel readComplexDependencyModel() {
+ Vnfc a = new Vnfc("A","Active-Passive",null);
+ Vnfc b = new Vnfc("B","Active-Active",null);
+ Vnfc c = new Vnfc("C","Active-Active",null);
+ Vnfc d = new Vnfc("D","Active-Active",null);
+ Vnfc e = new Vnfc("E","Active-Active",null);
+ Vnfc f = new Vnfc("F","Active-Active",null);
+ Vnfc g = new Vnfc("G","Active-Active",null);
+
+
+ Node aNode = new Node(a);
+ Node bNode = new Node(b);
+ Node cNode = new Node(c);
+ Node dNode = new Node(d);
+ Node eNode = new Node(e);
+ Node fNode = new Node(f);
+ Node gNode = new Node(g);
+
+ bNode.addParent(a);
+ cNode.addParent(a);
+
+ dNode.addParent(b);
+ eNode.addParent(b);
+ gNode.addParent(b);
+
+ fNode.addParent(c);
+
+ gNode.addParent(f);
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(aNode);
+ dependencies.add(bNode);
+ dependencies.add(cNode);
+ dependencies.add(dNode);
+ dependencies.add(eNode);
+ dependencies.add(fNode);
+ dependencies.add(gNode);
+
+ return new VnfcDependencyModel(dependencies);
+ }
+
+ private VnfcDependencyModel readDependencyModel() {
+
+ Vnfc smp = new Vnfc("SMP","Active-Passive",null);
+ Vnfc be = new Vnfc("BE","Active-Active",null);
+ Vnfc fe = new Vnfc("FE","Active-Active",null);
+
+
+ Node smpNode = new Node(smp);
+ Node beNode = new Node(be);
+ Node feNode = new Node(fe);
+
+ beNode.addParent(smp);
+ feNode.addParent(be);
+// smpNode.addParent(fe);
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(smpNode);
+ dependencies.add(feNode);
+ dependencies.add(beNode);
+
+ return new VnfcDependencyModel(dependencies);
+ }
+
+ private Map<String, String> prepareParams() {
+ Map<String,String> params = new HashMap<>();
+ params.put(Constants.DEPENDENCY_TYPE,"RESOURCE");
+ params.put(Constants.FLOW_STRATEGY,"FORWARD");
+
+ params.put(Constants.VNF_TYPE,"vSCP");
+ params.put(Constants.VNF_VERION,"1.00");
+ return params;
+ }
+
+ private SvcLogicContext prepareContext() {
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute("input.action-identifiers.vnf-id","1");
+ context.setAttribute("vnf.type","vSCP");
+ context.setAttribute("vnf.vnfcCount","3");
+
+ context.setAttribute("vnf.vnfc[0].name","SMPname");
+ context.setAttribute("vnf.vnfc[0].type","SMP");
+ context.setAttribute("vnf.vnfc[0].vm_count","2");
+ context.setAttribute("vnf.vnfc[0].vm[0].url","SMP_URL1");
+ context.setAttribute("vnf.vnfc[0].vm[1].url","SMP_URL2");
+
+ context.setAttribute("vnf.vnfc[1].name","BEname");
+ context.setAttribute("vnf.vnfc[1].type","BE");
+ context.setAttribute("vnf.vnfc[1].vm_count","5");
+ context.setAttribute("vnf.vnfc[1].vm[0].url","BE_URL1");
+ context.setAttribute("vnf.vnfc[1].vm[1].url","BE_URL2");
+ context.setAttribute("vnf.vnfc[1].vm[2].url","BE_URL3");
+ context.setAttribute("vnf.vnfc[1].vm[3].url","BE_URL4");
+ context.setAttribute("vnf.vnfc[1].vm[4].url","BE_URL5");
+
+ context.setAttribute("vnf.vnfc[2].name","FEname");
+ context.setAttribute("vnf.vnfc[2].type","FE");
+ context.setAttribute("vnf.vnfc[2].vm_count","2");
+ context.setAttribute("vnf.vnfc[2].vm[0].url","FE_URL1");
+ context.setAttribute("vnf.vnfc[2].vm[1].url","FE_URL2");
+
+ return context;
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testMissingVnfcTypeInDependencyModel() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContext();
+ context.setAttribute("vnf.vnfc[3].name","XEname");
+ context.setAttribute("vnf.vnfc[3].type","XE");
+ context.setAttribute("vnf.vnfc[3].vm_count","2");
+ context.setAttribute("vnf.vnfc[3].vm[0].url","XE_URL1");
+ context.setAttribute("vnf.vnfc[3].vm[1].url","XE_URL2");
+ context.setAttribute("vnf.vnfcCount","4");
+
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testMissingMandatoryVnfcTypeInInventoryModel() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContext();
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+
+ Vnfc xe = new Vnfc("XE","Active-Active",null, true);
+ Node xeNode = new Node(xe);
+ dependencyModel.getDependencies().add(xeNode);
+
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+
+ @Test
+ public void testMissingOptionalVnfcTypeInInventoryModel() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContext();
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+
+ Vnfc xe = new Vnfc("XE","Active-Active",null, false);
+ Node xeNode = new Node(xe);
+ dependencyModel.getDependencies().add(xeNode);
+
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+
+ @Test
+ public void testMissingOptionalVnfcTypeInInventoryModelWithDependentChild() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContext();
+ context.setAttribute("vnf.vnfc[3].name","YEname");
+ context.setAttribute("vnf.vnfc[3].type","YE");
+ context.setAttribute("vnf.vnfc[3].vm_count","2");
+ context.setAttribute("vnf.vnfc[3].vm[0].url","YE_URL1");
+ context.setAttribute("vnf.vnfc[3].vm[1].url","YE_URL2");
+ context.setAttribute("vnf.vnfcCount","4");
+
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+
+ Vnfc xe = new Vnfc("XE","Active-Active",null, false);
+ Vnfc ye = new Vnfc("YE","Active-Active",null, true);
+ Node xeNode = new Node(xe);
+ Node yeNode = new Node(ye);
+ yeNode.addParent(xe);
+
+ dependencyModel.getDependencies().add(yeNode);
+ dependencyModel.getDependencies().add(xeNode);
+
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/.gitignore b/appc-dg/appc-dg-shared/appc-dg-dependency-model/.gitignore
new file mode 100644
index 000000000..b83d22266
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/.settings/org.eclipse.core.resources.prefs b/appc-dg/appc-dg-shared/appc-dg-dependency-model/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 000000000..cdfe4f1b6
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/test/java=UTF-8
+encoding//src/test/resources=UTF-8
+encoding/<project>=UTF-8
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/.settings/org.eclipse.m2e.core.prefs b/appc-dg/appc-dg-shared/appc-dg-dependency-model/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 000000000..f897a7f1c
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/.settings/org.eclipse.wst.common.project.facet.core.xml b/appc-dg/appc-dg-shared/appc-dg-dependency-model/.settings/org.eclipse.wst.common.project.facet.core.xml
new file mode 100644
index 000000000..f4ef8aa0a
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <installed facet="java" version="1.8"/>
+</faceted-project>
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/pom.xml b/appc-dg/appc-dg-shared/appc-dg-dependency-model/pom.xml
new file mode 100644
index 000000000..20dbc6b46
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/pom.xml
@@ -0,0 +1,78 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-dg-shared</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>appc-dg-dependency-model</artifactId>
+ <packaging>jar</packaging>
+
+ <name>appc-dg-dependency-model</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-yaml</artifactId>
+ <version>2.3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.6.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.6.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-dg-domain-model-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyManager.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyManager.java
new file mode 100644
index 000000000..5b5b3451b
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyManager.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.dependencymanager;
+
+import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.objects.DependencyTypes;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+
+import org.openecomp.appc.metadata.objects.DependencyModelIdentifier;
+
+public interface DependencyManager {
+ VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier, DependencyTypes dependencyType) throws InvalidDependencyModel, DependencyModelNotFound;
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyType.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyType.java
new file mode 100644
index 000000000..06a29cd1d
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/DependencyType.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.dependencymanager;
+
+import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+
+import org.openecomp.appc.metadata.objects.DependencyModelIdentifier;
+
+public interface DependencyType {
+ VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier) throws InvalidDependencyModel, DependencyModelNotFound;
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/exception/DependencyModelNotFound.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/exception/DependencyModelNotFound.java
new file mode 100644
index 000000000..521e0edb3
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/exception/DependencyModelNotFound.java
@@ -0,0 +1,29 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.dependencymanager.exception;
+
+
+public class DependencyModelNotFound extends Exception {
+ public DependencyModelNotFound(String message){
+ super(message);
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/helper/DependencyModelParser.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/helper/DependencyModelParser.java
new file mode 100644
index 000000000..397042ecd
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/helper/DependencyModelParser.java
@@ -0,0 +1,183 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.dependencymanager.helper;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.objects.Node;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+import org.openecomp.appc.domainmodel.Vnfc;
+
+import java.io.IOException;
+import java.util.*;
+
+
+public class DependencyModelParser {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(DependencyModelParser.class);
+ private static Map<String, String> dependencyMap;
+ private static final String PROPERTIES = "properties";
+ private static final String ACTIVE_ACTIVE = "Active-Active";
+ private static final String ACTIVE_PASSIVE = "Active-Passive";
+ private static final String HIGH_AVAILABLITY = "high_availablity";
+ private static final String MANDATORY = "mandatory";
+ private static final String TOPOLOGY_TEMPLATE = "topology_template";
+
+ static {
+ Map<String, String> dependencyTypeMappingMap =new HashMap<>();
+ dependencyTypeMappingMap.put("geo-activeactive", ACTIVE_ACTIVE);
+ dependencyTypeMappingMap.put("geo-activestandby", ACTIVE_PASSIVE);
+ dependencyTypeMappingMap.put("local-activeactive", ACTIVE_ACTIVE);
+ dependencyTypeMappingMap.put("local-activestandby", ACTIVE_PASSIVE);
+ dependencyMap = Collections.unmodifiableMap(dependencyTypeMappingMap);
+ }
+
+ public VnfcDependencyModel generateDependencyModel(String vnfModel,String vnfType) {
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
+ boolean mandatory;
+ String resilienceType;
+ String prefix = "org.openecomp.resource.vfc."+vnfType+".abstract.nodes.";
+ try {
+ ObjectNode root = (ObjectNode) mapper.readTree(vnfModel);
+ logger.debug("VNF Model after parsing: " + root);
+
+ if(root.get(TOPOLOGY_TEMPLATE) == null || root.get(TOPOLOGY_TEMPLATE).get("node_templates") == null) {
+ throw new InvalidDependencyModel("Dependency model is missing 'topology_template' or 'node_templates' elements");
+ }
+
+ JsonNode topologyTemplateNode = root.get(TOPOLOGY_TEMPLATE);
+ JsonNode nodeTemplateNode = topologyTemplateNode.get("node_templates");
+ Iterator<Map.Entry<String, JsonNode>> itretor = nodeTemplateNode.fields();
+ for (JsonNode yamlNode : nodeTemplateNode) {
+ logger.debug("Processing node: " + yamlNode);
+ String vnfcType = itretor.next().getKey();
+ String type = yamlNode.get("type").textValue();
+ type = type.substring(0,type.lastIndexOf(".")+1);
+ if(type.concat(vnfcType).toLowerCase().startsWith(prefix.concat(vnfcType).toLowerCase())) {
+
+ if(yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY) == null || yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY).asText().isEmpty()) {
+ resilienceType = ACTIVE_ACTIVE;
+ }else {
+ resilienceType = dependencyMap.get(yamlNode.get(PROPERTIES).findValue(HIGH_AVAILABLITY).textValue());
+ }
+
+ if(yamlNode.get(PROPERTIES).findValue(MANDATORY) == null || yamlNode.get(PROPERTIES).findValue(MANDATORY).asText().isEmpty()) {
+ mandatory = false;
+ }else {
+ mandatory = yamlNode.get(PROPERTIES).findValue(MANDATORY).booleanValue();
+ }
+ String[] parentList = getDependencyArray(yamlNode);
+ Node<Vnfc> vnfcNode = getNode(dependencies, vnfcType);
+ if (vnfcNode != null) {
+ logger.debug("Dependency node already exists for vnfc Type: " + vnfcType);
+ if (StringUtils.isEmpty(vnfcNode.getChild().getResilienceType())) {
+ logger.debug("Updating resilience type, dependencies and mandatory attribute for VNFC type: " + vnfcType);
+ vnfcNode.getChild().setResilienceType(resilienceType);
+ if (parentList != null && parentList.length > 0) {
+ addDependencies(dependencies, vnfcNode, parentList);
+ }
+ vnfcNode.getChild().setMandatory(mandatory);
+ }
+
+ } else {
+ logger.debug("Creating dependency node for : " + vnfcType);
+ vnfcNode = new Node<>(new Vnfc(vnfcType, resilienceType, null, mandatory));
+ if (parentList != null && parentList.length > 0)
+ addDependencies(dependencies, vnfcNode, parentList);
+ logger.debug("Adding VNFC to dependency model : " + vnfcNode);
+ dependencies.add(vnfcNode);
+ }
+ }
+ }
+ } catch (IOException e) {
+ logger.error("Error parsing dependency model : " + vnfModel);
+ logger.error("Error message : " + e);
+ throw new InvalidDependencyModel("Error parsing dependency model. " + e.getMessage());
+ }
+ return new VnfcDependencyModel(dependencies);
+ }
+
+ private void addDependencies(Set<Node<Vnfc>> nodes, Node node, String[] parentList) {
+ for (String type : parentList) {
+ String parentType = getVnfcType(type);
+ Node<Vnfc> parentNode = getNode(nodes, parentType);
+ if (parentNode != null) {
+ logger.debug("VNFC already exists for VNFC type: " + parentType + ". Adding it to parent list ");
+ node.addParent(parentNode.getChild());
+ } else {
+ logger.debug("VNFC does not exist for VNFC type: " + parentType + ". Creating new VNFC ");
+ parentNode = new Node<>(new Vnfc(parentType, null));
+ node.addParent(parentNode.getChild());
+ logger.debug("Adding VNFC to dependency model : " + parentNode);
+ nodes.add(parentNode);
+ }
+ }
+ }
+
+ private String[] getDependencyArray(JsonNode node) {
+ JsonNode requirementsNode = node.get("requirements");
+ List<String> dependencyList = new ArrayList();
+ if(requirementsNode!=null) {
+ for (JsonNode internalNode : requirementsNode) {
+ if (nodeNullCheck(internalNode) &&"tosca.capabilities.Node".equalsIgnoreCase(internalNode.get("capability").asText())
+ && "tosca.relationships.DependsOn".equalsIgnoreCase(internalNode.get("relationship").asText())) {
+ if(internalNode.get("node") != null) {
+ dependencyList.add(internalNode.get("node").asText());
+ }else{
+ throw new InvalidDependencyModel("Error parsing dependency model. " + "Dependent Node not found for "+ node.get("type"));
+ }
+ }
+ }
+ return dependencyList.toArray(new String[0]);
+ }else{
+ return new String[0];
+ }
+ }
+
+ private boolean nodeNullCheck(JsonNode internalNode) {
+ return internalNode.get("dependency") != null && internalNode.get("capability") != null && internalNode.get("relationship") != null;
+ }
+
+ private Node<Vnfc> getNode(Set<Node<Vnfc>> nodes, String vnfcType) {
+ Iterator itr = nodes.iterator();
+ Node<Vnfc> node;
+ while (itr.hasNext()) {
+ node = (Node<Vnfc>) itr.next();
+ if (node.getChild().getVnfcType().equalsIgnoreCase(vnfcType)) {
+ return node;
+ }
+ }
+ return null;
+ }
+
+ private String getVnfcType(String type) {
+ return type.substring(type.lastIndexOf('.') + 1, type.length());
+ }
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyManagerImpl.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyManagerImpl.java
new file mode 100644
index 000000000..758d5ee7e
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyManagerImpl.java
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.dependencymanager.impl;
+
+import org.openecomp.appc.dg.dependencymanager.DependencyManager;
+import org.openecomp.appc.dg.dependencymanager.DependencyType;
+import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.objects.DependencyTypes;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+
+import org.openecomp.appc.cache.MetadataCache;
+import org.openecomp.appc.cache.impl.MetadataCacheFactory;
+import org.openecomp.appc.metadata.objects.DependencyModelIdentifier;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class DependencyManagerImpl implements DependencyManager {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(DependencyManagerImpl.class);
+
+ MetadataCache<DependencyModelIdentifier,VnfcDependencyModel> cache;
+
+ DependencyManagerImpl(){
+ cache = MetadataCacheFactory.getInstance().getMetadataCache();
+ }
+
+ public VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier,DependencyTypes dependencyType) throws InvalidDependencyModel, DependencyModelNotFound {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering to getVnfcDependencyModel with DependencyModelIdentifier = "+ modelIdentifier
+ + " , DependencyTypes = " + dependencyType);
+ }
+ VnfcDependencyModel dependencyModel = cache.getObject(modelIdentifier);
+ if(dependencyModel == null){
+ logger.debug("Dependency model not found in cache, creating strategy for reading it");
+ DependencyType strategy = getStrategy(dependencyType);
+ dependencyModel = strategy.getVnfcDependencyModel(modelIdentifier);
+ }
+ if (logger.isTraceEnabled()) {
+ logger.trace("Returning getVnfcDependencyModel with dependency model = "+ dependencyModel);
+ }
+ return dependencyModel;
+ }
+
+ private DependencyType getStrategy(DependencyTypes dependencyType) {
+ switch (dependencyType){
+ case RESOURCE:
+ return new ResourceDependency();
+ }
+ return null;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyModelFactory.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyModelFactory.java
new file mode 100644
index 000000000..87bdd32fa
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/DependencyModelFactory.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.dependencymanager.impl;
+
+import org.openecomp.appc.dg.dependencymanager.DependencyManager;
+
+
+public class DependencyModelFactory {
+
+ private static class ReferenceHolder{
+ private static final DependencyManagerImpl INSTANCE = new DependencyManagerImpl();
+ }
+
+ public static DependencyManager createDependencyManager(){
+ return ReferenceHolder.INSTANCE;
+ }
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/ResourceDependency.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/ResourceDependency.java
new file mode 100644
index 000000000..0cb9eebb4
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/dependencymanager/impl/ResourceDependency.java
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.dependencymanager.impl;
+
+import org.openecomp.appc.metadata.MetadataService;
+import org.openecomp.appc.metadata.objects.DependencyModelIdentifier;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import org.openecomp.appc.dg.dependencymanager.DependencyType;
+import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound;
+import org.openecomp.appc.dg.dependencymanager.helper.DependencyModelParser;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+
+
+public class ResourceDependency implements DependencyType{
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(ResourceDependency.class);
+
+
+ private MetadataService metadataService;
+
+ public ResourceDependency(){
+ getMetadataServiceRef();
+ }
+
+ private void getMetadataServiceRef() {
+ BundleContext bctx = FrameworkUtil.getBundle(MetadataService.class).getBundleContext();
+ // Get MetadataService reference
+ ServiceReference sref = bctx.getServiceReference(MetadataService.class.getName());
+ if (sref != null) {
+ logger.info("MetadataService from bundlecontext");
+ metadataService = (MetadataService) bctx.getService(sref);
+
+ } else {
+ logger.info("MetadataService error from bundlecontext");
+ logger.warn("Cannot find service reference for org.openecomp.appc.metadata.MetadataService");
+ }
+ }
+
+ public void setMetadataService(MetadataService metadataService) {
+ this.metadataService = metadataService;
+ }
+
+ public VnfcDependencyModel getVnfcDependencyModel(DependencyModelIdentifier modelIdentifier) throws InvalidDependencyModel, DependencyModelNotFound {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering to getVnfcDependencyModel with DependencyModelIdentifier = "+ modelIdentifier);
+ }
+ String vnfModel = metadataService.getVnfModel(modelIdentifier);
+ if(vnfModel ==null){
+ logger.debug("Vnf model not found from metadata service");
+ throw new DependencyModelNotFound("Invalid or Empty VNF Model");
+ }
+ if (logger.isTraceEnabled()) {
+ logger.trace("Building dependency model for Vnf Model : " + vnfModel);
+ }
+ DependencyModelParser modelParser = new DependencyModelParser();
+ return modelParser.generateDependencyModel(vnfModel,modelIdentifier.getVnfType());
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowBuilder.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowBuilder.java
new file mode 100644
index 000000000..6b87e6621
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowBuilder.java
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.flowbuilder;
+
+import org.openecomp.appc.dg.objects.InventoryModel;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+import org.openecomp.appc.dg.objects.VnfcFlowModel;
+
+
+public interface FlowBuilder {
+ VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel,InventoryModel inventoryModel);
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowStrategy.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowStrategy.java
new file mode 100644
index 000000000..3c3488f70
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/FlowStrategy.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.flowbuilder;
+
+import org.openecomp.appc.dg.objects.InventoryModel;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+import org.openecomp.appc.dg.objects.VnfcFlowModel;
+
+
+public interface FlowStrategy {
+
+ VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel);
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/exception/InvalidDependencyModel.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/exception/InvalidDependencyModel.java
new file mode 100644
index 000000000..8bec80a47
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/exception/InvalidDependencyModel.java
@@ -0,0 +1,29 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.flowbuilder.exception;
+
+
+public class InvalidDependencyModel extends RuntimeException {
+ public InvalidDependencyModel(String message){
+ super(message);
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/helper/Graph.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/helper/Graph.java
new file mode 100644
index 000000000..b9115187c
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/helper/Graph.java
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.flowbuilder.helper;
+
+import java.util.*;
+
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+
+
+public class Graph<T> {
+ private int size;
+ private List<T> vertexList;
+
+ private int[][] dependencyMatrix;
+
+ public Graph(int size){
+ this.size =size;
+ vertexList = new ArrayList<>();
+ dependencyMatrix = new int[size][size];
+ }
+
+ public void addVertex(T vertex){
+ vertexList.add(vertex);
+ }
+
+ public int getIndex(T vertex){
+ return vertexList.indexOf(vertex);
+ }
+
+ public void addEdge(T vertex1,T vertex2){
+ dependencyMatrix[vertexList.indexOf(vertex1)][vertexList.indexOf(vertex2)] = 1;
+ }
+
+ public int[][] getDependencyMatrix() {
+ return dependencyMatrix;
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public List<T> getVertexList() {
+ return vertexList;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/AbstractFlowStrategy.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/AbstractFlowStrategy.java
new file mode 100644
index 000000000..15ff20083
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/AbstractFlowStrategy.java
@@ -0,0 +1,133 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.flowbuilder.impl;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.openecomp.appc.dg.flowbuilder.FlowStrategy;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.flowbuilder.helper.Graph;
+import org.openecomp.appc.dg.objects.*;
+import org.openecomp.appc.domainmodel.Vnfc;
+
+
+public abstract class AbstractFlowStrategy implements FlowStrategy {
+
+ protected Graph<Vnfc> graph;
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(AbstractFlowStrategy.class);
+
+ public VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) {
+ if(logger.isTraceEnabled()){
+ logger.trace("Entering into buildFlowModel with dependency model = " + dependencyModel
+ + "inventory model = " +inventoryModel);
+ }
+
+ if(dependencyModel == null
+ || dependencyModel.getDependencies() ==null
+ || dependencyModel.getDependencies().size() ==0){
+ logger.debug("Dependency model not available, building flow model with sequence");
+ throw new InvalidDependencyModel("Dependency model either null or does not contain any dependency");
+ }
+
+ VnfcFlowModel flowModel = buildFlowModel(dependencyModel);
+ if(logger.isDebugEnabled()){
+ logger.debug("Flow Model without instance data: \n" + flowModel);
+ }
+
+ logger.info("Populating flow model with A&AI data");
+ populateFlowModel(flowModel,inventoryModel);
+ if(logger.isDebugEnabled()){
+ logger.debug("Flow Model with instance data: \n" + flowModel);
+ }
+
+ return flowModel;
+ }
+
+ private void populateFlowModel(VnfcFlowModel flowModel, InventoryModel inventoryModel) {
+ Iterator<List<Vnfc>> flowIterator = null;
+
+ for(Vnfc vnfcFromInventory:inventoryModel.getVnf().getVnfcs()){
+ flowIterator = flowModel.getModelIterator();
+ String vnfcType = vnfcFromInventory.getVnfcType();
+ while (flowIterator.hasNext()){
+ for(Vnfc vnfcFromFlowModel:flowIterator.next() ){
+ if(vnfcType.equalsIgnoreCase(vnfcFromFlowModel.getVnfcType())){
+ vnfcFromFlowModel.setVnfcName(vnfcFromInventory.getVnfcName());
+ vnfcFromFlowModel.addVms(vnfcFromInventory.getVserverList());
+ }
+ }
+ }
+
+ }
+
+ }
+
+ private VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel) throws InvalidDependencyModel {
+ Set<Node<Vnfc>> dependencies = dependencyModel.getDependencies();
+ graph = new Graph(dependencies.size());
+
+ for(Node<Vnfc> node:dependencies){
+ graph.addVertex(node.getChild());
+ }
+
+ for(Node node:dependencies){
+ Vnfc child = (Vnfc)node.getChild();
+ List<Vnfc> parents = node.getParents();
+ for(Vnfc parent:parents){
+ graph.addEdge(child,parent);
+ }
+ }
+ List<List<Vnfc>> dependencyList = orderDependencies();
+
+ VnfcFlowModel.VnfcFlowModelBuilder builder = new VnfcFlowModel.VnfcFlowModelBuilder();
+ int count=0;
+ int flowModelSize = 0;
+ for(List<Vnfc> vnfcList:dependencyList){
+ builder.addMetadata(count,vnfcList);
+ flowModelSize += vnfcList.size();
+ count++;
+ }
+ if(flowModelSize != dependencies.size()){
+ throw new InvalidDependencyModel("Cycle detected in the VNFC dependencies");
+ }
+
+ return builder.build();
+ }
+
+ protected abstract List<List<Vnfc>> orderDependencies();
+
+ /*private VnfcFlowModel buildFlowModelWithoutSequence(InventoryModel inventoryModel) {
+ VnfcFlowModel.VnfcFlowModelBuilder builder = new VnfcFlowModel.VnfcFlowModelBuilder();
+
+ for(Vnfc vnfc:inventoryModel.getVnf().getVnfcs()){
+ builder = builder.addMetadata(0,vnfc);
+ }
+
+ return builder.build();
+ }*/
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderFactory.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderFactory.java
new file mode 100644
index 000000000..7b9759852
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderFactory.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.flowbuilder.impl;
+
+import org.openecomp.appc.dg.flowbuilder.FlowBuilder;
+import org.openecomp.appc.dg.objects.FlowStrategies;
+
+
+public class FlowBuilderFactory {
+ private static class ReferenceHolder{
+ private static final FlowBuilderFactory FACTORY = new FlowBuilderFactory();
+ }
+
+ public static FlowBuilderFactory getInstance(){
+ return ReferenceHolder.FACTORY;
+ }
+
+ public FlowBuilder getFlowBuilder(FlowStrategies flowStrategy){
+
+ switch (flowStrategy){
+ case FORWARD:
+ return new FlowBuilderImpl(new ForwardFlowStrategy());
+ case REVERSE:
+ return new FlowBuilderImpl(new ReverseFlowStrategy());
+ }
+ return null;
+
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderImpl.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderImpl.java
new file mode 100644
index 000000000..80bd3eec2
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/FlowBuilderImpl.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.flowbuilder.impl;
+
+import org.openecomp.appc.dg.flowbuilder.FlowBuilder;
+import org.openecomp.appc.dg.flowbuilder.FlowStrategy;
+import org.openecomp.appc.dg.objects.InventoryModel;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+import org.openecomp.appc.dg.objects.VnfcFlowModel;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+
+public class FlowBuilderImpl implements FlowBuilder {
+
+
+
+ private FlowStrategy strategy;
+
+ FlowBuilderImpl(FlowStrategy strategy){
+ this.strategy = strategy;
+ }
+
+ public VnfcFlowModel buildFlowModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) {
+ return strategy.buildFlowModel(dependencyModel, inventoryModel);
+ }
+
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ForwardFlowStrategy.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ForwardFlowStrategy.java
new file mode 100644
index 000000000..486e942a7
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ForwardFlowStrategy.java
@@ -0,0 +1,114 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.flowbuilder.impl;
+
+import java.util.*;
+
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.domainmodel.Vnfc;
+
+
+public class ForwardFlowStrategy extends AbstractFlowStrategy {
+ @Override
+ protected List<List<Vnfc>> orderDependencies() {
+ ArrayList<List<Vnfc>> arrayList = new ArrayList<>();
+
+ Queue<Vnfc> queue1 = new LinkedList();
+ Set<Vnfc> queue2 = new LinkedHashSet<>();
+
+ Set<Vnfc> uniqueElementSet = new HashSet<>();
+ Set<Vnfc> duplicateElementSet = new HashSet<>();
+
+ // identifying independent nodes in queue1
+ for(int rowIndex=0;rowIndex<graph.getSize();rowIndex++){
+ Integer sum = 0;
+ for(int colIndex=0;colIndex<graph.getSize();colIndex++){
+ sum+= graph.getDependencyMatrix()[rowIndex][colIndex];
+ }
+ if(sum==0){
+ Vnfc vnfc = graph.getVertexList().get(rowIndex);
+ queue1.add(vnfc);
+ }
+ }
+ if(queue1.isEmpty()){
+ throw new InvalidDependencyModel("There seems to be no Root/Independent node for Vnfc dependencies");
+ }
+ arrayList.add((List<Vnfc>)queue1);
+ queue1 = new LinkedList<>(queue1);
+
+ boolean flag = true;
+
+ while(flag){
+ // iterating over queue1 and for each node in it finding all dependent nodes and putting them on queue2
+ while(!queue1.isEmpty()){
+ Vnfc listItem = queue1.remove();
+ Integer colIndex = graph.getIndex(listItem);
+ for(Integer index =0;index<graph.getSize();index++){
+ Integer value = graph.getDependencyMatrix()[index][colIndex];
+ if(value ==1){
+ Vnfc vnfc = graph.getVertexList().get(index);
+ queue2.add(vnfc);
+ }
+ }
+ }
+ for(Vnfc vnfc:queue2){
+ if(!uniqueElementSet.add(vnfc)){
+ duplicateElementSet.add(vnfc);
+ }
+ }
+ if(queue2.isEmpty()){
+ flag= false; // empty queue2 indicates that all leaf nodes have been identified, i.e. stop the iteration
+ }
+ else{
+ arrayList.add(new ArrayList<Vnfc>(queue2));
+ if(arrayList.size()>graph.getSize()){
+ // dependency list cannot be larger than total number of nodes
+ // if it happens indicates cycle in the dependency
+ throw new InvalidDependencyModel("Cycle detected in the VNFC dependencies");
+ }
+ queue1.addAll(queue2);
+ queue2 = new LinkedHashSet<>();
+ }
+ }
+ // If any node depends on multiple nodes present in different execution sequence,
+ // its execution should happen on the higher order, removing its presence on lower execution sequence
+ if(!duplicateElementSet.isEmpty()){
+ for(Vnfc vnfc:duplicateElementSet){
+ boolean firstOccurrence= true;
+ for(int i=arrayList.size()-1;i>=0;i--){
+ List<Vnfc> list = arrayList.get(i);
+ if(list.contains(vnfc)){
+ if(firstOccurrence){
+ firstOccurrence =false;
+ continue;
+ }
+ else{
+ list.remove(vnfc);
+ }
+ }
+
+ }
+ }
+ }
+ return arrayList;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ReverseFlowStrategy.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ReverseFlowStrategy.java
new file mode 100644
index 000000000..2ef051da1
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/flowbuilder/impl/ReverseFlowStrategy.java
@@ -0,0 +1,115 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.flowbuilder.impl;
+
+import java.util.*;
+
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.domainmodel.Vnfc;
+
+
+public class ReverseFlowStrategy extends AbstractFlowStrategy {
+
+ @Override
+ protected List<List<Vnfc>> orderDependencies() {
+ ArrayList<List<Vnfc>> arrayList = new ArrayList<>();
+
+ Queue<Vnfc> queue1 = new LinkedList();
+ Set<Vnfc> queue2 = new LinkedHashSet<>();
+
+ Set<Vnfc> uniqueElementSet = new HashSet<>();
+ Set<Vnfc> duplicateElementSet = new HashSet<>();
+
+ // identifying independent nodes in queue1
+ for(int colIndex=0;colIndex<graph.getSize();colIndex++){
+ Integer sum = 0;
+ for(int rowIndex=0;rowIndex<graph.getSize();rowIndex++){
+ sum+= graph.getDependencyMatrix()[rowIndex][colIndex];
+ }
+ if(sum==0){
+ Vnfc vnfc = graph.getVertexList().get(colIndex);
+ queue1.add(vnfc);
+ }
+ }
+ if(queue1.isEmpty()){
+ throw new InvalidDependencyModel("There seems to be no leaf node for Vnfc dependencies");
+ }
+ arrayList.add((List<Vnfc>)queue1);
+ queue1 = new LinkedList<>(queue1);
+
+ boolean flag = true;
+
+ while(flag){
+ // iterating over queue1 and for each node in it finding all dependent nodes and putting them on queue2
+ while(!queue1.isEmpty()){
+ Vnfc listItem = queue1.remove();
+ Integer rowIndex = graph.getIndex(listItem);
+ for(Integer index =0;index<graph.getSize();index++){
+ Integer value = graph.getDependencyMatrix()[rowIndex][index];
+ if(value ==1){
+ Vnfc vnfc = graph.getVertexList().get(index);
+ queue2.add(vnfc);
+ }
+ }
+ }
+ for(Vnfc vnfc:queue2){
+ if(!uniqueElementSet.add(vnfc)){
+ duplicateElementSet.add(vnfc);
+ }
+ }
+ if(queue2.isEmpty()){
+ flag= false; // empty queue2 indicates that all leaf nodes have been identified, i.e. stop the iteration
+ }
+ else{
+ arrayList.add(new ArrayList<Vnfc>(queue2));
+ if(arrayList.size()>graph.getSize()){
+ // dependency list cannot be larger than total number of nodes
+ // if it happens indicates cycle in the dependency
+ throw new InvalidDependencyModel("Cycle detected in the VNFC dependencies");
+ }
+ queue1.addAll(queue2);
+ queue2 = new LinkedHashSet<>();
+ }
+ }
+ // If any node depends on multiple nodes present in different execution sequence,
+ // its execution should happen on the higher order, removing its presence on lower execution sequence
+ if(!duplicateElementSet.isEmpty()){
+ for(Vnfc vnfc:duplicateElementSet){
+ boolean firstOccurrence= true;
+ for(int i=0;i<arrayList.size();i++){
+ List<Vnfc> list = arrayList.get(i);
+ if(list.contains(vnfc)){
+ if(firstOccurrence){
+ firstOccurrence =false;
+ list.remove(vnfc);
+ }
+ else{
+ continue;
+ }
+ }
+
+ }
+ }
+ }
+ return arrayList;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/DependencyTypes.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/DependencyTypes.java
new file mode 100644
index 000000000..e8b8c2591
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/DependencyTypes.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.objects;
+
+
+public enum DependencyTypes {
+ RESOURCE;
+
+ public static DependencyTypes findByString(String dependencyTypeStr){
+ for(DependencyTypes dependencyType : DependencyTypes.values()){
+ if(dependencyType.name().equalsIgnoreCase(dependencyTypeStr)){
+ return dependencyType;
+ }
+ }
+ return null;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/FlowStrategies.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/FlowStrategies.java
new file mode 100644
index 000000000..8c3126bb5
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/FlowStrategies.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.objects;
+
+
+public enum FlowStrategies {
+ FORWARD,REVERSE;
+
+ public static FlowStrategies findByString(String flowStrategyStr){
+ for(FlowStrategies flowStrategy:FlowStrategies.values()){
+ if(flowStrategy.name().equalsIgnoreCase(flowStrategyStr)){
+ return flowStrategy;
+ }
+ }
+ return null;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/InventoryModel.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/InventoryModel.java
new file mode 100644
index 000000000..ffd3a35ba
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/InventoryModel.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.objects;
+
+import org.openecomp.appc.domainmodel.Vnf;
+
+
+public class InventoryModel {
+
+ private Vnf vnf;
+
+ public InventoryModel(Vnf vnf){
+ this.vnf= vnf;
+ }
+
+ public Vnf getVnf() {
+ return vnf;
+ }
+
+ @Override
+ public String toString() {
+ return "InventoryModel = " + vnf.toString();
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/Node.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/Node.java
new file mode 100644
index 000000000..a751504b8
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/Node.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.objects;
+
+import java.util.LinkedList;
+import java.util.List;
+
+
+public class Node<T> {
+ T child;
+ List<T> parents;
+
+ @Override
+ public int hashCode(){
+ return child.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object object){
+ if(object == null){
+ return false;
+ }
+ if(!(object instanceof Node)){
+ return false;
+ }
+ Node node = (Node)object;
+ return this.child.equals(node.getChild());
+ }
+
+ public Node(T child){
+ this.child = child;
+ this.parents = new LinkedList<>();
+ }
+
+ public T getChild() {
+ return child;
+ }
+
+ public List<T> getParents() {
+ return parents;
+ }
+
+ public void addParent(T parent){
+ this.parents.add(parent);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder stringBuilder = new StringBuilder("Node : child = " + child + " , parents = ");
+ for(T parent:parents){
+ stringBuilder.append(parent).append(",");
+ }
+ return stringBuilder.toString();
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcDependencyModel.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcDependencyModel.java
new file mode 100644
index 000000000..12b5c15a5
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcDependencyModel.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.objects;
+
+import java.util.Set;
+
+import org.openecomp.appc.domainmodel.Vnfc;
+
+
+public class VnfcDependencyModel {
+ private Set<Node<Vnfc>> dependencies;
+
+ public VnfcDependencyModel(Set<Node<Vnfc>> dependencies){
+ this.dependencies = dependencies;
+ }
+
+ public Set<Node<Vnfc>> getDependencies() {
+ return dependencies;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder stringBuilder = new StringBuilder("dependencies = ");
+ for(Node node:dependencies){
+ stringBuilder.append(node.toString()).append(", ");
+ }
+ return super.toString();
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcFlowModel.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcFlowModel.java
new file mode 100644
index 000000000..ef3934162
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/main/java/org/openecomp/appc/dg/objects/VnfcFlowModel.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.objects;
+
+import java.util.*;
+
+import org.openecomp.appc.domainmodel.Vnfc;
+
+
+public class VnfcFlowModel {
+ private Map<Integer,List<Vnfc>> flowModelMap;
+
+ private VnfcFlowModel(VnfcFlowModelBuilder builder){
+ this.flowModelMap = builder.map;
+
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder stringBuilder = new StringBuilder("Flow Model : ");
+ Iterator<List<Vnfc>> iterator = getModelIterator();
+ while(iterator.hasNext()){
+ for(Vnfc vnfc:iterator.next()){
+ stringBuilder.append(vnfc.toString()).append(", \n");
+ }
+ }
+
+ return stringBuilder.toString();
+ }
+
+ public Iterator<List<Vnfc>> getModelIterator(){
+ return flowModelMap.values().iterator();
+ }
+
+ public static class VnfcFlowModelBuilder{
+
+ Map<Integer,List<Vnfc>> map;
+
+ public VnfcFlowModelBuilder(){
+ map = new HashMap<>();
+ }
+
+ public VnfcFlowModelBuilder addMetadata(Integer index,Vnfc vnfc){
+ List<Vnfc> vnfcList = this.map.get(index);
+ if(vnfcList == null){
+ vnfcList = new LinkedList<>();
+ map.put(index,vnfcList);
+ }
+ vnfcList.add(vnfc);
+ return this;
+ }
+
+ public VnfcFlowModelBuilder addMetadata(Integer index,List<Vnfc> vnfcs){
+ List<Vnfc> vnfcList = this.map.get(index);
+ if(vnfcList == null){
+ vnfcList = new LinkedList<>();
+ map.put(index,vnfcList);
+ }
+ vnfcList.addAll(vnfcs);
+ return this;
+ }
+
+ public VnfcFlowModel build(){
+ return new VnfcFlowModel(this);
+ }
+
+ }
+
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/openecomp/appc/dg/flowbuilder/TestFlowBuilder.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/openecomp/appc/dg/flowbuilder/TestFlowBuilder.java
new file mode 100644
index 000000000..c6b36da86
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/openecomp/appc/dg/flowbuilder/TestFlowBuilder.java
@@ -0,0 +1,329 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.dg.flowbuilder;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.appc.dg.flowbuilder.FlowBuilder;
+import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.openecomp.appc.dg.flowbuilder.impl.FlowBuilderFactory;
+import org.openecomp.appc.dg.objects.*;
+import org.openecomp.appc.domainmodel.Vnf;
+import org.openecomp.appc.domainmodel.Vnfc;
+import org.openecomp.appc.domainmodel.Vserver;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+
+public class TestFlowBuilder {
+
+ @Test
+ public void testForwardFlowBuilder(){
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.FORWARD);
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+ InventoryModel inventoryModel = readInventoryModel();
+ VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel,inventoryModel);
+ Iterator<List<Vnfc>> itr = flowModel.getModelIterator();
+
+ List<Vnfc> list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("SMP","Active-Passive","SMP_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("BE","Active-Active","BE_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("FE","Active-Active","FE_Name")));
+ }
+
+ @Test
+ public void testReverseFlowBuilder(){
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.REVERSE);
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+ InventoryModel inventoryModel = readInventoryModel();
+ VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel,inventoryModel);
+ Iterator<List<Vnfc>> itr = flowModel.getModelIterator();
+
+ List<Vnfc> list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("FE","Active-Active","FE_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("BE","Active-Active","BE_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("SMP","Active-Passive","SMP_Name")));
+ }
+
+ @Test
+ public void testComplexFlowBuilderForward(){
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.FORWARD);
+ VnfcDependencyModel dependencyModel = readComplexDependencyModel();
+ InventoryModel inventoryModel = readComplexInventoryModel();
+ VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel,inventoryModel);
+ Iterator<List<Vnfc>> itr = flowModel.getModelIterator();
+
+ List<Vnfc> list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("A","Active-Active","A_Name")));
+ Assert.assertTrue(list.contains(new Vnfc("E","Active-Active","E_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("B","Active-Active","B_Name")));
+ Assert.assertTrue(list.contains(new Vnfc("C","Active-Active","C_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("D","Active-Active","D_Name")));
+ Assert.assertTrue(list.contains(new Vnfc("F","Active-Active","F_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("G","Active-Active","G_Name")));
+
+ }
+
+ @Test
+ public void testComplexFlowBuilderReverse(){
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.REVERSE);
+ VnfcDependencyModel dependencyModel = readComplexDependencyModel();
+ InventoryModel inventoryModel = readComplexInventoryModel();
+ VnfcFlowModel flowModel = builder.buildFlowModel(dependencyModel,inventoryModel);
+ Iterator<List<Vnfc>> itr = flowModel.getModelIterator();
+
+ List<Vnfc> list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("D","Active-Active","D_Name")));
+
+ Assert.assertTrue(list.contains(new Vnfc("G","Active-Active","G_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("B","Active-Active","B_Name")));
+ Assert.assertTrue(list.contains(new Vnfc("F","Active-Active","F_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("C","Active-Active","C_Name")));
+
+ list = itr.next();
+ Assert.assertTrue(list.contains(new Vnfc("E","Active-Active","E_Name")));
+ Assert.assertTrue(list.contains(new Vnfc("A","Active-Active","A_Name")));
+
+ }
+
+ @Test(expected = InvalidDependencyModel.class)
+ public void testCyclicBuilder(){
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.FORWARD);
+ VnfcDependencyModel dependencyModel = readCyclicDependencyModel();
+ InventoryModel inventoryModel = readInventoryModel();
+ builder.buildFlowModel(dependencyModel,inventoryModel);
+ }
+
+ @Test(expected = InvalidDependencyModel.class)
+ public void testCyclicBuilderWithRootNode(){
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.FORWARD);
+ VnfcDependencyModel dependencyModel = readCyclicDependencyModelWithRootNode();
+ InventoryModel inventoryModel = readInventoryModel();
+ builder.buildFlowModel(dependencyModel,inventoryModel);
+ }
+
+ private VnfcDependencyModel readCyclicDependencyModelWithRootNode() {
+ Vnfc a = new Vnfc("A","Active-Passive",null);
+ Vnfc b = new Vnfc("B","Active-Active",null);
+ Vnfc c = new Vnfc("C","Active-Active",null);
+
+
+ Node aNode = new Node(a);
+ Node bNode = new Node(b);
+ Node cNode = new Node(c);
+
+ bNode.addParent(c);
+ cNode.addParent(b);
+
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(aNode);
+ dependencies.add(bNode);
+ dependencies.add(cNode);
+
+ return new VnfcDependencyModel(dependencies);
+ }
+
+ private InventoryModel readComplexInventoryModel() {
+ Vnf vnf = new Vnf("vnf_1","vABCD","1");
+
+ Vnfc vnfcA = new Vnfc("A","Active-Active","A_Name");
+ Vnfc vnfcB = new Vnfc("B","Active-Active","B_Name");
+ Vnfc vnfcC = new Vnfc("C","Active-Active","C_Name");
+ Vnfc vnfcD = new Vnfc("D","Active-Active","D_Name");
+ Vnfc vnfcE = new Vnfc("E","Active-Active","E_Name");
+ Vnfc vnfcF = new Vnfc("F","Active-Active","F_Name");
+ Vnfc vnfcG = new Vnfc("G","Active-Active","G_Name");
+
+ vnfcA.addVm(new Vserver("VM_URL_A1"));
+ vnfcB.addVm(new Vserver("VM_URL_B1"));
+ vnfcC.addVm(new Vserver("VM_URL_C1"));
+ vnfcD.addVm(new Vserver("VM_URL_D1"));
+ vnfcE.addVm(new Vserver("VM_URL_E1"));
+ vnfcF.addVm(new Vserver("VM_URL_F1"));
+ vnfcG.addVm(new Vserver("VM_URL_G1"));
+
+ vnf.addVnfc(vnfcA);
+ vnf.addVnfc(vnfcB);
+ vnf.addVnfc(vnfcC);
+ vnf.addVnfc(vnfcD);
+ vnf.addVnfc(vnfcE);
+ vnf.addVnfc(vnfcF);
+ vnf.addVnfc(vnfcG);
+
+ return new InventoryModel(vnf);
+ }
+
+ private VnfcDependencyModel readComplexDependencyModel() {
+ Vnfc a = new Vnfc("A","Active-Active",null);
+ Vnfc b = new Vnfc("B","Active-Active",null);
+ Vnfc c = new Vnfc("C","Active-Active",null);
+ Vnfc d = new Vnfc("D","Active-Active",null);
+ Vnfc e = new Vnfc("E","Active-Active",null);
+ Vnfc f = new Vnfc("F","Active-Active",null);
+ Vnfc g = new Vnfc("G","Active-Active",null);
+
+
+ Node aNode = new Node(a);
+ Node bNode = new Node(b);
+ Node cNode = new Node(c);
+ Node dNode = new Node(d);
+ Node eNode = new Node(e);
+ Node fNode = new Node(f);
+ Node gNode = new Node(g);
+
+ bNode.addParent(a);
+ cNode.addParent(a);
+
+ bNode.addParent(e);
+ cNode.addParent(e);
+
+ dNode.addParent(b);
+ gNode.addParent(b);
+
+ fNode.addParent(c);
+
+ gNode.addParent(f);
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(aNode);
+ dependencies.add(bNode);
+ dependencies.add(cNode);
+ dependencies.add(dNode);
+ dependencies.add(eNode);
+ dependencies.add(fNode);
+ dependencies.add(gNode);
+
+ return new VnfcDependencyModel(dependencies);
+ }
+
+ private VnfcDependencyModel readCyclicDependencyModel() {
+
+ Vnfc a = new Vnfc("A","Active-Passive",null);
+ Vnfc b = new Vnfc("B","Active-Active",null);
+ Vnfc c = new Vnfc("C","Active-Active",null);
+ Vnfc d = new Vnfc("D","Active-Active",null);
+
+
+ Node aNode = new Node(a);
+ Node bNode = new Node(b);
+ Node cNode = new Node(c);
+ Node dNode = new Node(d);
+
+ bNode.addParent(a);
+
+ bNode.addParent(d);
+ dNode.addParent(c);
+ cNode.addParent(b);
+
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(aNode);
+ dependencies.add(bNode);
+ dependencies.add(cNode);
+ dependencies.add(dNode);
+
+ return new VnfcDependencyModel(dependencies);
+
+ }
+
+ private InventoryModel readInventoryModel() {
+ Vnf vnf = new Vnf("vnf_1","vSCP","1");
+
+ Vnfc smp = new Vnfc("SMP",null,"SMP_Name");
+ Vserver smpVm1 = new Vserver("SMP_URL1");
+ Vserver smpVm2 = new Vserver("SMP_URL2");
+
+ smp.addVm(smpVm1);
+ smp.addVm(smpVm2);
+
+ Vnfc be = new Vnfc("BE",null,"BE_Name");
+
+ Vserver beVm1 = new Vserver("BE_URL1");
+ Vserver beVm2 = new Vserver("BE_URL2");
+ Vserver beVm3 = new Vserver("BE_URL3");
+ Vserver beVm4 = new Vserver("BE_URL4");
+ Vserver beVm5 = new Vserver("BE_URL5");
+
+ be.addVm(beVm1);
+ be.addVm(beVm2);
+ be.addVm(beVm3);
+ be.addVm(beVm4);
+ be.addVm(beVm5);
+
+ Vnfc fe = new Vnfc("FE",null,"FE_Name");
+
+ Vserver feVm1 = new Vserver("FE_URL1");
+ Vserver feVm2 = new Vserver("FE_URL2");
+
+ fe.addVm(feVm1);
+ fe.addVm(feVm2);
+
+ vnf.addVnfc(smp);
+ vnf.addVnfc(be);
+ vnf.addVnfc(fe);
+
+ return new InventoryModel(vnf);
+ }
+
+ private VnfcDependencyModel readDependencyModel() {
+ Vnfc smp = new Vnfc("SMP","Active-Passive",null);
+ Vnfc be = new Vnfc("BE","Active-Active",null);
+ Vnfc fe = new Vnfc("FE","Active-Active",null);
+
+
+ Node smpNode = new Node(smp);
+ Node beNode = new Node(be);
+ Node feNode = new Node(fe);
+
+ beNode.addParent(smp);
+ feNode.addParent(be);
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(smpNode);
+ dependencies.add(feNode);
+ dependencies.add(beNode);
+
+ return new VnfcDependencyModel(dependencies);
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.gitignore b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.gitignore
new file mode 100644
index 000000000..b83d22266
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.settings/org.eclipse.core.resources.prefs b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 000000000..e9441bb12
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding/<project>=UTF-8
diff --git a/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.settings/org.eclipse.m2e.core.prefs b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 000000000..f897a7f1c
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.settings/org.eclipse.wst.common.project.facet.core.xml b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.settings/org.eclipse.wst.common.project.facet.core.xml
new file mode 100644
index 000000000..f4ef8aa0a
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <installed facet="java" version="1.8"/>
+</faceted-project>
diff --git a/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/pom.xml b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/pom.xml
new file mode 100644
index 000000000..640a4b7e9
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/pom.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-dg-shared</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-dg-domain-model-lib</artifactId>
+
+ <name>appc-dg-domain-model-lib</name>
+ <url>http://maven.apache.org</url>
+
+ <packaging>jar</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/Vnf.java b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/Vnf.java
new file mode 100644
index 000000000..60e9a9fb2
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/Vnf.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.domainmodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class Vnf {
+ private String vnfId;
+ private String vnfType;
+ private String vnfVersion;
+
+ private List<Vnfc> vnfcs;
+
+ public Vnf(String vnfId,String vnfType,String vnfVersion){
+ this.vnfId = vnfId;
+ this.vnfType = vnfType;
+ this.vnfVersion = vnfVersion;
+ this.vnfcs = new LinkedList<>();
+ }
+
+ public String getVnfVersion() {
+ return vnfVersion;
+ }
+
+ public String getVnfId() {
+ return vnfId;
+ }
+
+ public String getVnfType() {
+ return vnfType;
+ }
+
+ public void addVnfc(Vnfc vnfc){
+ this.vnfcs.add(vnfc);
+ }
+
+ public List<Vnfc> getVnfcs() {
+ return vnfcs;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder stringBuilder = new StringBuilder("Vnf : vnfId = " + vnfId +" , vnfType = " + vnfType);
+ for(Vnfc vnfc:vnfcs){
+ stringBuilder.append(vnfc.toString()).append(",");
+ }
+ return stringBuilder.toString();
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/Vnfc.java b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/Vnfc.java
new file mode 100644
index 000000000..0064ed62f
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/Vnfc.java
@@ -0,0 +1,145 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.domainmodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+
+public class Vnfc {
+
+ private String vnfcType;
+
+ public void setResilienceType(String resilienceType) {
+ this.resilienceType = resilienceType;
+ }
+
+ private String resilienceType;
+ private boolean mandatory;
+ private String vnfcName;
+ private List<Vserver> vserverList;
+
+ public Vnfc(String vnfcType,String resilienceType){
+ this(vnfcType,resilienceType,null, false);
+ }
+
+ public Vnfc(String vnfcType,String resilienceType,String vnfcName){
+ this(vnfcType,resilienceType,vnfcName, false);
+ }
+
+ public Vnfc(String vnfcType,String resilienceType,String vnfcName, boolean mandatory){
+ this.vnfcName = vnfcName;
+ this.vnfcType = vnfcType;
+ this.resilienceType = resilienceType;
+ this.mandatory = mandatory;
+ this.vserverList = new LinkedList<>();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder stringBuilder = new StringBuilder("Vnfc : vnfcType = " + vnfcType + ", vnfcName = " +vnfcName + ", resilienceType = " + resilienceType+", mandatory = " + mandatory);
+ for(Vserver vserver:vserverList){
+ stringBuilder.append(vserver.toString()).append(", \n");
+ }
+ return stringBuilder.toString();
+ }
+
+ @Override
+ public int hashCode(){
+ final int prime = 31;
+ int result = 1;
+ result = result * prime + (this.vnfcType == null ? 0 :this.vnfcType.hashCode());
+ result = result * prime + (this.resilienceType == null ? 0 :this.resilienceType.hashCode());
+ result = result * prime + (this.vnfcName == null ? 0 :this.vnfcName.hashCode());
+ result = result * prime + (Boolean.valueOf(this.mandatory).hashCode());
+ return result;
+ }
+ @Override
+ public boolean equals(Object object){
+ if(object == null){
+ return false;
+ }
+ if(!(object instanceof Vnfc)){
+ return false;
+ }
+ Vnfc vnfc = (Vnfc)object;
+
+ if(this.vnfcType == null){
+ if(vnfc.vnfcType !=null)
+ return false;
+ }
+ else if(!this.vnfcType.equals(vnfc.vnfcType))
+ return false;
+
+ if(this.resilienceType == null){
+ if(vnfc.resilienceType !=null)
+ return false;
+ }
+ else if(!this.resilienceType.equals(vnfc.resilienceType))
+ return false;
+
+ if(this.vnfcName == null){
+ if(vnfc.vnfcName !=null)
+ return false;
+ }
+ else if(!this.vnfcName.equals(vnfc.vnfcName))
+ return false;
+ if (this.mandatory != vnfc.mandatory)
+ return false;
+ return true;
+ }
+
+ public void addVm(Vserver vserver){
+ this.vserverList.add(vserver);
+ }
+ public void addVms(List<Vserver> vserverList){
+ this.vserverList.addAll(vserverList);
+ }
+
+ public void setVnfcName(String vnfcName) {
+ this.vnfcName = vnfcName;
+ }
+
+ public String getVnfcType() {
+ return vnfcType;
+ }
+
+ public String getResilienceType() {
+ return resilienceType;
+ }
+
+ public String getVnfcName() {
+ return vnfcName;
+ }
+
+ public List<Vserver> getVserverList() {
+ return vserverList;
+ }
+
+ public boolean isMandatory() {
+ return mandatory;
+ }
+
+ public void setMandatory(boolean mandatory) {
+ this.mandatory = mandatory;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/Vserver.java b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/Vserver.java
new file mode 100644
index 000000000..e536535cb
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/Vserver.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.domainmodel;
+
+
+public class Vserver {
+
+ private String url;
+
+ private String tenantId;
+ private String id;
+ private String relatedLink;
+ private String name;
+
+ public Vserver(String url){
+ this(url,null,null,null,null);
+ }
+
+ public Vserver(String url,
+ String tenantId,
+ String id,
+ String relatedLink,
+ String name){
+ this.url = url;
+ this.tenantId =tenantId;
+ this.id = id;
+ this.relatedLink =relatedLink;
+ this.name = name;
+
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ @Override
+ public String toString() {
+ return "Vserver : url = " +url + ", tenantId = " +tenantId +", id = " +id + " ,relatedLink = " +relatedLink +" , name = "+name;
+ }
+
+ public String getTenantId() {
+ return tenantId;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getRelatedLink() {
+ return relatedLink;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-license-manager/pom.xml b/appc-dg/appc-dg-shared/appc-dg-license-manager/pom.xml
index d6904babc..78882587b 100644
--- a/appc-dg/appc-dg-shared/appc-dg-license-manager/pom.xml
+++ b/appc-dg/appc-dg-shared/appc-dg-license-manager/pom.xml
@@ -46,9 +46,11 @@
<Export-Package>org.openecomp.appc.dg.licmgr</Export-Package>
<Export-Service>org.openecomp.appc.dg.licmgr.LicenseManagerPlugin</Export-Service>
<Private-Package>org.openecomp.appc.dg.licmgr.impl</Private-Package>
- <Import-Package>org.openecomp.appc.licmgr,org.openecomp.appc.licmgr.exception,org.openecomp.appc.licmgr.objects,!org.apache.log,!org.apache.commons.logging,!groovy.lang,!javax.jms,!org.codehaus.commons.compiler,!org.codehaus.groovy.*,!org.codehaus.janino,!com.ibm.icu.*,!com.sun.faces.*,!org.jasypt.*,*;resolution:=optional</Import-Package>
- <Embed-Dependency>appc-license-manager-api,appc-common,eelf-core,logback-core,logback-classic;scope=compile|runtime;inline=false</Embed-Dependency>
- <Embed-Transitive>true</Embed-Transitive>
+ <Import-Package>
+ org.openecomp.appc.licmgr,org.openecomp.appc.licmgr.exception,org.openecomp.appc.licmgr.objects,
+ org.openecomp.appc.exceptions, com.att.eelf.configuration,
+ *;resolution:=optional
+ </Import-Package>
</instructions>
</configuration>
</plugin>
diff --git a/appc-dg/appc-dg-shared/appc-dg-license-manager/src/main/java/org/openecomp/appc/dg/licmgr/LicenseManagerPlugin.java b/appc-dg/appc-dg-shared/appc-dg-license-manager/src/main/java/org/openecomp/appc/dg/licmgr/LicenseManagerPlugin.java
index 6ca6b6ab5..1624f448c 100644
--- a/appc-dg/appc-dg-shared/appc-dg-license-manager/src/main/java/org/openecomp/appc/dg/licmgr/LicenseManagerPlugin.java
+++ b/appc-dg/appc-dg-shared/appc-dg-license-manager/src/main/java/org/openecomp/appc/dg/licmgr/LicenseManagerPlugin.java
@@ -28,7 +28,6 @@ import org.openecomp.sdnc.sli.SvcLogicContext;
import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
-
public interface LicenseManagerPlugin extends SvcLogicJavaPlugin {
/**
* Retrieves license model from APPC database and populate flags into svc context
diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/pom.xml b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/pom.xml
new file mode 100644
index 000000000..8123d17bb
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/pom.xml
@@ -0,0 +1,45 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-dg-shared</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>appc-dg-mdsal-store</artifactId>
+ <packaging>jar</packaging>
+
+ <name>appc-dg-mdsal-store</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-model-api</artifactId>
+ <version>${odl.yangtools.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/MDSALStore.java b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/MDSALStore.java
new file mode 100644
index 000000000..cb6e2fd11
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/MDSALStore.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.mdsal;
+
+import org.openecomp.appc.mdsal.exception.MDSALStoreException;
+import org.openecomp.appc.mdsal.objects.BundleInfo;
+
+import java.util.Date;
+
+/**
+ * Provides APIs for interacting with MD-SAL store
+ */
+public interface MDSALStore {
+
+ /**
+ * Checks the presence of any yang module in the MD-SAL store,
+ * <i>Due to limitation of SchemaContext interface of ODL that it does not
+ * contain the information about dynamically loaded yang modules, it
+ * checks the presence of OSGI bundle</i>
+ * @param moduleName Name of the Module
+ * @param revision revision of the Module
+ * @return returns true- module is present, false - module is absent
+ */
+ boolean isModulePresent(String moduleName, Date revision);
+
+ /**
+ * This method will be used to store yang module to MD-SAL store
+ * @param yang - yang module that need to be stored. In String format
+ * @param bundleInfo - Bundle Information that contains name , description, version , location. These parameters used to create bundle which will push yang to MD-SAL store.
+ * @throws MDSALStoreException
+ */
+ void storeYangModule(String yang, BundleInfo bundleInfo) throws MDSALStoreException;
+
+ /**
+ * This method is used to store configuration JSON to MD-SAL store. It invokes store configuration Operation with required parameters
+ * @param moduleName - Yang module name where JSON need to be posted
+ * @param requestId - Request ID which is used as unique key for configuration JSON
+ * @param configJSON - String value of configuration JSON that needs to be stored in MD-SAl store
+ * @throws MDSALStoreException
+ */
+ void storeJson(String moduleName , String requestId , String configJSON ) throws MDSALStoreException;
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/exception/MDSALStoreException.java b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/exception/MDSALStoreException.java
new file mode 100644
index 000000000..0628ef78d
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/exception/MDSALStoreException.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.mdsal.exception;
+
+/**
+ * This is custom exception type defined for MD-SAL store. All exceptions thrown by mdsal store module need to be wrapped in this class.
+*/
+ public class MDSALStoreException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public MDSALStoreException(){
+ }
+
+ /**
+ * Create MDSALStoreException using only message.
+ * @param message -- message to the caller.
+ */
+ public MDSALStoreException (String message){
+ super(message);
+ }
+
+ /**
+ * Create MDSALStoreException using orignal cause
+ * @param cause - cause that is being wrapped / suppressed.
+ */
+ public MDSALStoreException (Throwable cause){
+ super(cause);
+ }
+
+ /**
+ *
+ * @param message - message to the caller.
+ * @param cause - cause that is being wrapped / suppressed .
+ */
+ public MDSALStoreException(String message , Throwable cause){
+ super(message , cause);
+ }
+
+ /**
+ *
+ * @param message - message to the caller.
+ * @param cause - cause that is being wrapped / suppressed .
+ * @param enableSuppression - Indicates if suppression is enabled.
+ * @param writableStackTrace - Indicates if writable stacktrace is supported
+ */
+ public MDSALStoreException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/Constants.java b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/Constants.java
new file mode 100644
index 000000000..a41c49de7
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/Constants.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.mdsal.impl;
+/**
+ * This class contains the definitions of all constant values used in the appc-dg-mdsal-store
+ * These properties are used for creating osgi bundle zip file. It also defines contents for Blueprint.xml file of bundle
+*/
+public class Constants {
+
+ private Constants(){}
+ /**
+ * Manifest attribute for OSGI Bundle Name
+ */
+ public static final String MANIFEST_ATTR_BUNDLE_NAME= "Bundle-Name";
+
+ /**
+ * Manifest attribute for OSGI Bundle Symbolic Name
+ */
+ public static final String MANIFEST_ATTR_BUNDLE_SYMBOLIC_NAME= "Bundle-SymbolicName";
+
+ /**
+ * Manifest attribute for OSGI Bundle Description
+ */
+ public static final String MANIFEST_ATTR_BUNDLE_DESCRIPTION= "Bundle-Description";
+
+ /**
+ * Manifest attribute for OSGI Bundle Manifest version
+ */
+ public static final String MANIFEST_ATTR_BUNDLE_MANIFEST_VERSION= "Bundle-ManifestVersion";
+
+ /**
+ * Manifest attribute for OSGI Bundle Version
+ */
+ public static final String MANIFEST_ATTR_BUNDLE_VERSION= "Bundle-Version";
+
+ /**
+ * Manifest attribute for OSGI Bundle Blueprint
+ */
+ public static final String MANIFEST_ATTR_BUNDLE_BLUEPRINT= "Bundle-Blueprint";
+
+ /**
+ * Manifest value for Mainfest Version
+ */
+ public static final String MANIFEST_VALUE_VERSION= "1.0";
+
+ /**
+ * Manifest value for OSGI Bundle Vesion
+ */
+ public static final String MANIFEST_VALUE_BUNDLE_MAN_VERSION= "2";
+
+ /**
+ * Manifest value for OSGI Bundle Blueprint location
+ */
+ public static final String MANIFEST_VALUE_BUNDLE_BLUEPRINT= "OSGI-INF/blueprint/blueprint.xml";
+
+ /**
+ * Base URL for config actions exposed by RESTCONF API
+ */
+
+ public static final String CONFIG_URL = "https://localhost:8443/restconf/config";
+
+ /**
+ * Content for blueprint.xml used while creation of OSGI bundle.
+ */
+ public static final String BLUEPRINT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<!--\n" +
+ " Starter Blueprint Camel Definition appc-aai-adapter-blueprint\n" +
+ "-->\n" +
+ "<blueprint xmlns=\"http://www.osgi.org/xmlns/blueprint/v1.0.0\"\n" +
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
+ " xsi:schemaLocation=\"http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd\">\n" +
+ "\n" +
+ "</blueprint>";
+
+ /**
+ * HTTP Header attribute for Content type - JSON
+ */
+ public static final String OPERATION_APPLICATION_JSON= " application/json";
+
+ /**
+ * HTTP protocol used for config operations
+ */
+ public static final String OPERATION_HTTPS= "https";
+
+ /**
+ * Constant for backslash to be used while formatting URL
+ */
+ public static final String URL_BACKSLASH ="/";
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/MDSALStoreFactory.java b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/MDSALStoreFactory.java
new file mode 100644
index 000000000..7550ad9e2
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/MDSALStoreFactory.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.mdsal.impl;
+
+import org.openecomp.appc.mdsal.MDSALStore;
+
+/*
+ * Factory class to create/get instance of MDSALStore
+ */
+public class MDSALStoreFactory {
+ private static class ReferenceHolder{
+ private static MDSALStore store = new MDSALStoreImpl();
+ private ReferenceHolder(){}
+ }
+ private MDSALStoreFactory(){
+
+ }
+
+ /**
+ * Method for creating MDSALStore instance, It creates an instance of
+ * MDSALStoreImpl once and returns the same instance everytime it is invoked.
+ * @return
+ */
+ public static MDSALStore createMDSALStore (){
+ return ReferenceHolder.store;
+ }
+}
+
diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/MDSALStoreImpl.java b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/MDSALStoreImpl.java
new file mode 100644
index 000000000..6f43bfc65
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/impl/MDSALStoreImpl.java
@@ -0,0 +1,137 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.mdsal.impl;
+
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.mdsal.MDSALStore;
+import org.openecomp.appc.mdsal.exception.MDSALStoreException;
+import org.openecomp.appc.mdsal.objects.BundleInfo;
+import org.openecomp.appc.mdsal.operation.ConfigOperation;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Date;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+/**
+ * Implementation of MDSALStore
+ */
+public class MDSALStoreImpl implements MDSALStore{
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(MDSALStoreImpl.class);
+
+ MDSALStoreImpl(){
+ ConfigOperation.setUrl(Constants.CONFIG_URL);
+ ConfigOperation.setAuthentication(null,null);
+ }
+
+
+ @Override
+ public boolean isModulePresent(String moduleName, Date revision) {
+
+ if(logger.isDebugEnabled()){
+ logger.debug("isModulePresent invoked with moduleName = " +moduleName + " , revision = " +revision);
+ }
+
+ BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
+ /**
+ * SchemaContext interface of ODL provides APIs for querying details of yang modules
+ * loaded into MD-SAL store, but its limitation is, it only returns information about
+ * static yang modules loaded on server start up, it does not return information about
+ * the yang modules loaded dynamically. Due to this limitation, we are checking the
+ * presence of OSGI bundle instead of yang module. (Note: Assuming OSGI bundle is named
+ * with the yang module name).
+ */
+
+ Bundle bundle = bundleContext.getBundle(moduleName);
+ if(logger.isDebugEnabled()){
+ logger.debug("isModulePresent returned = " + (bundle != null));
+ }
+ return bundle != null;
+ }
+
+ @Override
+ public void storeYangModule(String yang, BundleInfo bundleInfo) throws MDSALStoreException {
+
+ BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
+ byte[] byteArray = createBundleJar(yang, Constants.BLUEPRINT, bundleInfo);
+
+ try (ByteArrayInputStream inputStream = new ByteArrayInputStream(byteArray)){
+ Bundle bundle = bundleContext.installBundle(bundleInfo.getLocation(), inputStream);
+ bundle.start();
+ } catch (Exception e) {
+ logger.error("Error storing yang module: " + yang + ". Error message: " + e.getMessage());
+ throw new MDSALStoreException("Error storing yang module: " + yang + " " + e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public void storeJson( String module , String requestId ,String configJSON) throws MDSALStoreException {
+
+ try {
+ ConfigOperation.storeConfig(configJSON , module , org.openecomp.appc.Constants.YANG_BASE_CONTAINER, org.openecomp.appc.Constants.YANG_VNF_CONFIG_LIST,requestId,org.openecomp.appc.Constants.YANG_VNF_CONFIG);
+ } catch (APPCException e) {
+ throw new MDSALStoreException("Exception while storing config json to MDSAL store." +e.getMessage(), e);
+ }
+ }
+
+ private byte[] createBundleJar(String yang, String blueprint, BundleInfo bundleInfo) throws MDSALStoreException {
+
+ Manifest manifest = new Manifest();
+ manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, Constants.MANIFEST_VALUE_VERSION);
+ manifest.getMainAttributes().put(new Attributes.Name(Constants.MANIFEST_ATTR_BUNDLE_NAME), bundleInfo.getName());
+ manifest.getMainAttributes().put(new Attributes.Name(Constants.MANIFEST_ATTR_BUNDLE_SYMBOLIC_NAME), bundleInfo.getName());
+ manifest.getMainAttributes().put(new Attributes.Name(Constants.MANIFEST_ATTR_BUNDLE_DESCRIPTION), bundleInfo.getDescription());
+ manifest.getMainAttributes().put(new Attributes.Name(Constants.MANIFEST_ATTR_BUNDLE_MANIFEST_VERSION), Constants.MANIFEST_VALUE_BUNDLE_MAN_VERSION);
+ manifest.getMainAttributes().put(new Attributes.Name(Constants.MANIFEST_ATTR_BUNDLE_VERSION), String.valueOf(bundleInfo.getVersion()));
+ manifest.getMainAttributes().put(new Attributes.Name(Constants.MANIFEST_ATTR_BUNDLE_BLUEPRINT), Constants.MANIFEST_VALUE_BUNDLE_BLUEPRINT);
+
+ byte[] retunValue;
+
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ JarOutputStream jarOutputStream = new JarOutputStream(outputStream, manifest)) {
+ jarOutputStream.putNextEntry(new JarEntry("META-INF/yang/"));
+ jarOutputStream.putNextEntry(new JarEntry("META-INF/yang/"+bundleInfo.getName()+".yang"));
+ jarOutputStream.write(yang.getBytes());
+ jarOutputStream.closeEntry();
+
+ jarOutputStream.putNextEntry(new JarEntry("OSGI-INF/blueprint/"));
+ jarOutputStream.putNextEntry(new JarEntry(Constants.MANIFEST_VALUE_BUNDLE_BLUEPRINT));
+ jarOutputStream.write(blueprint.getBytes());
+ jarOutputStream.closeEntry();
+ jarOutputStream.close();
+ retunValue = outputStream.toByteArray();
+ } catch (Exception e) {
+ logger.error("Error creating bundle jar: " + bundleInfo.getName() + ". Error message: " + e.getMessage());
+ throw new MDSALStoreException("Error creating bundle jar: " + bundleInfo.getName() + " " + e.getMessage(), e);
+ }
+ return retunValue;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/objects/BundleInfo.java b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/objects/BundleInfo.java
new file mode 100644
index 000000000..f4bd1feba
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/objects/BundleInfo.java
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.mdsal.objects;
+/**
+ * Holds bundle information which includes name , description , version and location. This information will be used to create osgi bundle.
+ */
+ public class BundleInfo {
+
+ private String name;
+ private String description;
+ private Integer version;
+ private String location;
+
+ /**
+ * Creates an object of BundleInfo with version initialized to 1
+ */
+ public BundleInfo(){
+ version =1;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Integer getVersion() {
+ return version;
+ }
+
+ public void setVersion(Integer version) {
+ this.version = version;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperation.java b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperation.java
new file mode 100644
index 000000000..15b632731
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperation.java
@@ -0,0 +1,289 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.mdsal.operation;
+
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.mdsal.impl.Constants;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.http.HttpHeaders;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.protocol.HTTP;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.Socket;
+import java.net.URL;
+import java.security.*;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.commons.io.IOUtils;
+
+/**
+ * Provides method to store configuration to MD-SAL store. It also exposes doPut operation which can be used to invoke REST Put operation.
+*/
+public class ConfigOperation {
+ private static final EELFLogger LOG = EELFManager.getInstance().getLogger(ConfigOperation.class);
+
+ private static URL url;
+ private static String basicAuth;
+
+ ConfigOperation(){}
+
+ private static ConfigOperationRequestFormatter requestFormatter = new ConfigOperationRequestFormatter();
+
+ private static ObjectMapper mapper = new ObjectMapper();
+
+ /**
+ * This method stores configuration JSON to MD-SAL store. Following input parameters are expected as input
+ * @param configJson - configuration JSON as String. This value will be stored in MD-SAL store
+ * @param module - Module name that contains yang Schema
+ * @param containerName - yang container name which will be used as base container.
+ * @param subModules - Sub modules list if any. Order of sub module is top to bottom.
+ * @throws APPCException
+ */
+ public static void storeConfig(String configJson , String module, String containerName, String... subModules ) throws APPCException {
+ if (configJson == null) {
+ throw new APPCException("Provided message was null");
+ }
+ LOG.debug("Config JSON: " + configJson +"\n"
+ +"module" + module +"\n"
+ +"containerName" + containerName +"\n"
+ +"subModules length : " + subModules.length );
+
+ int httpCode;
+ String respBody ;
+ try {
+ String path = requestFormatter.buildPath(url, module, containerName, subModules);
+ LOG.debug("Configuration Path : " + path);
+ URL serviceUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
+ HttpResponse response = doPut(serviceUrl , configJson);
+ httpCode = response.getStatusLine().getStatusCode();
+ respBody = IOUtils.toString(response.getEntity().getContent());
+ } catch (IOException e) {
+ LOG.error("Error while storing configuration json "+e.getMessage(), e);
+ throw new APPCException(e);
+ }
+
+ if (httpCode != 200 ) {
+ try {
+ ArrayList<String> errorMessage = new ArrayList<>();
+ JsonNode responseJson = toJsonNodeFromJsonString(respBody);
+ if(responseJson!=null && responseJson.get("errors")!=null) {
+ JsonNode errors = responseJson.get("errors").get("error");
+ for (Iterator<JsonNode> i = errors.elements();i.hasNext();){
+ JsonNode error = i.next();
+ errorMessage.add(error.get("error-message").textValue());
+ }
+ }
+ throw new APPCException("Failed to load config JSON to MD SAL store. Error Message:" + errorMessage.toString());
+ } catch (Exception e) {
+ LOG.error("Error while loading config JSON to MD SAL store. "+e.getMessage(), e);
+ throw new APPCException("Error while loading config JSON to MD SAL store. "+ e.getMessage(),e);
+ }
+ }
+ }
+
+ /**
+ * This is Generic method that can be used to perform REST Put operation
+ * @param url - Destination URL for put
+ * @param body - payload for put action which will be sent as request body.
+ * @return - HttpResponse object which is returned from put REST call.
+ * @throws APPCException
+ */
+ public static HttpResponse doPut (URL url, String body) throws APPCException {
+ HttpPut put;
+ try {
+ put = new HttpPut(url.toExternalForm());
+ put.setHeader(HttpHeaders.CONTENT_TYPE, Constants.OPERATION_APPLICATION_JSON);
+ put.setHeader(HttpHeaders.ACCEPT, Constants.OPERATION_APPLICATION_JSON);
+
+ if (basicAuth != null) {
+ put.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + basicAuth);
+ }
+
+ StringEntity entity = new StringEntity(body);
+ entity.setContentType(Constants.OPERATION_APPLICATION_JSON);
+ put.setEntity(new StringEntity(body));
+ } catch (UnsupportedEncodingException e) {
+ throw new APPCException(e);
+ }
+
+ HttpClient client = getHttpClient();
+
+ try {
+ return client.execute(put);
+ } catch (IOException e) {
+ throw new APPCException(e);
+ }
+
+ }
+
+ /**
+ * Updates the static var URL and returns the value;
+ *
+ * @return The new value of URL
+ */
+ public static String getUrl() {
+ return url.toExternalForm();
+ }
+
+ public static void setUrl(String newUrl) {
+ try {
+ url = new URL(newUrl);
+ } catch (MalformedURLException e) {
+ LOG.error("Malformed URL " +newUrl + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Sets the basic authentication header for the given user and password. If either entry is null then set basic auth
+ * to null
+ *
+ * @param user The user with optional domain name (for AAF)
+ * @param password The password for the user
+ * @return The new value of the basic auth string that will be used in the request headers
+ */
+ public static String setAuthentication(String user, String password) {
+ if (user != null && password != null) {
+ String authStr = user + ":" + password;
+ basicAuth = new String(Base64.encodeBase64(authStr.getBytes()));
+ } else {
+ basicAuth = null;
+ }
+ return basicAuth;
+ }
+
+ @SuppressWarnings("deprecation")
+ private static HttpClient getHttpClient() throws APPCException {
+ HttpClient client;
+ if (url.getProtocol().equals(Constants.OPERATION_HTTPS)) {
+ try {
+ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ trustStore.load(null, null);
+ MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
+ sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+
+ HttpParams params = new BasicHttpParams();
+ HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
+ HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
+
+ SchemeRegistry registry = new SchemeRegistry();
+ registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ registry.register(new Scheme(Constants.OPERATION_HTTPS, sf, 443));
+ registry.register(new Scheme(Constants.OPERATION_HTTPS, sf, 8443));
+ registry.register(new Scheme("http", sf, 8181));
+
+ ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
+ client = new DefaultHttpClient(ccm, params);
+ } catch (Exception e) {
+ LOG.error("Error creating HTTP Client. Creating default client." , e);
+ client = new DefaultHttpClient();
+ }
+ } else if ("http".equals(url.getProtocol())) {
+ client = new DefaultHttpClient();
+ } else {
+ throw new APPCException(
+ "The provider.topology.url property is invalid. The url did not start with http[s]");
+ }
+ return client;
+ }
+
+ @SuppressWarnings("deprecation")
+ private static class MySSLSocketFactory extends SSLSocketFactory {
+ private SSLContext sslContext = SSLContext.getInstance("TLS");
+
+ private MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException,
+ KeyStoreException, UnrecoverableKeyException {
+ super(truststore);
+
+ TrustManager tm = new X509TrustManager() {
+ @Override
+ public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ LOG.debug("Inside checkClientTrusted");
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ LOG.debug("Inside checkServerTrusted");
+ }
+
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return new X509Certificate[1];
+ }
+ };
+
+ sslContext.init(null, new TrustManager[]{
+ tm
+ }, null);
+ }
+
+ @Override
+ public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
+ throws IOException {
+ return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
+ }
+
+ @Override
+ public Socket createSocket() throws IOException {
+ return sslContext.getSocketFactory().createSocket();
+ }
+ }
+
+ private static JsonNode toJsonNodeFromJsonString(String jsonStr) {
+ JsonNode jsonNode = null;
+ if(jsonStr != null) {
+ try {
+ jsonNode = mapper.readTree(jsonStr);
+ } catch (IOException e) {
+ LOG.warn(String.format("Could not map %s to jsonNode.", jsonStr), e);
+ }
+ }
+ return jsonNode;
+ }
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperationRequestFormatter.java b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperationRequestFormatter.java
new file mode 100644
index 000000000..13a587477
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-mdsal-store/src/main/java/org/openecomp/appc/mdsal/operation/ConfigOperationRequestFormatter.java
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.mdsal.operation;
+
+import org.openecomp.appc.mdsal.impl.Constants;
+
+import java.net.URL;
+/**
+ * Creates request url path for config actions based on parameter like module name , container-name and sub modules if any.
+ */
+
+public class ConfigOperationRequestFormatter {
+ /**
+ * Build a request url path for config actions
+ * @param url - base url
+ * @param module - yang module name
+ * @param containerName - yang container name
+ * @param subModules - sub module /container names as string in varargs ( String ) format
+ * @return - resultant path in String format
+ */
+ public String buildPath(URL url,String module, String containerName , String... subModules ) {
+
+ StringBuilder path = new StringBuilder( url.getPath()+ Constants.URL_BACKSLASH + module + ":"+containerName + Constants.URL_BACKSLASH);
+ if(subModules.length >0){
+ for(String subModule : subModules){
+ path.append(subModule);
+ path.append("/");
+ }
+ }
+ return path.toString();
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-netconf/pom.xml b/appc-dg/appc-dg-shared/appc-dg-netconf/pom.xml
index 705f425ca..8ccb980e8 100644
--- a/appc-dg/appc-dg-shared/appc-dg-netconf/pom.xml
+++ b/appc-dg/appc-dg-shared/appc-dg-netconf/pom.xml
@@ -78,8 +78,10 @@
<Bundle-SymbolicName>appc-dg-netconf</Bundle-SymbolicName>
<Export-Package>org.openecomp.appc.dg.netconf</Export-Package>
<Private-Package>org.openecomp.appc.dg.netconf.impl.*</Private-Package>
- <Import-Package>!org.apache.log,!org.apache.commons.logging,!groovy.lang,!javax.jms,!org.codehaus.commons.compiler,!org.codehaus.groovy.*,!org.codehaus.janino,!com.ibm.icu.*,!com.sun.faces.*,!org.jasypt.*,*;resolution:=optional</Import-Package>
- <Embed-Dependency>appc-common,eelf-core,logback-core,logback-classic;scope=compile|runtime;inline=false</Embed-Dependency>
+ <Import-Package>
+ *;resolution:=optional
+ </Import-Package>
+ <!--Embed-Dependency>eelf-core,logback-core,logback-classic;scope=compile|runtime;inline=false</Embed-Dependency-->
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
diff --git a/appc-dg/appc-dg-shared/appc-dg-netconf/src/main/java/org/openecomp/appc/dg/netconf/NetconfClientPlugin.java b/appc-dg/appc-dg-shared/appc-dg-netconf/src/main/java/org/openecomp/appc/dg/netconf/NetconfClientPlugin.java
index 3b75f4070..29334e2f6 100644
--- a/appc-dg/appc-dg-shared/appc-dg-netconf/src/main/java/org/openecomp/appc/dg/netconf/NetconfClientPlugin.java
+++ b/appc-dg/appc-dg-shared/appc-dg-netconf/src/main/java/org/openecomp/appc/dg/netconf/NetconfClientPlugin.java
@@ -28,7 +28,6 @@ import org.openecomp.sdnc.sli.SvcLogicContext;
import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
-
public interface NetconfClientPlugin extends SvcLogicJavaPlugin {
void configure(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
void operationStateValidation(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
diff --git a/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/openecomp/appc/dg/netconf/impl/NetconfClientPluginImplTest.java b/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/openecomp/appc/dg/netconf/impl/NetconfClientPluginImplTest.java
deleted file mode 100644
index 3b4a32385..000000000
--- a/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/openecomp/appc/dg/netconf/impl/NetconfClientPluginImplTest.java
+++ /dev/null
@@ -1,679 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * openECOMP : APP-C
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.appc.dg.netconf.impl;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.Ignore;
-import org.junit.runner.RunWith;
-import org.mockito.Matchers;
-import org.mockito.Mockito;
-import org.openecomp.appc.adapter.netconf.*;
-import org.openecomp.appc.adapter.netconf.util.Constants;
-import org.openecomp.appc.dg.netconf.impl.NetconfClientPluginImpl;
-import org.openecomp.appc.exceptions.APPCException;
-import org.openecomp.sdnc.sli.SvcLogicContext;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import java.lang.reflect.Field;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.powermock.api.mockito.PowerMockito.when;
-
-
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({OperationalStateValidatorFactory.class, NetconfClientPluginImpl.class, FrameworkUtil.class, ObjectMapper.class})
-@Ignore
-public class NetconfClientPluginImplTest {
- private NetconfClientPluginImpl netconfClientPlugin;
- private NetconfDataAccessService dao;
- private NetconfClientFactory clientFactory;
- private Map<String, String> params;
-
- private final BundleContext bundleContext = Mockito.mock(BundleContext.class);
- private final Bundle bundleService = Mockito.mock(Bundle.class);
- private final ServiceReference sref1 = Mockito.mock(ServiceReference.class);
- private final ServiceReference sref2 = Mockito.mock(ServiceReference.class);
- private final ServiceReference sref3 = Mockito.mock(ServiceReference.class);
- private static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message";
-
-
- String host = "http://www.test.com";
- String host1 = "http://www.test1.com";
- String vnfType = "VNF";
- int port = 8080;
- String username = "test";
- String password = "test";
- String connectionDetails = "{\"host\":\"" + host + "\",\"port\":" + port + ",\"username\":\"" + username + "\",\"password\":\"" + password + "\",\"capabilities\":null,\"additionalProperties\":null}";
- String fileContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
- "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
- "\t<get-config>\n" +
- "\t\t<source>\n" +
- "\t\t\t<running/>\n" +
- "\t\t </source>\n" +
- "\t</get-config>\n" +
- "</rpc>'";
- String operationalState = "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
- " <get>\n" +
- " <filter>\n" +
- " <ManagedElement xmlns=\"urn:org:openecomp:appc:Test\">\n" +
- " <VnfFunction xmlns=\"urn:org:openecomop:appc:Test\">\n" +
- " <ProcessorManagement>\n" +
- " <MatedPair>\n" +
- " <operationalState/>\n" +
- " <PayloadProcessor>\n" +
- " <operationalState/>\n" +
- " </PayloadProcessor>\n" +
- " </MatedPair>\n" +
- " <SystemController>\n" +
- " <operationalState/>\n" +
- " </SystemController>\n" +
- " </ProcessorManagement>\n" +
- " </VnfFunction>\n" +
- " </ManagedElement>\n" +
- " </filter>\n" +
- " </get>\n" +
- "</rpc>\n";
-
-
- @Before
- public void setUp() throws NoSuchFieldException, IllegalAccessException {
- clientFactory = new NetconfClientFactoryMock();
-
- }
-
-
- @Test
- public void testConfigure() throws Exception {
-
- shortInit();
- SvcLogicContext ctx = new SvcLogicContext();
-
- params = new HashMap<>();
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
- params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
-
- netconfClientPlugin.configure(params, ctx);
-
- NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
-
- try {
- Assert.assertEquals("wrong configuration", fileContent, client.getConf());
- Assert.assertEquals("wrong host", host, client.getLastConnectionDetails().getHost());
- Assert.assertEquals("wrong port", port, client.getLastConnectionDetails().getPort());
- Assert.assertEquals("wrong username", username, client.getLastConnectionDetails().getUsername());
- Assert.assertEquals("wrong password", password, client.getLastConnectionDetails().getPassword());
- Assert.assertFalse(client.isConnection());
- } catch (Exception e) {
- Assert.fail("failed with because of " + e.getCause());
- }
-
-
- }
-
-
- @Test
- public void testConfigureNegativeIOException() throws Exception {
- shortInit();
- SvcLogicContext ctx = new SvcLogicContext();
-
- params = new HashMap<>();
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
- params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
- NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
-
-
- try {
- netconfClientPlugin.configure(params, ctx);
- Assert.assertTrue(false);
- } catch (APPCException e) {
- Assert.assertNull(client.getLastConnectionDetails());
- Assert.assertNull(client.getConf());
- }
-
- }
-
- @Test
- public void testOperationStateValidation() throws Exception {
- shortInit();
- SvcLogicContext ctx = new SvcLogicContext();
- DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
- daoServiceMock.setConfigFile(fileContent);
-
- NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
- client.setAnswer(operationalState);
-
-
- params = new HashMap<>();
- params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
- params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
- MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
- validatorMock.setConfigurationFileName("VnfGetRunningConfig");
-
- PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
- when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
-
- netconfClientPlugin.operationStateValidation(params, ctx);
-
- Assert.assertTrue("validation process failed", validatorMock.isValidated());
- Assert.assertEquals(fileContent, client.getLastMessage());
- }
-
-
- @Test
- public void testOperationStateValidationNegativeJsonProcessingNullIllegalStateException() throws Exception {
- shortInit();
- SvcLogicContext ctx = new SvcLogicContext();
- DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
- daoServiceMock.setConfigFile(fileContent);
-
- NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
- client.setAnswer(operationalState);
-
- params = new HashMap<>();
- params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
- params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
- MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
- validatorMock.setConfigurationFileName("VnfGetRunningConfig");
-
- PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
- when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
- substituteMapper(true);
-
- try {
- netconfClientPlugin.operationStateValidation(params, ctx);
- substituteMapper(false);
- } catch (APPCException e) {
- substituteMapper(false);
- Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
- Assert.assertFalse(validatorMock.isValidated());
- Assert.assertNull(client.getLastMessage());
- }
- }
-
- @Test
- public void testOperationStateValidationNegativeConnectionDetailsAreNullNullPointerException() throws Exception {
- shortInit();
- SvcLogicContext ctx = new SvcLogicContext();
- DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
- daoServiceMock.setConfigFile(fileContent);
-
- NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
- client.setAnswer(operationalState);
-
-
- params = new HashMap<>();
- params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
- params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
- MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
- validatorMock.setConfigurationFileName("VnfGetRunningConfig");
-
- PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
- when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
- ObjectMapper mapper = PowerMockito.mock(ObjectMapper.class);
- final NetconfConnectionDetails netconfConnectionDetails = null;
- when(mapper.readValue(Matchers.anyString(), Matchers.any(Class.class))).thenReturn(netconfConnectionDetails);
-
-
- try {
- netconfClientPlugin.operationStateValidation(params, ctx);
- Assert.assertTrue(false);
- } catch (APPCException e) {
- Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
- Assert.assertFalse("validation process failed", validatorMock.isValidated());
-
- }
- }
-
-
- @Test
- public void testOperationStateValidationNegativeAppcException() throws Exception {
- shortInit();
- SvcLogicContext ctx = new SvcLogicContext();
- DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
- daoServiceMock.setConfigFile(fileContent);
-
- NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
- client.setAnswer("wrong");
-
-
- params = new HashMap<>();
- params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
- params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
- MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
- validatorMock.setConfigurationFileName("VnfGetRunningConfig");
-
- PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
- when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
-
-
- try {
- netconfClientPlugin.operationStateValidation(params, ctx);
- Assert.assertTrue(false);
- } catch (APPCException e) {
- Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
- Assert.assertFalse("validation process failed", validatorMock.isValidated());
-
- }
- }
-
-
- @Test
- public void testOperationStateValidatioConnectionDetailsInParamsAreEmpty() throws Exception {
- shortInit();
- SvcLogicContext ctx = new SvcLogicContext();
- DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
- daoServiceMock.setConfigFile(fileContent);
-
- NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
- client.setAnswer(operationalState);
- ((DAOServiceMock) dao).setConnection(getConnectionDetails());
-
-
- params = new HashMap<>();
- params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
- params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "");
- MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
- validatorMock.setConfigurationFileName("VnfGetRunningConfig");
-
- PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
- when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
-
- netconfClientPlugin.operationStateValidation(params, ctx);
-
- Assert.assertTrue("validation process failed", validatorMock.isValidated());
- Assert.assertEquals(fileContent, client.getLastMessage());
- }
-
- @Test
- public void testOperationStateValidatioConnectionDetailsInParamsAreNull() throws Exception {
- shortInit();
- SvcLogicContext ctx = new SvcLogicContext();
- DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
- daoServiceMock.setConfigFile(fileContent);
-
- NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
- client.setAnswer(operationalState);
- ((DAOServiceMock) dao).setConnection(getConnectionDetails());
-
-
- params = new HashMap<>();
- params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
- params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
- MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
- validatorMock.setConfigurationFileName("VnfGetRunningConfig");
-
- PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
- when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
-
- netconfClientPlugin.operationStateValidation(params, ctx);
-
- Assert.assertTrue("validation process failed", validatorMock.isValidated());
- Assert.assertEquals(fileContent, client.getLastMessage());
- }
-
-
- @Test
- public void testBackupConfiguration() throws Exception {
- shortInit();
- SvcLogicContext ctx = new SvcLogicContext();
- params = new HashMap<>();
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
- NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
- client.setConf(fileContent);
- netconfClientPlugin.backupConfiguration(params, ctx);
-
- DAOServiceMock mockdao = (DAOServiceMock) dao;
- DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
- Date date = new Date();
- String creationDateExpected = dateFormat.format(date);
- String creationDateActual = mockdao.getBackupConf().get("creationDate").substring(0, 10);
-
-
- Assert.assertEquals("wrong configuration in db", fileContent, mockdao.getBackupConf().get("logText"));
- Assert.assertEquals(creationDateExpected, creationDateActual);
-
-
- }
-
-
- @Test
- public void testBackupConfigurationNegativeDgErrorFieldName() throws Exception {
- shortInit();
- SvcLogicContext ctx = new SvcLogicContext();
- params = new HashMap<>();
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
- NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
- client.setConf(fileContent);
- try {
- netconfClientPlugin.backupConfiguration(params, ctx);
- Assert.assertTrue(false);
- } catch (APPCException e) {
- Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
-
- DAOServiceMock mockdao = (DAOServiceMock) dao;
- Assert.assertNull(mockdao.getBackupConf());
- }
-
- }
-
- @Test
- public void testGetConfig() throws Exception {
- fullInit();
- String entity = "123";
-
- SvcLogicContext ctx = new SvcLogicContext();
- ctx.setAttribute("entity", entity);
-
- params = new HashMap<>();
- params.put("conf-id", "current");
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
- NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
- client.setConf(fileContent);
-
-
- netconfClientPlugin.getConfig(params, ctx);
-
- Assert.assertEquals("Success", ctx.getAttribute("getConfig_Result"));
- Assert.assertEquals(fileContent, ctx.getAttribute("fullConfig"));
- Assert.assertNotNull(ctx.getAttribute(entity + ".Configuration"));
- Assert.assertEquals(fileContent, ctx.getAttribute(entity + ".Configuration"));
- }
-
-
- @Test
- public void testGetConfigNegativeConfigurationNull() throws Exception {
- fullInit();
- String entity = "123";
-
- SvcLogicContext ctx = new SvcLogicContext();
- ctx.setAttribute("entity", entity);
-
- params = new HashMap<>();
- params.put("conf-id", "current");
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
-
-
- netconfClientPlugin.getConfig(params, ctx);
-
- Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
- Assert.assertNull(ctx.getAttribute("fullConfig"));
- Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
- Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
- }
-
-
- @Test
- public void testGetConfigNegativeNotSupportedConfId() throws Exception {
- fullInit();
- String entity = "123";
- SvcLogicContext ctx = new SvcLogicContext();
- ctx.setAttribute("entity", entity);
-
- params = new HashMap<>();
- params.put("conf-id", "current1");
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
-
-
- netconfClientPlugin.getConfig(params, ctx);
-
- Assert.assertNull(ctx.getAttribute("getConfig_Result"));
- Assert.assertNull(ctx.getAttribute("fullConfig"));
- Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
- Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
- }
-
- @Test
- public void testGetConfigNegativeWronjJsonConnectionDetailsException() throws Exception {
- fullInit();
- String entity = "123";
-
- SvcLogicContext ctx = new SvcLogicContext();
- ctx.setAttribute("entity", entity);
-
- params = new HashMap<>();
- params.put("conf-id", "current");
- params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
-
-
- try {
- netconfClientPlugin.getConfig(params, ctx);
- Assert.assertTrue(false);
- } catch (APPCException e) {
- Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
- Assert.assertNull(ctx.getAttribute("fullConfig"));
- Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
- Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
- Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
- }
-
-
- }
-
- @Test
- public void testGetRunningConfig() throws Exception {
- fullInit();
- SvcLogicContext ctx = new SvcLogicContext();
- params = new HashMap<>();
- params.put("host-ip-address", host);
- params.put("user-name", username);
- params.put("password", password);
- params.put("port-number", String.valueOf(port));
-
- NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
- client.setConf(fileContent);
-
- netconfClientPlugin.getRunningConfig(params, ctx);
-
- Assert.assertEquals("Success", ctx.getAttribute("getRunningConfig_Result"));
- Assert.assertEquals(fileContent, ctx.getAttribute("running-config"));
- Assert.assertEquals("success", ctx.getStatus());
- }
-
- @Test
- public void testGetRunningConfigWithoutPortNumberDgErrorFieldNameException() throws Exception {
- fullInit();
- SvcLogicContext ctx = new SvcLogicContext();
- params = new HashMap<>();
- params.put("host-ip-address", host);
- params.put("user-name", username);
- params.put("password", password);
-
- NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
- client.setConf(fileContent);
-
- try {
- netconfClientPlugin.getRunningConfig(params, ctx);
- Assert.assertTrue(false);
- } catch (APPCException e) {
- Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
- Assert.assertNull(ctx.getAttribute("running-config"));
- Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
- }
-
-
- }
-
- @Test
- public void testGetRunningConfigNegativeConfigurationNull() throws Exception {
- fullInit();
- SvcLogicContext ctx = new SvcLogicContext();
- params = new HashMap<>();
- params.put("host-ip-address", host);
- params.put("user-name", username);
- params.put("password", password);
- params.put("port-number", String.valueOf(port));
-
- netconfClientPlugin.getRunningConfig(params, ctx);
-
- Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
- Assert.assertNull(ctx.getAttribute("running-config"));
- }
-
- @Test
- public void testValidateMandatoryParamNegativeEmptyParamValue() throws Exception {
- shortInit();
- String paramName = "test";
- String paramValue = "";
-
- try {
- netconfClientPlugin.validateMandatoryParam(paramName, paramValue);
- Assert.assertTrue(false);
- } catch (Exception e) {
- Assert.assertTrue(true);
- }
- }
-
- @Test
- public void testRetrieveConnectionDetails() throws Exception {
- shortInit();
- DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
- daoServiceMock.setConfigFile(fileContent);
- ConnectionDetails connectionDetails1 = getConnectionDetails();
- daoServiceMock.setConnection(connectionDetails1);
-
- NetconfConnectionDetails connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.VNF);
-
-
- Assert.assertEquals("wrong host", connectionDetails1.getHost(), connectionDetailsActual.getHost());
- Assert.assertEquals("wrong password", connectionDetails1.getPassword(), connectionDetailsActual.getPassword());
- Assert.assertEquals("wrong port", connectionDetails1.getPort(), connectionDetailsActual.getPort());
- Assert.assertEquals("wrong usename", connectionDetails1.getUsername(), connectionDetailsActual.getUsername());
- }
-
-
- @Test
- public void testRetrieveConnectionDetailsNegativeMissingConfiguration() throws Exception {
- shortInit();
- DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
- daoServiceMock.setConfigFile(fileContent);
- ConnectionDetails connectionDetails1 = getConnectionDetails();
- daoServiceMock.setConnection(connectionDetails1);
-
- NetconfConnectionDetails connectionDetailsActual = null;
- try {
- connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.MOCK);
- Assert.assertTrue(false);
- } catch (APPCException e) {
- Assert.assertNull(connectionDetailsActual);
- }
-
-
- }
-
- @Test
- public void testRetrieveConfigurationFileContent() throws Exception {
- shortInit();
-
- DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
- daoServiceMock.setConfigFile(fileContent);
-
- Assert.assertEquals("wrong config in a database", fileContent, netconfClientPlugin.retrieveConfigurationFileContent("VnfGetRunningConfig"));
- }
-
- private ConnectionDetails getConnectionDetails() {
-
- ConnectionDetails connectionDetails = new ConnectionDetails();
- connectionDetails.setPassword(password);
- connectionDetails.setPort(port);
- connectionDetails.setUsername(username);
- connectionDetails.setHost(host);
- return connectionDetails;
- }
-
-
- private void initDao() throws NoSuchFieldException, IllegalAccessException {
- dao = new DAOServiceMock();
- PowerMockito.mockStatic(FrameworkUtil.class);
- when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
- when(bundleService.getBundleContext()).thenReturn(bundleContext);
- when(bundleContext.getServiceReference(NetconfDataAccessService.class)).thenReturn(sref1);
- when(bundleContext.<NetconfDataAccessService>getService(sref1)).thenReturn(dao);
-
-
- }
-
- private void fullInit() throws NoSuchFieldException, IllegalAccessException {
- initClientFactory();
- initClientFactory2();
- initDao();
- netconfClientPlugin = new NetconfClientPluginImpl();
- netconfClientPlugin.setDao(this.dao);
- }
-
- private void shortInit() throws NoSuchFieldException, IllegalAccessException {
- initClientFactory();
- initDao();
- netconfClientPlugin = new NetconfClientPluginImpl();
- netconfClientPlugin.setDao(this.dao);
- }
-
- private void initClientFactory() throws NoSuchFieldException, IllegalAccessException {
-
- PowerMockito.mockStatic(FrameworkUtil.class);
- when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
- when(bundleService.getBundleContext()).thenReturn(bundleContext);
- when(bundleContext.getServiceReference(NetconfClientFactory.class)).thenReturn(sref2);
- when(bundleContext.<NetconfClientFactory>getService(sref2)).thenReturn(clientFactory);
-
- }
-
- private void initClientFactory2() {
- PowerMockito.mockStatic(FrameworkUtil.class);
- when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
- when(bundleService.getBundleContext()).thenReturn(bundleContext);
- when(bundleContext.getServiceReference(Matchers.anyString())).thenReturn(sref3);
- when(bundleContext.<NetconfClientFactory>getService(sref3)).thenReturn(clientFactory);
- }
-
- private void substituteMapper(boolean command) throws NoSuchFieldException, IllegalAccessException {
- ObjectMapper mapper = new ObjectMapperMock();
- ObjectMapper mapper2 = new ObjectMapper();
- Field field = NetconfClientPluginImpl.class.getDeclaredField("mapper");
- field.setAccessible(true);
- if (command) {
- field.set(netconfClientPlugin, mapper);
- } else {
- field.set(netconfClientPlugin, mapper2);
- }
- }
-
-}
diff --git a/appc-dg/appc-dg-shared/appc-dg-shared-features/src/main/resources/features.xml b/appc-dg/appc-dg-shared/appc-dg-shared-features/src/main/resources/features.xml
index 3271f7ab8..c8925fe8f 100644
--- a/appc-dg/appc-dg-shared/appc-dg-shared-features/src/main/resources/features.xml
+++ b/appc-dg/appc-dg-shared/appc-dg-shared-features/src/main/resources/features.xml
@@ -29,7 +29,9 @@
<feature name='appc-dg-shared' description="appc-dg-shared" version='${project.version}'>
<feature version='${project.version}'>appc-ssh-adapter</feature>
<feature version='${project.version}'>appc-netconf-adapter</feature>
- <bundle>mvn:org.openecomp.appc/appc-dg-common/${project.version}</bundle>
+ <feature version='${sdnctl.sli.version}'>sdnc-sli</feature>
+ <bundle dependency="true">mvn:org.openecomp.appc/appc-common/${project.version}</bundle>
+ <bundle start-level="85" start="true">mvn:org.openecomp.appc/appc-dg-common/${project.version}</bundle>
<bundle>mvn:org.openecomp.appc/appc-dg-ssh/${project.version}</bundle>
<bundle start-level="85" start="true">mvn:org.openecomp.appc/appc-dg-netconf/${project.version}</bundle>
<bundle>mvn:org.openecomp.appc/appc-dg-license-manager/${project.version}</bundle>
diff --git a/appc-dg/appc-dg-shared/appc-dg-ssh/pom.xml b/appc-dg/appc-dg-shared/appc-dg-ssh/pom.xml
index 3f5c51f28..f27c2828e 100644
--- a/appc-dg/appc-dg-shared/appc-dg-ssh/pom.xml
+++ b/appc-dg/appc-dg-shared/appc-dg-ssh/pom.xml
@@ -58,8 +58,10 @@
<Bundle-SymbolicName>appc-dg-ssh</Bundle-SymbolicName>
<Export-Package>org.openecomp.appc.dg.ssh</Export-Package>
<Private-Package>org.openecomp.appc.dg.ssh.impl.*</Private-Package>
- <Import-Package>!org.apache.log,!org.apache.commons.logging,!groovy.lang,!javax.jms,!org.codehaus.commons.compiler,!org.codehaus.groovy.*,!org.codehaus.janino,!com.ibm.icu.*,!com.sun.faces.*,!org.jasypt.*,*;resolution:=optional</Import-Package>
- <Embed-Dependency>appc-common,eelf-core,logback-core,logback-classic;scope=compile|runtime;inline=false</Embed-Dependency>
+ <Import-Package>
+ *;resolution:=optional
+ </Import-Package>
+ <!--Embed-Dependency>eelf-core,logback-core,logback-classic;scope=compile|runtime;inline=false</Embed-Dependency-->
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
diff --git a/appc-dg/appc-dg-shared/appc-dg-ssh/src/main/java/org/openecomp/appc/dg/ssh/impl/SshDBPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-ssh/src/main/java/org/openecomp/appc/dg/ssh/impl/SshDBPluginImpl.java
index 382d41894..89dd424c9 100644
--- a/appc-dg/appc-dg-shared/appc-dg-ssh/src/main/java/org/openecomp/appc/dg/ssh/impl/SshDBPluginImpl.java
+++ b/appc-dg/appc-dg-shared/appc-dg-ssh/src/main/java/org/openecomp/appc/dg/ssh/impl/SshDBPluginImpl.java
@@ -21,6 +21,7 @@
package org.openecomp.appc.dg.ssh.impl;
+import com.att.eelf.i18n.EELFResourceManager;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -32,6 +33,8 @@ import org.openecomp.appc.adapter.ssh.SshDataAccessException;
import org.openecomp.appc.adapter.ssh.SshDataAccessService;
import org.openecomp.appc.dg.ssh.SshDBPlugin;
import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.i18n.Msg;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import org.openecomp.sdnc.sli.SvcLogicContext;
@@ -49,24 +52,29 @@ public class SshDBPluginImpl implements SshDBPlugin {
public void retrieveConnectionDetails(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
SshConnectionDetails connectionDetails = new SshConnectionDetails();
- String vnfType = ctx.getAttribute("aai.prefix")+"."+"vnf-type";
+ //String vnfType = ctx.getAttribute("aai.prefix")+"."+"vnf-type";
+ String vnfType = params.get("vnf-type");
try {
- if (!dataAccessService.retrieveConnectionDetails(ctx.getAttribute(vnfType), connectionDetails)) {
- logger.error("Missing configuration for " + params.get(vnfType));
- throw new APPCException("Missing configuration for " + params.get(vnfType) + " in " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME);
+ if (!dataAccessService.retrieveConnectionDetails(vnfType, connectionDetails)) {
+ logger.error("Missing connection details for VNF type: " + vnfType);
+ throw new APPCException("Missing configuration for " + vnfType + " in " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME);
}
connectionDetails.setHost(params.get(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME));
ctx.setAttribute(Constants.CONNECTION_DETAILS_FIELD_NAME, mapper.writeValueAsString(connectionDetails));
} catch(APPCException e) {
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
+ String msg = EELFResourceManager.format(Msg.APPC_EXCEPTION, vnfType, e.getMessage());
+ logger.error(msg);
+ ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg);
throw e;
} catch(SshDataAccessException e) {
- logger.error("Error " + e.getMessage());
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
+ String msg = EELFResourceManager.format(Msg.SSH_DATA_EXCEPTION, e.getMessage());
+ logger.error(msg);
+ ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
throw e;
} catch (JsonProcessingException e) {
- logger.error("Error " + e.getMessage());
- ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.getMessage());
+ String msg = EELFResourceManager.format(Msg.JSON_PROCESSING_EXCEPTION, e.getMessage());
+ logger.error(msg);
+ ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
throw new APPCException(e);
}
}
diff --git a/appc-dg/appc-dg-shared/pom.xml b/appc-dg/appc-dg-shared/pom.xml
index 1645866bf..9082e0d0e 100644
--- a/appc-dg/appc-dg-shared/pom.xml
+++ b/appc-dg/appc-dg-shared/pom.xml
@@ -11,11 +11,14 @@
<modules>
<module>appc-dg-common</module>
+ <module>appc-dg-dependency-model</module>
<module>appc-dg-ssh</module>
<module>appc-dg-aai</module>
<module>appc-dg-netconf</module>
<module>appc-dg-license-manager</module>
<module>appc-dg-shared-features</module>
<module>appc-dg-shared-installer</module>
- </modules>
+ <module>appc-dg-domain-model-lib</module>
+ <module>appc-dg-mdsal-store</module>
+ </modules>
</project>