From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:19:06 -0800 Subject: Third part of onap rename This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../onap/appc/dg/common/DCAEReporterPlugin.java | 37 ++ .../org/onap/appc/dg/common/DgResolverPlugin.java | 35 ++ .../appc/dg/common/IntermediateMessageSender.java | 51 +++ .../java/org/onap/appc/dg/common/JsonDgUtil.java | 54 +++ .../java/org/onap/appc/dg/common/LegacyUtil.java | 43 +++ .../onap/appc/dg/common/OutputMessagePlugin.java | 38 ++ .../onap/appc/dg/common/VNFCDgResolverPlugin.java | 37 ++ .../org/onap/appc/dg/common/VNFConfigurator.java | 46 +++ .../org/onap/appc/dg/common/VnfExecutionFlow.java | 34 ++ .../onap/appc/dg/common/impl/AbstractResolver.java | 117 ++++++ .../dg/common/impl/AbstractResolverDataReader.java | 130 +++++++ .../org/onap/appc/dg/common/impl/Constants.java | 99 +++++ .../dg/common/impl/DCAEReporterPluginImpl.java | 168 +++++++++ .../appc/dg/common/impl/DgResolverPluginImpl.java | 71 ++++ .../java/org/onap/appc/dg/common/impl/FlowKey.java | 62 +++ .../common/impl/IntermediateMessageSenderImpl.java | 172 +++++++++ .../onap/appc/dg/common/impl/JsonDgUtilImpl.java | 199 ++++++++++ .../onap/appc/dg/common/impl/LegacyUtilImpl.java | 60 +++ .../dg/common/impl/OutputMessagePluginImpl.java | 73 ++++ .../dg/common/impl/ResolverDataReaderFactory.java | 47 +++ .../onap/appc/dg/common/impl/ResolverFactory.java | 46 +++ .../dg/common/impl/VNFCDgResolverPluginImpl.java | 39 ++ .../org/onap/appc/dg/common/impl/VNFCResolver.java | 67 ++++ .../dg/common/impl/VNFCResolverDataReader.java | 40 ++ .../appc/dg/common/impl/VNFConfiguratorImpl.java | 115 ++++++ .../org/onap/appc/dg/common/impl/VNFResolver.java | 63 ++++ .../appc/dg/common/impl/VNFResolverDataReader.java | 43 +++ .../appc/dg/common/impl/VnfExecutionFlowImpl.java | 271 +++++++++++++ .../appc/dg/common/objects/ConnectionDetails.java | 68 ++++ .../org/onap/appc/dg/common/utils/JAXBUtil.java | 53 +++ .../org/onap/appc/dg/common/utils/JSONUtil.java | 83 ++++ .../appc/dg/common/DCAEReporterPlugin.java | 37 -- .../openecomp/appc/dg/common/DgResolverPlugin.java | 35 -- .../appc/dg/common/IntermediateMessageSender.java | 51 --- .../org/openecomp/appc/dg/common/JsonDgUtil.java | 54 --- .../org/openecomp/appc/dg/common/LegacyUtil.java | 43 --- .../appc/dg/common/OutputMessagePlugin.java | 38 -- .../appc/dg/common/VNFCDgResolverPlugin.java | 37 -- .../openecomp/appc/dg/common/VNFConfigurator.java | 46 --- .../openecomp/appc/dg/common/VnfExecutionFlow.java | 34 -- .../appc/dg/common/impl/AbstractResolver.java | 117 ------ .../dg/common/impl/AbstractResolverDataReader.java | 130 ------- .../openecomp/appc/dg/common/impl/Constants.java | 99 ----- .../dg/common/impl/DCAEReporterPluginImpl.java | 168 --------- .../appc/dg/common/impl/DgResolverPluginImpl.java | 71 ---- .../org/openecomp/appc/dg/common/impl/FlowKey.java | 62 --- .../common/impl/IntermediateMessageSenderImpl.java | 172 --------- .../appc/dg/common/impl/JsonDgUtilImpl.java | 199 ---------- .../appc/dg/common/impl/LegacyUtilImpl.java | 60 --- .../dg/common/impl/OutputMessagePluginImpl.java | 73 ---- .../dg/common/impl/ResolverDataReaderFactory.java | 47 --- .../appc/dg/common/impl/ResolverFactory.java | 46 --- .../dg/common/impl/VNFCDgResolverPluginImpl.java | 39 -- .../appc/dg/common/impl/VNFCResolver.java | 67 ---- .../dg/common/impl/VNFCResolverDataReader.java | 40 -- .../appc/dg/common/impl/VNFConfiguratorImpl.java | 115 ------ .../openecomp/appc/dg/common/impl/VNFResolver.java | 63 ---- .../appc/dg/common/impl/VNFResolverDataReader.java | 43 --- .../appc/dg/common/impl/VnfExecutionFlowImpl.java | 271 ------------- .../appc/dg/common/objects/ConnectionDetails.java | 68 ---- .../openecomp/appc/dg/common/utils/JAXBUtil.java | 53 --- .../openecomp/appc/dg/common/utils/JSONUtil.java | 83 ---- .../resources/org/onap/appc/default.properties | 50 +++ .../org/openecomp/appc/default.properties | 50 --- .../dg/common/impl/DCAEReporterPluginImplTest.java | 119 ++++++ .../onap/appc/dg/common/impl/EventSenderMock.java | 69 ++++ .../appc/dg/common/impl/JsonDgUtilImplTest.java | 172 +++++++++ .../dg/common/impl/TestVNFConfiguratorImpl.java | 108 ++++++ .../dg/common/impl/TestVnfExecutionFlowImpl.java | 420 +++++++++++++++++++++ .../dg/common/impl/DCAEReporterPluginImplTest.java | 119 ------ .../appc/dg/common/impl/EventSenderMock.java | 69 ---- .../appc/dg/common/impl/JsonDgUtilImplTest.java | 172 --------- .../dg/common/impl/TestVNFConfiguratorImpl.java | 108 ------ .../dg/common/impl/TestVnfExecutionFlowImpl.java | 420 --------------------- 74 files changed, 3399 insertions(+), 3399 deletions(-) create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DCAEReporterPlugin.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DgResolverPlugin.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/IntermediateMessageSender.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/JsonDgUtil.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/LegacyUtil.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/OutputMessagePlugin.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFCDgResolverPlugin.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFConfigurator.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VnfExecutionFlow.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolver.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolverDataReader.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/Constants.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImpl.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DgResolverPluginImpl.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/FlowKey.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/LegacyUtilImpl.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/OutputMessagePluginImpl.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverDataReaderFactory.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverFactory.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCDgResolverPluginImpl.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolver.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolverDataReader.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFConfiguratorImpl.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolver.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolverDataReader.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/objects/ConnectionDetails.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JAXBUtil.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JSONUtil.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/DCAEReporterPlugin.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/DgResolverPlugin.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/IntermediateMessageSender.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/JsonDgUtil.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/LegacyUtil.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/OutputMessagePlugin.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFCDgResolverPlugin.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFConfigurator.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VnfExecutionFlow.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolver.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolverDataReader.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/Constants.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DgResolverPluginImpl.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/FlowKey.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/IntermediateMessageSenderImpl.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImpl.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/LegacyUtilImpl.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/OutputMessagePluginImpl.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverDataReaderFactory.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverFactory.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCDgResolverPluginImpl.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolver.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolverDataReader.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFConfiguratorImpl.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolver.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolverDataReader.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VnfExecutionFlowImpl.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/objects/ConnectionDetails.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/utils/JAXBUtil.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/utils/JSONUtil.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/org/onap/appc/default.properties delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/org/openecomp/appc/default.properties create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/JsonDgUtilImplTest.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVNFConfiguratorImpl.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVnfExecutionFlowImpl.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/EventSenderMock.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVNFConfiguratorImpl.java delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVnfExecutionFlowImpl.java (limited to 'appc-dg/appc-dg-shared/appc-dg-common') diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DCAEReporterPlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DCAEReporterPlugin.java new file mode 100644 index 000000000..17bb56f66 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DCAEReporterPlugin.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common; + +import java.util.Map; + +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + + +public interface DCAEReporterPlugin extends SvcLogicJavaPlugin { + void report(Map params, SvcLogicContext ctx) throws APPCException; + void reportSuccess(Map params, SvcLogicContext ctx) throws APPCException; +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DgResolverPlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DgResolverPlugin.java new file mode 100644 index 000000000..b0ee4a5c9 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/DgResolverPlugin.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common; + +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +import java.util.Map; + +public interface DgResolverPlugin extends SvcLogicJavaPlugin { + void resolveDg(Map params, SvcLogicContext ctx) throws APPCException; +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/IntermediateMessageSender.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/IntermediateMessageSender.java new file mode 100644 index 000000000..3e03c2ff7 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/IntermediateMessageSender.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +import java.util.Map; + +/** + * 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 params, SvcLogicContext context); +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/JsonDgUtil.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/JsonDgUtil.java new file mode 100644 index 000000000..95143e145 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/JsonDgUtil.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common; + +import java.util.Map; + +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + + +public interface JsonDgUtil extends SvcLogicJavaPlugin { + void flatAndAddToContext(Map params, SvcLogicContext ctx) throws APPCException; + + void generateOutputPayloadFromContext(Map params, SvcLogicContext ctx) throws APPCException; + + /** + * Creates filename and content in Json format. + * @param params + * @param ctx + * @throws APPCException + */ + void cvaasFileNameAndFileContentToContext(Map params, SvcLogicContext ctx) throws APPCException; + + /** + * Checks if a file is created. + * @param params + * @param ctx + * @throws APPCException + */ + void checkFileCreated(Map params, SvcLogicContext ctx) throws APPCException; +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/LegacyUtil.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/LegacyUtil.java new file mode 100644 index 000000000..54456b385 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/LegacyUtil.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common; + +import java.util.Map; + +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + + + +public interface LegacyUtil extends SvcLogicJavaPlugin { + + void prepareRequest(Map params, SvcLogicContext ctx) throws APPCException; + + void convertPositiveResponse(Map params, SvcLogicContext ctx) throws APPCException; + + void convertNegativeResponse(Map params, SvcLogicContext ctx) throws APPCException; + +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/OutputMessagePlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/OutputMessagePlugin.java new file mode 100644 index 000000000..935aa877d --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/OutputMessagePlugin.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +import java.util.Map; + +import org.onap.appc.exceptions.APPCException; + +public interface OutputMessagePlugin extends SvcLogicJavaPlugin { + + void outputMessageBuilder(Map params, SvcLogicContext ctx) throws APPCException; + +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFCDgResolverPlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFCDgResolverPlugin.java new file mode 100644 index 000000000..06036c225 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFCDgResolverPlugin.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +import java.util.Map; + +import org.onap.appc.exceptions.APPCException; + + +public interface VNFCDgResolverPlugin extends SvcLogicJavaPlugin { + void resolveVNFCDg(Map params, SvcLogicContext ctx) throws APPCException; +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFConfigurator.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFConfigurator.java new file mode 100644 index 000000000..4ce0a9150 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VNFConfigurator.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common; + +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +import java.util.Map; +/** + * DG plugin created for VNF configuration operation to store data in MD-SAL store + **/ +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 params, SvcLogicContext context) throws APPCException; +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VnfExecutionFlow.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VnfExecutionFlow.java new file mode 100644 index 000000000..b25eaf10f --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/VnfExecutionFlow.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +import java.util.Map; + +public interface VnfExecutionFlow extends SvcLogicJavaPlugin { + void getVnfExecutionFlowData(Map params, SvcLogicContext context); +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolver.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolver.java new file mode 100644 index 000000000..3c70bab84 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolver.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import org.onap.appc.rankingframework.RankedAttributesResolver; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.util.concurrent.locks.ReentrantLock; + +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 dgResolver; + + private final ReentrantLock INIT_LOCK = new ReentrantLock(); + + AbstractResolver(int interval) { + this.interval = interval * 1000; + } + + private RankedAttributesResolver createResolver(String resolverType) { + AbstractResolverDataReader reader = ResolverDataReaderFactory.createResolverDataReader(resolverType); + return reader.read(); + } + + private boolean isExpired() { + return (System.currentTimeMillis() - lastUpdate) > interval; + } + + protected RankedAttributesResolver 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 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/onap/appc/dg/common/impl/AbstractResolverDataReader.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolverDataReader.java new file mode 100644 index 000000000..c5fe87c77 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/AbstractResolverDataReader.java @@ -0,0 +1,130 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import org.onap.appc.dao.util.DBUtils; +import org.onap.appc.rankingframework.AbstractRankedAttributesResolverFactory; +import org.onap.appc.rankingframework.ConfigurationEntry; +import org.onap.appc.rankingframework.ConfigurationSet; +import org.onap.appc.rankingframework.RankedAttributesResolver; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; +import java.util.Iterator; + +abstract class AbstractResolverDataReader { + + private class ConfigurationSetAdaptor implements ConfigurationSet { + + private final ResultSet resultSet; + + private class ResultSetIterator implements Iterator>, ConfigurationEntry { + @Override + public boolean hasNext() { + try { + return resultSet.next(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + @Override + public ConfigurationEntry 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> getEntries() { + return new Iterable>() { + + @Override + public Iterator> iterator() { + return new ResultSetIterator(); + } + }; + } + + @Override + public Collection getRankedAttributeNames() { + return getAttributeNames(); + } + } + + protected abstract Collection getAttributeNames(); + protected abstract String getQueryStmt(); + + + + RankedAttributesResolver 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 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/onap/appc/dg/common/impl/Constants.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/Constants.java new file mode 100644 index 000000000..603b65a19 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/Constants.java @@ -0,0 +1,99 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + + + +class Constants { + + public static final String DG_ERROR_FIELD_NAME = "org.onap.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.onap.appc.apiversion"; + public static final String REQ_ID_FIELD_NAME = "org.onap.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.onap.appc.action"), + VMID("org.onap.appc.vmid"), + IdentityURL("org.onap.appc.identity.url"), + TenantID("org.onap.appc.tenant.id"), + SkipHypervisorCheck("org.onap.appc.skiphypervisorcheck"); + + private String value; + LegacyAttributes(String value) {this.value = value;} + String getValue() {return value;} + }; + + enum LCMAttributes { + Action("input.action"), + Payload("input.payload"), + VMID("vm-id"), + IdentityURL("identity-url"), + 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/onap/appc/dg/common/impl/DCAEReporterPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImpl.java new file mode 100644 index 000000000..68f3cdc68 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImpl.java @@ -0,0 +1,168 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import org.apache.commons.lang3.StringUtils; +import org.onap.appc.adapter.message.EventSender; +import org.onap.appc.adapter.message.MessageDestination; +import org.onap.appc.adapter.message.event.EventHeader; +import org.onap.appc.adapter.message.event.EventMessage; +import org.onap.appc.adapter.message.event.EventStatus; +import org.onap.appc.dg.common.DCAEReporterPlugin; +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import java.util.Map; + +public class DCAEReporterPluginImpl implements DCAEReporterPlugin { + + private EventSender eventSender; + + public DCAEReporterPluginImpl() { + // do nothing + } + + /** + * Injected by blueprint + * + * @param eventSender to be set + */ + public void setEventSender(EventSender eventSender) { + this.eventSender = eventSender; + } + + @Override + public void report(Map params, SvcLogicContext ctx) throws APPCException { + String errorDescription,apiVersion,eventId ; + + Integer errorCode = readErrorCode(params,ctx); + errorDescription = params.get(Constants.EVENT_MESSAGE); + + if(StringUtils.isEmpty(errorDescription)) { + reportLegacy(params , ctx); + }else{ + apiVersion = ctx.getAttribute("input.common-header.api-ver"); + eventId = ctx.getAttribute("input.common-header.request-id"); + + 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 Integer readErrorCode(Map params, SvcLogicContext ctx) { + Integer errorReportCode = 501; + String errorCodeStr = params.get(Constants.DG_ERROR_CODE); + errorCodeStr = StringUtils.isEmpty(errorCodeStr)? + ctx.getAttribute(Constants.DG_ERROR_CODE):errorCodeStr; + try{ + errorReportCode = Integer.parseInt(errorCodeStr); + } + catch (NumberFormatException e){ + // Ignore Exception + } + return errorReportCode; + } + + @Override + public void reportSuccess(Map params, SvcLogicContext ctx) throws APPCException { + Integer successReportCode = 500; + String successDescription, apiVersion, eventId; + successDescription = params.get(Constants.EVENT_MESSAGE); + + if(StringUtils.isEmpty(successDescription)) { + successDescription = params.get(Constants.DG_OUTPUT_STATUS_MESSAGE); + } + + apiVersion = ctx.getAttribute("input.common-header.api-ver"); + eventId = ctx.getAttribute("input.common-header.request-id"); + + if (null == successDescription) { + successDescription = "Success"; + } + EventMessage eventMessage = new EventMessage(new EventHeader( + (new java.util.Date()).toString(), apiVersion, eventId), + new EventStatus(successReportCode, successDescription)); + String eventWriteTopic = params.get("event-topic-name"); + if(!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic!=null){ + eventSender.sendEvent(MessageDestination.DCAE, eventMessage,eventWriteTopic); + }else { + eventSender.sendEvent(MessageDestination.DCAE, eventMessage); + } + } + + private void reportLegacy(Map 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 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/onap/appc/dg/common/impl/DgResolverPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DgResolverPluginImpl.java new file mode 100644 index 000000000..c68fde5a2 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/DgResolverPluginImpl.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.i18n.Msg; +import com.att.eelf.i18n.EELFResourceManager; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import java.util.Map; + +import org.onap.appc.dg.common.DgResolverPlugin; + +public class DgResolverPluginImpl implements DgResolverPlugin { + + @Override + public void resolveDg(Map 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/onap/appc/dg/common/impl/FlowKey.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/FlowKey.java new file mode 100644 index 000000000..68f596f5d --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/FlowKey.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.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/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java new file mode 100644 index 000000000..026fa2841 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/IntermediateMessageSenderImpl.java @@ -0,0 +1,172 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.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.lang3.StringUtils; +import org.onap.appc.adapter.message.MessageAdapterFactory; +import org.onap.appc.adapter.message.Producer; +import org.onap.appc.configuration.Configuration; +import org.onap.appc.configuration.ConfigurationFactory; +import org.onap.appc.dg.common.IntermediateMessageSender; +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.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 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 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 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 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 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/onap/appc/dg/common/impl/JsonDgUtilImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java new file mode 100644 index 000000000..fff43cbf5 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java @@ -0,0 +1,199 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.appc.dg.common.JsonDgUtil; +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.i18n.Msg; +import org.onap.appc.util.JsonUtil; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.att.eelf.i18n.EELFResourceManager; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + + +public class JsonDgUtilImpl implements JsonDgUtil { + private static final EELFLogger logger = EELFManager.getInstance().getLogger(JsonDgUtilImpl.class); + + private static final ThreadLocal DATE_TIME_PARSER_THREAD_LOCAL = new ThreadLocal() { + protected SimpleDateFormat initialValue() { + return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + } + }; + + @Override + public void flatAndAddToContext(Map params, SvcLogicContext ctx) throws APPCException { + + if (logger.isTraceEnabled()) { + logger.trace("Entering to flatAndAddToContext with params = "+ ObjectUtils.toString(params)+", SvcLogicContext = "+ObjectUtils.toString(ctx)); + } + try { + String paramName = Constants.PAYLOAD; + String payload = params.get(paramName); + if (payload == "") + payload = ctx.getAttribute("input.payload"); + if (!StringUtils.isEmpty(payload)) { + Map flatMap = JsonUtil.convertJsonStringToFlatMap(payload); + if (flatMap != null && flatMap.size() > 0) { + for (Map.Entry entry : flatMap.entrySet()) { + ctx.setAttribute(entry.getKey(), entry.getValue()); + } + } + } else { + logger.warn("input payload param value is empty (\"\") or null"); + } + } 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 params, SvcLogicContext ctx) throws APPCException{ + if (logger.isTraceEnabled()) { + logger.trace("Entering to generateOutputPayloadFromContext with SvcLogicContext = "+ObjectUtils.toString(ctx)); + } + + try { + Set 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 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 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/onap/appc/dg/common/impl/LegacyUtilImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/LegacyUtilImpl.java new file mode 100644 index 000000000..ad0884b94 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/LegacyUtilImpl.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import java.util.Map; + +import org.onap.appc.dg.common.LegacyUtil; +import org.onap.appc.dg.common.utils.JSONUtil; +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + + + +public class LegacyUtilImpl implements LegacyUtil { + + @Override public void prepareRequest(Map params, SvcLogicContext ctx) throws APPCException { + ctx.setAttribute(Constants.LegacyAttributes.Action.getValue(), ctx.getAttribute(Constants.LCMAttributes.Action.getValue()).toLowerCase()); + + String payloadStr = ctx.getAttribute(Constants.LCMAttributes.Payload.getValue()); + Map payloads = JSONUtil.extractPlainValues(payloadStr, + Constants.LCMAttributes.VMID.getValue(), Constants.LCMAttributes.IdentityURL.getValue(), Constants.LCMAttributes.TenantID.getValue(), + Constants.LCMAttributes.SkipHypervisorCheck.getValue()); + + ctx.setAttribute(Constants.LegacyAttributes.VMID.getValue(), payloads.get(Constants.LCMAttributes.VMID.getValue())); + ctx.setAttribute(Constants.LegacyAttributes.IdentityURL.getValue(), payloads.get(Constants.LCMAttributes.IdentityURL.getValue())); + ctx.setAttribute(Constants.LegacyAttributes.TenantID.getValue(), payloads.get(Constants.LCMAttributes.TenantID.getValue())); + ctx.setAttribute(Constants.LegacyAttributes.SkipHypervisorCheck.getValue(), payloads.get(Constants.LCMAttributes.SkipHypervisorCheck.getValue())); + + } + + @Override + public void convertPositiveResponse(Map params, SvcLogicContext ctx) throws APPCException { + } + + @Override + public void convertNegativeResponse(Map params, SvcLogicContext ctx) throws APPCException { + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/OutputMessagePluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/OutputMessagePluginImpl.java new file mode 100644 index 000000000..66ac82fcb --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/OutputMessagePluginImpl.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import java.util.Map; + +import org.onap.appc.dg.common.OutputMessagePlugin; +import org.onap.appc.exceptions.APPCException; + +import static org.apache.commons.lang3.StringUtils.isEmpty; + +public class OutputMessagePluginImpl implements OutputMessagePlugin { + + @Override + public void outputMessageBuilder(Map 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/onap/appc/dg/common/impl/ResolverDataReaderFactory.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverDataReaderFactory.java new file mode 100644 index 000000000..790547f37 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverDataReaderFactory.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import org.onap.appc.configuration.Configuration; +import org.onap.appc.configuration.ConfigurationFactory; + +public class ResolverDataReaderFactory { + private static final Configuration configuration = ConfigurationFactory.getConfiguration(); + private static class ReferenceHolder{ + private static 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/onap/appc/dg/common/impl/ResolverFactory.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverFactory.java new file mode 100644 index 000000000..e39546846 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/ResolverFactory.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import org.onap.appc.configuration.Configuration; +import org.onap.appc.configuration.ConfigurationFactory; + +public class ResolverFactory { + private static final Configuration configuration = ConfigurationFactory.getConfiguration(); + private static class ReferenceHolder{ + private static final AbstractResolver VNFC_RESOLVER = new VNFCResolver(configuration.getIntegerProperty("org.onap.appc.workflow.resolver.refresh_interval", 300)); + private static final AbstractResolver VNF_RESOLVER = new VNFResolver(configuration.getIntegerProperty("org.onap.appc.workflow.resolver.refresh_interval", 300)); + } + + 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/onap/appc/dg/common/impl/VNFCDgResolverPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCDgResolverPluginImpl.java new file mode 100644 index 000000000..304bdf882 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCDgResolverPluginImpl.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import java.util.Map; + +public class VNFCDgResolverPluginImpl implements org.onap.appc.dg.common.VNFCDgResolverPlugin { + @Override + public void resolveVNFCDg(Map params, SvcLogicContext ctx) throws APPCException { + DgResolverPluginImpl dgResolverPlugin = new DgResolverPluginImpl(); + params.put("DGResolutionType" , "VNFC"); + dgResolverPlugin.resolveDg(params,ctx); + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolver.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolver.java new file mode 100644 index 000000000..e2893951b --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolver.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import org.onap.appc.rankingframework.RankedAttributesContext; + + +public class VNFCResolver extends AbstractResolver { + VNFCResolver(int interval) { + super(interval); + } + + @Override + protected FlowKey resolve(String... args) { + if(args.length !=4){ + 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/onap/appc/dg/common/impl/VNFCResolverDataReader.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolverDataReader.java new file mode 100644 index 000000000..c78da685c --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFCResolverDataReader.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import java.util.Arrays; +import java.util.Collection; + +public class VNFCResolverDataReader extends AbstractResolverDataReader { + @Override + protected Collection getAttributeNames() { + return Arrays.asList("action","api_version", "vnf_type", "vnfc_type"); + } + + @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/onap/appc/dg/common/impl/VNFConfiguratorImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFConfiguratorImpl.java new file mode 100644 index 000000000..c46a9c227 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFConfiguratorImpl.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import org.onap.appc.Constants; +import org.onap.appc.dg.common.VNFConfigurator; +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.mdsal.MDSALStore; +import org.onap.appc.mdsal.exception.MDSALStoreException; +import org.onap.appc.mdsal.impl.MDSALStoreFactory; +import org.onap.appc.mdsal.objects.BundleInfo; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.apache.commons.lang3.StringUtils; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; + + +public class VNFConfiguratorImpl implements VNFConfigurator { + + 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 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/onap/appc/dg/common/impl/VNFResolver.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolver.java new file mode 100644 index 000000000..501ad0713 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolver.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import org.onap.appc.rankingframework.RankedAttributesContext; + +public class VNFResolver extends AbstractResolver { + VNFResolver(int interval) { + super(interval); + } + + @Override + protected FlowKey resolve(String... args) { + return resolve(args[0],args[1],args[2],args[3]); + } + + + 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/onap/appc/dg/common/impl/VNFResolverDataReader.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolverDataReader.java new file mode 100644 index 000000000..3c4cf837e --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VNFResolverDataReader.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import java.util.Arrays; +import java.util.Collection; + +/** + * @since January 19,2017 + */ +public class VNFResolverDataReader extends AbstractResolverDataReader { + @Override + protected Collection getAttributeNames() { + return Arrays.asList("action","api_version", "vnf_type", "vnf_version"); + } + + @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/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java new file mode 100644 index 000000000..65b364f62 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java @@ -0,0 +1,271 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.att.eelf.i18n.EELFResourceManager; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import java.util.*; + +import org.onap.appc.dg.common.VnfExecutionFlow; +import org.onap.appc.dg.dependencymanager.DependencyManager; +import org.onap.appc.dg.dependencymanager.exception.DependencyModelNotFound; +import org.onap.appc.dg.dependencymanager.impl.DependencyModelFactory; +import org.onap.appc.dg.flowbuilder.FlowBuilder; +import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.onap.appc.dg.flowbuilder.impl.FlowBuilderFactory; +import org.onap.appc.dg.objects.*; +import org.onap.appc.domainmodel.Vnf; +import org.onap.appc.domainmodel.Vnfc; +import org.onap.appc.domainmodel.Vserver; +import org.onap.appc.i18n.Msg; +import org.onap.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 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.onap.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg); + } + + private void validateInput(String dependencyType, String flowStrategy, Map 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> 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 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 dependencyModelVnfcSet = new HashSet(); + Set dependencyModelMandatoryVnfcSet = new HashSet(); + Set inventoryModelVnfcsSet = new HashSet(); + + for (Node 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 difference = new HashSet(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 difference = new HashSet(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> flowIterator = flowModel.getModelIterator(); + while (flowIterator.hasNext()) { + Iterator 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/java/org/onap/appc/dg/common/objects/ConnectionDetails.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/objects/ConnectionDetails.java new file mode 100644 index 000000000..1572e726b --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/objects/ConnectionDetails.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.objects; + + + +public class ConnectionDetails { + + private String host; + private int port; + private String username; + private String password; + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JAXBUtil.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JAXBUtil.java new file mode 100644 index 000000000..38012b1bd --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JAXBUtil.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.utils; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; + + + +public class JAXBUtil { + + public static T toObject(String xml, Class type) throws JAXBException { + + //create JAXB context + JAXBContext context = JAXBContext.newInstance(type); + + //Create Unmarshaller using JAXB context + Unmarshaller unmarshaller = context.createUnmarshaller(); + + InputStream xmlInputStream = new ByteArrayInputStream(xml.getBytes()); + BufferedReader reader = new BufferedReader(new InputStreamReader(xmlInputStream)); + + return type.cast(unmarshaller.unmarshal(reader)); + + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JSONUtil.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JSONUtil.java new file mode 100644 index 000000000..388295a7d --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/utils/JSONUtil.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.utils; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.io.Reader; +import java.util.*; + + +public class JSONUtil { + + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + public static T fromJson(String json, Class clazz) { + + try { + return OBJECT_MAPPER.readValue(json, clazz); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static T fromJson(Reader reader, Class clazz) { + + try { + return OBJECT_MAPPER.readValue(reader, clazz); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static String toJson(Object object) { + + try { + return OBJECT_MAPPER.writeValueAsString(object); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static Map extractPlainValues(String json, String ... names) { + if (null == names) return Collections.emptyMap(); + Map values = new HashMap<>(); + try { + final JsonNode jsonNode = OBJECT_MAPPER.readTree(json); + for (String name : names) { + values.put(name, jsonNode.path(name).asText()); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + return values; + } + + + + +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/DCAEReporterPlugin.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/DCAEReporterPlugin.java deleted file mode 100644 index 17bb56f66..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/DCAEReporterPlugin.java +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common; - -import java.util.Map; - -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - - -public interface DCAEReporterPlugin extends SvcLogicJavaPlugin { - void report(Map params, SvcLogicContext ctx) throws APPCException; - void reportSuccess(Map params, SvcLogicContext ctx) throws APPCException; -} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/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 deleted file mode 100644 index b0ee4a5c9..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/DgResolverPlugin.java +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common; - -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -import java.util.Map; - -public interface DgResolverPlugin extends SvcLogicJavaPlugin { - void resolveDg(Map params, SvcLogicContext ctx) throws APPCException; -} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/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 deleted file mode 100644 index 3e03c2ff7..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/IntermediateMessageSender.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -import java.util.Map; - -/** - * 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 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 deleted file mode 100644 index 95143e145..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/JsonDgUtil.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common; - -import java.util.Map; - -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - - -public interface JsonDgUtil extends SvcLogicJavaPlugin { - void flatAndAddToContext(Map params, SvcLogicContext ctx) throws APPCException; - - void generateOutputPayloadFromContext(Map params, SvcLogicContext ctx) throws APPCException; - - /** - * Creates filename and content in Json format. - * @param params - * @param ctx - * @throws APPCException - */ - void cvaasFileNameAndFileContentToContext(Map params, SvcLogicContext ctx) throws APPCException; - - /** - * Checks if a file is created. - * @param params - * @param ctx - * @throws APPCException - */ - void checkFileCreated(Map params, SvcLogicContext ctx) throws APPCException; -} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/LegacyUtil.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/LegacyUtil.java deleted file mode 100644 index 54456b385..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/LegacyUtil.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common; - -import java.util.Map; - -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - - - -public interface LegacyUtil extends SvcLogicJavaPlugin { - - void prepareRequest(Map params, SvcLogicContext ctx) throws APPCException; - - void convertPositiveResponse(Map params, SvcLogicContext ctx) throws APPCException; - - void convertNegativeResponse(Map 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 deleted file mode 100644 index 935aa877d..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/OutputMessagePlugin.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -import java.util.Map; - -import org.onap.appc.exceptions.APPCException; - -public interface OutputMessagePlugin extends SvcLogicJavaPlugin { - - void outputMessageBuilder(Map 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 deleted file mode 100644 index 06036c225..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFCDgResolverPlugin.java +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -import java.util.Map; - -import org.onap.appc.exceptions.APPCException; - - -public interface VNFCDgResolverPlugin extends SvcLogicJavaPlugin { - void resolveVNFCDg(Map params, SvcLogicContext ctx) throws APPCException; -} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/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 deleted file mode 100644 index 4ce0a9150..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VNFConfigurator.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common; - -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -import java.util.Map; -/** - * DG plugin created for VNF configuration operation to store data in MD-SAL store - **/ -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 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 deleted file mode 100644 index b25eaf10f..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/VnfExecutionFlow.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -import java.util.Map; - -public interface VnfExecutionFlow extends SvcLogicJavaPlugin { - void getVnfExecutionFlowData(Map 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 deleted file mode 100644 index 3c70bab84..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolver.java +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import org.onap.appc.rankingframework.RankedAttributesResolver; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.util.concurrent.locks.ReentrantLock; - -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 dgResolver; - - private final ReentrantLock INIT_LOCK = new ReentrantLock(); - - AbstractResolver(int interval) { - this.interval = interval * 1000; - } - - private RankedAttributesResolver createResolver(String resolverType) { - AbstractResolverDataReader reader = ResolverDataReaderFactory.createResolverDataReader(resolverType); - return reader.read(); - } - - private boolean isExpired() { - return (System.currentTimeMillis() - lastUpdate) > interval; - } - - protected RankedAttributesResolver 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 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 deleted file mode 100644 index c5fe87c77..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/AbstractResolverDataReader.java +++ /dev/null @@ -1,130 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import org.onap.appc.dao.util.DBUtils; -import org.onap.appc.rankingframework.AbstractRankedAttributesResolverFactory; -import org.onap.appc.rankingframework.ConfigurationEntry; -import org.onap.appc.rankingframework.ConfigurationSet; -import org.onap.appc.rankingframework.RankedAttributesResolver; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Collection; -import java.util.Iterator; - -abstract class AbstractResolverDataReader { - - private class ConfigurationSetAdaptor implements ConfigurationSet { - - private final ResultSet resultSet; - - private class ResultSetIterator implements Iterator>, ConfigurationEntry { - @Override - public boolean hasNext() { - try { - return resultSet.next(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - @Override - public ConfigurationEntry 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> getEntries() { - return new Iterable>() { - - @Override - public Iterator> iterator() { - return new ResultSetIterator(); - } - }; - } - - @Override - public Collection getRankedAttributeNames() { - return getAttributeNames(); - } - } - - protected abstract Collection getAttributeNames(); - protected abstract String getQueryStmt(); - - - - RankedAttributesResolver 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 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 deleted file mode 100644 index 603b65a19..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/Constants.java +++ /dev/null @@ -1,99 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - - - -class Constants { - - public static final String DG_ERROR_FIELD_NAME = "org.onap.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.onap.appc.apiversion"; - public static final String REQ_ID_FIELD_NAME = "org.onap.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.onap.appc.action"), - VMID("org.onap.appc.vmid"), - IdentityURL("org.onap.appc.identity.url"), - TenantID("org.onap.appc.tenant.id"), - SkipHypervisorCheck("org.onap.appc.skiphypervisorcheck"); - - private String value; - LegacyAttributes(String value) {this.value = value;} - String getValue() {return value;} - }; - - enum LCMAttributes { - Action("input.action"), - Payload("input.payload"), - VMID("vm-id"), - IdentityURL("identity-url"), - 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 deleted file mode 100644 index 68f3cdc68..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImpl.java +++ /dev/null @@ -1,168 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import org.apache.commons.lang3.StringUtils; -import org.onap.appc.adapter.message.EventSender; -import org.onap.appc.adapter.message.MessageDestination; -import org.onap.appc.adapter.message.event.EventHeader; -import org.onap.appc.adapter.message.event.EventMessage; -import org.onap.appc.adapter.message.event.EventStatus; -import org.onap.appc.dg.common.DCAEReporterPlugin; -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import java.util.Map; - -public class DCAEReporterPluginImpl implements DCAEReporterPlugin { - - private EventSender eventSender; - - public DCAEReporterPluginImpl() { - // do nothing - } - - /** - * Injected by blueprint - * - * @param eventSender to be set - */ - public void setEventSender(EventSender eventSender) { - this.eventSender = eventSender; - } - - @Override - public void report(Map params, SvcLogicContext ctx) throws APPCException { - String errorDescription,apiVersion,eventId ; - - Integer errorCode = readErrorCode(params,ctx); - errorDescription = params.get(Constants.EVENT_MESSAGE); - - if(StringUtils.isEmpty(errorDescription)) { - reportLegacy(params , ctx); - }else{ - apiVersion = ctx.getAttribute("input.common-header.api-ver"); - eventId = ctx.getAttribute("input.common-header.request-id"); - - 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 Integer readErrorCode(Map params, SvcLogicContext ctx) { - Integer errorReportCode = 501; - String errorCodeStr = params.get(Constants.DG_ERROR_CODE); - errorCodeStr = StringUtils.isEmpty(errorCodeStr)? - ctx.getAttribute(Constants.DG_ERROR_CODE):errorCodeStr; - try{ - errorReportCode = Integer.parseInt(errorCodeStr); - } - catch (NumberFormatException e){ - // Ignore Exception - } - return errorReportCode; - } - - @Override - public void reportSuccess(Map params, SvcLogicContext ctx) throws APPCException { - Integer successReportCode = 500; - String successDescription, apiVersion, eventId; - successDescription = params.get(Constants.EVENT_MESSAGE); - - if(StringUtils.isEmpty(successDescription)) { - successDescription = params.get(Constants.DG_OUTPUT_STATUS_MESSAGE); - } - - apiVersion = ctx.getAttribute("input.common-header.api-ver"); - eventId = ctx.getAttribute("input.common-header.request-id"); - - if (null == successDescription) { - successDescription = "Success"; - } - EventMessage eventMessage = new EventMessage(new EventHeader( - (new java.util.Date()).toString(), apiVersion, eventId), - new EventStatus(successReportCode, successDescription)); - String eventWriteTopic = params.get("event-topic-name"); - if(!StringUtils.isEmpty(eventWriteTopic) && eventWriteTopic!=null){ - eventSender.sendEvent(MessageDestination.DCAE, eventMessage,eventWriteTopic); - }else { - eventSender.sendEvent(MessageDestination.DCAE, eventMessage); - } - } - - private void reportLegacy(Map 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 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 deleted file mode 100644 index c68fde5a2..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/DgResolverPluginImpl.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.i18n.Msg; -import com.att.eelf.i18n.EELFResourceManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import java.util.Map; - -import org.onap.appc.dg.common.DgResolverPlugin; - -public class DgResolverPluginImpl implements DgResolverPlugin { - - @Override - public void resolveDg(Map 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 deleted file mode 100644 index 68f596f5d..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/FlowKey.java +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.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 deleted file mode 100644 index 026fa2841..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/IntermediateMessageSenderImpl.java +++ /dev/null @@ -1,172 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.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.lang3.StringUtils; -import org.onap.appc.adapter.message.MessageAdapterFactory; -import org.onap.appc.adapter.message.Producer; -import org.onap.appc.configuration.Configuration; -import org.onap.appc.configuration.ConfigurationFactory; -import org.onap.appc.dg.common.IntermediateMessageSender; -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.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 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 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 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 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 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 deleted file mode 100644 index fff43cbf5..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImpl.java +++ /dev/null @@ -1,199 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import java.io.File; -import java.text.SimpleDateFormat; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.appc.dg.common.JsonDgUtil; -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.i18n.Msg; -import org.onap.appc.util.JsonUtil; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.att.eelf.i18n.EELFResourceManager; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - - -public class JsonDgUtilImpl implements JsonDgUtil { - private static final EELFLogger logger = EELFManager.getInstance().getLogger(JsonDgUtilImpl.class); - - private static final ThreadLocal DATE_TIME_PARSER_THREAD_LOCAL = new ThreadLocal() { - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - } - }; - - @Override - public void flatAndAddToContext(Map params, SvcLogicContext ctx) throws APPCException { - - if (logger.isTraceEnabled()) { - logger.trace("Entering to flatAndAddToContext with params = "+ ObjectUtils.toString(params)+", SvcLogicContext = "+ObjectUtils.toString(ctx)); - } - try { - String paramName = Constants.PAYLOAD; - String payload = params.get(paramName); - if (payload == "") - payload = ctx.getAttribute("input.payload"); - if (!StringUtils.isEmpty(payload)) { - Map flatMap = JsonUtil.convertJsonStringToFlatMap(payload); - if (flatMap != null && flatMap.size() > 0) { - for (Map.Entry entry : flatMap.entrySet()) { - ctx.setAttribute(entry.getKey(), entry.getValue()); - } - } - } else { - logger.warn("input payload param value is empty (\"\") or null"); - } - } 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 params, SvcLogicContext ctx) throws APPCException{ - if (logger.isTraceEnabled()) { - logger.trace("Entering to generateOutputPayloadFromContext with SvcLogicContext = "+ObjectUtils.toString(ctx)); - } - - try { - Set 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 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 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 deleted file mode 100644 index ad0884b94..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/LegacyUtilImpl.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import java.util.Map; - -import org.onap.appc.dg.common.LegacyUtil; -import org.onap.appc.dg.common.utils.JSONUtil; -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - - - -public class LegacyUtilImpl implements LegacyUtil { - - @Override public void prepareRequest(Map params, SvcLogicContext ctx) throws APPCException { - ctx.setAttribute(Constants.LegacyAttributes.Action.getValue(), ctx.getAttribute(Constants.LCMAttributes.Action.getValue()).toLowerCase()); - - String payloadStr = ctx.getAttribute(Constants.LCMAttributes.Payload.getValue()); - Map payloads = JSONUtil.extractPlainValues(payloadStr, - Constants.LCMAttributes.VMID.getValue(), Constants.LCMAttributes.IdentityURL.getValue(), Constants.LCMAttributes.TenantID.getValue(), - Constants.LCMAttributes.SkipHypervisorCheck.getValue()); - - ctx.setAttribute(Constants.LegacyAttributes.VMID.getValue(), payloads.get(Constants.LCMAttributes.VMID.getValue())); - ctx.setAttribute(Constants.LegacyAttributes.IdentityURL.getValue(), payloads.get(Constants.LCMAttributes.IdentityURL.getValue())); - ctx.setAttribute(Constants.LegacyAttributes.TenantID.getValue(), payloads.get(Constants.LCMAttributes.TenantID.getValue())); - ctx.setAttribute(Constants.LegacyAttributes.SkipHypervisorCheck.getValue(), payloads.get(Constants.LCMAttributes.SkipHypervisorCheck.getValue())); - - } - - @Override - public void convertPositiveResponse(Map params, SvcLogicContext ctx) throws APPCException { - } - - @Override - public void convertNegativeResponse(Map params, SvcLogicContext ctx) throws APPCException { - } -} 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 deleted file mode 100644 index 66ac82fcb..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/OutputMessagePluginImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import java.util.Map; - -import org.onap.appc.dg.common.OutputMessagePlugin; -import org.onap.appc.exceptions.APPCException; - -import static org.apache.commons.lang3.StringUtils.isEmpty; - -public class OutputMessagePluginImpl implements OutputMessagePlugin { - - @Override - public void outputMessageBuilder(Map 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 deleted file mode 100644 index 790547f37..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverDataReaderFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import org.onap.appc.configuration.Configuration; -import org.onap.appc.configuration.ConfigurationFactory; - -public class ResolverDataReaderFactory { - private static final Configuration configuration = ConfigurationFactory.getConfiguration(); - private static class ReferenceHolder{ - private static 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 deleted file mode 100644 index e39546846..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/ResolverFactory.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import org.onap.appc.configuration.Configuration; -import org.onap.appc.configuration.ConfigurationFactory; - -public class ResolverFactory { - private static final Configuration configuration = ConfigurationFactory.getConfiguration(); - private static class ReferenceHolder{ - private static final AbstractResolver VNFC_RESOLVER = new VNFCResolver(configuration.getIntegerProperty("org.onap.appc.workflow.resolver.refresh_interval", 300)); - private static final AbstractResolver VNF_RESOLVER = new VNFResolver(configuration.getIntegerProperty("org.onap.appc.workflow.resolver.refresh_interval", 300)); - } - - 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 deleted file mode 100644 index 304bdf882..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCDgResolverPluginImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import java.util.Map; - -public class VNFCDgResolverPluginImpl implements org.onap.appc.dg.common.VNFCDgResolverPlugin { - @Override - public void resolveVNFCDg(Map params, SvcLogicContext ctx) throws APPCException { - DgResolverPluginImpl dgResolverPlugin = new DgResolverPluginImpl(); - params.put("DGResolutionType" , "VNFC"); - dgResolverPlugin.resolveDg(params,ctx); - } -} 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 deleted file mode 100644 index e2893951b..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolver.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import org.onap.appc.rankingframework.RankedAttributesContext; - - -public class VNFCResolver extends AbstractResolver { - VNFCResolver(int interval) { - super(interval); - } - - @Override - protected FlowKey resolve(String... args) { - if(args.length !=4){ - 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 deleted file mode 100644 index c78da685c..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFCResolverDataReader.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import java.util.Arrays; -import java.util.Collection; - -public class VNFCResolverDataReader extends AbstractResolverDataReader { - @Override - protected Collection getAttributeNames() { - return Arrays.asList("action","api_version", "vnf_type", "vnfc_type"); - } - - @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 deleted file mode 100644 index c46a9c227..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFConfiguratorImpl.java +++ /dev/null @@ -1,115 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import org.onap.appc.Constants; -import org.onap.appc.dg.common.VNFConfigurator; -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.mdsal.MDSALStore; -import org.onap.appc.mdsal.exception.MDSALStoreException; -import org.onap.appc.mdsal.impl.MDSALStoreFactory; -import org.onap.appc.mdsal.objects.BundleInfo; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.apache.commons.lang3.StringUtils; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Map; - - -public class VNFConfiguratorImpl implements VNFConfigurator { - - 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 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 deleted file mode 100644 index 501ad0713..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolver.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import org.onap.appc.rankingframework.RankedAttributesContext; - -public class VNFResolver extends AbstractResolver { - VNFResolver(int interval) { - super(interval); - } - - @Override - protected FlowKey resolve(String... args) { - return resolve(args[0],args[1],args[2],args[3]); - } - - - 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 deleted file mode 100644 index 3c4cf837e..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VNFResolverDataReader.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import java.util.Arrays; -import java.util.Collection; - -/** - * @since January 19,2017 - */ -public class VNFResolverDataReader extends AbstractResolverDataReader { - @Override - protected Collection getAttributeNames() { - return Arrays.asList("action","api_version", "vnf_type", "vnf_version"); - } - - @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 deleted file mode 100644 index 65b364f62..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/impl/VnfExecutionFlowImpl.java +++ /dev/null @@ -1,271 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.att.eelf.i18n.EELFResourceManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import java.util.*; - -import org.onap.appc.dg.common.VnfExecutionFlow; -import org.onap.appc.dg.dependencymanager.DependencyManager; -import org.onap.appc.dg.dependencymanager.exception.DependencyModelNotFound; -import org.onap.appc.dg.dependencymanager.impl.DependencyModelFactory; -import org.onap.appc.dg.flowbuilder.FlowBuilder; -import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModel; -import org.onap.appc.dg.flowbuilder.impl.FlowBuilderFactory; -import org.onap.appc.dg.objects.*; -import org.onap.appc.domainmodel.Vnf; -import org.onap.appc.domainmodel.Vnfc; -import org.onap.appc.domainmodel.Vserver; -import org.onap.appc.i18n.Msg; -import org.onap.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 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.onap.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg); - } - - private void validateInput(String dependencyType, String flowStrategy, Map 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> 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 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 dependencyModelVnfcSet = new HashSet(); - Set dependencyModelMandatoryVnfcSet = new HashSet(); - Set inventoryModelVnfcsSet = new HashSet(); - - for (Node 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 difference = new HashSet(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 difference = new HashSet(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> flowIterator = flowModel.getModelIterator(); - while (flowIterator.hasNext()) { - Iterator 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/java/org/openecomp/appc/dg/common/objects/ConnectionDetails.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/objects/ConnectionDetails.java deleted file mode 100644 index 1572e726b..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/objects/ConnectionDetails.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.objects; - - - -public class ConnectionDetails { - - private String host; - private int port; - private String username; - private String password; - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - -} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/utils/JAXBUtil.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/utils/JAXBUtil.java deleted file mode 100644 index 38012b1bd..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/utils/JAXBUtil.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.utils; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.InputStreamReader; - - - -public class JAXBUtil { - - public static T toObject(String xml, Class type) throws JAXBException { - - //create JAXB context - JAXBContext context = JAXBContext.newInstance(type); - - //Create Unmarshaller using JAXB context - Unmarshaller unmarshaller = context.createUnmarshaller(); - - InputStream xmlInputStream = new ByteArrayInputStream(xml.getBytes()); - BufferedReader reader = new BufferedReader(new InputStreamReader(xmlInputStream)); - - return type.cast(unmarshaller.unmarshal(reader)); - - } -} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/utils/JSONUtil.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/utils/JSONUtil.java deleted file mode 100644 index 388295a7d..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/openecomp/appc/dg/common/utils/JSONUtil.java +++ /dev/null @@ -1,83 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.utils; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -import java.io.IOException; -import java.io.Reader; -import java.util.*; - - -public class JSONUtil { - - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - - public static T fromJson(String json, Class clazz) { - - try { - return OBJECT_MAPPER.readValue(json, clazz); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static T fromJson(Reader reader, Class clazz) { - - try { - return OBJECT_MAPPER.readValue(reader, clazz); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static String toJson(Object object) { - - try { - return OBJECT_MAPPER.writeValueAsString(object); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static Map extractPlainValues(String json, String ... names) { - if (null == names) return Collections.emptyMap(); - Map values = new HashMap<>(); - try { - final JsonNode jsonNode = OBJECT_MAPPER.readTree(json); - for (String name : names) { - values.put(name, jsonNode.path(name).asText()); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - return values; - } - - - - -} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/org/onap/appc/default.properties b/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/org/onap/appc/default.properties new file mode 100644 index 000000000..ec2a2b709 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/org/onap/appc/default.properties @@ -0,0 +1,50 @@ +### +# ============LICENSE_START======================================================= +# ONAP : APPC +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Copyright (C) 2017 Amdocs +# ============================================================================= +# 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. +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# ============LICENSE_END========================================================= +### + +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. + +org.onap.appc.netconf.db.url.netconfctl=jdbc:mysql://127.0.0.1:3306/test +org.onap.appc.netconf.db.user.netconfctl=test +org.onap.appc.netconf.db.pass.netconfctl=123456 + +org.onap.appc.db.url.sdnctl=jdbc:mysql://127.0.0.1:3306/test +org.onap.appc.db.user.sdnctl=test +org.onap.appc.db.pass.sdnctl=123456 + +org.onap.appc.netconf.db.url.sdnctl=jdbc:mysql://127.0.0.1:3306/test +org.onap.appc.netconf.db.user.sdnctl=test +org.onap.appc.netconf.db.pass.sdnctl=123456 + +### ### +### Properties commented out below provided in appc.properties ### +### ### +#event.pool.members= +event.topic.write=APPC-TEST1 +event.client.key=VIlbtVl6YLhNUrtU +event.client.secret=64AG2hF4pYeG2pq7CT6XwUOT +#restconf.user= +#restconf.pass= + +org.onap.appc.adapter.netconf.VNFOperationalStateValidatorImpl-CONFIG_FILE=VnfGetOperationalStates diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/org/openecomp/appc/default.properties b/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/org/openecomp/appc/default.properties deleted file mode 100644 index ec2a2b709..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/resources/org/openecomp/appc/default.properties +++ /dev/null @@ -1,50 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ONAP : APPC -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Copyright (C) 2017 Amdocs -# ============================================================================= -# 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. -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# ============LICENSE_END========================================================= -### - -org.onap.appc.bootstrap.file=appc.properties -org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. - -org.onap.appc.netconf.db.url.netconfctl=jdbc:mysql://127.0.0.1:3306/test -org.onap.appc.netconf.db.user.netconfctl=test -org.onap.appc.netconf.db.pass.netconfctl=123456 - -org.onap.appc.db.url.sdnctl=jdbc:mysql://127.0.0.1:3306/test -org.onap.appc.db.user.sdnctl=test -org.onap.appc.db.pass.sdnctl=123456 - -org.onap.appc.netconf.db.url.sdnctl=jdbc:mysql://127.0.0.1:3306/test -org.onap.appc.netconf.db.user.sdnctl=test -org.onap.appc.netconf.db.pass.sdnctl=123456 - -### ### -### Properties commented out below provided in appc.properties ### -### ### -#event.pool.members= -event.topic.write=APPC-TEST1 -event.client.key=VIlbtVl6YLhNUrtU -event.client.secret=64AG2hF4pYeG2pq7CT6XwUOT -#restconf.user= -#restconf.pass= - -org.onap.appc.adapter.netconf.VNFOperationalStateValidatorImpl-CONFIG_FILE=VnfGetOperationalStates diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java new file mode 100644 index 000000000..7c36360f8 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.*; +import org.onap.appc.adapter.message.EventSender; +import org.onap.appc.adapter.message.MessageDestination; +import org.onap.appc.adapter.message.event.EventMessage; +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import java.util.HashMap; +import java.util.Map; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({DCAEReporterPluginImpl.class, FrameworkUtil.class}) +public class DCAEReporterPluginImplTest { + private SvcLogicContext ctx; + private Map params; + + private final BundleContext bundleContext = Mockito.mock(BundleContext.class); + private final Bundle bundleService = Mockito.mock(Bundle.class); + private final ServiceReference sref = Mockito.mock(ServiceReference.class); + + @InjectMocks + private DCAEReporterPluginImpl dcaeReporterPlugin; + @Spy + private EventSenderMock eventSender = new EventSenderMock(); + + private String apiVer = "2.0.0"; + private String requestId = "123"; + private String error = "test-error"; + + @SuppressWarnings("unchecked") + @Before + public void setUp() throws NoSuchFieldException, IllegalAccessException { + PowerMockito.mockStatic(FrameworkUtil.class); + PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService); + PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext); + PowerMockito.when(bundleContext.getServiceReference(Matchers.any(Class.class))).thenReturn(sref); + PowerMockito.when(bundleContext.getService(sref)).thenReturn(eventSender); + } + + @Test + public void testReportErrorDescriptionNullBwcModeFalse() throws Exception { + ctx = new SvcLogicContext(); + params = new HashMap<>(); + params.put("output.status.message", null); + ctx.setAttribute("input.common-header.api-ver", apiVer); + ctx.setAttribute("input.common-header.request-id", requestId); + + errorReasonNullAssert(); + } + + @Test + public void testReportBwcFalse() throws Exception { + ctx = new SvcLogicContext(); + params = new HashMap<>(); + ctx.setAttribute("isBwcMode", "false"); + params.put("output.status.message", error); + ctx.setAttribute("input.common-header.api-ver", apiVer); + ctx.setAttribute("input.common-header.request-id", requestId); + + positiveAssert(); + } + + private void errorReasonNullAssert() throws APPCException { + dcaeReporterPlugin.report(params, ctx); + 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()); + Assert.assertEquals("wrong error message", "Unknown", msg.getEventStatus().getReason()); + Assert.assertEquals("wrong destination", destination.name(), "DCAE"); + } + + private void positiveAssert() throws APPCException { + dcaeReporterPlugin.report(params, ctx); + 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()); + Assert.assertEquals("wrong error message", error, msg.getEventStatus().getReason()); + Assert.assertEquals("wrong destination", destination.name(), "DCAE"); + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java new file mode 100644 index 000000000..cc30d3aea --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import java.util.Map; + +import org.onap.appc.adapter.message.EventSender; +import org.onap.appc.adapter.message.MessageDestination; +import org.onap.appc.adapter.message.event.EventMessage; +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + + +public class EventSenderMock implements EventSender { + EventMessage msg; + MessageDestination destination; + + @Override + public boolean sendEvent(MessageDestination destination, EventMessage msg) { + if (destination != null && msg != null){ + this.msg = msg; + this.destination = destination; + return true; + } + else{ + return false; + } + } + + @Override + public boolean sendEvent(MessageDestination destination, EventMessage msg, String eventTopicName) { + return false; + } + + @Override + public boolean sendEvent(MessageDestination destination, Map params, SvcLogicContext ctx) throws APPCException { + return false; + } + + public EventMessage getMsg() { + return msg; + } + + public MessageDestination getDestination() { + return destination; + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/JsonDgUtilImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/JsonDgUtilImplTest.java new file mode 100644 index 000000000..6f5a0f13d --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/JsonDgUtilImplTest.java @@ -0,0 +1,172 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import ch.qos.logback.core.Appender; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.appc.dg.common.impl.JsonDgUtilImpl; +import org.onap.appc.exceptions.APPCException; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import java.util.HashMap; +import java.util.Map; + +import static org.mockito.Mockito.mock; + +public class JsonDgUtilImplTest { + + private final Appender appender = mock(Appender.class); + + + @Test + public void testFlatAndAddToContext() throws Exception { + JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl(); + String key = "payload"; + String testValueKey = "test-key"; + String testValueValue = "test-value"; + String testValueKey2 = "test-key2"; + String testValueValue2 = "test-value2"; + String payload = "{\"" + testValueKey + "\": \"" + testValueValue + "\",\""+testValueKey2+"\": \""+testValueValue2+"\"}"; + + SvcLogicContext ctx = new SvcLogicContext(); + Map params = new HashMap<>(); + params.put(key, payload); + jsonDgUtil.flatAndAddToContext(params, ctx); + + + Assert.assertEquals(ctx.getAttribute(testValueKey), testValueValue); + Assert.assertEquals(ctx.getAttribute(testValueKey2), testValueValue2); + + + + } + + + @Test + public void testFlatAndAddToContextNegativeWrongPayload() throws Exception { + JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl(); + String key = "payload"; + String testValueKey = "test-key"; + String testValueValue = "test-value"; + String testValueKey2 = "test-key2"; + String testValueValue2 = "test-value2"; + String payload = "{{\"" + testValueKey + "\": \"" + testValueValue + "\",\""+testValueKey2+"\": \""+testValueValue2+"\"}"; + + SvcLogicContext ctx = new SvcLogicContext(); + Map params = new HashMap<>(); + params.put(key, payload); + try { + jsonDgUtil.flatAndAddToContext(params, ctx); + + } catch (APPCException e) { + Assert.assertNull(ctx.getAttribute(testValueKey)); + Assert.assertNull(ctx.getAttribute(testValueKey2)); + Assert.assertNotNull(ctx.getAttribute("error-message")); + } + + + } + + + @Test + public void testFlatAndAddToContextPayloadFromContext() throws Exception { + JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl(); + String key = "payload"; + String testValueKey = "test-key"; + String testValueValue = "test-value"; + String testValueKey2 = "test-key2"; + String testValueValue2 = "test-value2"; + String payload = "{\"" + testValueKey + "\": \"" + testValueValue + "\",\""+testValueKey2+"\": \""+testValueValue2+"\"}"; + + SvcLogicContext ctx = new SvcLogicContext(); + Map params = new HashMap<>(); + params.put(key, ""); + ctx.setAttribute("input.payload", payload); + jsonDgUtil.flatAndAddToContext(params, ctx); + + + Assert.assertEquals(ctx.getAttribute(testValueKey), testValueValue); + Assert.assertEquals(ctx.getAttribute(testValueKey2), testValueValue2); + } + + @Test + public void testFlatAndAddToContextNegativeNullPayload() throws Exception { + JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl(); + String testValueKey = "test-key"; + String testValueKey2 = "test-key2"; + SvcLogicContext ctx = new SvcLogicContext(); + Map params = new HashMap<>(); + jsonDgUtil.flatAndAddToContext(params, ctx); + + + Assert.assertNull(ctx.getAttribute(testValueKey)); + Assert.assertNull(ctx.getAttribute(testValueKey2)); + } + + + @Test + public void testFlatAndAddToContextNegativeEmptyPayload() throws Exception { + + JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl(); + String key = "payload"; + String testValueKey = "test-key"; + String testValueKey2 = "test-key2"; + + SvcLogicContext ctx = new SvcLogicContext(); + Map params = new HashMap<>(); + params.put(key, ""); + jsonDgUtil.flatAndAddToContext(params, ctx); + + 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 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/onap/appc/dg/common/impl/TestVNFConfiguratorImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVNFConfiguratorImpl.java new file mode 100644 index 000000000..ca3e7f5e2 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVNFConfiguratorImpl.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import org.onap.appc.dg.common.VNFConfigurator; +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.mdsal.MDSALStore; +import org.onap.appc.mdsal.impl.MDSALStoreFactory; +import org.onap.appc.mdsal.impl.MDSALStoreImpl; +import org.onap.appc.mdsal.objects.BundleInfo; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.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 params = new HashMap(); + 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 params = new HashMap(); + 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 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/onap/appc/dg/common/impl/TestVnfExecutionFlowImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVnfExecutionFlowImpl.java new file mode 100644 index 000000000..bad862030 --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVnfExecutionFlowImpl.java @@ -0,0 +1,420 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.onap.appc.dg.common.VnfExecutionFlow; +import org.onap.appc.dg.common.impl.Constants; +import org.onap.appc.dg.common.impl.VnfExecutionFlowImpl; +import org.onap.appc.dg.dependencymanager.DependencyManager; +import org.onap.appc.dg.dependencymanager.exception.DependencyModelNotFound; +import org.onap.appc.dg.dependencymanager.impl.DependencyModelFactory; +import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.onap.appc.dg.objects.DependencyTypes; +import org.onap.appc.dg.objects.Node; +import org.onap.appc.dg.objects.VnfcDependencyModel; +import org.onap.appc.domainmodel.Vnfc; +import org.onap.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 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 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 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> 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> 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> dependencies = new HashSet<>(); + dependencies.add(smpNode); + dependencies.add(feNode); + dependencies.add(beNode); + + return new VnfcDependencyModel(dependencies); + } + + private Map prepareParams() { + Map 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 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 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 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 params = prepareParams(); + SvcLogicContext context = prepareContext(); + context.setAttribute("vnf.vnfc[3].name","YEname"); + context.setAttribute("vnf.vnfc[3].type","YE"); + context.setAttribute("vnf.vnfc[3].vm_count","2"); + context.setAttribute("vnf.vnfc[3].vm[0].url","YE_URL1"); + context.setAttribute("vnf.vnfc[3].vm[1].url","YE_URL2"); + context.setAttribute("vnf.vnfcCount","4"); + + VnfcDependencyModel dependencyModel = readDependencyModel(); + + Vnfc xe = new Vnfc("XE","Active-Active",null, false); + Vnfc ye = new Vnfc("YE","Active-Active",null, true); + Node xeNode = new Node(xe); + Node yeNode = new Node(ye); + yeNode.addParent(xe); + + dependencyModel.getDependencies().add(yeNode); + dependencyModel.getDependencies().add(xeNode); + + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(( + DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } +} diff --git a/appc-dg/appc-dg-shared/appc-dg-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 deleted file mode 100644 index 7c36360f8..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/DCAEReporterPluginImplTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.*; -import org.onap.appc.adapter.message.EventSender; -import org.onap.appc.adapter.message.MessageDestination; -import org.onap.appc.adapter.message.event.EventMessage; -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import java.util.HashMap; -import java.util.Map; - - -@RunWith(PowerMockRunner.class) -@PrepareForTest({DCAEReporterPluginImpl.class, FrameworkUtil.class}) -public class DCAEReporterPluginImplTest { - private SvcLogicContext ctx; - private Map params; - - private final BundleContext bundleContext = Mockito.mock(BundleContext.class); - private final Bundle bundleService = Mockito.mock(Bundle.class); - private final ServiceReference sref = Mockito.mock(ServiceReference.class); - - @InjectMocks - private DCAEReporterPluginImpl dcaeReporterPlugin; - @Spy - private EventSenderMock eventSender = new EventSenderMock(); - - private String apiVer = "2.0.0"; - private String requestId = "123"; - private String error = "test-error"; - - @SuppressWarnings("unchecked") - @Before - public void setUp() throws NoSuchFieldException, IllegalAccessException { - PowerMockito.mockStatic(FrameworkUtil.class); - PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService); - PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext); - PowerMockito.when(bundleContext.getServiceReference(Matchers.any(Class.class))).thenReturn(sref); - PowerMockito.when(bundleContext.getService(sref)).thenReturn(eventSender); - } - - @Test - public void testReportErrorDescriptionNullBwcModeFalse() throws Exception { - ctx = new SvcLogicContext(); - params = new HashMap<>(); - params.put("output.status.message", null); - ctx.setAttribute("input.common-header.api-ver", apiVer); - ctx.setAttribute("input.common-header.request-id", requestId); - - errorReasonNullAssert(); - } - - @Test - public void testReportBwcFalse() throws Exception { - ctx = new SvcLogicContext(); - params = new HashMap<>(); - ctx.setAttribute("isBwcMode", "false"); - params.put("output.status.message", error); - ctx.setAttribute("input.common-header.api-ver", apiVer); - ctx.setAttribute("input.common-header.request-id", requestId); - - positiveAssert(); - } - - private void errorReasonNullAssert() throws APPCException { - dcaeReporterPlugin.report(params, ctx); - 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()); - Assert.assertEquals("wrong error message", "Unknown", msg.getEventStatus().getReason()); - Assert.assertEquals("wrong destination", destination.name(), "DCAE"); - } - - private void positiveAssert() throws APPCException { - dcaeReporterPlugin.report(params, ctx); - 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()); - Assert.assertEquals("wrong error message", error, msg.getEventStatus().getReason()); - Assert.assertEquals("wrong destination", destination.name(), "DCAE"); - } -} 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 deleted file mode 100644 index cc30d3aea..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/EventSenderMock.java +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import java.util.Map; - -import org.onap.appc.adapter.message.EventSender; -import org.onap.appc.adapter.message.MessageDestination; -import org.onap.appc.adapter.message.event.EventMessage; -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - - -public class EventSenderMock implements EventSender { - EventMessage msg; - MessageDestination destination; - - @Override - public boolean sendEvent(MessageDestination destination, EventMessage msg) { - if (destination != null && msg != null){ - this.msg = msg; - this.destination = destination; - return true; - } - else{ - return false; - } - } - - @Override - public boolean sendEvent(MessageDestination destination, EventMessage msg, String eventTopicName) { - return false; - } - - @Override - public boolean sendEvent(MessageDestination destination, Map params, SvcLogicContext ctx) throws APPCException { - return false; - } - - public EventMessage getMsg() { - return msg; - } - - 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 deleted file mode 100644 index 6f5a0f13d..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/JsonDgUtilImplTest.java +++ /dev/null @@ -1,172 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import ch.qos.logback.core.Appender; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.appc.dg.common.impl.JsonDgUtilImpl; -import org.onap.appc.exceptions.APPCException; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import java.util.HashMap; -import java.util.Map; - -import static org.mockito.Mockito.mock; - -public class JsonDgUtilImplTest { - - private final Appender appender = mock(Appender.class); - - - @Test - public void testFlatAndAddToContext() throws Exception { - JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl(); - String key = "payload"; - String testValueKey = "test-key"; - String testValueValue = "test-value"; - String testValueKey2 = "test-key2"; - String testValueValue2 = "test-value2"; - String payload = "{\"" + testValueKey + "\": \"" + testValueValue + "\",\""+testValueKey2+"\": \""+testValueValue2+"\"}"; - - SvcLogicContext ctx = new SvcLogicContext(); - Map params = new HashMap<>(); - params.put(key, payload); - jsonDgUtil.flatAndAddToContext(params, ctx); - - - Assert.assertEquals(ctx.getAttribute(testValueKey), testValueValue); - Assert.assertEquals(ctx.getAttribute(testValueKey2), testValueValue2); - - - - } - - - @Test - public void testFlatAndAddToContextNegativeWrongPayload() throws Exception { - JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl(); - String key = "payload"; - String testValueKey = "test-key"; - String testValueValue = "test-value"; - String testValueKey2 = "test-key2"; - String testValueValue2 = "test-value2"; - String payload = "{{\"" + testValueKey + "\": \"" + testValueValue + "\",\""+testValueKey2+"\": \""+testValueValue2+"\"}"; - - SvcLogicContext ctx = new SvcLogicContext(); - Map params = new HashMap<>(); - params.put(key, payload); - try { - jsonDgUtil.flatAndAddToContext(params, ctx); - - } catch (APPCException e) { - Assert.assertNull(ctx.getAttribute(testValueKey)); - Assert.assertNull(ctx.getAttribute(testValueKey2)); - Assert.assertNotNull(ctx.getAttribute("error-message")); - } - - - } - - - @Test - public void testFlatAndAddToContextPayloadFromContext() throws Exception { - JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl(); - String key = "payload"; - String testValueKey = "test-key"; - String testValueValue = "test-value"; - String testValueKey2 = "test-key2"; - String testValueValue2 = "test-value2"; - String payload = "{\"" + testValueKey + "\": \"" + testValueValue + "\",\""+testValueKey2+"\": \""+testValueValue2+"\"}"; - - SvcLogicContext ctx = new SvcLogicContext(); - Map params = new HashMap<>(); - params.put(key, ""); - ctx.setAttribute("input.payload", payload); - jsonDgUtil.flatAndAddToContext(params, ctx); - - - Assert.assertEquals(ctx.getAttribute(testValueKey), testValueValue); - Assert.assertEquals(ctx.getAttribute(testValueKey2), testValueValue2); - } - - @Test - public void testFlatAndAddToContextNegativeNullPayload() throws Exception { - JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl(); - String testValueKey = "test-key"; - String testValueKey2 = "test-key2"; - SvcLogicContext ctx = new SvcLogicContext(); - Map params = new HashMap<>(); - jsonDgUtil.flatAndAddToContext(params, ctx); - - - Assert.assertNull(ctx.getAttribute(testValueKey)); - Assert.assertNull(ctx.getAttribute(testValueKey2)); - } - - - @Test - public void testFlatAndAddToContextNegativeEmptyPayload() throws Exception { - - JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl(); - String key = "payload"; - String testValueKey = "test-key"; - String testValueKey2 = "test-key2"; - - SvcLogicContext ctx = new SvcLogicContext(); - Map params = new HashMap<>(); - params.put(key, ""); - jsonDgUtil.flatAndAddToContext(params, ctx); - - 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 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 deleted file mode 100644 index ca3e7f5e2..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVNFConfiguratorImpl.java +++ /dev/null @@ -1,108 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import org.onap.appc.dg.common.VNFConfigurator; -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.mdsal.MDSALStore; -import org.onap.appc.mdsal.impl.MDSALStoreFactory; -import org.onap.appc.mdsal.impl.MDSALStoreImpl; -import org.onap.appc.mdsal.objects.BundleInfo; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.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 params = new HashMap(); - 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 params = new HashMap(); - 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 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 deleted file mode 100644 index bad862030..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/openecomp/appc/dg/common/impl/TestVnfExecutionFlowImpl.java +++ /dev/null @@ -1,420 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.onap.appc.dg.common.VnfExecutionFlow; -import org.onap.appc.dg.common.impl.Constants; -import org.onap.appc.dg.common.impl.VnfExecutionFlowImpl; -import org.onap.appc.dg.dependencymanager.DependencyManager; -import org.onap.appc.dg.dependencymanager.exception.DependencyModelNotFound; -import org.onap.appc.dg.dependencymanager.impl.DependencyModelFactory; -import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModel; -import org.onap.appc.dg.objects.DependencyTypes; -import org.onap.appc.dg.objects.Node; -import org.onap.appc.dg.objects.VnfcDependencyModel; -import org.onap.appc.domainmodel.Vnfc; -import org.onap.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 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 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 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> 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> 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> dependencies = new HashSet<>(); - dependencies.add(smpNode); - dependencies.add(feNode); - dependencies.add(beNode); - - return new VnfcDependencyModel(dependencies); - } - - private Map prepareParams() { - Map 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 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 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 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 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); - } -} -- cgit 1.2.3-korg