summaryrefslogtreecommitdiffstats
path: root/appc-dg/appc-dg-shared/appc-dg-common/src/main/java
diff options
context:
space:
mode:
authorPatrick Brady <pb071s@att.com>2017-06-01 10:45:37 -0700
committerPatrick Brady <pb071s@att.com>2017-06-02 13:05:15 -0700
commitc7d0075d223eab9f89fd28853c4b138792059be9 (patch)
tree40aa3e41e598ea7a59bcf6899a2004c1abab11c2 /appc-dg/appc-dg-shared/appc-dg-common/src/main/java
parent8aac2df744820304ee29354333661699e9695939 (diff)
Merge of new rebased code
Change-Id: I9b8d1f69eb3e0af1935ed8304fea4bf54c1aac47 Signed-off-by: Patrick Brady <pb071s@att.com>
Diffstat (limited to 'appc-dg/appc-dg-shared/appc-dg-common/src/main/java')
-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
26 files changed, 1813 insertions, 56 deletions
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();
+ }
+ }
+ }
+ }
+}