diff options
author | Patrick Brady <pb071s@att.com> | 2017-06-01 10:45:37 -0700 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2017-06-02 13:05:15 -0700 |
commit | c7d0075d223eab9f89fd28853c4b138792059be9 (patch) | |
tree | 40aa3e41e598ea7a59bcf6899a2004c1abab11c2 /appc-dg/appc-dg-shared/appc-dg-common | |
parent | 8aac2df744820304ee29354333661699e9695939 (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')
33 files changed, 2442 insertions, 108 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/pom.xml b/appc-dg/appc-dg-shared/appc-dg-common/pom.xml index 6ad459162..ae59b07dc 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/pom.xml +++ b/appc-dg/appc-dg-shared/appc-dg-common/pom.xml @@ -17,18 +17,25 @@ </dependency> <dependency> <groupId>org.openecomp.appc</groupId> - <artifactId>appc-dmaap-adapter-bundle</artifactId> + <artifactId>appc-message-adapter-api</artifactId> <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.openecomp.appc</groupId> + <artifactId>appc-message-adapter-factory</artifactId> + <version>${project.version}</version> + <scope>provided</scope> </dependency> <dependency> <groupId>org.openecomp.sdnc.core</groupId> <artifactId>sli-common</artifactId> - <scope>compile</scope> + <scope>provided</scope> </dependency> <dependency> <groupId>org.openecomp.sdnc.core</groupId> <artifactId>sli-provider</artifactId> - <scope>compile</scope> + <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> @@ -43,13 +50,11 @@ <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> - <version>1.6.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> - <version>1.6.2</version> <scope>test</scope> </dependency> <dependency> @@ -57,6 +62,31 @@ <artifactId>powermock-api-easymock</artifactId> <version>1.6.2</version> </dependency> + <dependency> + <groupId>org.openecomp.appc</groupId> + <artifactId>appc-dg-dependency-model</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.appc</groupId> + <artifactId>appc-ranking-framework-lib</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.appc</groupId> + <artifactId>appc-data-access-lib</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>equinoxSDK381</groupId> + <artifactId>org.eclipse.osgi</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.openecomp.appc</groupId> + <artifactId>appc-dg-mdsal-store</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> <build> @@ -70,8 +100,11 @@ <Bundle-SymbolicName>appc-dg-common</Bundle-SymbolicName> <Export-Package>org.openecomp.appc.dg.common,org.openecomp.appc.dg.common.objects,org.openecomp.appc.dg.common.utils</Export-Package> <Private-Package>org.openecomp.appc.dg.common.impl.*</Private-Package> - <Import-Package>!org.apache.log,!org.apache.commons.logging,!groovy.lang,!javax.jms,!org.codehaus.commons.compiler,!org.codehaus.groovy.*,!org.codehaus.janino,!com.ibm.icu.*,!com.sun.faces.*,!org.jasypt.*,*;resolution:=optional</Import-Package> - <Embed-Dependency>appc-common,eelf-core,logback-core,logback-classic;scope=compile|runtime;inline=false</Embed-Dependency> + <Import-Package>org.openecomp.appc.adapter.message.*,org.openecomp.appc.adapter.factory.*,org.openecomp.appc.adapter.messaging.*, + *;resolution:=optional</Import-Package> + <Embed-Dependency>appc-dg-mdsal-store,appc-dg-domain-model-lib,appc-dg-dependency-model,jackson-dataformat-yaml,jackson-databind;scope=compile|runtime;inline=false;artifactId=!org.eclipse.osgi</Embed-Dependency> + + <!--Embed-Dependency>eelf-core,logback-core,logback-classic;scope=compile|runtime;inline=false</Embed-Dependency--> <Embed-Transitive>true</Embed-Transitive> </instructions> </configuration> diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/DgResolverPlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/DgResolverPlugin.java new file mode 100644 index 000000000..e2fabaa20 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/DgResolverPlugin.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common; + +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; + +import java.util.Map; + +public interface DgResolverPlugin extends SvcLogicJavaPlugin { + void resolveDg(Map<String, String> params, SvcLogicContext ctx) throws APPCException; +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/IntermediateMessageSender.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/IntermediateMessageSender.java new file mode 100644 index 000000000..f391c36ec --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/IntermediateMessageSender.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common; + +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; + +import java.util.Map; + +/** + * This interface provides api for sending intermediate messages from DG to initiator + */ +public interface IntermediateMessageSender extends SvcLogicJavaPlugin{ + + /** + * DG plugin which sends intermediate messages generated from DG to the initiator + * @param params expects 1. code, (mandatory) + * 2. message, (mandatory) + * 3. payload, + * 4. prefix + * @param context expects 1. input.common-header.timestamp, + * 2. input.common-header.api-ver, + * 3. input.common-header.originator-id, + * 4. input.common-header.request-id, (mandatory) + * 5. input.common-header.sub-request-id, + * 6. input.action + */ + void sendMessage(Map<String, String> params, SvcLogicContext context); +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/JsonDgUtil.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/JsonDgUtil.java index 2b3fbf793..ecdaea0dd 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/JsonDgUtil.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/JsonDgUtil.java @@ -30,4 +30,22 @@ import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; public interface JsonDgUtil extends SvcLogicJavaPlugin { void flatAndAddToContext(Map<String, String> params, SvcLogicContext ctx) throws APPCException; + + void generateOutputPayloadFromContext(Map<String, String> params, SvcLogicContext ctx) throws APPCException; + + /** + * Creates filename and content in Json format. + * @param params + * @param ctx + * @throws APPCException + */ + void cvaasFileNameAndFileContentToContext(Map<String, String> params, SvcLogicContext ctx) throws APPCException; + + /** + * Checks if a file is created. + * @param params + * @param ctx + * @throws APPCException + */ + void checkFileCreated(Map<String, String> params, SvcLogicContext ctx) throws APPCException; } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/OutputMessagePlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/OutputMessagePlugin.java new file mode 100644 index 000000000..35e7b2263 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/OutputMessagePlugin.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common; + +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; + +import java.util.Map; + +import org.openecomp.appc.exceptions.APPCException; + +public interface OutputMessagePlugin extends SvcLogicJavaPlugin { + + void outputMessageBuilder(Map<String, String> params, SvcLogicContext ctx) throws APPCException; + +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFCDgResolverPlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFCDgResolverPlugin.java new file mode 100644 index 000000000..0dd79998f --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFCDgResolverPlugin.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common; + +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; + +import java.util.Map; + +import org.openecomp.appc.exceptions.APPCException; + + +public interface VNFCDgResolverPlugin extends SvcLogicJavaPlugin { + void resolveVNFCDg(Map<String, String> params, SvcLogicContext ctx) throws APPCException; +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFConfigurator.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFConfigurator.java new file mode 100644 index 000000000..57acf5223 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFConfigurator.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common; + +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; + +import java.util.Map; +/** + * DG plugin created for VNF configuration operation to store data in MD-SAL store + **/ +public interface VNFConfigurator extends SvcLogicJavaPlugin{ + /** + * it is invoked from the DG, and it performs following operations + * 1. checks whether given yang module is present in the MD-SAL store + * 2. if it is absent, loads it into MD-SAL store + * 3. Stores the VNF configuration into MD-SAL store + * @param params should have 1. uniqueId, 2. yang, 3.configJSON, 4.requestId + * @param context - DG context + * @throws APPCException + */ + void storeConfig(Map<String, String> params, SvcLogicContext context) throws APPCException; +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VnfExecutionFlow.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VnfExecutionFlow.java new file mode 100644 index 000000000..f69985f03 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VnfExecutionFlow.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common; + +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; + +import java.util.Map; + +public interface VnfExecutionFlow extends SvcLogicJavaPlugin { + void getVnfExecutionFlowData(Map<String,String> params, SvcLogicContext context); +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolver.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolver.java new file mode 100644 index 000000000..1d7766fb2 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolver.java @@ -0,0 +1,114 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import org.openecomp.appc.rankingframework.RankedAttributesResolver; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.util.concurrent.locks.ReentrantLock; + +abstract class AbstractResolver { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(AbstractResolver.class); + + private long interval; + + private volatile long lastUpdate = 0l; + private volatile boolean isUpdateInProgress = false; + private volatile RankedAttributesResolver<FlowKey> dgResolver; + + private final ReentrantLock INIT_LOCK = new ReentrantLock(); + + AbstractResolver(int interval) { + this.interval = interval * 1000; + } + + private RankedAttributesResolver<FlowKey> createResolver(String resolverType) { + AbstractResolverDataReader reader = ResolverDataReaderFactory.createResolverDataReader(resolverType); + return reader.read(); + } + + private boolean isExpired() { + return (System.currentTimeMillis() - lastUpdate) > interval; + } + + protected RankedAttributesResolver<FlowKey> resolver(String resolverType) { + + /* + * In general case, the method implementation is non-blocking. The first + * thread that identifies data expiration will be used to refresh it. In + * meanwhile, any other thread will get the old instance without waiting + * for the updated one. The only exception is the very first time when + * previous instance doesn't exist - in such a cases all the threads + * will be waiting on INIT_LOCK while one of them initializes the + * resolver instance. NOTE: The initialization is intentionally + * implemented in lazy manner to make sure the bundle is initialized + * properly on startup regardless whether or not the data is correct. + * Afterwards, the resolver may be instantiated as many times as needed. + */ + + try { + + if (dgResolver == null) { + INIT_LOCK.lock(); + if (dgResolver != null) { + INIT_LOCK.unlock(); + } + } + + if (!isUpdateInProgress && isExpired()) { + + boolean doUpgrade = false; + + synchronized (this) { + if (!isUpdateInProgress) { + isUpdateInProgress = true; + doUpgrade = true; + } + } + + if (doUpgrade) { + + logger.info("DG resolver configuration data has expired - initiating refresh"); + + try { + RankedAttributesResolver<FlowKey> temp = createResolver(resolverType); + dgResolver = temp; + lastUpdate = System.currentTimeMillis(); + + logger.info("DG resolver configuration data has been refreshed successfully"); + } finally { + isUpdateInProgress = false; + } + } + } + } finally { + if (INIT_LOCK.isHeldByCurrentThread()) { + INIT_LOCK.unlock(); + } + } + + return dgResolver; + } + protected abstract FlowKey resolve(final String...args); +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolverDataReader.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolverDataReader.java new file mode 100644 index 000000000..edfc8f4b8 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolverDataReader.java @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import org.openecomp.appc.dao.util.DBUtils; +import org.openecomp.appc.rankingframework.AbstractRankedAttributesResolverFactory; +import org.openecomp.appc.rankingframework.ConfigurationEntry; +import org.openecomp.appc.rankingframework.ConfigurationSet; +import org.openecomp.appc.rankingframework.RankedAttributesResolver; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; +import java.util.Iterator; + +abstract class AbstractResolverDataReader { + + private class ConfigurationSetAdaptor implements ConfigurationSet<FlowKey> { + + private final ResultSet resultSet; + + private class ResultSetIterator implements Iterator<ConfigurationEntry<FlowKey>>, ConfigurationEntry<FlowKey> { + @Override + public boolean hasNext() { + try { + return resultSet.next(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + @Override + public ConfigurationEntry<FlowKey> next() { + return this; + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + @Override + public Object getAttributeValue(String name) { + try { + return resultSet.getObject(name); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + @Override + public FlowKey getResult() { + try { + return new FlowKey(resultSet.getString("dg_name"), resultSet.getString("dg_version"), resultSet.getString("dg_module")); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + } + + ConfigurationSetAdaptor(ResultSet resultSet) { + this.resultSet = resultSet; + } + + @Override + public Iterable<ConfigurationEntry<FlowKey>> getEntries() { + return new Iterable<ConfigurationEntry<FlowKey>>() { + + @Override + public Iterator<ConfigurationEntry<FlowKey>> iterator() { + return new ResultSetIterator(); + } + }; + } + + @Override + public Collection<String> getRankedAttributeNames() { + return getAttributeNames(); + } + } + + protected abstract Collection<String> getAttributeNames(); + protected abstract String getQueryStmt(); + + + + RankedAttributesResolver<FlowKey> read() { + try { + try (Connection conn = DBUtils.getConnection("sdnctl")) { + try (PreparedStatement stmt = conn.prepareStatement(getQueryStmt())) { + try (ResultSet res = stmt.executeQuery()) { + if (res.next()) { + res.beforeFirst(); + ConfigurationSet<FlowKey> resolverConfig = new ConfigurationSetAdaptor(res); + return AbstractRankedAttributesResolverFactory.getInstance().create(resolverConfig); + } else { + throw new IllegalStateException(); + } + } + } + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/Constants.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/Constants.java index 92d23e3a6..3a5bb91ac 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/Constants.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/Constants.java @@ -27,15 +27,35 @@ class Constants { public static final String DG_ERROR_FIELD_NAME = "org.openecomp.appc.dg.error"; public static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message"; + public static final String EVENT_MESSAGE = "event-message"; + public static final String ATTRIBUTE_ERROR_MESSAGE = "error-message"; + public static final String ATTRIBUTE_SUCCESS_MESSAGE = "success-message"; + public static final String DG_ERROR_CODE = "output.status.dgerror.code"; public static final String API_VERSION_FIELD_NAME = "org.openecomp.appc.apiversion"; public static final String REQ_ID_FIELD_NAME = "org.openecomp.appc.reqid"; public static final String PAYLOAD = "payload"; + public static final String OUTPUT_PAYLOAD = "output.payload"; + + //Added for VnfExecution Flow + public static final String FLOW_STRATEGY = "FlowStrategy" ; + public static final String DEPENDENCY_TYPE = "DependencyType"; + public static final String VNF_TYPE = "vnfType"; + public static final String VNF_VERION = "vnfVersion"; + + + public static final String APPC_INSTANCE_ID= "appc-instance-id"; + + //Added for Cvaas + public static final String CVAAS_DIRECTORY_PATH = "cvaas-directory-path"; + public static final String CVAAS_FILE_NAME = "cvaas-file-name"; + public static final String CVAAS_FILE_CONTENT = "cvaas-file-content"; enum LegacyAttributes { Action("org.openecomp.appc.action"), VMID("org.openecomp.appc.vmid"), IdentityURL("org.openecomp.appc.identity.url"), - TenantID("org.openecomp.appc.tenant.id"); + TenantID("org.openecomp.appc.tenant.id"), + SkipHypervisorCheck("org.openecomp.appc.skiphypervisorcheck"); private String value; LegacyAttributes(String value) {this.value = value;} @@ -47,11 +67,30 @@ class Constants { Payload("input.payload"), VMID("vm-id"), IdentityURL("identity-url"), - TenantID("tenant.id"); + TenantID("tenant.id"), + SkipHypervisorCheck("skip-hypervisor-check"); private String value; LCMAttributes(String value) {this.value = value;} String getValue() {return value;} }; + // DG Resolver Constants + public static final String IN_PARAM_VNF_TYPE = "vnfType"; + public static final String IN_PARAM_VNFC_TYPE = "vnfcType"; + public static final String IN_PARAM_ACTION = "action"; + public static final String IN_PARAM_API_VERSION = "api-ver"; + + public static final String OUT_PARAM_DG_NAME = "dg_name"; + public static final String OUT_PARAM_DG_VERSION= "dg_version"; + public static final String OUT_PARAM_DG_MODULE = "dg_module"; + + public static final String TABLE_NAME = "VNFC_DG_MAPPING"; + public static final String TABLE_COLUMN_VNF_TYPE = "VNF_TYPE"; + public static final String TABLE_COLUMN_VNFC_TYPE = "VNFC_TYPE"; + public static final String TABLE_COLUMN_ACTION = "ACTION"; + public static final String TABLE_COLUMN_API_VERSION = "API_VERSION"; + public static final String TABLE_COLUMN_DG_NAME = "DG_NAME"; + public static final String TABLE_COLUMN_DG_VERSION= "DG_VERSION"; + public static final String TABLE_COLUMN_DG_MODULE = "DG_MODULE"; } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java index 4458de10b..8081a6ff3 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java @@ -22,11 +22,11 @@ package org.openecomp.appc.dg.common.impl; import org.apache.commons.lang3.StringUtils; -import org.openecomp.appc.adapter.dmaap.EventSender; -import org.openecomp.appc.adapter.dmaap.DmaapDestination; -import org.openecomp.appc.adapter.dmaap.event.EventHeader; -import org.openecomp.appc.adapter.dmaap.event.EventMessage; -import org.openecomp.appc.adapter.dmaap.event.EventStatus; +import org.openecomp.appc.adapter.message.EventSender; +import org.openecomp.appc.adapter.message.MessageDestination; +import org.openecomp.appc.adapter.message.event.EventHeader; +import org.openecomp.appc.adapter.message.event.EventMessage; +import org.openecomp.appc.adapter.message.event.EventStatus; import org.openecomp.appc.dg.common.DCAEReporterPlugin; import org.openecomp.appc.exceptions.APPCException; import org.openecomp.sdnc.sli.SvcLogicContext; @@ -48,74 +48,108 @@ public class DCAEReporterPluginImpl implements DCAEReporterPlugin { @Override public void report(Map<String, String> params, SvcLogicContext ctx) throws APPCException { - Integer errorReportCode = 501; - boolean bwcMode = Boolean.parseBoolean(ctx.getAttribute("isBwcMode")); String errorDescription,apiVersion,eventId ; - errorDescription = getErrorDescriptionAndAddToCtx(bwcMode,params,ctx); - if(!bwcMode){ - apiVersion = ctx.getAttribute("input.common-header.api-ver"); - eventId = ctx.getAttribute("input.common-header.request-id"); - }else { - apiVersion = ctx.getAttribute(Constants.API_VERSION_FIELD_NAME); - eventId = ctx.getAttribute(Constants.REQ_ID_FIELD_NAME); - } - EventMessage eventMessage = new EventMessage(new EventHeader((new java.util.Date()).toString(), apiVersion, eventId), new EventStatus(errorReportCode, errorDescription)); - eventSender.sendEvent(DmaapDestination.DCAE, eventMessage); - } + Integer errorCode = readErrorCode(params,ctx); + errorDescription = params.get(Constants.EVENT_MESSAGE); - private String getErrorDescriptionAndAddToCtx(boolean bwcMode, Map<String, String> params, SvcLogicContext ctx) { - String errorDescription; - if(!bwcMode) { - errorDescription = params.get(Constants.DG_OUTPUT_STATUS_MESSAGE); - if(StringUtils.isEmpty(errorDescription)) { - errorDescription = ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE); - }else { - addToContextIfNotContains(bwcMode,errorDescription,ctx); - } + if(StringUtils.isEmpty(errorDescription)) { + reportLegacy(params , ctx); }else{ - errorDescription = params.get(Constants.DG_ERROR_FIELD_NAME); - if(StringUtils.isEmpty(errorDescription)) { - errorDescription = ctx.getAttribute("org.openecomp.appc.dg.error"); + apiVersion = ctx.getAttribute("input.common-header.api-ver"); + eventId = ctx.getAttribute("input.common-header.request-id"); + + EventMessage eventMessage = new EventMessage(new EventHeader((new java.util.Date()).toString(), apiVersion, eventId), new EventStatus(errorCode, errorDescription)); + String eventWriteTopic = params.get("event-topic-name"); + if(!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic!=null){ + eventSender.sendEvent(MessageDestination.DCAE, eventMessage,eventWriteTopic); }else { - addToContextIfNotContains(bwcMode, errorDescription,ctx); + eventSender.sendEvent(MessageDestination.DCAE, eventMessage); } } - - if(StringUtils.isEmpty(errorDescription)) { - errorDescription = "Unknown"; - } - return errorDescription; } - private void addToContextIfNotContains(boolean bwcMode, String errorDescription, SvcLogicContext ctx) { - String errorDescriptionFromCtx; - if(!StringUtils.isEmpty(errorDescription)) { - String outputStatusMessageProperty = bwcMode ? "org.openecomp.appc.dg.error" : Constants.DG_OUTPUT_STATUS_MESSAGE; - errorDescriptionFromCtx = ctx.getAttribute(outputStatusMessageProperty); - if(StringUtils.isEmpty(errorDescriptionFromCtx)){ - ctx.setAttribute(outputStatusMessageProperty, errorDescription); - }else if (!errorDescriptionFromCtx.contains(errorDescription)){ - ctx.setAttribute(outputStatusMessageProperty, errorDescriptionFromCtx+ " | "+ errorDescription); - } + private Integer readErrorCode(Map<String, String> params, SvcLogicContext ctx) { + Integer errorReportCode = 501; + String errorCodeStr = params.get(Constants.DG_ERROR_CODE); + errorCodeStr = StringUtils.isEmpty(errorCodeStr)? + ctx.getAttribute(Constants.DG_ERROR_CODE):errorCodeStr; + try{ + errorReportCode = Integer.parseInt(errorCodeStr); } + catch (NumberFormatException e){ + // Ignore Exception + } + return errorReportCode; } - @Override public void reportSuccess(Map<String, String> params, SvcLogicContext ctx) throws APPCException { Integer successReportCode = 500; String successDescription, apiVersion, eventId; - successDescription = params.get(Constants.DG_OUTPUT_STATUS_MESSAGE); + successDescription = params.get(Constants.EVENT_MESSAGE); + + if(StringUtils.isEmpty(successDescription)) { + successDescription = params.get(Constants.DG_OUTPUT_STATUS_MESSAGE); + } + apiVersion = ctx.getAttribute("input.common-header.api-ver"); eventId = ctx.getAttribute("input.common-header.request-id"); - ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, successDescription); if (null == successDescription) { successDescription = "Success"; } EventMessage eventMessage = new EventMessage(new EventHeader((new java.util.Date()).toString(), apiVersion, eventId), new EventStatus(successReportCode, successDescription)); - eventSender.sendEvent(DmaapDestination.DCAE, eventMessage); + String eventWriteTopic = params.get("event-topic-name"); + if(!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic!=null){ + eventSender.sendEvent(MessageDestination.DCAE, eventMessage,eventWriteTopic); + }else { + eventSender.sendEvent(MessageDestination.DCAE, eventMessage); + } + } + + private void reportLegacy(Map<String, String> params, SvcLogicContext ctx) throws APPCException { + String errorDescription,apiVersion,eventId ; + + Integer errorCode = readErrorCode(params,ctx); + errorDescription = getErrorDescriptionAndAddToCtx(params,ctx); + + apiVersion = ctx.getAttribute("input.common-header.api-ver"); + eventId = ctx.getAttribute("input.common-header.request-id"); + + EventMessage eventMessage = new EventMessage(new EventHeader((new java.util.Date()).toString(), apiVersion, eventId), new EventStatus(errorCode, errorDescription)); + String eventWriteTopic = params.get("event-topic-name"); + if(!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic!=null){ + eventSender.sendEvent(MessageDestination.DCAE, eventMessage,eventWriteTopic); + }else { + eventSender.sendEvent(MessageDestination.DCAE, eventMessage); + } + } + + private String getErrorDescriptionAndAddToCtx(Map<String, String> params, SvcLogicContext ctx) { + String errorDescription; + errorDescription = params.get(Constants.DG_OUTPUT_STATUS_MESSAGE); + if(StringUtils.isEmpty(errorDescription)) { + errorDescription = ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE); + } + if(StringUtils.isEmpty(errorDescription)) { + errorDescription = "Unknown"; + } + addToContextIfNotContains(errorDescription,ctx); + return errorDescription; + } + + private void addToContextIfNotContains(String errorDescription, SvcLogicContext ctx) { + String errorDescriptionFromCtx; + errorDescriptionFromCtx = ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE); + if(StringUtils.isEmpty(errorDescriptionFromCtx)){ + errorDescriptionFromCtx = ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE); + } + if(StringUtils.isEmpty(errorDescriptionFromCtx)){ + ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorDescription); + }else if (!errorDescriptionFromCtx.contains(errorDescription)){ + ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorDescriptionFromCtx+ " | "+ errorDescription); + } } } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DgResolverPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DgResolverPluginImpl.java new file mode 100644 index 000000000..497cb7f66 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DgResolverPluginImpl.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.appc.i18n.Msg; +import com.att.eelf.i18n.EELFResourceManager; +import org.openecomp.sdnc.sli.SvcLogicContext; + +import java.util.Map; + +import org.openecomp.appc.dg.common.DgResolverPlugin; + +public class DgResolverPluginImpl implements DgResolverPlugin { + + @Override + public void resolveDg(Map<String, String> params, SvcLogicContext ctx) throws APPCException { + + String DGName, DGVersion, DGModule = null; + String prefix = params.containsKey("prefix") ? params.get("prefix") + "." : ""; + AbstractResolver resolver = ResolverFactory.createResolver(params.get("DGResolutionType")); + FlowKey flowKey = null; + try { + + if(params.get("DGResolutionType").equalsIgnoreCase("VNFC")) { + flowKey = resolver.resolve(params.get(Constants.IN_PARAM_ACTION), params.get(Constants.IN_PARAM_VNF_TYPE), params.get(Constants.IN_PARAM_VNFC_TYPE), params.get(Constants.IN_PARAM_API_VERSION)); + }else if(params.get("DGResolutionType").equalsIgnoreCase("VNF")){ + flowKey = resolver.resolve(params.get(Constants.IN_PARAM_ACTION), params.get(Constants.IN_PARAM_VNF_TYPE), params.get("vnfVersion"), params.get(Constants.IN_PARAM_API_VERSION)); + } + if (flowKey != null) { + DGName = flowKey.name(); + ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_NAME, DGName); + DGVersion = flowKey.version(); + ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_VERSION, DGVersion); + DGModule = flowKey.module(); + ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_MODULE, DGModule); + } else { + throw new RuntimeException(params.get("DGResolutionType")+ " DG not found for vnf type :" + params.get(Constants.IN_PARAM_VNF_TYPE) + + " vnfc type : " + params.get(Constants.IN_PARAM_VNFC_TYPE) + + " action : " + params.get(Constants.IN_PARAM_ACTION) + + " api version : " + params.get(Constants.IN_PARAM_API_VERSION)); + } + } catch (Exception e) { + String msg = EELFResourceManager.format(Msg.FAILURE_RETRIEVE_VNFC_DG,params.get(Constants.IN_PARAM_VNFC_TYPE), e.getMessage()); + ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg); + throw new RuntimeException(e); + } + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/FlowKey.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/FlowKey.java new file mode 100644 index 000000000..416f90786 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/FlowKey.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +class FlowKey { + private final String name; + private final String version; + private final String module; + + FlowKey(String name, String version, String module) { + this.name = name; + this.version = version; + this.module = module; + } + + String name() { + return name; + } + + String version() { + return version; + } + + String module() { + return module; + } + + @Override + public String toString() { + StringBuilder buff = new StringBuilder(128); + buff.append("{"); + buff.append("module = ").append(module); + buff.append(", "); + buff.append("name = ").append(name); + buff.append(", "); + buff.append("version = ").append(version); + buff.append("}"); + return buff.toString(); + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/IntermediateMessageSenderImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/IntermediateMessageSenderImpl.java new file mode 100644 index 000000000..3732ded04 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/IntermediateMessageSenderImpl.java @@ -0,0 +1,169 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.apache.commons.lang.StringUtils; +import org.openecomp.appc.adapter.message.MessageAdapterFactory; +import org.openecomp.appc.adapter.message.Producer; +import org.openecomp.appc.configuration.Configuration; +import org.openecomp.appc.configuration.ConfigurationFactory; +import org.openecomp.appc.dg.common.IntermediateMessageSender; +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; + +import java.util.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +public class IntermediateMessageSenderImpl implements IntermediateMessageSender { + + + private Producer producer; + + private Configuration configuration; + + private final EELFLogger logger = EELFManager.getInstance().getLogger(IntermediateMessageSenderImpl.class); + + private static final String STATUS = "STATUS"; + private static final String FAILURE = "FAILURE"; + private static final String SUCCESS = "SUCCESS"; + private static final String ERROR_MESSAGE = "ERROR_MESSAGE"; + + private static final String RESPONSE = "response"; + private static final String MSO = "MSO"; + + public void init(){ + configuration = ConfigurationFactory.getConfiguration(); + Properties properties=configuration.getProperties(); + + String writeTopic = properties.getProperty("appc.LCM.topic.write"); + String apiKey = properties.getProperty("appc.LCM.client.key"); + String apiSecret = properties.getProperty("appc.LCM.client.secret"); + String hostNames = properties.getProperty("appc.LCM.poolMembers"); + + logger.debug("Configuration Read : writeTopic = " + writeTopic +", " + + "hostNames = " + hostNames); + + Set<String> pool = new HashSet<>(); + if (!StringUtils.isEmpty(hostNames)) { + for (String name : hostNames.split(",")) { + pool.add(name); + } + } + + BundleContext ctx = FrameworkUtil.getBundle(IntermediateMessageSenderImpl.class).getBundleContext(); + if (ctx != null) { + ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName()); + if (svcRef != null) { + producer = ((MessageAdapterFactory) ctx.getService(svcRef)).createProducer(pool, writeTopic,apiKey, apiSecret); + } + } + } + + @Override + public void sendMessage(Map<String, String> params, SvcLogicContext context) { + String prefix = params.get("prefix"); + prefix = StringUtils.isEmpty(prefix)? "":prefix+"."; + try{ + validateInputs(params,context); + String jsonMessage = getJsonMessage(params, context); + logger.debug("Constructed JSON Message : " + jsonMessage); + producer.post("",jsonMessage); + context.setAttribute(prefix + STATUS, SUCCESS); + } + catch(Exception e){ + String errorMessage = "Error sending intermediate message to initiator " + e.getMessage(); + context.setAttribute(prefix + STATUS, FAILURE); + context.setAttribute(prefix + ERROR_MESSAGE, errorMessage); + logger.error(errorMessage,e); + } + } + + private void validateInputs(Map<String, String> params, SvcLogicContext context) throws APPCException { + String code = params.get("code"); + String message = params.get("message"); + if(StringUtils.isEmpty(code) || StringUtils.isEmpty(message)){ + throw new APPCException("code or message is empty"); + } + String requestId = context.getAttribute("input.common-header.request-id"); + if(StringUtils.isEmpty(requestId)){ + throw new APPCException("requestId is empty"); + } + } + + private String getJsonMessage(Map<String, String> params, SvcLogicContext context) { + ObjectMapper objectMapper = new ObjectMapper(); + + ObjectNode commonHeader = getCommonHeader(context); + ObjectNode status = getStatus(params); + + ObjectNode output = objectMapper.createObjectNode(); + output.put("common-header",commonHeader); + output.put("status",status); + + ObjectNode body = objectMapper.createObjectNode(); + body.put("output",output); + + ObjectNode root = objectMapper.createObjectNode(); + root.put("type", RESPONSE); + root.put("rpc-name",context.getAttribute("input.action")); + root.put("cambria.partition", MSO); + root.put("correlation-id",getCorrelationId(context)); + root.put("body",body); + + return root.toString(); + } + + private String getCorrelationId(SvcLogicContext context) { + String requestId = context.getAttribute("input.common-header.request-id"); + String subRequestId = context.getAttribute("input.common-header.sub-request-id"); + return requestId + (StringUtils.isEmpty(subRequestId)?"":("-"+subRequestId)); + } + + private ObjectNode getStatus(Map<String,String> params) { + ObjectMapper objectMapper = new ObjectMapper(); + ObjectNode status = objectMapper.createObjectNode(); + status.put("code",params.get("code")); + status.put("message",params.get("message")); + return status; + } + + private ObjectNode getCommonHeader(SvcLogicContext context) { + ObjectMapper objectMapper = new ObjectMapper(); + ObjectNode commonHeader = objectMapper.createObjectNode(); + commonHeader.put("api-ver",context.getAttribute("input.common-header.api-ver")); + commonHeader.put("timestamp",context.getAttribute("input.common-header.timestamp")); + commonHeader.put("originator-id",context.getAttribute("input.common-header.originator-id")); + commonHeader.put("request-id",context.getAttribute("input.common-header.request-id")); + commonHeader.put("sub-request-id",context.getAttribute("input.common-header.sub-request-id")); + return commonHeader; + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImpl.java index 95191132a..1ba2b5b07 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImpl.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImpl.java @@ -21,21 +21,36 @@ package org.openecomp.appc.dg.common.impl; +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Map; +import java.util.Set; + import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.openecomp.appc.dg.common.JsonDgUtil; import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.appc.i18n.Msg; import org.openecomp.appc.util.JsonUtil; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.openecomp.sdnc.sli.SvcLogicContext; -import java.util.Map; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.att.eelf.i18n.EELFResourceManager; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; public class JsonDgUtilImpl implements JsonDgUtil { private static final EELFLogger logger = EELFManager.getInstance().getLogger(JsonDgUtilImpl.class); + private static final ThreadLocal<SimpleDateFormat> DATE_TIME_PARSER_THREAD_LOCAL = new ThreadLocal<SimpleDateFormat>() { + protected SimpleDateFormat initialValue() { + return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + } + }; + @Override public void flatAndAddToContext(Map<String, String> params, SvcLogicContext ctx) throws APPCException { @@ -59,8 +74,123 @@ public class JsonDgUtilImpl implements JsonDgUtil { } } catch (Exception e) { logger.error(e.toString()); + String msg = EELFResourceManager.format(Msg.INPUT_PAYLOAD_PARSING_FAILED,params.get(Constants.PAYLOAD)); + ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg); + throw new APPCException(e); + } + } + + @Override + public void generateOutputPayloadFromContext(Map<String, String> params, SvcLogicContext ctx) throws APPCException{ + if (logger.isTraceEnabled()) { + logger.trace("Entering to generateOutputPayloadFromContext with SvcLogicContext = "+ObjectUtils.toString(ctx)); + } + + try { + Set<String> keys = ctx.getAttributeKeySet(); + ObjectMapper objectMapper = new ObjectMapper(); + ObjectNode JsonNode = objectMapper.createObjectNode(); + for (String key : keys) { + if(key.startsWith(Constants.OUTPUT_PAYLOAD+".")){ + String objkey= key.replaceFirst(Constants.OUTPUT_PAYLOAD + ".", ""); + if(objkey.contains("[") && objkey.contains("]")){ + ArrayNode arrayNode; + String arrayKey = objkey.substring(0,objkey.indexOf('[')); + int arrayIndex = Integer.parseInt(objkey.substring(objkey.indexOf('[')+1,objkey.indexOf(']'))); + if(JsonNode.has(arrayKey)){ + arrayNode = (ArrayNode)JsonNode.get(arrayKey); + arrayNode.insert(arrayIndex,ctx.getAttribute(key)); + }else { + arrayNode = objectMapper.createArrayNode(); + arrayNode.insert(arrayIndex,ctx.getAttribute(key)); + JsonNode.put(arrayKey,arrayNode); + } + }else { + JsonNode.put(objkey, ctx.getAttribute(key)); + } + } + } + if(JsonNode.size()>0) { + ctx.setAttribute(Constants.OUTPUT_PAYLOAD, objectMapper.writeValueAsString(JsonNode)); + } + } catch (Exception e) { + logger.error(e.toString()); ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, e.toString()); throw new APPCException(e); } + + } + + @Override + public void cvaasFileNameAndFileContentToContext(Map<String, String> params, SvcLogicContext ctx) + throws APPCException { + + if (logger.isTraceEnabled()) { + logger.trace("Entering to caasFileNameAndFileContentToContext with SvcLogicContext = " + + ObjectUtils.toString(ctx)); + } + + String vnfId = null; + try { + String cvassDirectoryPath = params.get(Constants.CVAAS_DIRECTORY_PATH); + String appcInstanceId = params.get(Constants.APPC_INSTANCE_ID); + + /* + * File name + */ + vnfId = params.get("vnf-id"); + long timestampAsLongRepresentingFileCreationTime = System.currentTimeMillis(); + + ctx.setAttribute(Constants.CVAAS_FILE_NAME, cvassDirectoryPath + File.separator + vnfId + "_" + + timestampAsLongRepresentingFileCreationTime + "_" + appcInstanceId + ".json"); + + /* + * File content + */ + + String uploadDate = ctx.getAttribute("running-config.upload-date"); + long epochUploadTimestamp = DATE_TIME_PARSER_THREAD_LOCAL.get().parse(uploadDate).getTime(); + + ObjectMapper objectMapper = new ObjectMapper(); + ObjectNode jsonNode = objectMapper.createObjectNode(); + jsonNode.put("UPLOAD_CONFIG_ID", ctx.getAttribute("running-config.upload-config-id")); + jsonNode.put("REQUEST_ID", ctx.getAttribute("running-config.request-id")); + jsonNode.put("ORIGINATOR_ID", ctx.getAttribute("running-config.originator-id")); + jsonNode.put("SERVICE_DESCRIPTION", ctx.getAttribute("running-config.service-description")); + jsonNode.put("ACTION", ctx.getAttribute("running-config.action")); + jsonNode.put("UPLOAD_TIMESTAMP", epochUploadTimestamp); + jsonNode.put("UPLOAD_DATE", uploadDate); + jsonNode.put("VNF_ID", vnfId); + jsonNode.put("VNF_NAME", ctx.getAttribute("running-config.vnf-name")); + jsonNode.put("VM_NAME", ctx.getAttribute("running-config.vm-name")); + jsonNode.put("VNF_TYPE", ctx.getAttribute("running-config.vnf-type")); + jsonNode.put("VNFC_TYPE", ctx.getAttribute("running-config.vnfc-type")); + jsonNode.put("HOST_IP_ADDRESS", ctx.getAttribute("running-config.host-ip-address")); + jsonNode.put("CONFIG_INDICATOR", ctx.getAttribute("running-config.config-indicator")); + jsonNode.put("PENDING_DELETE", ctx.getAttribute("running-config.pending-delete")); + jsonNode.put("CONTENT", ctx.getAttribute("running-config.content")); + + ctx.setAttribute(Constants.CVAAS_FILE_CONTENT, + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode)); + + } catch (Exception e) { + String errorMessage = "Failed to parse create cvass file for vnf with id : " + vnfId; + logger.error(errorMessage, e); + ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, errorMessage); + throw new APPCException(e); + } + } + + @Override + public void checkFileCreated(Map<String, String> params, SvcLogicContext ctx) throws APPCException { + String filePath = ctx.getAttribute(Constants.CVAAS_FILE_NAME); + File file = new File(filePath); + + if (!file.exists()) { + String vnfId = params.get("vnf-id"); + String errorMessage = "Cvass file could not be created for vnf with id : " + vnfId; + ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, errorMessage); + throw new APPCException(errorMessage); + } } } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/LegacyUtilImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/LegacyUtilImpl.java index 6354b2044..3ab8ee28f 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/LegacyUtilImpl.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/LegacyUtilImpl.java @@ -37,11 +37,13 @@ public class LegacyUtilImpl implements LegacyUtil { String payloadStr = ctx.getAttribute(Constants.LCMAttributes.Payload.getValue()); Map<String,String> payloads = JSONUtil.extractPlainValues(payloadStr, - Constants.LCMAttributes.VMID.getValue(), Constants.LCMAttributes.IdentityURL.getValue(), Constants.LCMAttributes.TenantID.getValue()); + Constants.LCMAttributes.VMID.getValue(), Constants.LCMAttributes.IdentityURL.getValue(), Constants.LCMAttributes.TenantID.getValue(), + Constants.LCMAttributes.SkipHypervisorCheck.getValue()); ctx.setAttribute(Constants.LegacyAttributes.VMID.getValue(), payloads.get(Constants.LCMAttributes.VMID.getValue())); ctx.setAttribute(Constants.LegacyAttributes.IdentityURL.getValue(), payloads.get(Constants.LCMAttributes.IdentityURL.getValue())); ctx.setAttribute(Constants.LegacyAttributes.TenantID.getValue(), payloads.get(Constants.LCMAttributes.TenantID.getValue())); + ctx.setAttribute(Constants.LegacyAttributes.SkipHypervisorCheck.getValue(), payloads.get(Constants.LCMAttributes.SkipHypervisorCheck.getValue())); } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/OutputMessagePluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/OutputMessagePluginImpl.java new file mode 100644 index 000000000..c70c754ca --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/OutputMessagePluginImpl.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import org.openecomp.sdnc.sli.SvcLogicContext; + +import java.util.Map; + +import org.openecomp.appc.dg.common.OutputMessagePlugin; +import org.openecomp.appc.exceptions.APPCException; + +import static org.apache.commons.lang3.StringUtils.isEmpty; + +public class OutputMessagePluginImpl implements OutputMessagePlugin { + + @Override + public void outputMessageBuilder(Map<String, String> params, SvcLogicContext ctx) throws APPCException { + String errorDescription, eventDescription; + + //making output.status.message + errorDescription = params.get(Constants.ATTRIBUTE_ERROR_MESSAGE); + eventDescription = params.get(Constants.EVENT_MESSAGE); + + addToContextIfNotContains(errorDescription , eventDescription, ctx); + + //making event-message + + if (!isEmpty(eventDescription)) { + ctx.setAttribute(Constants.EVENT_MESSAGE, eventDescription); + } else { + ctx.setAttribute(Constants.EVENT_MESSAGE, ctx.getAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE)); + } + } + + public static void addToContextIfNotContains(String errorDescription, String eventDescription, SvcLogicContext ctx) { + if (!isEmpty(errorDescription)){ + if (isEmpty(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE))) { + ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorDescription); + }else if (!ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE).contains(errorDescription)) { + ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE) + " | " + errorDescription); + } + } + if (!isEmpty(eventDescription)){ + if (isEmpty(ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE))) { + ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, eventDescription); + }else if (!ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE).contains(eventDescription)) { + ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, ctx.getAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE) + " | " + eventDescription); + } + } + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverDataReaderFactory.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverDataReaderFactory.java new file mode 100644 index 000000000..9dc43abee --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverDataReaderFactory.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import org.openecomp.appc.configuration.Configuration; +import org.openecomp.appc.configuration.ConfigurationFactory; + +public class ResolverDataReaderFactory { + private static final Configuration configuration = ConfigurationFactory.getConfiguration(); + private static class ReferenceHolder{ + private static final AbstractResolverDataReader VNFC_RESOLVER_DATA_READER = new VNFCResolverDataReader(); + + private static final AbstractResolverDataReader VNF_RESOLVER_DATA_READER = new VNFResolverDataReader(); + } + + public static AbstractResolverDataReader createResolverDataReader(String resolverType){ + if(resolverType.equalsIgnoreCase("VNF")){ + return ReferenceHolder.VNF_RESOLVER_DATA_READER; + }else if(resolverType.equalsIgnoreCase("VNFC")){ + return ReferenceHolder.VNFC_RESOLVER_DATA_READER; + }else { + return null; + } + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverFactory.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverFactory.java new file mode 100644 index 000000000..afc7907db --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverFactory.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import org.openecomp.appc.configuration.Configuration; +import org.openecomp.appc.configuration.ConfigurationFactory; + +public class ResolverFactory { + private static final Configuration configuration = ConfigurationFactory.getConfiguration(); + private static class ReferenceHolder{ + private static final AbstractResolver VNFC_RESOLVER = new VNFCResolver(configuration.getIntegerProperty("org.openecomp.appc.workflow.resolver.refresh_interval", 300)); + private static final AbstractResolver VNF_RESOLVER = new VNFResolver(configuration.getIntegerProperty("org.openecomp.appc.workflow.resolver.refresh_interval", 300)); + } + + public static AbstractResolver createResolver(String resolverType){ + if(resolverType.equalsIgnoreCase("VNF")){ + return ReferenceHolder.VNF_RESOLVER; + }else if(resolverType.equalsIgnoreCase("VNFC")){ + return ReferenceHolder.VNFC_RESOLVER; + }else { + return null; + } + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCDgResolverPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCDgResolverPluginImpl.java new file mode 100644 index 000000000..404d9087b --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCDgResolverPluginImpl.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.sdnc.sli.SvcLogicContext; + +import java.util.Map; + +public class VNFCDgResolverPluginImpl implements org.openecomp.appc.dg.common.VNFCDgResolverPlugin { + @Override + public void resolveVNFCDg(Map<String, String> params, SvcLogicContext ctx) throws APPCException { + DgResolverPluginImpl dgResolverPlugin = new DgResolverPluginImpl(); + params.put("DGResolutionType" , "VNFC"); + dgResolverPlugin.resolveDg(params,ctx); + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolver.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolver.java new file mode 100644 index 000000000..7c90b57f9 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolver.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import org.openecomp.appc.rankingframework.RankedAttributesContext; + + +public class VNFCResolver extends AbstractResolver { + VNFCResolver(int interval) { + super(interval); + } + + @Override + protected FlowKey resolve(String... args) { + if(args.length !=4){ + throw new IllegalStateException(args.toString()); + } + return resolve(args[0],args[1],args[2],args[3]); + } + + protected FlowKey resolve(final String action, final String vnfType, final String vnfcType, final String apiVersion) { + RankedAttributesContext context = new RankedAttributesContext() { + @Override + public Object getAttributeValue(String name) { + switch (name) { + case "action": + return action; + case "api_version": + return apiVersion; + case "vnf_type": + return vnfType; + case "vnfc_type": + return vnfcType; + default: + throw new IllegalStateException(name); + } + } + }; + + FlowKey wfKey = resolver("VNFC").resolve(context); + + return wfKey; + } +} + diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolverDataReader.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolverDataReader.java new file mode 100644 index 000000000..b49d1fa54 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolverDataReader.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import java.util.Arrays; +import java.util.Collection; + +public class VNFCResolverDataReader extends AbstractResolverDataReader { + @Override + protected Collection<String> getAttributeNames() { + return Arrays.asList("action","api_version", "vnf_type", "vnfc_type"); + } + + @Override + protected String getQueryStmt() { + return "select vnf_type,vnfc_type,api_version,action,dg_name,dg_version,dg_module FROM VNFC_DG_MAPPING"; + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFConfiguratorImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFConfiguratorImpl.java new file mode 100644 index 000000000..169114330 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFConfiguratorImpl.java @@ -0,0 +1,112 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import org.openecomp.appc.Constants; +import org.openecomp.appc.dg.common.VNFConfigurator; +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.appc.mdsal.MDSALStore; +import org.openecomp.appc.mdsal.exception.MDSALStoreException; +import org.openecomp.appc.mdsal.impl.MDSALStoreFactory; +import org.openecomp.appc.mdsal.objects.BundleInfo; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.apache.commons.lang.StringUtils; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; + + +public class VNFConfiguratorImpl implements VNFConfigurator { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(VNFConfiguratorImpl.class); + private static final String STATUS = "STATUS"; + private static final String FAILURE = "FAILURE"; + private static final String SUCCESS = "SUCCESS"; + private static final String ERROR_MESSAGE = "ERROR_MESSAGE"; + + @Override + public void storeConfig(Map<String, String> params, SvcLogicContext context) throws APPCException { + String uniqueId = params.get("uniqueId"); + String yang = params.get("yang"); + String configJSON = params.get("configJSON"); + String requestId = params.get("requestId"); + String prefix = params.get("prefix"); + prefix = StringUtils.isEmpty(prefix)? "":prefix+"."; + + MDSALStore store = MDSALStoreFactory.createMDSALStore(); + + logger.debug("Inputs Received : uniqueId = " + uniqueId + + " , yang = " + yang + + " , configJSON = " + configJSON + + " , requestId = " + requestId + + " , prefix = " +prefix); + + try { + + if(StringUtils.isEmpty(uniqueId) + ||StringUtils.isEmpty(yang) + || StringUtils.isEmpty(configJSON) + || StringUtils.isEmpty(requestId)){ + throw new APPCException("One or more input parameters are empty : uniqueId = " + uniqueId + " " + + ", yang = " + yang + + " , configJSON = " + configJSON + + " , requestId = " + requestId); + } + + Date revision = new SimpleDateFormat(Constants.YANG_REVISION_FORMAT).parse(Constants.YANG_REVISION); + + boolean isYangAlreadyLoaded = store.isModulePresent(uniqueId,revision); + + if(!isYangAlreadyLoaded){ + BundleInfo bundleInfo = getBundleInfo(uniqueId); + store.storeYangModule(yang,bundleInfo); + } + store.storeJson(uniqueId, requestId , configJSON); + context.setAttribute(prefix + STATUS, SUCCESS); + } catch (ParseException e) { + String errorMessage ="Error parsing the date : " + Constants.YANG_REVISION + " into format " + Constants.YANG_REVISION_FORMAT; + logger.error(errorMessage,e); + context.setAttribute(prefix + STATUS, FAILURE); + context.setAttribute(prefix + ERROR_MESSAGE, errorMessage); + throw new APPCException(e.getMessage()); + }catch (MDSALStoreException e){ + String errorMessage = "Error while adding yang to MD-SAL store." + e.getMessage(); + logger.error(errorMessage,e); + context.setAttribute(prefix + STATUS,FAILURE); + context.setAttribute(prefix + ERROR_MESSAGE, errorMessage); + throw new APPCException(e.getMessage()); + } + + } + + private BundleInfo getBundleInfo(String uniqueId) { + BundleInfo bundleInfo = new BundleInfo(); + bundleInfo.setDescription(uniqueId); + bundleInfo.setName(uniqueId); + bundleInfo.setLocation(uniqueId); + return bundleInfo; + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolver.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolver.java new file mode 100644 index 000000000..b6002c65e --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolver.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import org.openecomp.appc.rankingframework.RankedAttributesContext; + +public class VNFResolver extends AbstractResolver { + VNFResolver(int interval) { + super(interval); + } + + @Override + protected FlowKey resolve(String... args) { + return resolve(args[0],args[1],args[2],args[3]); + } + + + protected FlowKey resolve(final String action, final String vnfType, final String vnfVersion, final String apiVersion) { + RankedAttributesContext context = new RankedAttributesContext() { + @Override + public Object getAttributeValue(String name) { + switch (name) { + case "action": + return action; + case "api_version": + return apiVersion; + case "vnf_type": + return vnfType; + case "vnf_version": + return vnfVersion; + default: + throw new IllegalStateException(name); + } + } + }; + + FlowKey wfKey = resolver("VNF").resolve(context); + + return wfKey; + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolverDataReader.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolverDataReader.java new file mode 100644 index 000000000..7d91bee15 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolverDataReader.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import java.util.Arrays; +import java.util.Collection; + +/** + * @since January 19,2017 + */ +public class VNFResolverDataReader extends AbstractResolverDataReader { + @Override + protected Collection<String> getAttributeNames() { + return Arrays.asList("action","api_version", "vnf_type", "vnf_version"); + } + + @Override + protected String getQueryStmt() { + return "select vnf_type,vnf_version,api_version,action,dg_name,dg_version,dg_module FROM VNF_DG_MAPPING"; + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VnfExecutionFlowImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VnfExecutionFlowImpl.java new file mode 100644 index 000000000..e8975da0f --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VnfExecutionFlowImpl.java @@ -0,0 +1,268 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.att.eelf.i18n.EELFResourceManager; +import org.openecomp.sdnc.sli.SvcLogicContext; + +import java.util.*; + +import org.openecomp.appc.dg.common.VnfExecutionFlow; +import org.openecomp.appc.dg.dependencymanager.DependencyManager; +import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound; +import org.openecomp.appc.dg.dependencymanager.impl.DependencyModelFactory; +import org.openecomp.appc.dg.flowbuilder.FlowBuilder; +import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.openecomp.appc.dg.flowbuilder.impl.FlowBuilderFactory; +import org.openecomp.appc.dg.objects.*; +import org.openecomp.appc.domainmodel.Vnf; +import org.openecomp.appc.domainmodel.Vnfc; +import org.openecomp.appc.domainmodel.Vserver; +import org.openecomp.appc.i18n.Msg; +import org.openecomp.appc.metadata.objects.DependencyModelIdentifier; + +public class VnfExecutionFlowImpl implements VnfExecutionFlow { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(VnfExecutionFlowImpl.class); + + public VnfExecutionFlowImpl(){ + + } + + @Override + public void getVnfExecutionFlowData(Map<String, String> params, SvcLogicContext context) { + String dependencyType = params.get(Constants.DEPENDENCY_TYPE); + String flowStrategy = params.get(Constants.FLOW_STRATEGY); + DependencyModelIdentifier modelIdentifier = readDependencyModelIdentifier(params); + VnfcDependencyModel dependencyModel = null; + try { + validateInput(dependencyType, flowStrategy, params); + + if (logger.isTraceEnabled()) { + logger.trace("Input received from DG Node : dependencyType = " + dependencyType + + " , flowStrategy = " + flowStrategy + + ", DependencyModelIdentifier = " + modelIdentifier.toString()); + } + + DependencyManager dependencyManager = DependencyModelFactory.createDependencyManager(); + + + dependencyModel = dependencyManager.getVnfcDependencyModel( + modelIdentifier, DependencyTypes.findByString(dependencyType)); + } catch (DependencyModelNotFound e) { + String msg = EELFResourceManager.format(Msg.DEPENDENCY_MODEL_NOT_FOUND,params.get(Constants.VNF_TYPE), e.getMessage()); + logger.error(msg); + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg); + context.setAttribute("dependencyModelFound","false"); + return; + } catch (InvalidDependencyModel e){ + String msg = EELFResourceManager.format(Msg.INVALID_DEPENDENCY_MODEL,params.get(Constants.VNF_TYPE), e.getMessage()); + logger.error(msg); + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg); + throw e; + }catch (RuntimeException e){ + logger.error(e.getMessage()); + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); + throw e; + } + + + context.setAttribute("dependencyModelFound","true"); + if(logger.isDebugEnabled()){ + logger.debug("Dependency Model = " +dependencyModel); + } + logger.info("Building Inventory Model from DG context"); + InventoryModel inventoryModel = readInventoryModel(context); + if(logger.isDebugEnabled()){ + logger.debug("Inventory Model = " +inventoryModel); + } + + if(logger.isDebugEnabled()){ + logger.debug("Validating inventory model with dependency model"); + } + try { + validateInventoryModelWithDependencyModel(dependencyModel, inventoryModel); + }catch (RuntimeException e){ + logger.error(e.getMessage()); + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); + throw e; + } + logger.info("Creating flow builder"); + FlowBuilder flowBuilder = FlowBuilderFactory.getInstance().getFlowBuilder( + FlowStrategies.findByString(flowStrategy)); + + logger.info("Building Vnf flow model"); + VnfcFlowModel flowModel = null; + try{ + flowModel = flowBuilder.buildFlowModel(dependencyModel,inventoryModel); + } + catch (InvalidDependencyModel e){ + String msg = EELFResourceManager.format(Msg.INVALID_DEPENDENCY_MODEL,params.get(Constants.VNF_TYPE), e.getMessage()); + logger.error(msg); + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg); + throw e; + } + + // remove VNFCs from the flow model where vserver list is empty + reconcileFlowModel(flowModel); + populateContext(flowModel,context); + if(logger.isDebugEnabled()){ + logContext(context); + } + String msg = EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "GetVnfExecutionFlowData","VNF ID " + params.get(Constants.VNF_TYPE)); + context.setAttribute(org.openecomp.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg); + } + + private void validateInput(String dependencyType, String flowStrategy, Map<String, String> params) { + DependencyTypes dependencyTypes = DependencyTypes.findByString(dependencyType); + if(dependencyTypes == null){ + throw new RuntimeException("Dependency type from the input : " + dependencyType +" is invalid."); + } + FlowStrategies flowStrategies = FlowStrategies.findByString(flowStrategy); + if(flowStrategies == null){ + throw new RuntimeException("Flow Strategy from the input : " + flowStrategy +" is invalid."); + } + String vnfType = params.get(Constants.VNF_TYPE); + if(vnfType ==null || vnfType.length() ==0){ + throw new RuntimeException("Vnf Type is not passed in the input"); + } + String vnfVersion = params.get(Constants.VNF_VERION); + if(vnfVersion == null || vnfVersion.length() ==0){ + throw new RuntimeException("Vnf Version not found"); + } + } + + private void logContext(SvcLogicContext context) { + for(String key:context.getAttributeKeySet()){ + logger.debug(key + " = " + context.getAttribute(key) + "\n" ); + } + } + + private void populateContext(VnfcFlowModel flowModel, SvcLogicContext context) { + int flowIndex=0; + Iterator<List<Vnfc>> iterator = flowModel.getModelIterator(); + while (iterator.hasNext()){ + for(Vnfc vnfc:iterator.next()){ + context.setAttribute("vnfcFlow["+flowIndex+"].vnfcName",vnfc.getVnfcName()); + context.setAttribute("vnfcFlow["+flowIndex+"].vnfcType",vnfc.getVnfcType()); + context.setAttribute("vnfcFlow["+flowIndex+"].resilienceType",vnfc.getResilienceType()); + context.setAttribute("vnfcFlow["+flowIndex+"].vmCount",Integer.toString(vnfc.getVserverList().size())); + int vmIndex =0; + for(Vserver vm :vnfc.getVserverList()){ + context.setAttribute("vnfcFlow["+flowIndex+"].vm["+vmIndex+"].url",vm.getUrl()); + vmIndex++; + } + flowIndex++; + } + } + context.setAttribute("vnfcFlowCount",Integer.toString(flowIndex)); + } + + private InventoryModel readInventoryModel(SvcLogicContext context) { + String vnfId = context.getAttribute("input.action-identifiers.vnf-id"); + String vnfType = context.getAttribute("vnf.type"); + String vnfVersion = context.getAttribute("vnf.version"); + String vnfcCountStr = context.getAttribute("vnf.vnfcCount"); + Integer vnfcCount = Integer.parseInt(vnfcCountStr); + + Vnf vnf = new Vnf(vnfId,vnfType,vnfVersion); + + for(Integer i=0;i<vnfcCount;i++){ + String vnfcName = context.getAttribute("vnf.vnfc["+ i+"].name"); + String vnfcType = context.getAttribute("vnf.vnfc["+ i+"].type"); + String vmCountStr = context.getAttribute("vnf.vnfc["+ i+"].vm_count"); + if(vnfcType ==null || vnfcType.length() ==0){ + throw new RuntimeException("Could not retrieve VNFC Type from DG Context for vnf.vnfc["+ i+"].type"); + } + Integer vmCount = Integer.parseInt(vmCountStr); + Vnfc vnfc = new Vnfc(vnfcType,null,vnfcName); + for(Integer j=0;j<vmCount;j++){ + String vmURL = context.getAttribute("vnf.vnfc["+i+"].vm["+j+"].url"); + Vserver vm = new Vserver(vmURL); + vnfc.addVm(vm); + } + vnf.addVnfc(vnfc); + } + return new InventoryModel(vnf); + } + + private DependencyModelIdentifier readDependencyModelIdentifier(Map<String, String> params) { + String vnfType = params.get(Constants.VNF_TYPE); + String catalogVersion = params.get(Constants.VNF_VERION); + return new DependencyModelIdentifier(vnfType,catalogVersion); + } + + private void validateInventoryModelWithDependencyModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) { + Set<String> dependencyModelVnfcSet = new HashSet<String>(); + Set<String> dependencyModelMandatoryVnfcSet = new HashSet<String>(); + Set<String> inventoryModelVnfcsSet = new HashSet<String>(); + + for (Node<Vnfc> node : dependencyModel.getDependencies()) { + dependencyModelVnfcSet.add(node.getChild().getVnfcType().toLowerCase()); + if (node.getChild().isMandatory()) { + dependencyModelMandatoryVnfcSet.add(node.getChild().getVnfcType().toLowerCase()); + } + } + + for (Vnfc vnfc : inventoryModel.getVnf().getVnfcs()) { + inventoryModelVnfcsSet.add(vnfc.getVnfcType().toLowerCase()); + } + + // if dependency model and inventory model contains same set of VNFCs, validation succeed and hence return + if (dependencyModelVnfcSet.equals(inventoryModelVnfcsSet)) { + return; + } + + if (inventoryModelVnfcsSet.size() >= dependencyModelVnfcSet.size()) { + Set<String> difference = new HashSet<String>(inventoryModelVnfcsSet); + difference.removeAll(dependencyModelVnfcSet); + logger.error("Dependency model is missing following vnfc type(s): " + difference); + throw new RuntimeException("Dependency model is missing following vnfc type(s): " + difference); + } else { + Set<String> difference = new HashSet<String>(dependencyModelVnfcSet); + difference.removeAll(inventoryModelVnfcsSet); + difference.retainAll(dependencyModelMandatoryVnfcSet); + if (difference.size() > 0) { + logger.error("Inventory model is missing following mandatory vnfc type(s): " + difference); + throw new RuntimeException("Inventory model is missing following mandatory vnfc type(s): " + difference); + } + } + } + + private void reconcileFlowModel(VnfcFlowModel flowModel) { + Iterator<List<Vnfc>> flowIterator = flowModel.getModelIterator(); + while (flowIterator.hasNext()) { + Iterator<Vnfc> vnfcIterator = flowIterator.next().iterator(); + while (vnfcIterator.hasNext()) { + Vnfc vnfc = vnfcIterator.next(); + if (vnfc.getVserverList().size() == 0) { + if (logger.isDebugEnabled()) { + logger.debug("No vservers present for Vnfc type: " + vnfc.getVnfcType() + ". Hence, removing it from the flow model."); + } + vnfcIterator.remove(); + } + } + } + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 53b5367e4..fcbaaf776 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -30,12 +30,35 @@ <bean id="JsonDgUtilBean" class="org.openecomp.appc.dg.common.impl.JsonDgUtilImpl"/> <service id="JsonDgUtil" interface="org.openecomp.appc.dg.common.JsonDgUtil" ref="JsonDgUtilBean"/> - <reference id="eventSenderRef" availability="mandatory" activation="eager" interface="org.openecomp.appc.adapter.dmaap.EventSender" /> + <!-- <reference id="eventSenderRef" availability="mandatory" activation="eager" interface="org.openecomp.appc.adapter.message.EventSender" /> --> <bean id="DCAEReporterPluginBean" class="org.openecomp.appc.dg.common.impl.DCAEReporterPluginImpl" scope="singleton"/> <service id="DCAEReporterPlugin" interface="org.openecomp.appc.dg.common.DCAEReporterPlugin" ref="DCAEReporterPluginBean"/> + <bean id="OutputMessagePluginBean" class="org.openecomp.appc.dg.common.impl.OutputMessagePluginImpl" scope="singleton"/> + <service id="OutputMessagePlugin" interface="org.openecomp.appc.dg.common.OutputMessagePlugin" ref="OutputMessagePluginBean"/> + <bean id="legacyUtilBean" class="org.openecomp.appc.dg.common.impl.LegacyUtilImpl" scope="singleton"/> <service id="legacyUtil" interface="org.openecomp.appc.dg.common.LegacyUtil" ref="legacyUtilBean"/> + <bean id="DgResolverPluginBean" class="org.openecomp.appc.dg.common.impl.DgResolverPluginImpl" scope="singleton"> + </bean> + + <service id="DgResolverPlugin" interface="org.openecomp.appc.dg.common.DgResolverPlugin" ref="DgResolverPluginBean"/> + + <bean id="vnfExecutionFlowBean" class="org.openecomp.appc.dg.common.impl.VnfExecutionFlowImpl" scope="singleton"/> + <service id="vnfExecutionFlowService" interface="org.openecomp.appc.dg.common.VnfExecutionFlow" ref="vnfExecutionFlowBean"/> + + <bean id="VNFCDgResolverPluginBean" class="org.openecomp.appc.dg.common.impl.VNFCDgResolverPluginImpl" scope="singleton"> + </bean> + + <service id="VNFCDgResolverPlugin" interface="org.openecomp.appc.dg.common.VNFCDgResolverPlugin" ref="VNFCDgResolverPluginBean"/> + + <bean id="vnfConfiguratorBean" class="org.openecomp.appc.dg.common.impl.VNFConfiguratorImpl" scope="singleton"/> + + <service id="vnfConfigurationService" interface="org.openecomp.appc.dg.common.VNFConfigurator" ref="vnfConfiguratorBean"/> + + <bean id="interimMessageSender" class="org.openecomp.appc.dg.common.impl.IntermediateMessageSenderImpl" init-method="init" scope="singleton"/> + <service id="interimMessageSenderService" ref="interimMessageSender" interface="org.openecomp.appc.dg.common.IntermediateMessageSender"/> + </blueprint> diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java index 834bd8655..44b71fb4d 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java @@ -24,10 +24,9 @@ package org.openecomp.appc.dg.common.impl; import org.junit.*; import org.junit.runner.RunWith; import org.mockito.*; -import org.openecomp.appc.adapter.dmaap.EventSender; -import org.openecomp.appc.adapter.dmaap.DmaapDestination; -import org.openecomp.appc.adapter.dmaap.event.EventMessage; -import org.openecomp.appc.dg.common.impl.Constants; +import org.openecomp.appc.adapter.message.EventSender; +import org.openecomp.appc.adapter.message.MessageDestination; +import org.openecomp.appc.adapter.message.event.EventMessage; import org.openecomp.appc.dg.common.impl.DCAEReporterPluginImpl; import org.openecomp.appc.exceptions.APPCException; import org.openecomp.sdnc.sli.SvcLogicContext; @@ -44,7 +43,6 @@ import java.util.Map; @RunWith(PowerMockRunner.class) @PrepareForTest({DCAEReporterPluginImpl.class, FrameworkUtil.class}) -@Ignore public class DCAEReporterPluginImplTest { private SvcLogicContext ctx; private Map<String, String> params; @@ -75,39 +73,11 @@ public class DCAEReporterPluginImplTest { - - @Test - public void testReportBwcTrue() throws Exception { - - ctx = new SvcLogicContext(); - params = new HashMap<>(); - ctx.setAttribute("isBwcMode", "true"); - params.put(Constants.DG_ERROR_FIELD_NAME, error); - ctx.setAttribute(Constants.API_VERSION_FIELD_NAME, apiVer); - ctx.setAttribute(Constants.REQ_ID_FIELD_NAME, requestId); - - positiveAssert(); - } - - @Test - public void testReportErrorDescriptionNullBwcModeTrue() throws Exception { - - ctx = new SvcLogicContext(); - params = new HashMap<>(); - ctx.setAttribute("isBwcMode", "true"); - params.put(Constants.DG_ERROR_FIELD_NAME, null); - ctx.setAttribute(Constants.API_VERSION_FIELD_NAME, apiVer); - ctx.setAttribute(Constants.REQ_ID_FIELD_NAME, requestId); - - errorReasonNullAssert(); - } - @Test public void testReportErrorDescriptionNullBwcModeFalse() throws Exception { ctx = new SvcLogicContext(); params = new HashMap<>(); - ctx.setAttribute("isBwcMode", "false"); params.put("output.status.message", null); ctx.setAttribute("input.common-header.api-ver", apiVer); ctx.setAttribute("input.common-header.request-id", requestId); @@ -118,7 +88,7 @@ public class DCAEReporterPluginImplTest { private void errorReasonNullAssert() throws APPCException { dcaeReporterPlugin.report(params, ctx); - DmaapDestination destination = eventSender.getDestination(); + MessageDestination destination = eventSender.getDestination(); EventMessage msg = eventSender.getMsg(); Assert.assertEquals("wrong API version", apiVer, msg.getEventHeader().getApiVer()); Assert.assertEquals("wrong requestId", requestId, msg.getEventHeader().getEventId()); @@ -130,7 +100,7 @@ public class DCAEReporterPluginImplTest { private void positiveAssert() throws APPCException { dcaeReporterPlugin.report(params, ctx); - DmaapDestination destination = eventSender.getDestination(); + MessageDestination destination = eventSender.getDestination(); EventMessage msg = eventSender.getMsg(); Assert.assertEquals("wrong API version", apiVer, msg.getEventHeader().getApiVer()); Assert.assertEquals("wrong requestId", requestId, msg.getEventHeader().getEventId()); diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/EventSenderMock.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/EventSenderMock.java index 0e6b1651b..86532922d 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/EventSenderMock.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/EventSenderMock.java @@ -23,19 +23,19 @@ package org.openecomp.appc.dg.common.impl; import java.util.Map; -import org.openecomp.appc.adapter.dmaap.EventSender; -import org.openecomp.appc.adapter.dmaap.DmaapDestination; -import org.openecomp.appc.adapter.dmaap.event.EventMessage; +import org.openecomp.appc.adapter.message.EventSender; +import org.openecomp.appc.adapter.message.MessageDestination; +import org.openecomp.appc.adapter.message.event.EventMessage; import org.openecomp.appc.exceptions.APPCException; import org.openecomp.sdnc.sli.SvcLogicContext; public class EventSenderMock implements EventSender { EventMessage msg; - DmaapDestination destination; + MessageDestination destination; @Override - public boolean sendEvent(DmaapDestination destination, EventMessage msg) { + public boolean sendEvent(MessageDestination destination, EventMessage msg) { if (destination != null && msg != null){ this.msg = msg; this.destination = destination; @@ -47,7 +47,12 @@ public class EventSenderMock implements EventSender { } @Override - public boolean sendEvent(DmaapDestination destination, Map<String, String> params, SvcLogicContext ctx) throws APPCException { + public boolean sendEvent(MessageDestination destination, EventMessage msg, String eventTopicName) { + return false; + } + + @Override + public boolean sendEvent(MessageDestination destination, Map<String, String> params, SvcLogicContext ctx) throws APPCException { return false; } @@ -55,7 +60,7 @@ public class EventSenderMock implements EventSender { return msg; } - public DmaapDestination getDestination() { + public MessageDestination getDestination() { return destination; } } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java index 70534872d..0a49d5326 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java @@ -32,7 +32,6 @@ import org.openecomp.sdnc.sli.SvcLogicContext; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.*; import static org.mockito.Mockito.mock; public class JsonDgUtilImplTest { @@ -83,7 +82,7 @@ public class JsonDgUtilImplTest { } catch (APPCException e) { Assert.assertNull(ctx.getAttribute(testValueKey)); Assert.assertNull(ctx.getAttribute(testValueKey2)); - Assert.assertNotNull(ctx.getAttribute("output.status.message")); + Assert.assertNotNull(ctx.getAttribute("error-message")); } @@ -142,4 +141,29 @@ public class JsonDgUtilImplTest { Assert.assertNull(ctx.getAttribute(testValueKey)); Assert.assertNull(ctx.getAttribute(testValueKey2)); } + + + @Test + public void testGenerateOutputPayloadFromContext() throws Exception { + + JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl(); + String key = "output.payload"; + String key1 = "output.payload.test-key[0]"; + String key2 = "output.payload.test-key[1]"; + String testValueKey1 = "value1"; + String testValueKey2 = "value2"; + + String key3 = "output.payload.test-key3"; + String testValueKey3 = "value3"; + + SvcLogicContext ctx = new SvcLogicContext(); + Map<String, String> params = new HashMap<>(); + ctx.setAttribute(key1, testValueKey1); + ctx.setAttribute(key2, testValueKey2); + ctx.setAttribute(key3, testValueKey3); + jsonDgUtil.generateOutputPayloadFromContext(params, ctx); + + Assert.assertNotNull(ctx.getAttribute(key)); + + } } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVNFConfiguratorImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVNFConfiguratorImpl.java new file mode 100644 index 000000000..0ee06362e --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVNFConfiguratorImpl.java @@ -0,0 +1,105 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import org.openecomp.appc.dg.common.VNFConfigurator; +import org.openecomp.appc.exceptions.APPCException; +import org.openecomp.appc.mdsal.MDSALStore; +import org.openecomp.appc.mdsal.impl.MDSALStoreFactory; +import org.openecomp.appc.mdsal.impl.MDSALStoreImpl; +import org.openecomp.appc.mdsal.objects.BundleInfo; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({MDSALStoreImpl.class,MDSALStoreFactory.class}) +public class TestVNFConfiguratorImpl { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVNFConfiguratorImpl.class); + + @Before + public void setUp() { + logger.setLevel(EELFLogger.Level.DEBUG); + } + + @Test(expected = APPCException.class) + public void testValidations() throws APPCException { + VNFConfigurator configurator = new VNFConfiguratorImpl(); + Map<String,String> params = new HashMap<String, String>(); + params.put("uniqueId","uniqueId"); + params.put("yang","yang"); + params.put("configJSON","configJSON"); + configurator.storeConfig(params,new SvcLogicContext()); + } + + @Test + public void testYangPresentScenario() throws APPCException { + + VNFConfigurator configurator = new VNFConfiguratorImpl(); + PowerMockito.mockStatic(MDSALStoreFactory.class); + MDSALStore mdsalStore = PowerMockito.mock(MDSALStoreImpl.class); + PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore); + PowerMockito.when(mdsalStore.isModulePresent(Matchers.anyString(),(Date) Matchers.anyObject())).thenReturn(true); + + Map<String,String> params = new HashMap<String, String>(); + params.put("uniqueId","uniqueId"); + params.put("yang","yang"); + params.put("configJSON","configJSON"); + params.put("requestId","requestId"); + configurator.storeConfig(params,new SvcLogicContext()); + } + + @Test + public void testYangAbsentScenario() throws Exception { + + VNFConfigurator configurator = new VNFConfiguratorImpl(); + PowerMockito.mockStatic(MDSALStoreFactory.class); + + MDSALStore mdsalStore = PowerMockito.mock(MDSALStoreImpl.class); + + PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore); + + PowerMockito.when(mdsalStore.isModulePresent(Matchers.anyString(),(Date) Matchers.anyObject())).thenReturn(false); + + PowerMockito.doNothing().when(mdsalStore).storeYangModule(Matchers.anyString(),(BundleInfo)Matchers.anyObject()); + + Map<String,String> params = new HashMap<>(); + params.put("uniqueId","uniqueId"); + params.put("yang","yang"); + params.put("configJSON","configJSON"); + params.put("requestId","requestId"); + configurator.storeConfig(params,new SvcLogicContext()); + + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVnfExecutionFlowImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVnfExecutionFlowImpl.java new file mode 100644 index 000000000..773b6b61a --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVnfExecutionFlowImpl.java @@ -0,0 +1,417 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.dg.common.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.openecomp.appc.dg.common.VnfExecutionFlow; +import org.openecomp.appc.dg.common.impl.Constants; +import org.openecomp.appc.dg.common.impl.VnfExecutionFlowImpl; +import org.openecomp.appc.dg.dependencymanager.DependencyManager; +import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound; +import org.openecomp.appc.dg.dependencymanager.impl.DependencyModelFactory; +import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.openecomp.appc.dg.objects.DependencyTypes; +import org.openecomp.appc.dg.objects.Node; +import org.openecomp.appc.dg.objects.VnfcDependencyModel; +import org.openecomp.appc.domainmodel.Vnfc; +import org.openecomp.appc.metadata.objects.DependencyModelIdentifier; +import org.osgi.framework.FrameworkUtil; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({TestVnfExecutionFlowImpl.class, FrameworkUtil.class,DependencyManager.class,DependencyModelFactory.class}) +public class TestVnfExecutionFlowImpl { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVnfExecutionFlowImpl.class); + + @Before + public void setUp() { + logger.setLevel(EELFLogger.Level.DEBUG); + } + + @Test + public void testPositiveFlow() throws DependencyModelNotFound { + Map<String, String> params = prepareParams(); + SvcLogicContext context = prepareContext(); + VnfcDependencyModel dependencyModel = readDependencyModel(); + + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(( + DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } + + @Test + public void testComplexFlow() throws DependencyModelNotFound { + Map<String, String> params = prepareParams(); + SvcLogicContext context = prepareContextForComplexDependency(); + VnfcDependencyModel dependencyModel = readComplexDependencyModel(); + + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(( + DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } + + @Test(expected = InvalidDependencyModel.class) + public void testCycleFlow() throws DependencyModelNotFound { + Map<String, String> params = prepareParams(); + SvcLogicContext context = prepareContextForComplexDependency(); + VnfcDependencyModel dependencyModel = readCyclicDependencyModel(); + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(( + DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } + + private VnfcDependencyModel readCyclicDependencyModel() { + + Vnfc a = new Vnfc("A","Active-Passive",null); + Vnfc b = new Vnfc("B","Active-Active",null); + Vnfc c = new Vnfc("C","Active-Active",null); + Vnfc d = new Vnfc("D","Active-Active",null); + Vnfc e = new Vnfc("E","Active-Active",null); + Vnfc f = new Vnfc("F","Active-Active",null); + Vnfc g = new Vnfc("G","Active-Active",null); + + Node aNode = new Node(a); + Node bNode = new Node(b); + Node cNode = new Node(c); + Node dNode = new Node(d); + Node eNode = new Node(e); + Node fNode = new Node(f); + Node gNode = new Node(g); + + bNode.addParent(a); + cNode.addParent(a); + cNode.addParent(b); + + bNode.addParent(d); + dNode.addParent(c); + + Set<Node<Vnfc>> dependencies = new HashSet<>(); + dependencies.add(aNode); + dependencies.add(bNode); + dependencies.add(cNode); + dependencies.add(dNode); + dependencies.add(eNode); + dependencies.add(fNode); + dependencies.add(gNode); + + return new VnfcDependencyModel(dependencies); + + } + + private SvcLogicContext prepareContextForComplexDependency() { + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("input.action-identifiers.vnf-id","1"); + context.setAttribute("vnf.type","vSCP"); + context.setAttribute("vnf.vnfcCount","7"); + + context.setAttribute("vnf.vnfc[0].name","A"); + context.setAttribute("vnf.vnfc[0].type","A"); + context.setAttribute("vnf.vnfc[0].vm_count","2"); + context.setAttribute("vnf.vnfc[0].vm[0].url","A1"); + context.setAttribute("vnf.vnfc[0].vm[1].url","A2"); + + context.setAttribute("vnf.vnfc[1].name","B"); + context.setAttribute("vnf.vnfc[1].type","B"); + context.setAttribute("vnf.vnfc[1].vm_count","5"); + context.setAttribute("vnf.vnfc[1].vm[0].url","B1"); + context.setAttribute("vnf.vnfc[1].vm[1].url","B2"); + context.setAttribute("vnf.vnfc[1].vm[2].url","B3"); + context.setAttribute("vnf.vnfc[1].vm[3].url","B4"); + context.setAttribute("vnf.vnfc[1].vm[4].url","B5"); + + context.setAttribute("vnf.vnfc[2].name","C"); + context.setAttribute("vnf.vnfc[2].type","C"); + context.setAttribute("vnf.vnfc[2].vm_count","4"); + context.setAttribute("vnf.vnfc[2].vm[0].url","C1"); + context.setAttribute("vnf.vnfc[2].vm[1].url","C2"); + context.setAttribute("vnf.vnfc[2].vm[2].url","C3"); + context.setAttribute("vnf.vnfc[2].vm[3].url","C4"); + + context.setAttribute("vnf.vnfc[3].name","D"); + context.setAttribute("vnf.vnfc[3].type","D"); + context.setAttribute("vnf.vnfc[3].vm_count","3"); + context.setAttribute("vnf.vnfc[3].vm[0].url","D1"); + context.setAttribute("vnf.vnfc[3].vm[1].url","D2"); + context.setAttribute("vnf.vnfc[3].vm[2].url","D3"); + + context.setAttribute("vnf.vnfc[4].name","E"); + context.setAttribute("vnf.vnfc[4].type","E"); + context.setAttribute("vnf.vnfc[4].vm_count","2"); + context.setAttribute("vnf.vnfc[4].vm[0].url","E1"); + context.setAttribute("vnf.vnfc[4].vm[1].url","E2"); + + context.setAttribute("vnf.vnfc[5].name","F"); + context.setAttribute("vnf.vnfc[5].type","F"); + context.setAttribute("vnf.vnfc[5].vm_count","1"); + context.setAttribute("vnf.vnfc[5].vm[0].url","F1"); + + context.setAttribute("vnf.vnfc[6].name","G"); + context.setAttribute("vnf.vnfc[6].type","G"); + context.setAttribute("vnf.vnfc[6].vm_count","1"); + context.setAttribute("vnf.vnfc[6].vm[0].url","G1"); + + + return context; + } + + private VnfcDependencyModel readComplexDependencyModel() { + Vnfc a = new Vnfc("A","Active-Passive",null); + Vnfc b = new Vnfc("B","Active-Active",null); + Vnfc c = new Vnfc("C","Active-Active",null); + Vnfc d = new Vnfc("D","Active-Active",null); + Vnfc e = new Vnfc("E","Active-Active",null); + Vnfc f = new Vnfc("F","Active-Active",null); + Vnfc g = new Vnfc("G","Active-Active",null); + + + Node aNode = new Node(a); + Node bNode = new Node(b); + Node cNode = new Node(c); + Node dNode = new Node(d); + Node eNode = new Node(e); + Node fNode = new Node(f); + Node gNode = new Node(g); + + bNode.addParent(a); + cNode.addParent(a); + + dNode.addParent(b); + eNode.addParent(b); + gNode.addParent(b); + + fNode.addParent(c); + + gNode.addParent(f); + + Set<Node<Vnfc>> dependencies = new HashSet<>(); + dependencies.add(aNode); + dependencies.add(bNode); + dependencies.add(cNode); + dependencies.add(dNode); + dependencies.add(eNode); + dependencies.add(fNode); + dependencies.add(gNode); + + return new VnfcDependencyModel(dependencies); + } + + private VnfcDependencyModel readDependencyModel() { + + Vnfc smp = new Vnfc("SMP","Active-Passive",null); + Vnfc be = new Vnfc("BE","Active-Active",null); + Vnfc fe = new Vnfc("FE","Active-Active",null); + + + Node smpNode = new Node(smp); + Node beNode = new Node(be); + Node feNode = new Node(fe); + + beNode.addParent(smp); + feNode.addParent(be); +// smpNode.addParent(fe); + + Set<Node<Vnfc>> dependencies = new HashSet<>(); + dependencies.add(smpNode); + dependencies.add(feNode); + dependencies.add(beNode); + + return new VnfcDependencyModel(dependencies); + } + + private Map<String, String> prepareParams() { + Map<String,String> params = new HashMap<>(); + params.put(Constants.DEPENDENCY_TYPE,"RESOURCE"); + params.put(Constants.FLOW_STRATEGY,"FORWARD"); + + params.put(Constants.VNF_TYPE,"vSCP"); + params.put(Constants.VNF_VERION,"1.00"); + return params; + } + + private SvcLogicContext prepareContext() { + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("input.action-identifiers.vnf-id","1"); + context.setAttribute("vnf.type","vSCP"); + context.setAttribute("vnf.vnfcCount","3"); + + context.setAttribute("vnf.vnfc[0].name","SMPname"); + context.setAttribute("vnf.vnfc[0].type","SMP"); + context.setAttribute("vnf.vnfc[0].vm_count","2"); + context.setAttribute("vnf.vnfc[0].vm[0].url","SMP_URL1"); + context.setAttribute("vnf.vnfc[0].vm[1].url","SMP_URL2"); + + context.setAttribute("vnf.vnfc[1].name","BEname"); + context.setAttribute("vnf.vnfc[1].type","BE"); + context.setAttribute("vnf.vnfc[1].vm_count","5"); + context.setAttribute("vnf.vnfc[1].vm[0].url","BE_URL1"); + context.setAttribute("vnf.vnfc[1].vm[1].url","BE_URL2"); + context.setAttribute("vnf.vnfc[1].vm[2].url","BE_URL3"); + context.setAttribute("vnf.vnfc[1].vm[3].url","BE_URL4"); + context.setAttribute("vnf.vnfc[1].vm[4].url","BE_URL5"); + + context.setAttribute("vnf.vnfc[2].name","FEname"); + context.setAttribute("vnf.vnfc[2].type","FE"); + context.setAttribute("vnf.vnfc[2].vm_count","2"); + context.setAttribute("vnf.vnfc[2].vm[0].url","FE_URL1"); + context.setAttribute("vnf.vnfc[2].vm[1].url","FE_URL2"); + + return context; + } + + @Test(expected = RuntimeException.class) + public void testMissingVnfcTypeInDependencyModel() throws DependencyModelNotFound { + Map<String, String> params = prepareParams(); + SvcLogicContext context = prepareContext(); + context.setAttribute("vnf.vnfc[3].name","XEname"); + context.setAttribute("vnf.vnfc[3].type","XE"); + context.setAttribute("vnf.vnfc[3].vm_count","2"); + context.setAttribute("vnf.vnfc[3].vm[0].url","XE_URL1"); + context.setAttribute("vnf.vnfc[3].vm[1].url","XE_URL2"); + context.setAttribute("vnf.vnfcCount","4"); + + VnfcDependencyModel dependencyModel = readDependencyModel(); + + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(( + DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } + + @Test(expected = RuntimeException.class) + public void testMissingMandatoryVnfcTypeInInventoryModel() throws DependencyModelNotFound { + Map<String, String> params = prepareParams(); + SvcLogicContext context = prepareContext(); + VnfcDependencyModel dependencyModel = readDependencyModel(); + + Vnfc xe = new Vnfc("XE","Active-Active",null, true); + Node xeNode = new Node(xe); + dependencyModel.getDependencies().add(xeNode); + + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(( + DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } + + @Test + public void testMissingOptionalVnfcTypeInInventoryModel() throws DependencyModelNotFound { + Map<String, String> params = prepareParams(); + SvcLogicContext context = prepareContext(); + VnfcDependencyModel dependencyModel = readDependencyModel(); + + Vnfc xe = new Vnfc("XE","Active-Active",null, false); + Node xeNode = new Node(xe); + dependencyModel.getDependencies().add(xeNode); + + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(( + DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } + + @Test + public void testMissingOptionalVnfcTypeInInventoryModelWithDependentChild() throws DependencyModelNotFound { + Map<String, String> params = prepareParams(); + SvcLogicContext context = prepareContext(); + context.setAttribute("vnf.vnfc[3].name","YEname"); + context.setAttribute("vnf.vnfc[3].type","YE"); + context.setAttribute("vnf.vnfc[3].vm_count","2"); + context.setAttribute("vnf.vnfc[3].vm[0].url","YE_URL1"); + context.setAttribute("vnf.vnfc[3].vm[1].url","YE_URL2"); + context.setAttribute("vnf.vnfcCount","4"); + + VnfcDependencyModel dependencyModel = readDependencyModel(); + + Vnfc xe = new Vnfc("XE","Active-Active",null, false); + Vnfc ye = new Vnfc("YE","Active-Active",null, true); + Node xeNode = new Node(xe); + Node yeNode = new Node(ye); + yeNode.addParent(xe); + + dependencyModel.getDependencies().add(yeNode); + dependencyModel.getDependencies().add(xeNode); + + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(( + DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } +} |