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 --- .../artifact/handler/ArtifactHandlerProvider.java | 213 +++++++ .../handler/SdcArtifactHandlerActivator.java | 58 ++ .../artifact/handler/dbservices/DBService.java | 531 +++++++++++++++++ .../artifact/handler/node/ArtifactHandlerNode.java | 533 +++++++++++++++++ .../handler/utils/ArtifactHandlerProviderUtil.java | 191 ++++++ .../appc/artifact/handler/utils/EscapeUtils.java | 43 ++ .../handler/utils/SdcArtifactHandlerConstants.java | 93 +++ .../rev170321/ArtifactHandlerProviderModule.java | 59 ++ .../ArtifactHandlerProviderModuleFactory.java | 37 ++ .../rev170321/ArtifactHandlerProviderModule.java | 59 -- .../ArtifactHandlerProviderModuleFactory.java | 37 -- .../artifact/handler/ArtifactHandlerProvider.java | 213 ------- .../handler/SdcArtifactHandlerActivator.java | 58 -- .../artifact/handler/dbservices/DBService.java | 531 ----------------- .../artifact/handler/node/ArtifactHandlerNode.java | 533 ----------------- .../handler/utils/ArtifactHandlerProviderUtil.java | 191 ------ .../appc/artifact/handler/utils/EscapeUtils.java | 43 -- .../handler/utils/SdcArtifactHandlerConstants.java | 93 --- .../artifact/handler/dbservices/DBServiceTest.java | 298 ++++++++++ .../artifact/handler/dbservices/MockDBService.java | 51 ++ .../handler/dbservices/MockSvcLogicResource.java | 55 ++ .../handler/node/ArtifactHandlerNodeTest.java | 174 ++++++ .../handler/node/MockArtifactHandlerNode.java | 65 +++ .../utils/ArtifactHandlerProviderUtilTest.java | 82 +++ .../artifact/handler/dbservices/DBServiceTest.java | 298 ---------- .../artifact/handler/dbservices/MockDBService.java | 51 -- .../handler/dbservices/MockSvcLogicResource.java | 55 -- .../handler/node/ArtifactHandlerNodeTest.java | 174 ------ .../handler/node/MockArtifactHandlerNode.java | 65 --- .../utils/ArtifactHandlerProviderUtilTest.java | 82 --- .../org/onap/appc/design/data/ArtifactInfo.java | 42 ++ .../java/org/onap/appc/design/data/DesignInfo.java | 115 ++++ .../org/onap/appc/design/data/DesignRequest.java | 132 +++++ .../org/onap/appc/design/data/DesignResponse.java | 77 +++ .../java/org/onap/appc/design/data/StatusInfo.java | 86 +++ .../appc/design/dbervices/DbResponseProcessor.java | 110 ++++ .../org/onap/appc/design/dbervices/DbService.java | 146 +++++ .../appc/design/dbervices/DesignDBService.java | 645 +++++++++++++++++++++ .../appc/design/dbervices/RequestValidator.java | 126 ++++ .../propertyServices/PropertyUpdateService.java | 30 + .../design/services/DesignServiceProvider.java | 72 +++ .../design/services/impl/DesignServicesImpl.java | 160 +++++ .../services/util/ArtifactHandlerClient.java | 187 ++++++ .../services/util/DesignServiceConstants.java | 106 ++++ .../appc/design/services/util/EscapeUtils.java | 44 ++ .../util/SecureRestClientTrustManager.java | 58 ++ .../validator/ValidatorResponseProcessor.java | 38 ++ .../appc/design/validator/ValidatorService.java | 168 ++++++ .../appc/design/xinterface/XInterfaceService.java | 43 ++ .../appc/design/xinterface/XResponseProcessor.java | 38 ++ .../openecomp/appc/design/data/ArtifactInfo.java | 42 -- .../org/openecomp/appc/design/data/DesignInfo.java | 115 ---- .../openecomp/appc/design/data/DesignRequest.java | 132 ----- .../openecomp/appc/design/data/DesignResponse.java | 77 --- .../org/openecomp/appc/design/data/StatusInfo.java | 86 --- .../appc/design/dbervices/DbResponseProcessor.java | 110 ---- .../openecomp/appc/design/dbervices/DbService.java | 146 ----- .../appc/design/dbervices/DesignDBService.java | 645 --------------------- .../appc/design/dbervices/RequestValidator.java | 126 ---- .../propertyServices/PropertyUpdateService.java | 30 - .../design/services/DesignServiceProvider.java | 72 --- .../design/services/impl/DesignServicesImpl.java | 160 ----- .../services/util/ArtifactHandlerClient.java | 187 ------ .../services/util/DesignServiceConstants.java | 106 ---- .../appc/design/services/util/EscapeUtils.java | 44 -- .../util/SecureRestClientTrustManager.java | 58 -- .../validator/ValidatorResponseProcessor.java | 38 -- .../appc/design/validator/ValidatorService.java | 168 ------ .../appc/design/xinterface/XInterfaceService.java | 43 -- .../appc/design/xinterface/XResponseProcessor.java | 38 -- .../design/validator/TestArifactHandlerClient.java | 73 +++ .../onap/appc/design/validator/TestDBService.java | 242 ++++++++ .../onap/appc/design/validator/TestDbResponse.java | 51 ++ .../onap/appc/design/validator/TestDesigndata.java | 102 ++++ .../appc/design/validator/TestEscapeUtils.java | 52 ++ .../design/validator/TestValidatorService.java | 131 +++++ .../design/validator/TestArifactHandlerClient.java | 73 --- .../appc/design/validator/TestDBService.java | 242 -------- .../appc/design/validator/TestDbResponse.java | 51 -- .../appc/design/validator/TestDesigndata.java | 102 ---- .../appc/design/validator/TestEscapeUtils.java | 52 -- .../design/validator/TestValidatorService.java | 131 ----- 82 files changed, 5557 insertions(+), 5557 deletions(-) create mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/ArtifactHandlerProvider.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/SdcArtifactHandlerActivator.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/EscapeUtils.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModule.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModuleFactory.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModule.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModuleFactory.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/ArtifactHandlerProvider.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/SdcArtifactHandlerActivator.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/dbservices/DBService.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNode.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/EscapeUtils.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/DBServiceTest.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockDBService.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockSvcLogicResource.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/MockArtifactHandlerNode.java create mode 100644 appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/DBServiceTest.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/MockDBService.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/MockSvcLogicResource.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNodeTest.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/MockArtifactHandlerNode.java delete mode 100644 appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/ArtifactInfo.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignInfo.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignRequest.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignResponse.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/StatusInfo.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbService.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/propertyServices/PropertyUpdateService.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/DesignServiceProvider.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/DesignServicesImpl.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/EscapeUtils.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/SecureRestClientTrustManager.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/validator/ValidatorResponseProcessor.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/validator/ValidatorService.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java create mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/ArtifactInfo.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/DesignInfo.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/DesignRequest.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/DesignResponse.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/StatusInfo.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/DbResponseProcessor.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/DbService.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/DesignDBService.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/RequestValidator.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/propertyServices/PropertyUpdateService.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/DesignServiceProvider.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/impl/DesignServicesImpl.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/ArtifactHandlerClient.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/DesignServiceConstants.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/EscapeUtils.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/SecureRestClientTrustManager.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/validator/ValidatorResponseProcessor.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/validator/ValidatorService.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/xinterface/XInterfaceService.java delete mode 100644 appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/xinterface/XResponseProcessor.java create mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestArifactHandlerClient.java create mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDBService.java create mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDbResponse.java create mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesigndata.java create mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestEscapeUtils.java create mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestValidatorService.java delete mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestArifactHandlerClient.java delete mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDBService.java delete mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDbResponse.java delete mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDesigndata.java delete mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestEscapeUtils.java delete mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestValidatorService.java (limited to 'appc-inbound') diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/ArtifactHandlerProvider.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/ArtifactHandlerProvider.java new file mode 100644 index 000000000..d5ccd45b0 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/ArtifactHandlerProvider.java @@ -0,0 +1,213 @@ +/*- + * ============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.artifact.handler; + +import java.util.HashMap; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.ArtifactHandlerService; +import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactOutput; +import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.uploadartifact.output.ConfigDocumentResponseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.Services; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.ServicesBuilder; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.onap.appc.artifact.handler.node.ArtifactHandlerNode; +import org.onap.appc.artifact.handler.utils.ArtifactHandlerProviderUtil; +import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.Futures; + + + +public class ArtifactHandlerProvider implements AutoCloseable, ArtifactHandlerService, DataChangeListener { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerProvider.class); + private final String appName = "ArtifactsHandler"; + private final ExecutorService executor; + protected DataBroker dataBroker; + protected NotificationProviderService notificationService; + protected RpcProviderRegistry rpcRegistry; + private ListenerRegistration dclServices; + + protected BindingAwareBroker.RpcRegistration rpcRegistration; + + public ArtifactHandlerProvider(DataBroker dataBroker2, + NotificationProviderService notificationProviderService, + RpcProviderRegistry rpcProviderRegistry) { + this.log.info("Creating provider for " + appName); + executor = Executors.newFixedThreadPool(10); + dataBroker = dataBroker2; + notificationService = notificationProviderService; + rpcRegistry = rpcProviderRegistry; + initialize(); + + } + + public void initialize() { + log.info("Initializing provider for " + appName); + // Create the top level containers + createContainers(); + try { + ArtifactHandlerProviderUtil.loadProperties(); + } catch (Exception e) { + log.error("Caught Exception while trying to load properties file"); + } + // Listener for changes to Services tree + + rpcRegistration = rpcRegistry.addRpcImplementation( + ArtifactHandlerService.class, this); + + log.info("Initialization complete for " + appName); + } + private void createContainers() { + final WriteTransaction t = dataBroker.newReadWriteTransaction(); + // Create the Services container + t.merge(LogicalDatastoreType.CONFIGURATION,InstanceIdentifier.create(Services.class),new ServicesBuilder().build()); + t.merge(LogicalDatastoreType.OPERATIONAL,InstanceIdentifier.create(Services.class),new ServicesBuilder().build()); + + try { + CheckedFuture checkedFuture = t.submit(); + checkedFuture.get(); + log.info("Create Containers succeeded!: "); + + } catch (InterruptedException | ExecutionException e) { + log.error("Create Containers Failed: " + e); + e.printStackTrace(); + } + } + + + @Override + public void onDataChanged(AsyncDataChangeEvent, DataObject> arg0) { + // TODO Auto-generated method stub + + } + + + + @Override + public void close() throws Exception { + + log.info("Closing provider for " + appName); + if(this.executor != null){ + executor.shutdown(); + } + if(this.rpcRegistration != null){ + rpcRegistration.close(); + } + log.info("Successfully closed provider for " + appName); + + } + + private RpcResult buildResponse1( + String svcRequestId, + String topic, + String code, + String message, + String finalInd) { + + UploadartifactOutputBuilder responseBuilder = new UploadartifactOutputBuilder(); + ConfigDocumentResponseBuilder configResponseBuilder=new ConfigDocumentResponseBuilder(); + configResponseBuilder.setRequestId(svcRequestId); + configResponseBuilder.setStatus(code); + configResponseBuilder.setErrorReason(message); + RpcResult rpcResult = RpcResultBuilder. status(true) + .withResult(responseBuilder.build()).build(); + return rpcResult; + } + + @Override + public Future> uploadartifact(UploadartifactInput input) { + + if (input == null || input.getDocumentParameters() == null || input.getDocumentParameters().getArtifactContents() == null ) { + RpcResult rpcResult = + buildResponse1("N/A", "N/A", "INVALID_INPUT", "Invalid input, null or empty document information" , "Y"); + return Futures.immediateFuture(rpcResult); + } + UploadartifactInputBuilder inputBuilder = new UploadartifactInputBuilder(input); + ConfigDocumentResponseBuilder configResponseBuilder = new ConfigDocumentResponseBuilder(); + UploadartifactOutputBuilder responseBuilder = new UploadartifactOutputBuilder(); + log.info("Received input = " + input ); + ArtifactHandlerProviderUtil designUtil = new ArtifactHandlerProviderUtil(input); + configResponseBuilder.setRequestId(input.getRequestInformation().getRequestId()); + try{ + + if(input.getRequestInformation().getSource() !=null){ + if(input.getRequestInformation().getSource().equalsIgnoreCase(SdcArtifactHandlerConstants.DESIGN_TOOL)){ + designUtil.processTemplate(designUtil.createDummyRequestData()); + configResponseBuilder.setStatus(ArtifactHandlerProviderUtil.DistributionStatusEnum.DEPLOY_OK.toString()); + } + else + { + designUtil.processTemplate(designUtil.createRequestData()); + configResponseBuilder.setStatus(ArtifactHandlerProviderUtil.DistributionStatusEnum.DEPLOY_OK.toString()); + } + } + else + { + throw new Exception("No Tempalte data found"); + } + + + } + catch (Exception e) { + + configResponseBuilder.setErrorReason(e.getMessage()); + configResponseBuilder.setStatus(ArtifactHandlerProviderUtil.DistributionStatusEnum.DEPLOY_ERROR.toString()); + log.error("Caught exception looking for Artifact Handler", e); + log.info("Caught exception looking for Artifact Handler: "); + } + + responseBuilder.setConfigDocumentResponse(configResponseBuilder.build()); + RpcResult rpcResult = RpcResultBuilder. status(true).withResult(responseBuilder.build()).build(); + return Futures.immediateFuture(rpcResult); + + } +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/SdcArtifactHandlerActivator.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/SdcArtifactHandlerActivator.java new file mode 100644 index 000000000..ebbbe4735 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/SdcArtifactHandlerActivator.java @@ -0,0 +1,58 @@ +/*- + * ============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.artifact.handler; + +import java.util.LinkedList; +import java.util.List; + +import org.onap.appc.artifact.handler.node.ArtifactHandlerNode; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class SdcArtifactHandlerActivator implements BundleActivator { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(SdcArtifactHandlerActivator.class); + private List registrations = new LinkedList(); + + @Override + public void start(BundleContext ctx) throws Exception { + ArtifactHandlerNode artifactHandlerNode = new ArtifactHandlerNode(); + log.info("Registering service-- " + artifactHandlerNode.getClass().getName()); + registrations.add(ctx.registerService(artifactHandlerNode.getClass().getName(), artifactHandlerNode, null)); + + } + + @Override + public void stop(BundleContext arg0) throws Exception { + for (ServiceRegistration registration : registrations) { + registration.unregister(); + registration = null; + } + } +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java new file mode 100644 index 000000000..031d53e28 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java @@ -0,0 +1,531 @@ +/*- + * ============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.artifact.handler.dbservices; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; +import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; + +import java.sql.SQLException; +import java.util.HashMap; +import org.apache.commons.lang.StringUtils; + +public class DBService { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(DBService.class); + private SvcLogicResource serviceLogic; + private static DBService dgGeneralDBService = null; + + public static DBService initialise() { + if (dgGeneralDBService == null) { + dgGeneralDBService = new DBService(); + } + return dgGeneralDBService; + } + + private DBService() { + if (serviceLogic == null) { + serviceLogic = new SqlResource(); + } + } + + protected DBService(SqlResource svcLogic) { + if (serviceLogic == null) { + serviceLogic = svcLogic; + } + } + + public String getInternalVersionNumber(SvcLogicContext ctx, String artifactName, String prefix) + throws SvcLogicException { + String fn = "DBService.getInternalVersionNumber"; + QueryStatus status = null; + String artifactInternalVersion = null; + if (serviceLogic != null && ctx != null) { + String key = "select max(internal_version) as maximum from ASDC_ARTIFACTS WHERE ARTIFACT_NAME = '" + + artifactName + "'"; + log.info("Getting internal Versoin :" + key); + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + if (status.toString().equals("FAILURE")) + throw new SvcLogicException("Error - getting internal Artifact Number"); + artifactInternalVersion = ctx.getAttribute("maximum"); + log.info("Internal Version received as : " + artifactInternalVersion); + log.info("Internal Version received as1 : " + ctx.getAttribute("max(internal_version)")); + log.info("Internal Version received as1 : " + ctx.getAttribute("max")); + log.info("Internal Version received as1 : " + ctx.getAttribute("internal_version")); + log.info("Internal Version received as1 : " + ctx.getAttributeKeySet().toString()); + } + return artifactInternalVersion; + } + + public String getArtifactID(SvcLogicContext ctx, String artifactName) throws SvcLogicException { + String fn = "DBService.getArtifactID"; + QueryStatus status = null; + String artifactID = null; + if (serviceLogic != null && ctx != null) { + String key = "select max(ASDC_ARTIFACTS_ID) as id from ASDC_ARTIFACTS WHERE ARTIFACT_NAME = '" + + artifactName + "'"; + log.info("Getting Artifact ID String :" + key); + status = serviceLogic.query("SQL", false, null, key, null, null, ctx); + if (status.toString().equals("FAILURE")) + throw new SvcLogicException("Error - getting Artifact ID from database"); + artifactID = ctx.getAttribute("id"); + log.info("SDC_ARTIFACTS_ID received as : " + ctx.getAttribute("id")); + } + return artifactID; + } + + public QueryStatus saveArtifacts(SvcLogicContext ctx, int intversion) throws SvcLogicException { + String fn = "DBService.saveArtifacts"; + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "INSERT INTO ASDC_ARTIFACTS " + "SET SERVICE_UUID = $service-uuid , " + + " DISTRIBUTION_ID = $distribution-id ," + " SERVICE_NAME = $service-name ," + + " SERVICE_DESCRIPTION = $service-description ," + " RESOURCE_UUID = $resource-uuid ," + + " RESOURCE_INSTANCE_NAME = $resource-instance-name ," + " RESOURCE_NAME = $resource-name ," + + " RESOURCE_VERSION = $resource-version ," + " RESOURCE_TYPE = $resource-type ," + + " ARTIFACT_UUID = $artifact-uuid ," + " ARTIFACT_TYPE = $artifact-type ," + + " ARTIFACT_VERSION = $artifact-version ," + " ARTIFACT_DESCRIPTION = $artifact-description ," + + " INTERNAL_VERSION = " + intversion + "," + " ARTIFACT_NAME = $artifact-name ," + + " ARTIFACT_CONTENT = $artifact-contents "; + + status = serviceLogic.save("SQL", false, false, key, null, null, ctx); + if (status.toString().equals("FAILURE")) + throw new SvcLogicException("Error While processing storing Artifact: " + + ctx.getAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME)); + } + return status; + + } + + public QueryStatus logData(SvcLogicContext ctx, String prefix) throws SvcLogicException { + String fn = "DBService.saveReferenceData"; + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + String key = "INSERT INTO CONFIG_TRANSACTION_LOG " + " SET request_id = $request-id , " + + " message_type = $log-message-type , " + " message = $log-message ;"; + status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx); + if (status.toString().equals("FAILURE")) + throw new SvcLogicException("Error while loging data"); + + } + return status; + } + + public void processConfigureActionDg(SvcLogicContext context, boolean isUpdate) { + String fn = "DBService.processConfigureActionDg"; + log.info("Update Parameter for SDC Reference " + isUpdate); + String key = ""; + QueryStatus status = null; + if (isUpdate) + ; + } + + public void processSdcReferences(SvcLogicContext context, boolean isUpdate) throws SvcLogicException { + String fn = "DBService.processSdcReferences"; + String key = ""; + QueryStatus status = null; + + if (isUpdate && context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY).equals(SdcArtifactHandlerConstants.CAPABILITY)) { + log.info("Updating capability artifact in ASDC_REFERENCE"); + key = "update " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set ARTIFACT_NAME = $" + + SdcArtifactHandlerConstants.ARTIFACT_NAME + " where " + "FILE_CATEGORY = $" + + SdcArtifactHandlerConstants.FILE_CATEGORY + " and VNF_TYPE = $" + + SdcArtifactHandlerConstants.VNF_TYPE ; + } else if (isUpdate) + key = "update " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set ARTIFACT_NAME = $" + + SdcArtifactHandlerConstants.ARTIFACT_NAME + " where VNFC_TYPE = $" + + SdcArtifactHandlerConstants.VNFC_TYPE + " and FILE_CATEGORY = $" + + SdcArtifactHandlerConstants.FILE_CATEGORY + " and ACTION = $" + + SdcArtifactHandlerConstants.ACTION + " and VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE; + + else { + if (context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY).equals(SdcArtifactHandlerConstants.CAPABILITY)) { + key = "insert into " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set VNFC_TYPE = null " + + " , FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY + " , VNF_TYPE = $" + + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = null " + " , ARTIFACT_TYPE = null " + + " , ARTIFACT_NAME = $" + SdcArtifactHandlerConstants.ARTIFACT_NAME; + } else { + key = "insert into " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set VNFC_TYPE = $" + + SdcArtifactHandlerConstants.VNFC_TYPE + " , FILE_CATEGORY = $" + + SdcArtifactHandlerConstants.FILE_CATEGORY + " , VNF_TYPE = $" + + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = $" + SdcArtifactHandlerConstants.ACTION + + " , ARTIFACT_TYPE = $" + SdcArtifactHandlerConstants.ARTIFACT_TYPE + " , ARTIFACT_NAME = $" + + SdcArtifactHandlerConstants.ARTIFACT_NAME; + } + } + if (serviceLogic != null && context != null) { + log.info("Insert Key: " + key); + status = serviceLogic.save("SQL", false, false, key, null, null, context); + if (status.toString().equals("FAILURE")) + throw new SvcLogicException("Error While processing sdc_reference table "); + } + } + + public boolean isArtifactUpdateRequired(SvcLogicContext context, String db) throws SvcLogicException, SQLException { + String fn = "DBService.isArtifactUpdateRequired"; + log.info("Checking if Update required for this data"); + + log.info("db" + db); + log.info("ACTION=" + context.getAttribute(SdcArtifactHandlerConstants.ACTION)); + log.info("VNFC_TYPE=" + context.getAttribute(SdcArtifactHandlerConstants.VNFC_TYPE)); + log.info("VNFC_INSTANCE=" + context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE)); + log.info("VM_INSTANCE=" + context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE)); + log.info("VNF_TYPE=" + context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE)); + String whereClause = ""; + + QueryStatus status = null; + whereClause = " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE; + + if (db != null) { + if (db.equals(SdcArtifactHandlerConstants.DB_SDC_REFERENCE) + && context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY) + .equals(SdcArtifactHandlerConstants.CAPABILITY) + && context.getAttribute(SdcArtifactHandlerConstants.ACTION) == null) { + whereClause = whereClause + " and FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY; + } + + else if (db.equals(SdcArtifactHandlerConstants.DB_SDC_REFERENCE)) { + whereClause = whereClause + " and VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE + + " and FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY + " and ACTION = $" + + SdcArtifactHandlerConstants.ACTION; + } + + else if (db.equals(SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE)) { + whereClause = " where PROTOCOL = $" + SdcArtifactHandlerConstants.DEVICE_PROTOCOL; + } else if (db.equals(SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG)) { + whereClause = whereClause + " and ACTION = $" + SdcArtifactHandlerConstants.ACTION; + } else if (db.equals(SdcArtifactHandlerConstants.DB_VNFC_REFERENCE)) { + int vm_instance = -1; + if (context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE) != null) + vm_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE)); + int vnfc_instance = -1; + if (context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE) != null) + vnfc_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE)); + whereClause = whereClause + " and ACTION = $" + SdcArtifactHandlerConstants.ACTION + " and VNFC_TYPE = $" + + SdcArtifactHandlerConstants.VNFC_TYPE + " and VNFC_INSTANCE = $" + + SdcArtifactHandlerConstants.VNFC_INSTANCE + " and VM_INSTANCE = $" + + SdcArtifactHandlerConstants.VM_INSTANCE; + + } + } + + if (serviceLogic != null && context != null) { + String key = "select COUNT(*) from " + db + whereClause; + log.info("SELECT String : " + key); + status = serviceLogic.query("SQL", false, null, key, null, null, context); + if (status.toString().equals("FAILURE")) { + throw new SvcLogicException("Error while reading data from " + db); + } + String count = context.getAttribute("COUNT(*)"); + log.info("Number of row Returned : " + count + ": " + status + ":"); + if (count != null && Integer.parseInt(count) > 0) { + context.setAttribute(count, null); + return true; + } else + return false; + } + return false; + } + + public void processDeviceInterfaceProtocol(SvcLogicContext context, boolean isUpdate) throws SvcLogicException { + String fn = "DBService.processDeviceInterfaceProtocol"; + log.info("Starting DB operation for Device Interface Protocol " + isUpdate); + String key = ""; + QueryStatus status = null; + if (isUpdate) + key = "update " + SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL + " set PROTOCOL = $" + + SdcArtifactHandlerConstants.DEVICE_PROTOCOL + " , DG_RPC = 'getDeviceRunningConfig' " + + " , MODULE = 'APPC' " + " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE; + else + key = "insert into " + SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL + " set VNF_TYPE = $" + + SdcArtifactHandlerConstants.VNF_TYPE + " , PROTOCOL = $" + + SdcArtifactHandlerConstants.DEVICE_PROTOCOL + " , DG_RPC = 'getDeviceRunningConfig' " + + " , MODULE = 'APPC' "; + + if (serviceLogic != null && context != null) { + + status = serviceLogic.save("SQL", false, false, key, null, null, context); + if (status.toString().equals("FAILURE")) + throw new SvcLogicException("Error While processing DEVICE_INTERFACE_PROTOCOL table "); + } + + } + + public void processDeviceAuthentication(SvcLogicContext context, boolean isUpdate) throws SvcLogicException { + String fn = "DBService.processDeviceAuthentication"; + log.info(fn + "Starting DB operation for Device Authentication " + isUpdate); + String key = ""; + QueryStatus status = null; + if (isUpdate) + key = "update " + SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION + " set USER_NAME = $" + + SdcArtifactHandlerConstants.USER_NAME +/* " , PASSWORD = 'dummy' " +*/ " , PORT_NUMBER = $" + + SdcArtifactHandlerConstants.PORT_NUMBER + " where VNF_TYPE = $" + + SdcArtifactHandlerConstants.VNF_TYPE; + else + key = "insert into " + SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION + " set VNF_TYPE = $" + + SdcArtifactHandlerConstants.VNF_TYPE + " , USER_NAME = $" + SdcArtifactHandlerConstants.USER_NAME + +/* " , PASSWORD = 'dummy' " + */ " , PORT_NUMBER = $" + SdcArtifactHandlerConstants.PORT_NUMBER; + + if (serviceLogic != null && context != null) { + status = serviceLogic.save("SQL", false, false, key, null, null, context); + if (status.toString().equals("FAILURE")) + throw new SvcLogicException("Error While processing DEVICE_AUTHENTICATION table "); + } + } + + public void processVnfcReference(SvcLogicContext context, boolean isUpdate) throws SvcLogicException { + String fn = "DBService.processVnfcReference"; + log.info(fn + "Starting DB operation for Vnfc Reference " + isUpdate); + String key = ""; + int vm_instance = -1; + if (context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE) != null) + vm_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE)); + int vnfc_instance = -1; + if (context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE) != null) + vnfc_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE)); + QueryStatus status = null; + if (isUpdate) + key = "update " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE + " set VM_INSTANCE = " + vm_instance + + " , VNFC_INSTANCE = " + vnfc_instance + " , VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE + + " , VNFC_FUNCTION_CODE = $" + SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE + + " , GROUP_NOTATION_TYPE = $" + SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE + + " , GROUP_NOTATION_VALUE = $" + SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE + + " , IPADDRESS_V4_OAM_VIP = $" + SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP + + " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE + " and ACTION = $" + + SdcArtifactHandlerConstants.ACTION + " and VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE + + " and VNFC_INSTANCE = $" + SdcArtifactHandlerConstants.VNFC_INSTANCE + " and VM_INSTANCE = $" + + SdcArtifactHandlerConstants.VM_INSTANCE; + else + key = "insert into " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE + " set VNF_TYPE = $" + + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = $" + SdcArtifactHandlerConstants.ACTION + + " , VM_INSTANCE = $" + SdcArtifactHandlerConstants.VM_INSTANCE + " , VNFC_INSTANCE = $" + + SdcArtifactHandlerConstants.VNFC_INSTANCE + " , VNFC_TYPE = $" + + SdcArtifactHandlerConstants.VNFC_TYPE + " , VNFC_FUNCTION_CODE = $" + + SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE + " , GROUP_NOTATION_TYPE = $" + + SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE + " , IPADDRESS_V4_OAM_VIP = $" + + SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP + " , GROUP_NOTATION_VALUE = $" + + SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE; + + if (serviceLogic != null && context != null) { + status = serviceLogic.save("SQL", false, false, key, null, null, context); + if (status.toString().equals("FAILURE")) + throw new SvcLogicException("Error While processing VNFC_REFERENCE table "); + } + } + + public void processDownloadDgReference(SvcLogicContext context, boolean isUpdate) + throws SvcLogicException, SQLException { + String fn = "DBService.processDownloadDgReference"; + log.info(fn + "Starting DB operation for Download DG Reference " + isUpdate); + String key = ""; + QueryStatus status = null; + + if (isUpdate) + key = "update " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE + " set DOWNLOAD_CONFIG_DG = $" + + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " where PROTOCOL = $" + + SdcArtifactHandlerConstants.DEVICE_PROTOCOL; + else + key = "insert into " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE + " set DOWNLOAD_CONFIG_DG = $" + + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " , PROTOCOL = $" + + SdcArtifactHandlerConstants.DEVICE_PROTOCOL; + + if (serviceLogic != null && context != null) + status = serviceLogic.save("SQL", false, false, key, null, null, context); + if ((status == null) || status.toString().equals("FAILURE")) + throw new SvcLogicException("Error While processing DOWNLOAD_DG_REFERENCE table "); + } + + public void processConfigActionDg(SvcLogicContext context, boolean isUpdate) throws SvcLogicException { + String fn = "DBService.processConfigActionDg"; + log.info(fn + "Starting DB operation for Config DG Action " + isUpdate); + String key = ""; + QueryStatus status = null; + + if (context.getAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE) != null + && context.getAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE).length() > 0) { + if (isUpdate) + key = "update " + SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG + " set DOWNLOAD_CONFIG_DG = $" + + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " where ACTION = $" + + SdcArtifactHandlerConstants.ACTION + " and VNF_TYPE = $" + + SdcArtifactHandlerConstants.VNF_TYPE; + else + key = "insert into " + SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG + " set DOWNLOAD_CONFIG_DG = $" + + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " , ACTION = $" + + SdcArtifactHandlerConstants.ACTION + " , VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE; + + if (serviceLogic != null && context != null) + status = serviceLogic.save("SQL", false, false, key, null, null, context); + if ((status == null) || status.toString().equals("FAILURE")) + throw new SvcLogicException("Error While processing Configure DG Action table "); + } else + log.info("No Update required for Config DG Action"); + + } + + public String getModelDataInformationbyArtifactName(String artifact_name) throws SvcLogicException { + String fn = "DBService.getVnfData"; + String key = ""; + SvcLogicContext con = new SvcLogicContext(); + HashMap modelData = new HashMap(); + QueryStatus status = null; + key = "select VNF_TYPE, VNFC_TYPE, ACTION, FILE_CATEGORY, ARTIFACT_TYPE from ASDC_REFERENCE where ARTIFACT_NAME = " + + artifact_name; + + if (serviceLogic != null && con != null) { + log.info(fn + "select Key: " + key); + status = serviceLogic.query("SQL", false, null, key, null, null, con); + if (status.toString().equals("FAILURE")) + throw new SvcLogicException("Error While processing is ArtifactUpdateRequiredforPD table "); + + } + + log.info(fn + "Vnf_received :" + con.getAttribute("VNF_TYPE")); + + return con.getAttribute("VNF_TYPE"); + + } + + public void updateYangContents(SvcLogicContext context, String artifactId, String yangContents) + throws SvcLogicException { + String fn = "DBService.updateYangContents"; + log.info(fn + "Starting DB operation for updateYangContents"); + String key = ""; + QueryStatus status = null; + + key = "update ASDC_ARTIFACTS " + " set ARTIFACT_CONTENT = '" + yangContents + "'" + + " where ASDC_ARTIFACTS_ID = " + artifactId; + + if (serviceLogic != null && context != null) + status = serviceLogic.save("SQL", false, false, key, null, null, context); + if ((status == null) || status.toString().equals("FAILURE")) + throw new SvcLogicException("Error While processing Configure DG Action table "); + + } + + + public void insertProtocolReference(SvcLogicContext context, String vnfType, String protocol, String action, + String action_level, String template) throws SvcLogicException { + String fn = "DBService.insertProtocolReference"; + log.info(fn + "Starting DB operation for insertProtocolReference"); + String key = ""; + QueryStatus status = null; + + key = "insert into PROTOCOL_REFERENCE (ACTION, VNF_TYPE, PROTOCOL, UPDATED_DATE, TEMPLATE, ACTION_LEVEL)" + + " values (" + "'" + action + "', '" + vnfType + "', '" + protocol + "', now(),'" + template + "', '" + + action_level + "')"; + + if (serviceLogic != null && context != null) + status = serviceLogic.save("SQL", false, false, key, null, null, context); + if ((status == null) || status.toString().equals("FAILURE")) + throw new SvcLogicException("Error While processing insertProtocolReference "); + + } + + public boolean isProtocolReferenceUpdateRequired(SvcLogicContext context, String vnfType, String protocol, + String action, String action_level, String template) throws SvcLogicException { + SvcLogicContext localContext = new SvcLogicContext(); + String fn = "DBService.isProtocolReferenceUpdateRequired"; + log.info(fn + "Starting DB operation for isProtocolReferenceUpdateRequired"); + String key = ""; + QueryStatus status = null; + + key = "select COUNT(*) from PROTOCOL_REFERENCE where ACTION='" + action + "' and ACTION_LEVEL='" + action_level + + "' and VNF_TYPE='" + vnfType + "'"; + status = serviceLogic.query("SQL", false, null, key, null, null, localContext); + String countStr = localContext.getAttribute("COUNT(*)"); + int count = Integer.parseInt(countStr); + if (count > 0) + return true; + else + return false; + } + + public void updateProtocolReference(SvcLogicContext context, String vnfType, String protocol, String action, + String action_level, String template) throws SvcLogicException { + + String fn = "DBService.isProtocolReferenceUpdateRequired"; + log.info(fn + "Starting DB operation for isProtocolReferenceUpdateRequired"); + String key = ""; + QueryStatus status = null; + + key = "update PROTOCOL_REFERENCE set UPDATED_DATE=now(), template='" + template + "' where ACTION='" + action + + "' and ACTION_LEVEL='" + action_level + "' and VNF_TYPE='" + vnfType + "'"; + status = serviceLogic.save("SQL", false, false, key, null, null, context); + if (status == QueryStatus.FAILURE) { + log.info("updateProtocolReference:: Error updating protocol reference"); + throw new SvcLogicException("Error - updating PROTOCOL_REFERENCE_TABLE in updateProtocolReference"); + } + return; + } + + public String getDownLoadDGReference(SvcLogicContext context) throws Exception { + String fn = "DBService.setDownLoadDGReference"; + String downloadConfigDg = null; + log.info(fn + "Setting Download DG Reference from DB"); + String key = ""; + QueryStatus status = null; + String protocol = context.getAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL); + if (StringUtils.isBlank(protocol)) { + log.info(fn + " :: Protocol is Blank!! Returning without querying DB"); + throw new Exception(fn+":: Protocol is Blank!! Returning without querying DB"); + } + key = "select download_config_dg from " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE + + " where protocol = '" + protocol + "'"; + SvcLogicContext localContext = new SvcLogicContext(); + status = serviceLogic.query("SQL", false, null, key, null, null, localContext); + if (status == QueryStatus.FAILURE) { + log.info(fn + ":: Error retrieving download_config_dg"); + throw new SvcLogicException("Error retrieving download_config_dg"); + } + if (status == QueryStatus.NOT_FOUND) { + log.info(fn + ":: NOT_FOUND! No data found for download_config_dg!!"); + throw new Exception(fn + ":: NOT_FOUND! No data found for download_config_dg!"); + } + downloadConfigDg = localContext.getAttribute("download-config-dg"); + log.info(fn + "download_config_dg::" + downloadConfigDg); + return downloadConfigDg; + } + + public void cleanUpVnfcReferencesForVnf(SvcLogicContext context) throws SvcLogicException { + String key1 = "delete from " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE + + " where action = 'Configure' and vnf_type = $" + SdcArtifactHandlerConstants.VNF_TYPE; + QueryStatus status = null; + log.info("cleanUpVnfcReferencesForVnf()::Query:" + key1); + if (serviceLogic != null && context != null) { + status = serviceLogic.save("SQL", false, false, key1, null, null, context); + if (status.toString().equals("FAILURE")) { + log.debug("Error deleting from VNFC_REFERENCE table"); + throw new SvcLogicException("Error While processing VNFC_REFERENCE table "); + } + } + } + + +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java new file mode 100644 index 000000000..f56581977 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java @@ -0,0 +1,533 @@ +/*- + * ============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.artifact.handler.node; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.util.Map; + +import org.apache.commons.lang.StringUtils; +import org.json.JSONArray; +import org.json.JSONObject; +import org.onap.appc.artifact.handler.dbservices.DBService; +import org.onap.appc.artifact.handler.utils.ArtifactHandlerProviderUtil; +import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; +import org.onap.appc.yang.YANGGenerator; +import org.onap.appc.yang.impl.YANGGeneratorFactory; +import org.openecomp.sdnc.config.params.transformer.tosca.ArtifactProcessorImpl; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + + + +public class ArtifactHandlerNode implements SvcLogicJavaPlugin { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerNode.class); + + public void processArtifact(Map inParams, SvcLogicContext ctx) throws Exception { + String responsePrefix = inParams.get("response_prefix"); + try { + if (inParams != null && !inParams.isEmpty() && inParams.get("postData") != null) { + log.info("Received request for process Artifact with params: " + inParams.toString()); + String postData = inParams.get("postData"); + JSONObject input = new JSONObject(postData).getJSONObject("input"); + responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : ""; + storeUpdateSdcArtifacts(input); + } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + private boolean storeUpdateSdcArtifacts(JSONObject postDataJson) throws Exception { + log.info("Starting processing of SDC Artifacs into Handler with Data : " + postDataJson.toString()); + try { + JSONObject request_information = + (JSONObject) postDataJson.get(SdcArtifactHandlerConstants.REQUEST_INFORMATION); + JSONObject document_information = + (JSONObject) postDataJson.get(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS); + String artifact_name = document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME); + if (artifact_name != null) { + updateStoreArtifacts(request_information, document_information); + if (artifact_name.toLowerCase().startsWith(SdcArtifactHandlerConstants.REFERENCE)) + return storeReferenceData(request_information, document_information); + else if (artifact_name.toLowerCase().startsWith(SdcArtifactHandlerConstants.PD)) + return createDataForPD(request_information, document_information); + + } else + throw new Exception("Missing Artifact Name for Request : " + + request_information.getString(SdcArtifactHandlerConstants.REQUETS_ID)); + } catch (Exception e) { + e.printStackTrace(); + throw new Exception("Error while processing Request ID : " + + ((JSONObject) postDataJson.get(SdcArtifactHandlerConstants.REQUEST_INFORMATION)) + .getString(SdcArtifactHandlerConstants.REQUETS_ID) + + e.getMessage()); + } + return false; + + } + + private boolean createDataForPD(JSONObject request_information, JSONObject document_information) throws Exception { + + String fn = "ArtifactHandlerNode.createReferenceDataForPD"; + String artifact_name = document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME); + log.info(fn + "Received PD File Name: " + artifact_name + " and suffix lenght " + + SdcArtifactHandlerConstants.PD.length()); + try { + + String suffix = artifact_name.substring(SdcArtifactHandlerConstants.PD.length()); + createArtifactRecords(request_information, document_information, suffix); + } catch (Exception e) { + e.printStackTrace(); + throw new Exception("Error while createing PD data records " + e.getMessage()); + } + return true; + } + + private void createArtifactRecords(JSONObject request_information, JSONObject document_information, String suffix) + throws Exception { + + log.info("Creating Tosca Records and storing into SDC Artifacs"); + String[] docs = {"Tosca", "Yang"}; + ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil(); + String PDFileContents = document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS); + + // Tosca generation + OutputStream toscaStream = new ByteArrayOutputStream(); + String toscaContents = null; + ArtifactProcessorImpl toscaGenerator = new ArtifactProcessorImpl(); + toscaGenerator.generateArtifact(PDFileContents, toscaStream); + if (toscaStream != null) + toscaContents = toscaStream.toString(); + log.info("Generated Tosca File : " + toscaContents); + + String yangContents = "YANG generation is in Progress"; + String yangName = null; + + for (String doc : docs) { + document_information.put(SdcArtifactHandlerConstants.ARTIFACT_TYPE, doc.concat("Type")); + document_information.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, doc.concat("Model")); + if (doc.equals("Tosca")) + document_information.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, + ahpUtil.escapeSql(toscaContents)); + else if (doc.equals("Yang")) + document_information.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, + ahpUtil.escapeSql(yangContents)); + document_information.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, doc.concat(suffix)); + yangName = doc.concat(suffix); + updateStoreArtifacts(request_information, document_information); + } + + String artifactId = getArtifactID(yangName); + OutputStream yangStream = new ByteArrayOutputStream(); + YANGGenerator yangGenerator = YANGGeneratorFactory.getYANGGenerator(); + yangGenerator.generateYANG(artifactId, toscaContents, yangStream); + if (yangStream != null) + yangContents = yangStream.toString(); + + if (yangContents != null) { + updateYangContents(artifactId, ahpUtil.escapeSql(yangContents)); + } + + } + + private void updateYangContents(String artifactId, String yangContents) throws SvcLogicException { + SvcLogicContext context = new SvcLogicContext(); + DBService dbservice = DBService.initialise(); + dbservice.updateYangContents(context, artifactId, yangContents); + } + + private String getArtifactID(String yangName) throws SvcLogicException { + SvcLogicContext context = new SvcLogicContext(); + DBService dbservice = DBService.initialise(); + return dbservice.getArtifactID(context, yangName); + } + + protected boolean updateStoreArtifacts(JSONObject request_information, JSONObject document_information) + throws Exception { + log.info("UpdateStoreArtifactsStarted storing of SDC Artifacs "); + + SvcLogicContext context = new SvcLogicContext(); + DBService dbservice = DBService.initialise(); + ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil(); + int intversion = 0; + context.setAttribute("artifact_name", + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME)); + String internal_version = dbservice.getInternalVersionNumber(context, + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME), null); + log.info("Internal Version number received from Database : " + internal_version); + if (internal_version != null) { + intversion = Integer.parseInt(internal_version); + intversion++; + } + context.setAttribute(SdcArtifactHandlerConstants.SERVICE_UUID, + document_information.getString(SdcArtifactHandlerConstants.SERVICE_UUID)); + context.setAttribute(SdcArtifactHandlerConstants.DISTRIBUTION_ID, + document_information.getString(SdcArtifactHandlerConstants.DISTRIBUTION_ID)); + context.setAttribute(SdcArtifactHandlerConstants.SERVICE_NAME, + document_information.getString(SdcArtifactHandlerConstants.SERVICE_NAME)); + context.setAttribute(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, + document_information.getString(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION)); + context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_UUID, + document_information.getString(SdcArtifactHandlerConstants.RESOURCE_UUID)); + context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, + document_information.getString(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME)); + context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_VERSOIN, + document_information.getString(SdcArtifactHandlerConstants.RESOURCE_VERSOIN)); + context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_TYPE, + document_information.getString(SdcArtifactHandlerConstants.RESOURCE_TYPE)); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_UUID, + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_UUID)); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_TYPE, + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_TYPE)); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN, + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN)); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION)); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, + ahpUtil.escapeSql(document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS))); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME, + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME)); + dbservice.saveArtifacts(context, intversion); + return true; + + } + + public boolean storeReferenceData(JSONObject request_information, JSONObject document_information) + throws Exception { + log.info("Started storing of SDC Artifacs into Handler"); + try { + boolean updateRequired = false; + boolean pdFile = false; + String suffix = null; + String categorySuffix = null; + DBService dbservice = DBService.initialise(); + ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil(); + String contentString = + ahpUtil.escapeSql(document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS)); + String artifactName = + ahpUtil.escapeSql(document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME)); + String capabilityArtifactName = + StringUtils.replace(artifactName, SdcArtifactHandlerConstants.ARTIFACT_NAME_REFERENCE, + SdcArtifactHandlerConstants.ARTIFACT_NAME_CAPABILITY); + JSONObject capabilities = new JSONObject(); + JSONArray vnfActionList = new JSONArray(); + JSONArray vfModuleActionList = new JSONArray(); + JSONArray vnfcActionList = new JSONArray(); + JSONArray vmActionList = new JSONArray(); + String vnfType = null; + JSONObject contentObject = new JSONObject(contentString); + JSONArray contentArray = contentObject.getJSONArray("reference_data"); + boolean storeCapabilityArtifact=true; + for (int a = 0; a < contentArray.length(); a++) { + + JSONObject content = (JSONObject) contentArray.get(a); + log.info("contentString =" + content.toString()); + JSONObject scope = content.getJSONObject("scope"); + log.info("scope :" + scope); + SvcLogicContext context = new SvcLogicContext(); + vnfType = scope.getString(SdcArtifactHandlerConstants.VNF_TYPE); + context.setAttribute(SdcArtifactHandlerConstants.VNF_TYPE, + scope.getString(SdcArtifactHandlerConstants.VNF_TYPE)); + context.setAttribute(SdcArtifactHandlerConstants.ACTION, + content.getString(SdcArtifactHandlerConstants.ACTION)); + String actionLevel = content.getString(SdcArtifactHandlerConstants.ACTION_LEVEL); + context.setAttribute(SdcArtifactHandlerConstants.ACTION_LEVEL, + content.getString(SdcArtifactHandlerConstants.ACTION_LEVEL)); + if ((null != actionLevel) + && actionLevel.equalsIgnoreCase(SdcArtifactHandlerConstants.ACTION_LEVEL_VNFC)) { + vnfcActionList.put(content.getString(SdcArtifactHandlerConstants.ACTION)); + } + if (null != actionLevel + && actionLevel.equalsIgnoreCase(SdcArtifactHandlerConstants.ACTION_LEVEL_VF_MODULE)) { + vfModuleActionList.put(content.getString(SdcArtifactHandlerConstants.ACTION)); + } + if (null != actionLevel && actionLevel.equalsIgnoreCase(SdcArtifactHandlerConstants.ACTION_LEVEL_VNF)) { + vnfActionList.put(content.getString(SdcArtifactHandlerConstants.ACTION)); + } + if (null != actionLevel && actionLevel.equalsIgnoreCase(SdcArtifactHandlerConstants.ACTION_LEVEL_VM)) { + vmActionList.put(content.getString(SdcArtifactHandlerConstants.ACTION)); + } + if (scope.has(SdcArtifactHandlerConstants.VNFC_TYPE) + && !scope.isNull(SdcArtifactHandlerConstants.VNFC_TYPE)) { + context.setAttribute(SdcArtifactHandlerConstants.VNFC_TYPE, + scope.getString(SdcArtifactHandlerConstants.VNFC_TYPE)); + String vnfcTypeScope = scope.getString(SdcArtifactHandlerConstants.VNFC_TYPE); + if (StringUtils.isNotBlank(vnfcTypeScope)) { + storeCapabilityArtifact = false; + log.info("No capability Artifact for this reference data as it is at VNFC level!!"); + } + } + else + context.setAttribute(SdcArtifactHandlerConstants.VNFC_TYPE, null); + if (content.has(SdcArtifactHandlerConstants.DEVICE_PROTOCOL)) + context.setAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL, + content.getString(SdcArtifactHandlerConstants.DEVICE_PROTOCOL)); + if (content.has(SdcArtifactHandlerConstants.USER_NAME)) + context.setAttribute(SdcArtifactHandlerConstants.USER_NAME, + content.getString(SdcArtifactHandlerConstants.USER_NAME)); + if (content.has(SdcArtifactHandlerConstants.PORT_NUMBER)) + context.setAttribute(SdcArtifactHandlerConstants.PORT_NUMBER, + content.getString(SdcArtifactHandlerConstants.PORT_NUMBER)); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_TYPE, ""); + if (content.has("artifact-list") && content.get("artifact-list") instanceof JSONArray) { + JSONArray artifactLists = (JSONArray) content.get("artifact-list"); + for (int i = 0; i < artifactLists.length(); i++) { + JSONObject artifact = (JSONObject) artifactLists.get(i); + log.info("artifact is " + artifact); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME, + artifact.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME)); + context.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, + artifact.getString(SdcArtifactHandlerConstants.ARTIFACT_TYPE)); + + if (artifact.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME) != null + && artifact.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME).toLowerCase() + .startsWith(SdcArtifactHandlerConstants.PD)) { + suffix = artifact.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME) + .substring(SdcArtifactHandlerConstants.PD.length()); + categorySuffix = artifact.getString(SdcArtifactHandlerConstants.ARTIFACT_TYPE) + .substring(SdcArtifactHandlerConstants.PD.length()); + pdFile = true; + } + + dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context, + SdcArtifactHandlerConstants.DB_SDC_REFERENCE)); + + cleanArtifactInstanceData(context); + } + + if (pdFile) { + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME, "Tosca".concat(suffix)); + context.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, + SdcArtifactHandlerConstants.TOSCA_MODEL); + dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context, + SdcArtifactHandlerConstants.DB_SDC_REFERENCE)); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME, "Yang".concat(suffix)); + context.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, + SdcArtifactHandlerConstants.PARAMETER_YANG); + dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context, + SdcArtifactHandlerConstants.DB_SDC_REFERENCE)); + } + } + if (content.getString(SdcArtifactHandlerConstants.ACTION).equals("Configure") + || content.getString(SdcArtifactHandlerConstants.ACTION).equals("ConfigModify")) { + if (content.has(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE) + && content.getString(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE).length() > 0) { + context.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, + content.getString(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE)); + dbservice.processDownloadDgReference(context, dbservice.isArtifactUpdateRequired(context, + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE)); + } + if (StringUtils.isBlank(context.getAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE))) + context.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, + dbservice.getDownLoadDGReference(context)); + dbservice.processConfigActionDg(context, dbservice.isArtifactUpdateRequired(context, + SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG)); + if (content.getString(SdcArtifactHandlerConstants.ACTION).equals("Configure")) { + dbservice.processDeviceInterfaceProtocol(context, dbservice.isArtifactUpdateRequired(context, + SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL)); + dbservice.processDeviceAuthentication(context, dbservice.isArtifactUpdateRequired(context, + SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION)); + } + + } + + + populateProtocolReference(dbservice, content); + + context.setAttribute(SdcArtifactHandlerConstants.VNFC_TYPE, null); + + if (content.has(SdcArtifactHandlerConstants.VM) + && content.get(SdcArtifactHandlerConstants.VM) instanceof JSONArray) { + JSONArray vmList = (JSONArray) content.get(SdcArtifactHandlerConstants.VM); + dbservice.cleanUpVnfcReferencesForVnf(context); + for (int i = 0; i < vmList.length(); i++) { + JSONObject vmInstance = (JSONObject) vmList.get(i); + context.setAttribute(SdcArtifactHandlerConstants.VM_INSTANCE, + String.valueOf(vmInstance.getInt(SdcArtifactHandlerConstants.VM_INSTANCE))); + log.info("VALUE = " + context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE)); + if (vmInstance.get(SdcArtifactHandlerConstants.VNFC) instanceof JSONArray) { + JSONArray vnfcInstanceList = (JSONArray) vmInstance.get(SdcArtifactHandlerConstants.VNFC); + for (int k = 0; k < vnfcInstanceList.length(); k++) { + JSONObject vnfcInstance = (JSONObject) vnfcInstanceList.get(k); + context.setAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE, + String.valueOf(vnfcInstance.getInt(SdcArtifactHandlerConstants.VNFC_INSTANCE))); + context.setAttribute(SdcArtifactHandlerConstants.VNFC_TYPE, + vnfcInstance.getString(SdcArtifactHandlerConstants.VNFC_TYPE)); + context.setAttribute(SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE, + vnfcInstance.getString(SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE)); + if (vnfcInstance.has(SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP)) + context.setAttribute(SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP, + vnfcInstance.getString(SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP)); + if (vnfcInstance.has(SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE)) + context.setAttribute(SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE, + vnfcInstance.getString(SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE)); + if (vnfcInstance.has(SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE)) + context.setAttribute(SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE, + vnfcInstance.getString(SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE)); + if (content.getString(SdcArtifactHandlerConstants.ACTION).equals("Configure")) { + dbservice.processVnfcReference(context,false); + } + cleanVnfcInstance(context); + } + context.setAttribute(SdcArtifactHandlerConstants.VM_INSTANCE, null); + } + } + } + + + } + if (storeCapabilityArtifact) { + capabilities.put("vnf", vnfActionList); + capabilities.put("vf-module", vfModuleActionList); + capabilities.put("vnfc", vnfcActionList); + capabilities.put("vm", vmActionList); + processAndStoreCapablitiesArtifact(dbservice, document_information, capabilities, capabilityArtifactName, + vnfType); + } + + } catch (Exception e) { + e.printStackTrace(); + throw new Exception("Error While Storing : " + e.getMessage()); + } + + return true; + } + + private void cleanArtifactInstanceData(SvcLogicContext context) { + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME, null); + context.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, null); + } + + private void cleanVnfcInstance(SvcLogicContext context) { + + context.setAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE, null); + context.setAttribute(SdcArtifactHandlerConstants.VNFC_TYPE, null); + context.setAttribute(SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE, null); + context.setAttribute(SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP, null); + context.setAttribute(SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE, null); + context.setAttribute(SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE, null); + + } + + private void processAndStoreCapablitiesArtifact(DBService dbservice, JSONObject document_information, + JSONObject capabilities, String capabilityArtifactName, String vnfType) throws Exception { + log.info("Begin-->processAndStoreCapablitiesArtifact "); + + try { + + JSONObject newCapabilitiesObject = new JSONObject(); + newCapabilitiesObject.put("capabilities", capabilities); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME, capabilityArtifactName); + context.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, SdcArtifactHandlerConstants.CAPABILITY); + context.setAttribute(SdcArtifactHandlerConstants.ACTION, null); + context.setAttribute(SdcArtifactHandlerConstants.VNFC_TYPE, null); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_TYPE, null); + context.setAttribute(SdcArtifactHandlerConstants.VNF_TYPE, vnfType); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, newCapabilitiesObject.toString()); + dbservice.processSdcReferences(context, + dbservice.isArtifactUpdateRequired(context, SdcArtifactHandlerConstants.DB_SDC_REFERENCE)); + int intversion = 0; + + String internal_version = dbservice.getInternalVersionNumber(context, + context.getAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME), null); + log.info("Internal Version number received from Database : " + internal_version); + if (internal_version != null) { + intversion = Integer.parseInt(internal_version); + intversion++; + } + context.setAttribute(SdcArtifactHandlerConstants.SERVICE_UUID, + document_information.getString(SdcArtifactHandlerConstants.SERVICE_UUID)); + context.setAttribute(SdcArtifactHandlerConstants.DISTRIBUTION_ID, + document_information.getString(SdcArtifactHandlerConstants.DISTRIBUTION_ID)); + context.setAttribute(SdcArtifactHandlerConstants.SERVICE_NAME, + document_information.getString(SdcArtifactHandlerConstants.SERVICE_NAME)); + context.setAttribute(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, + document_information.getString(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION)); + context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_UUID, + document_information.getString(SdcArtifactHandlerConstants.RESOURCE_UUID)); + context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, + document_information.getString(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME)); + context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_VERSOIN, + document_information.getString(SdcArtifactHandlerConstants.RESOURCE_VERSOIN)); + context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_TYPE, + document_information.getString(SdcArtifactHandlerConstants.RESOURCE_TYPE)); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_UUID, + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_UUID)); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN, + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN)); + context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION)); + + + dbservice.saveArtifacts(context, intversion); + return; + } catch (Exception e) { + log.error("Error saving capabilities artifact to DB: " + e.toString()); + throw e; + } finally { + log.info("End-->processAndStoreCapablitiesArtifact "); + } + + } + + private void populateProtocolReference(DBService dbservice, JSONObject content) throws Exception { + log.info("Begin-->populateProtocolReference "); + try { + SvcLogicContext context = new SvcLogicContext(); + JSONObject scope = content.getJSONObject("scope"); + String vnfType = null, protocol = null, action = null, actionLevel = null, template = null; + if (scope.has(SdcArtifactHandlerConstants.VNF_TYPE) && !scope.isNull(SdcArtifactHandlerConstants.VNF_TYPE)) + vnfType = scope.getString(SdcArtifactHandlerConstants.VNF_TYPE); + if (content.has(SdcArtifactHandlerConstants.DEVICE_PROTOCOL)) + protocol = content.getString(SdcArtifactHandlerConstants.DEVICE_PROTOCOL); + if (content.has(SdcArtifactHandlerConstants.ACTION)) + action = content.getString(SdcArtifactHandlerConstants.ACTION); + if (content.has(SdcArtifactHandlerConstants.ACTION_LEVEL)) + actionLevel = content.getString(SdcArtifactHandlerConstants.ACTION_LEVEL); + if (content.has(SdcArtifactHandlerConstants.TEMPLATE) + && !content.isNull(SdcArtifactHandlerConstants.TEMPLATE)) + template = content.getString(SdcArtifactHandlerConstants.TEMPLATE); + boolean isUpdateNeeded=dbservice.isProtocolReferenceUpdateRequired(context, vnfType, protocol, action, actionLevel, template); + if (isUpdateNeeded) + dbservice.updateProtocolReference(context, vnfType, protocol, action, actionLevel, template); + else + dbservice.insertProtocolReference(context, vnfType,protocol,action,actionLevel,template); + } catch (Exception e) { + log.error("Error inserting record into protocolReference: " + e.toString()); + throw e; + } finally { + log.info("End-->populateProtocolReference "); + } + } + +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java new file mode 100644 index 000000000..15859178a --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java @@ -0,0 +1,191 @@ +/*- + * ============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.artifact.handler.utils; + +import java.io.IOException; +import java.security.SecureRandom; +import java.util.HashMap; + +import org.apache.commons.lang3.StringUtils; +import org.json.JSONException; +import org.json.JSONObject; +import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactInput; +import org.onap.appc.artifact.handler.node.ArtifactHandlerNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ArtifactHandlerProviderUtil { + + public UploadartifactInput templateData ; + SvcLogicContext context = null; + private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerProviderUtil.class); + public static void loadProperties() { + // TODO Auto-generated method stub + + } + public enum DistributionStatusEnum { + DOWNLOAD_OK, + DOWNLOAD_ERROR, + ALREADY_DOWNLOADED, + DEPLOY_OK, + DEPLOY_ERROR, + ALREADY_DEPLOYED; + } + + public ArtifactHandlerProviderUtil(){}; + + public ArtifactHandlerProviderUtil(UploadartifactInput input) { + this.templateData = input; + log.info("templateData " + this.templateData); + } + + public void processTemplate(String requestInfo) throws Exception { + if(context == null) + context = new SvcLogicContext(); + + ArtifactHandlerNode node = new ArtifactHandlerNode(); + try { + + HashMap processdata = new HashMap(); + processdata.put("postData", requestInfo); + log.info("Post data = " + requestInfo); + node.processArtifact(processdata, context); + } catch (Exception e) { + // TODO Auto-generated catch block + log.error("Error: " + e.getMessage()); + e.printStackTrace(); + throw e; + } + + } + public String createDummyRequestData() throws JSONException, IOException{ + + + JSONObject info = new JSONObject(this.templateData); + log.info("INFO = " + info); + String artifact_name = templateData.getDocumentParameters().getArtifactName(); + String artifact_version = templateData.getDocumentParameters().getArtifactVersion(); + + JSONObject json = new JSONObject(); + JSONObject requestInfo = new JSONObject(); + String random = getRandom(); + + requestInfo.put(SdcArtifactHandlerConstants.REQUETS_ID, "TLRID-" + random); + requestInfo.put(SdcArtifactHandlerConstants.REQUEST_ACTION, "StoreSdcDocumentRequest"); + requestInfo.put(SdcArtifactHandlerConstants.SOURCE, "TemplateLoader"); + + JSONObject docParams = new JSONObject(); + docParams.put(SdcArtifactHandlerConstants.SERVICE_UUID, "TLSUUID" + templateData.getRequestInformation().getRequestId()); + docParams.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "TLDID" + random); + docParams.put(SdcArtifactHandlerConstants.SERVICE_NAME, "TLServiceName"); + docParams.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "Template Loader Test"); + docParams.put(SdcArtifactHandlerConstants.SERVICE_ARTIFACTS, "[]"); + docParams.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "TLRUID" + random); + docParams.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "TLRIName"); + docParams.put(SdcArtifactHandlerConstants.REOURCE_NAME, "TLResourceName"); + docParams.put(SdcArtifactHandlerConstants.RESOURCE_VERSOIN, "TLResourceVersion"); + docParams.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "TLResourceType"); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "TLAUUID" + random); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName()); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_TYPE, "APPC-CONFIG"); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN, templateData.getDocumentParameters().getArtifactVersion()); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "SdcTestDescription"); + // String data = IOUtils.toString(TestartifactHandlerNode.class.getClassLoader().getResourceAsStream("template_msrp_msc_a_template.json"), "utf-8"); + // String data = IOUtils.toString(TemplateProcessor.class.getClassLoader().getResourceAsStream("referenceData.json"), "utf-8"); + + // this.templateData = this.templateData.substring(this.templateData.indexOf("}") + 1); + docParams.put("artifact-contents", templateData.getDocumentParameters().getArtifactContents()); + + json.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); + json.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, docParams); + System.out.println("Final data =" + this.templateData); + return String.format("{\"input\": %s}", json.toString()); + } + + private String getRandom() { + SecureRandom random = new SecureRandom(); + int num = random.nextInt(100000); + String formatted = String.format("%05d", num); + return formatted; + } + + public String escapeSql(String str) { + if (str == null) { + return null; + } + String searchList[] = new String[]{"'","\\"}; + String replacementList[] = new String[]{ "''","\\\\"}; + return StringUtils.replaceEach(str,searchList, replacementList); + } + public String createRequestData() throws JSONException, IOException{ + + + JSONObject info = new JSONObject(this.templateData); + log.info("INFO = " + info); + + JSONObject json = new JSONObject(); + JSONObject requestInfo = new JSONObject(); + String random = getRandom(); + + requestInfo.put(SdcArtifactHandlerConstants.REQUETS_ID, templateData.getRequestInformation().getRequestId()); + requestInfo.put(SdcArtifactHandlerConstants.REQUEST_ACTION, "StoreSdcDocumentRequest"); + requestInfo.put(SdcArtifactHandlerConstants.SOURCE, templateData.getRequestInformation().getSource()); + + String serviceDescription = serviceDescriptionData(templateData.getDocumentParameters().getServiceDescription()); + + JSONObject docParams = new JSONObject(); + docParams.put(SdcArtifactHandlerConstants.SERVICE_UUID, templateData.getDocumentParameters().getResourceUuid()); + docParams.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, templateData.getDocumentParameters().getDistributionId()); + docParams.put(SdcArtifactHandlerConstants.SERVICE_NAME, templateData.getDocumentParameters().getServiceName()); + docParams.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION,serviceDescription); + docParams.put(SdcArtifactHandlerConstants.SERVICE_ARTIFACTS, templateData.getDocumentParameters().getServiceArtifacts()); + docParams.put(SdcArtifactHandlerConstants.RESOURCE_UUID, templateData.getDocumentParameters().getResourceUuid()); + docParams.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, templateData.getDocumentParameters().getResourceInstanceName()); + docParams.put(SdcArtifactHandlerConstants.REOURCE_NAME, templateData.getDocumentParameters().getResourceName()); + docParams.put(SdcArtifactHandlerConstants.RESOURCE_VERSOIN, templateData.getDocumentParameters().getResourceVersion()); + docParams.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, templateData.getDocumentParameters().getResourceType()); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, templateData.getDocumentParameters().getArtifactUuid()); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName()); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_TYPE, templateData.getDocumentParameters().getArtifactType()); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN, templateData.getDocumentParameters().getArtifactVersion()); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, templateData.getDocumentParameters().getArtifactDescription()); + + docParams.put("artifact-contents", templateData.getDocumentParameters().getArtifactContents()); + + json.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); + json.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, docParams); + System.out.println("Final data =" + this.templateData); + return String.format("{\"input\": %s}", json.toString()); + } + + private String serviceDescriptionData(String serviceDescription){ + if(!StringUtils.isBlank(serviceDescription)&&serviceDescription.length()>255){ + serviceDescription = serviceDescription.substring(0, 255); + } + return serviceDescription; + } +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/EscapeUtils.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/EscapeUtils.java new file mode 100644 index 000000000..ece5cdb24 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/EscapeUtils.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.artifact.handler.utils; + +import org.apache.commons.lang3.StringUtils; + +public class EscapeUtils { + + public EscapeUtils() { + // TODO Auto-generated constructor stub + } + + public static String escapeSql(String str) { + if (str == null) { + return null; + } + String searchList[] = new String[]{"'","\\"}; + String replacementList[] = new String[]{ "''","\\\\"}; + return StringUtils.replaceEach(str,searchList, replacementList); + } +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java new file mode 100644 index 000000000..c045ee7d4 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java @@ -0,0 +1,93 @@ +/*- + * ============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.artifact.handler.utils; + +public class SdcArtifactHandlerConstants { + + public static final String DOCUMENT_PARAMETERS = "document-parameters"; + public static final String SERVICE_UUID = "service-uuid"; + public static final String DISTRIBUTION_ID = "distribution-id"; + public static final String REQUETS_ID = "request-id"; + public static final String REQUEST_ACTION = "request-action"; + public static final String SOURCE = "source"; + public static final String SERVICE_NAME = "service-name"; + public static final String SERVICE_DESCRIPTION ="service-description"; + public static final String SERVICE_ARTIFACTS = "service-artifacts"; + public static final String RESOURCE_UUID ="resource-uuid"; + public static final String RESOURCE_INSTANCE_NAME = "resource-instance-name"; + public static final String REOURCE_NAME = "resource-name"; + public static final String RESOURCE_VERSOIN ="resource-version"; + public static final String RESOURCE_TYPE= "resource-type"; + public static final String ARTIFACT_UUID ="artifact-uuid"; + public static final String ARTIFACT_NAME = "artifact-name"; + public static final String ARTIFACT_TYPE = "artifact-type"; + public static final String ARTIFACT_VERSOIN = "artifact-version"; + public static final String ARTIFACT_DESRIPTION = "artifact-description"; + public static final String ARTIFACT_CONTENTS = "artifact-contents"; + public static final String REQUEST_INFORMATION = "request-information"; + public static final String INTERNAL_VERSION = "internal-versoin"; + public static final String FILE_CATEGORY = "file-category"; + public static final String VNF_TYPE = "vnf-type"; + public static final String ACTION = "action"; + public static final String ACTION_LEVEL = "action-level"; + public static final String VNFC_TYPE = "vnfc-type"; + public static final String VM_INSTANCE = "vm-instance"; + public static final String VM = "vm"; + public static final String VNFC = "vnfc"; + public static final String VNFC_FUNCTION_CODE = "vnfc-function-code"; + public static final String GROUP_NOTATION = "group-notation"; + public static final String IPADDRESS_V4_OAM_VIP = "ipaddress-v4-oam-vip"; + public static final String GROUP_NOTATION_TYPE = "group-notation-type"; + public static final String GROUP_NOTATION_VALUE = "group-notation-value"; + public static final String REFERENCE = "reference"; + public static final String VNFC_INSTANCE = "vnfc-instance"; + public static final String DEVICE_PROTOCOL = "device-protocol"; + public static final String DG_RPC = "dg-rpc"; + public static final String MODULE = "module"; + public static final String USER_NAME = "user-name"; + public static final String PORT_NUMBER = "port-number"; + public static final String DOWNLOAD_DG_REFERENCE = "download-dg-reference"; + + + public static final String DB_DOWNLOAD_DG_REFERENCE = "DOWNLOAD_DG_REFERENCE"; + public static final String DB_SDC_REFERENCE = "ASDC_REFERENCE"; + public static final String DB_DEVICE_INTERFACE_PROTOCOL = "DEVICE_INTERFACE_PROTOCOL"; + public static final String DB_DEVICE_AUTHENTICATION = "DEVICE_AUTHENTICATION"; + public static final String DB_VNFC_REFERENCE = "VNFC_REFERENCE"; + public static final String DB_CONFIG_ACTION_DG = "CONFIGURE_ACTION_DG"; + public static final String PD = "pd"; + public static final String PARAMETER_YANG = "parameter_yang"; + public static final String TOSCA_MODEL = "tosca_model"; + public static final String DESIGN_TOOL = "Design-tool"; + public static final String ACTION_LEVEL_VNFC = "VNFC"; + public static final String ACTION_LEVEL_VF_MODULE ="VF-MODULE"; + public static final String ACTION_LEVEL_VNF = "VNF"; + public static final String ACTION_LEVEL_VM = "VM"; + public static final String CAPABILITY = "capability"; + public static final String TEMPLATE = "template"; + public static final String ARTIFACT_NAME_REFERENCE = "reference"; + public static final String ARTIFACT_NAME_CAPABILITY = "capability"; +} + diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModule.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModule.java new file mode 100644 index 000000000..67bb19941 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModule.java @@ -0,0 +1,59 @@ +/*- + * ============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.opendaylight.yang.gen.v1.org.onap.appc.artifact.handler.provider.impl.rev170321; + +import org.onap.appc.artifact.handler.ArtifactHandlerProvider; + +public class ArtifactHandlerProviderModule extends org.opendaylight.yang.gen.v1.org.onap.appc.artifact.handler.provider.impl.rev170321.AbstractArtifactHandlerProviderModule { + public ArtifactHandlerProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public ArtifactHandlerProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.org.onap.appc.artifact.handler.provider.impl.rev170321.ArtifactHandlerProviderModule oldModule, java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + final ArtifactHandlerProvider provider = new ArtifactHandlerProvider(getDataBrokerDependency() + , getNotificationServiceDependency() + , getRpcRegistryDependency()); + + return new AutoCloseable() { + + @Override + public void close() throws Exception { + provider.close(); + } + }; + } + + +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModuleFactory.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModuleFactory.java new file mode 100644 index 000000000..7190da5b9 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/onap/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModuleFactory.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========================================================= + */ + +/* +* Generated file +* +* Generated from: yang module name: artifact-handler-provider-impl yang module local name: artifact-handler-provider-impl +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Wed Aug 09 09:36:59 EDT 2017 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.yang.gen.v1.org.onap.appc.artifact.handler.provider.impl.rev170321; +public class ArtifactHandlerProviderModuleFactory extends org.opendaylight.yang.gen.v1.org.onap.appc.artifact.handler.provider.impl.rev170321.AbstractArtifactHandlerProviderModuleFactory { + +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModule.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModule.java deleted file mode 100644 index 67bb19941..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModule.java +++ /dev/null @@ -1,59 +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.opendaylight.yang.gen.v1.org.onap.appc.artifact.handler.provider.impl.rev170321; - -import org.onap.appc.artifact.handler.ArtifactHandlerProvider; - -public class ArtifactHandlerProviderModule extends org.opendaylight.yang.gen.v1.org.onap.appc.artifact.handler.provider.impl.rev170321.AbstractArtifactHandlerProviderModule { - public ArtifactHandlerProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { - super(identifier, dependencyResolver); - } - - public ArtifactHandlerProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.org.onap.appc.artifact.handler.provider.impl.rev170321.ArtifactHandlerProviderModule oldModule, java.lang.AutoCloseable oldInstance) { - super(identifier, dependencyResolver, oldModule, oldInstance); - } - - @Override - public void customValidation() { - // add custom validation form module attributes here. - } - - @Override - public java.lang.AutoCloseable createInstance() { - final ArtifactHandlerProvider provider = new ArtifactHandlerProvider(getDataBrokerDependency() - , getNotificationServiceDependency() - , getRpcRegistryDependency()); - - return new AutoCloseable() { - - @Override - public void close() throws Exception { - provider.close(); - } - }; - } - - -} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModuleFactory.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModuleFactory.java deleted file mode 100644 index 7190da5b9..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/appc/artifact/handler/provider/impl/rev170321/ArtifactHandlerProviderModuleFactory.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========================================================= - */ - -/* -* Generated file -* -* Generated from: yang module name: artifact-handler-provider-impl yang module local name: artifact-handler-provider-impl -* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator -* Generated at: Wed Aug 09 09:36:59 EDT 2017 -* -* Do not modify this file unless it is present under src/main directory -*/ -package org.opendaylight.yang.gen.v1.org.onap.appc.artifact.handler.provider.impl.rev170321; -public class ArtifactHandlerProviderModuleFactory extends org.opendaylight.yang.gen.v1.org.onap.appc.artifact.handler.provider.impl.rev170321.AbstractArtifactHandlerProviderModuleFactory { - -} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/ArtifactHandlerProvider.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/ArtifactHandlerProvider.java deleted file mode 100644 index d5ccd45b0..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/ArtifactHandlerProvider.java +++ /dev/null @@ -1,213 +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.artifact.handler; - -import java.util.HashMap; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -import org.json.JSONArray; -import org.json.JSONObject; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.NotificationProviderService; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; -import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.ArtifactHandlerService; -import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactInput; -import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactOutput; -import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.uploadartifact.output.ConfigDocumentResponseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.Services; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.ServicesBuilder; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import org.onap.appc.artifact.handler.node.ArtifactHandlerNode; -import org.onap.appc.artifact.handler.utils.ArtifactHandlerProviderUtil; -import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.Futures; - - - -public class ArtifactHandlerProvider implements AutoCloseable, ArtifactHandlerService, DataChangeListener { - - private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerProvider.class); - private final String appName = "ArtifactsHandler"; - private final ExecutorService executor; - protected DataBroker dataBroker; - protected NotificationProviderService notificationService; - protected RpcProviderRegistry rpcRegistry; - private ListenerRegistration dclServices; - - protected BindingAwareBroker.RpcRegistration rpcRegistration; - - public ArtifactHandlerProvider(DataBroker dataBroker2, - NotificationProviderService notificationProviderService, - RpcProviderRegistry rpcProviderRegistry) { - this.log.info("Creating provider for " + appName); - executor = Executors.newFixedThreadPool(10); - dataBroker = dataBroker2; - notificationService = notificationProviderService; - rpcRegistry = rpcProviderRegistry; - initialize(); - - } - - public void initialize() { - log.info("Initializing provider for " + appName); - // Create the top level containers - createContainers(); - try { - ArtifactHandlerProviderUtil.loadProperties(); - } catch (Exception e) { - log.error("Caught Exception while trying to load properties file"); - } - // Listener for changes to Services tree - - rpcRegistration = rpcRegistry.addRpcImplementation( - ArtifactHandlerService.class, this); - - log.info("Initialization complete for " + appName); - } - private void createContainers() { - final WriteTransaction t = dataBroker.newReadWriteTransaction(); - // Create the Services container - t.merge(LogicalDatastoreType.CONFIGURATION,InstanceIdentifier.create(Services.class),new ServicesBuilder().build()); - t.merge(LogicalDatastoreType.OPERATIONAL,InstanceIdentifier.create(Services.class),new ServicesBuilder().build()); - - try { - CheckedFuture checkedFuture = t.submit(); - checkedFuture.get(); - log.info("Create Containers succeeded!: "); - - } catch (InterruptedException | ExecutionException e) { - log.error("Create Containers Failed: " + e); - e.printStackTrace(); - } - } - - - @Override - public void onDataChanged(AsyncDataChangeEvent, DataObject> arg0) { - // TODO Auto-generated method stub - - } - - - - @Override - public void close() throws Exception { - - log.info("Closing provider for " + appName); - if(this.executor != null){ - executor.shutdown(); - } - if(this.rpcRegistration != null){ - rpcRegistration.close(); - } - log.info("Successfully closed provider for " + appName); - - } - - private RpcResult buildResponse1( - String svcRequestId, - String topic, - String code, - String message, - String finalInd) { - - UploadartifactOutputBuilder responseBuilder = new UploadartifactOutputBuilder(); - ConfigDocumentResponseBuilder configResponseBuilder=new ConfigDocumentResponseBuilder(); - configResponseBuilder.setRequestId(svcRequestId); - configResponseBuilder.setStatus(code); - configResponseBuilder.setErrorReason(message); - RpcResult rpcResult = RpcResultBuilder. status(true) - .withResult(responseBuilder.build()).build(); - return rpcResult; - } - - @Override - public Future> uploadartifact(UploadartifactInput input) { - - if (input == null || input.getDocumentParameters() == null || input.getDocumentParameters().getArtifactContents() == null ) { - RpcResult rpcResult = - buildResponse1("N/A", "N/A", "INVALID_INPUT", "Invalid input, null or empty document information" , "Y"); - return Futures.immediateFuture(rpcResult); - } - UploadartifactInputBuilder inputBuilder = new UploadartifactInputBuilder(input); - ConfigDocumentResponseBuilder configResponseBuilder = new ConfigDocumentResponseBuilder(); - UploadartifactOutputBuilder responseBuilder = new UploadartifactOutputBuilder(); - log.info("Received input = " + input ); - ArtifactHandlerProviderUtil designUtil = new ArtifactHandlerProviderUtil(input); - configResponseBuilder.setRequestId(input.getRequestInformation().getRequestId()); - try{ - - if(input.getRequestInformation().getSource() !=null){ - if(input.getRequestInformation().getSource().equalsIgnoreCase(SdcArtifactHandlerConstants.DESIGN_TOOL)){ - designUtil.processTemplate(designUtil.createDummyRequestData()); - configResponseBuilder.setStatus(ArtifactHandlerProviderUtil.DistributionStatusEnum.DEPLOY_OK.toString()); - } - else - { - designUtil.processTemplate(designUtil.createRequestData()); - configResponseBuilder.setStatus(ArtifactHandlerProviderUtil.DistributionStatusEnum.DEPLOY_OK.toString()); - } - } - else - { - throw new Exception("No Tempalte data found"); - } - - - } - catch (Exception e) { - - configResponseBuilder.setErrorReason(e.getMessage()); - configResponseBuilder.setStatus(ArtifactHandlerProviderUtil.DistributionStatusEnum.DEPLOY_ERROR.toString()); - log.error("Caught exception looking for Artifact Handler", e); - log.info("Caught exception looking for Artifact Handler: "); - } - - responseBuilder.setConfigDocumentResponse(configResponseBuilder.build()); - RpcResult rpcResult = RpcResultBuilder. status(true).withResult(responseBuilder.build()).build(); - return Futures.immediateFuture(rpcResult); - - } -} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/SdcArtifactHandlerActivator.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/SdcArtifactHandlerActivator.java deleted file mode 100644 index ebbbe4735..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/SdcArtifactHandlerActivator.java +++ /dev/null @@ -1,58 +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.artifact.handler; - -import java.util.LinkedList; -import java.util.List; - -import org.onap.appc.artifact.handler.node.ArtifactHandlerNode; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class SdcArtifactHandlerActivator implements BundleActivator { - - private static final EELFLogger log = EELFManager.getInstance().getLogger(SdcArtifactHandlerActivator.class); - private List registrations = new LinkedList(); - - @Override - public void start(BundleContext ctx) throws Exception { - ArtifactHandlerNode artifactHandlerNode = new ArtifactHandlerNode(); - log.info("Registering service-- " + artifactHandlerNode.getClass().getName()); - registrations.add(ctx.registerService(artifactHandlerNode.getClass().getName(), artifactHandlerNode, null)); - - } - - @Override - public void stop(BundleContext arg0) throws Exception { - for (ServiceRegistration registration : registrations) { - registration.unregister(); - registration = null; - } - } -} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/dbservices/DBService.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/dbservices/DBService.java deleted file mode 100644 index 031d53e28..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/dbservices/DBService.java +++ /dev/null @@ -1,531 +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.artifact.handler.dbservices; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; -import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; - -import java.sql.SQLException; -import java.util.HashMap; -import org.apache.commons.lang.StringUtils; - -public class DBService { - - private static final EELFLogger log = EELFManager.getInstance().getLogger(DBService.class); - private SvcLogicResource serviceLogic; - private static DBService dgGeneralDBService = null; - - public static DBService initialise() { - if (dgGeneralDBService == null) { - dgGeneralDBService = new DBService(); - } - return dgGeneralDBService; - } - - private DBService() { - if (serviceLogic == null) { - serviceLogic = new SqlResource(); - } - } - - protected DBService(SqlResource svcLogic) { - if (serviceLogic == null) { - serviceLogic = svcLogic; - } - } - - public String getInternalVersionNumber(SvcLogicContext ctx, String artifactName, String prefix) - throws SvcLogicException { - String fn = "DBService.getInternalVersionNumber"; - QueryStatus status = null; - String artifactInternalVersion = null; - if (serviceLogic != null && ctx != null) { - String key = "select max(internal_version) as maximum from ASDC_ARTIFACTS WHERE ARTIFACT_NAME = '" - + artifactName + "'"; - log.info("Getting internal Versoin :" + key); - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); - if (status.toString().equals("FAILURE")) - throw new SvcLogicException("Error - getting internal Artifact Number"); - artifactInternalVersion = ctx.getAttribute("maximum"); - log.info("Internal Version received as : " + artifactInternalVersion); - log.info("Internal Version received as1 : " + ctx.getAttribute("max(internal_version)")); - log.info("Internal Version received as1 : " + ctx.getAttribute("max")); - log.info("Internal Version received as1 : " + ctx.getAttribute("internal_version")); - log.info("Internal Version received as1 : " + ctx.getAttributeKeySet().toString()); - } - return artifactInternalVersion; - } - - public String getArtifactID(SvcLogicContext ctx, String artifactName) throws SvcLogicException { - String fn = "DBService.getArtifactID"; - QueryStatus status = null; - String artifactID = null; - if (serviceLogic != null && ctx != null) { - String key = "select max(ASDC_ARTIFACTS_ID) as id from ASDC_ARTIFACTS WHERE ARTIFACT_NAME = '" - + artifactName + "'"; - log.info("Getting Artifact ID String :" + key); - status = serviceLogic.query("SQL", false, null, key, null, null, ctx); - if (status.toString().equals("FAILURE")) - throw new SvcLogicException("Error - getting Artifact ID from database"); - artifactID = ctx.getAttribute("id"); - log.info("SDC_ARTIFACTS_ID received as : " + ctx.getAttribute("id")); - } - return artifactID; - } - - public QueryStatus saveArtifacts(SvcLogicContext ctx, int intversion) throws SvcLogicException { - String fn = "DBService.saveArtifacts"; - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "INSERT INTO ASDC_ARTIFACTS " + "SET SERVICE_UUID = $service-uuid , " - + " DISTRIBUTION_ID = $distribution-id ," + " SERVICE_NAME = $service-name ," - + " SERVICE_DESCRIPTION = $service-description ," + " RESOURCE_UUID = $resource-uuid ," - + " RESOURCE_INSTANCE_NAME = $resource-instance-name ," + " RESOURCE_NAME = $resource-name ," - + " RESOURCE_VERSION = $resource-version ," + " RESOURCE_TYPE = $resource-type ," - + " ARTIFACT_UUID = $artifact-uuid ," + " ARTIFACT_TYPE = $artifact-type ," - + " ARTIFACT_VERSION = $artifact-version ," + " ARTIFACT_DESCRIPTION = $artifact-description ," - + " INTERNAL_VERSION = " + intversion + "," + " ARTIFACT_NAME = $artifact-name ," - + " ARTIFACT_CONTENT = $artifact-contents "; - - status = serviceLogic.save("SQL", false, false, key, null, null, ctx); - if (status.toString().equals("FAILURE")) - throw new SvcLogicException("Error While processing storing Artifact: " - + ctx.getAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME)); - } - return status; - - } - - public QueryStatus logData(SvcLogicContext ctx, String prefix) throws SvcLogicException { - String fn = "DBService.saveReferenceData"; - QueryStatus status = null; - if (serviceLogic != null && ctx != null) { - String key = "INSERT INTO CONFIG_TRANSACTION_LOG " + " SET request_id = $request-id , " - + " message_type = $log-message-type , " + " message = $log-message ;"; - status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx); - if (status.toString().equals("FAILURE")) - throw new SvcLogicException("Error while loging data"); - - } - return status; - } - - public void processConfigureActionDg(SvcLogicContext context, boolean isUpdate) { - String fn = "DBService.processConfigureActionDg"; - log.info("Update Parameter for SDC Reference " + isUpdate); - String key = ""; - QueryStatus status = null; - if (isUpdate) - ; - } - - public void processSdcReferences(SvcLogicContext context, boolean isUpdate) throws SvcLogicException { - String fn = "DBService.processSdcReferences"; - String key = ""; - QueryStatus status = null; - - if (isUpdate && context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY).equals(SdcArtifactHandlerConstants.CAPABILITY)) { - log.info("Updating capability artifact in ASDC_REFERENCE"); - key = "update " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set ARTIFACT_NAME = $" - + SdcArtifactHandlerConstants.ARTIFACT_NAME + " where " + "FILE_CATEGORY = $" - + SdcArtifactHandlerConstants.FILE_CATEGORY + " and VNF_TYPE = $" - + SdcArtifactHandlerConstants.VNF_TYPE ; - } else if (isUpdate) - key = "update " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set ARTIFACT_NAME = $" - + SdcArtifactHandlerConstants.ARTIFACT_NAME + " where VNFC_TYPE = $" - + SdcArtifactHandlerConstants.VNFC_TYPE + " and FILE_CATEGORY = $" - + SdcArtifactHandlerConstants.FILE_CATEGORY + " and ACTION = $" - + SdcArtifactHandlerConstants.ACTION + " and VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE; - - else { - if (context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY).equals(SdcArtifactHandlerConstants.CAPABILITY)) { - key = "insert into " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set VNFC_TYPE = null " - + " , FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY + " , VNF_TYPE = $" - + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = null " + " , ARTIFACT_TYPE = null " - + " , ARTIFACT_NAME = $" + SdcArtifactHandlerConstants.ARTIFACT_NAME; - } else { - key = "insert into " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set VNFC_TYPE = $" - + SdcArtifactHandlerConstants.VNFC_TYPE + " , FILE_CATEGORY = $" - + SdcArtifactHandlerConstants.FILE_CATEGORY + " , VNF_TYPE = $" - + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = $" + SdcArtifactHandlerConstants.ACTION - + " , ARTIFACT_TYPE = $" + SdcArtifactHandlerConstants.ARTIFACT_TYPE + " , ARTIFACT_NAME = $" - + SdcArtifactHandlerConstants.ARTIFACT_NAME; - } - } - if (serviceLogic != null && context != null) { - log.info("Insert Key: " + key); - status = serviceLogic.save("SQL", false, false, key, null, null, context); - if (status.toString().equals("FAILURE")) - throw new SvcLogicException("Error While processing sdc_reference table "); - } - } - - public boolean isArtifactUpdateRequired(SvcLogicContext context, String db) throws SvcLogicException, SQLException { - String fn = "DBService.isArtifactUpdateRequired"; - log.info("Checking if Update required for this data"); - - log.info("db" + db); - log.info("ACTION=" + context.getAttribute(SdcArtifactHandlerConstants.ACTION)); - log.info("VNFC_TYPE=" + context.getAttribute(SdcArtifactHandlerConstants.VNFC_TYPE)); - log.info("VNFC_INSTANCE=" + context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE)); - log.info("VM_INSTANCE=" + context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE)); - log.info("VNF_TYPE=" + context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE)); - String whereClause = ""; - - QueryStatus status = null; - whereClause = " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE; - - if (db != null) { - if (db.equals(SdcArtifactHandlerConstants.DB_SDC_REFERENCE) - && context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY) - .equals(SdcArtifactHandlerConstants.CAPABILITY) - && context.getAttribute(SdcArtifactHandlerConstants.ACTION) == null) { - whereClause = whereClause + " and FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY; - } - - else if (db.equals(SdcArtifactHandlerConstants.DB_SDC_REFERENCE)) { - whereClause = whereClause + " and VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE - + " and FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY + " and ACTION = $" - + SdcArtifactHandlerConstants.ACTION; - } - - else if (db.equals(SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE)) { - whereClause = " where PROTOCOL = $" + SdcArtifactHandlerConstants.DEVICE_PROTOCOL; - } else if (db.equals(SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG)) { - whereClause = whereClause + " and ACTION = $" + SdcArtifactHandlerConstants.ACTION; - } else if (db.equals(SdcArtifactHandlerConstants.DB_VNFC_REFERENCE)) { - int vm_instance = -1; - if (context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE) != null) - vm_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE)); - int vnfc_instance = -1; - if (context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE) != null) - vnfc_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE)); - whereClause = whereClause + " and ACTION = $" + SdcArtifactHandlerConstants.ACTION + " and VNFC_TYPE = $" - + SdcArtifactHandlerConstants.VNFC_TYPE + " and VNFC_INSTANCE = $" - + SdcArtifactHandlerConstants.VNFC_INSTANCE + " and VM_INSTANCE = $" - + SdcArtifactHandlerConstants.VM_INSTANCE; - - } - } - - if (serviceLogic != null && context != null) { - String key = "select COUNT(*) from " + db + whereClause; - log.info("SELECT String : " + key); - status = serviceLogic.query("SQL", false, null, key, null, null, context); - if (status.toString().equals("FAILURE")) { - throw new SvcLogicException("Error while reading data from " + db); - } - String count = context.getAttribute("COUNT(*)"); - log.info("Number of row Returned : " + count + ": " + status + ":"); - if (count != null && Integer.parseInt(count) > 0) { - context.setAttribute(count, null); - return true; - } else - return false; - } - return false; - } - - public void processDeviceInterfaceProtocol(SvcLogicContext context, boolean isUpdate) throws SvcLogicException { - String fn = "DBService.processDeviceInterfaceProtocol"; - log.info("Starting DB operation for Device Interface Protocol " + isUpdate); - String key = ""; - QueryStatus status = null; - if (isUpdate) - key = "update " + SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL + " set PROTOCOL = $" - + SdcArtifactHandlerConstants.DEVICE_PROTOCOL + " , DG_RPC = 'getDeviceRunningConfig' " - + " , MODULE = 'APPC' " + " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE; - else - key = "insert into " + SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL + " set VNF_TYPE = $" - + SdcArtifactHandlerConstants.VNF_TYPE + " , PROTOCOL = $" - + SdcArtifactHandlerConstants.DEVICE_PROTOCOL + " , DG_RPC = 'getDeviceRunningConfig' " - + " , MODULE = 'APPC' "; - - if (serviceLogic != null && context != null) { - - status = serviceLogic.save("SQL", false, false, key, null, null, context); - if (status.toString().equals("FAILURE")) - throw new SvcLogicException("Error While processing DEVICE_INTERFACE_PROTOCOL table "); - } - - } - - public void processDeviceAuthentication(SvcLogicContext context, boolean isUpdate) throws SvcLogicException { - String fn = "DBService.processDeviceAuthentication"; - log.info(fn + "Starting DB operation for Device Authentication " + isUpdate); - String key = ""; - QueryStatus status = null; - if (isUpdate) - key = "update " + SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION + " set USER_NAME = $" - + SdcArtifactHandlerConstants.USER_NAME +/* " , PASSWORD = 'dummy' " +*/ " , PORT_NUMBER = $" - + SdcArtifactHandlerConstants.PORT_NUMBER + " where VNF_TYPE = $" - + SdcArtifactHandlerConstants.VNF_TYPE; - else - key = "insert into " + SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION + " set VNF_TYPE = $" - + SdcArtifactHandlerConstants.VNF_TYPE + " , USER_NAME = $" + SdcArtifactHandlerConstants.USER_NAME - +/* " , PASSWORD = 'dummy' " + */ " , PORT_NUMBER = $" + SdcArtifactHandlerConstants.PORT_NUMBER; - - if (serviceLogic != null && context != null) { - status = serviceLogic.save("SQL", false, false, key, null, null, context); - if (status.toString().equals("FAILURE")) - throw new SvcLogicException("Error While processing DEVICE_AUTHENTICATION table "); - } - } - - public void processVnfcReference(SvcLogicContext context, boolean isUpdate) throws SvcLogicException { - String fn = "DBService.processVnfcReference"; - log.info(fn + "Starting DB operation for Vnfc Reference " + isUpdate); - String key = ""; - int vm_instance = -1; - if (context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE) != null) - vm_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE)); - int vnfc_instance = -1; - if (context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE) != null) - vnfc_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE)); - QueryStatus status = null; - if (isUpdate) - key = "update " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE + " set VM_INSTANCE = " + vm_instance - + " , VNFC_INSTANCE = " + vnfc_instance + " , VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE - + " , VNFC_FUNCTION_CODE = $" + SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE - + " , GROUP_NOTATION_TYPE = $" + SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE - + " , GROUP_NOTATION_VALUE = $" + SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE - + " , IPADDRESS_V4_OAM_VIP = $" + SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP - + " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE + " and ACTION = $" - + SdcArtifactHandlerConstants.ACTION + " and VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE - + " and VNFC_INSTANCE = $" + SdcArtifactHandlerConstants.VNFC_INSTANCE + " and VM_INSTANCE = $" - + SdcArtifactHandlerConstants.VM_INSTANCE; - else - key = "insert into " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE + " set VNF_TYPE = $" - + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = $" + SdcArtifactHandlerConstants.ACTION - + " , VM_INSTANCE = $" + SdcArtifactHandlerConstants.VM_INSTANCE + " , VNFC_INSTANCE = $" - + SdcArtifactHandlerConstants.VNFC_INSTANCE + " , VNFC_TYPE = $" - + SdcArtifactHandlerConstants.VNFC_TYPE + " , VNFC_FUNCTION_CODE = $" - + SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE + " , GROUP_NOTATION_TYPE = $" - + SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE + " , IPADDRESS_V4_OAM_VIP = $" - + SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP + " , GROUP_NOTATION_VALUE = $" - + SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE; - - if (serviceLogic != null && context != null) { - status = serviceLogic.save("SQL", false, false, key, null, null, context); - if (status.toString().equals("FAILURE")) - throw new SvcLogicException("Error While processing VNFC_REFERENCE table "); - } - } - - public void processDownloadDgReference(SvcLogicContext context, boolean isUpdate) - throws SvcLogicException, SQLException { - String fn = "DBService.processDownloadDgReference"; - log.info(fn + "Starting DB operation for Download DG Reference " + isUpdate); - String key = ""; - QueryStatus status = null; - - if (isUpdate) - key = "update " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE + " set DOWNLOAD_CONFIG_DG = $" - + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " where PROTOCOL = $" - + SdcArtifactHandlerConstants.DEVICE_PROTOCOL; - else - key = "insert into " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE + " set DOWNLOAD_CONFIG_DG = $" - + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " , PROTOCOL = $" - + SdcArtifactHandlerConstants.DEVICE_PROTOCOL; - - if (serviceLogic != null && context != null) - status = serviceLogic.save("SQL", false, false, key, null, null, context); - if ((status == null) || status.toString().equals("FAILURE")) - throw new SvcLogicException("Error While processing DOWNLOAD_DG_REFERENCE table "); - } - - public void processConfigActionDg(SvcLogicContext context, boolean isUpdate) throws SvcLogicException { - String fn = "DBService.processConfigActionDg"; - log.info(fn + "Starting DB operation for Config DG Action " + isUpdate); - String key = ""; - QueryStatus status = null; - - if (context.getAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE) != null - && context.getAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE).length() > 0) { - if (isUpdate) - key = "update " + SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG + " set DOWNLOAD_CONFIG_DG = $" - + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " where ACTION = $" - + SdcArtifactHandlerConstants.ACTION + " and VNF_TYPE = $" - + SdcArtifactHandlerConstants.VNF_TYPE; - else - key = "insert into " + SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG + " set DOWNLOAD_CONFIG_DG = $" - + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " , ACTION = $" - + SdcArtifactHandlerConstants.ACTION + " , VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE; - - if (serviceLogic != null && context != null) - status = serviceLogic.save("SQL", false, false, key, null, null, context); - if ((status == null) || status.toString().equals("FAILURE")) - throw new SvcLogicException("Error While processing Configure DG Action table "); - } else - log.info("No Update required for Config DG Action"); - - } - - public String getModelDataInformationbyArtifactName(String artifact_name) throws SvcLogicException { - String fn = "DBService.getVnfData"; - String key = ""; - SvcLogicContext con = new SvcLogicContext(); - HashMap modelData = new HashMap(); - QueryStatus status = null; - key = "select VNF_TYPE, VNFC_TYPE, ACTION, FILE_CATEGORY, ARTIFACT_TYPE from ASDC_REFERENCE where ARTIFACT_NAME = " - + artifact_name; - - if (serviceLogic != null && con != null) { - log.info(fn + "select Key: " + key); - status = serviceLogic.query("SQL", false, null, key, null, null, con); - if (status.toString().equals("FAILURE")) - throw new SvcLogicException("Error While processing is ArtifactUpdateRequiredforPD table "); - - } - - log.info(fn + "Vnf_received :" + con.getAttribute("VNF_TYPE")); - - return con.getAttribute("VNF_TYPE"); - - } - - public void updateYangContents(SvcLogicContext context, String artifactId, String yangContents) - throws SvcLogicException { - String fn = "DBService.updateYangContents"; - log.info(fn + "Starting DB operation for updateYangContents"); - String key = ""; - QueryStatus status = null; - - key = "update ASDC_ARTIFACTS " + " set ARTIFACT_CONTENT = '" + yangContents + "'" - + " where ASDC_ARTIFACTS_ID = " + artifactId; - - if (serviceLogic != null && context != null) - status = serviceLogic.save("SQL", false, false, key, null, null, context); - if ((status == null) || status.toString().equals("FAILURE")) - throw new SvcLogicException("Error While processing Configure DG Action table "); - - } - - - public void insertProtocolReference(SvcLogicContext context, String vnfType, String protocol, String action, - String action_level, String template) throws SvcLogicException { - String fn = "DBService.insertProtocolReference"; - log.info(fn + "Starting DB operation for insertProtocolReference"); - String key = ""; - QueryStatus status = null; - - key = "insert into PROTOCOL_REFERENCE (ACTION, VNF_TYPE, PROTOCOL, UPDATED_DATE, TEMPLATE, ACTION_LEVEL)" - + " values (" + "'" + action + "', '" + vnfType + "', '" + protocol + "', now(),'" + template + "', '" - + action_level + "')"; - - if (serviceLogic != null && context != null) - status = serviceLogic.save("SQL", false, false, key, null, null, context); - if ((status == null) || status.toString().equals("FAILURE")) - throw new SvcLogicException("Error While processing insertProtocolReference "); - - } - - public boolean isProtocolReferenceUpdateRequired(SvcLogicContext context, String vnfType, String protocol, - String action, String action_level, String template) throws SvcLogicException { - SvcLogicContext localContext = new SvcLogicContext(); - String fn = "DBService.isProtocolReferenceUpdateRequired"; - log.info(fn + "Starting DB operation for isProtocolReferenceUpdateRequired"); - String key = ""; - QueryStatus status = null; - - key = "select COUNT(*) from PROTOCOL_REFERENCE where ACTION='" + action + "' and ACTION_LEVEL='" + action_level - + "' and VNF_TYPE='" + vnfType + "'"; - status = serviceLogic.query("SQL", false, null, key, null, null, localContext); - String countStr = localContext.getAttribute("COUNT(*)"); - int count = Integer.parseInt(countStr); - if (count > 0) - return true; - else - return false; - } - - public void updateProtocolReference(SvcLogicContext context, String vnfType, String protocol, String action, - String action_level, String template) throws SvcLogicException { - - String fn = "DBService.isProtocolReferenceUpdateRequired"; - log.info(fn + "Starting DB operation for isProtocolReferenceUpdateRequired"); - String key = ""; - QueryStatus status = null; - - key = "update PROTOCOL_REFERENCE set UPDATED_DATE=now(), template='" + template + "' where ACTION='" + action - + "' and ACTION_LEVEL='" + action_level + "' and VNF_TYPE='" + vnfType + "'"; - status = serviceLogic.save("SQL", false, false, key, null, null, context); - if (status == QueryStatus.FAILURE) { - log.info("updateProtocolReference:: Error updating protocol reference"); - throw new SvcLogicException("Error - updating PROTOCOL_REFERENCE_TABLE in updateProtocolReference"); - } - return; - } - - public String getDownLoadDGReference(SvcLogicContext context) throws Exception { - String fn = "DBService.setDownLoadDGReference"; - String downloadConfigDg = null; - log.info(fn + "Setting Download DG Reference from DB"); - String key = ""; - QueryStatus status = null; - String protocol = context.getAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL); - if (StringUtils.isBlank(protocol)) { - log.info(fn + " :: Protocol is Blank!! Returning without querying DB"); - throw new Exception(fn+":: Protocol is Blank!! Returning without querying DB"); - } - key = "select download_config_dg from " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE - + " where protocol = '" + protocol + "'"; - SvcLogicContext localContext = new SvcLogicContext(); - status = serviceLogic.query("SQL", false, null, key, null, null, localContext); - if (status == QueryStatus.FAILURE) { - log.info(fn + ":: Error retrieving download_config_dg"); - throw new SvcLogicException("Error retrieving download_config_dg"); - } - if (status == QueryStatus.NOT_FOUND) { - log.info(fn + ":: NOT_FOUND! No data found for download_config_dg!!"); - throw new Exception(fn + ":: NOT_FOUND! No data found for download_config_dg!"); - } - downloadConfigDg = localContext.getAttribute("download-config-dg"); - log.info(fn + "download_config_dg::" + downloadConfigDg); - return downloadConfigDg; - } - - public void cleanUpVnfcReferencesForVnf(SvcLogicContext context) throws SvcLogicException { - String key1 = "delete from " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE - + " where action = 'Configure' and vnf_type = $" + SdcArtifactHandlerConstants.VNF_TYPE; - QueryStatus status = null; - log.info("cleanUpVnfcReferencesForVnf()::Query:" + key1); - if (serviceLogic != null && context != null) { - status = serviceLogic.save("SQL", false, false, key1, null, null, context); - if (status.toString().equals("FAILURE")) { - log.debug("Error deleting from VNFC_REFERENCE table"); - throw new SvcLogicException("Error While processing VNFC_REFERENCE table "); - } - } - } - - -} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNode.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNode.java deleted file mode 100644 index f56581977..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNode.java +++ /dev/null @@ -1,533 +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.artifact.handler.node; - -import java.io.ByteArrayOutputStream; -import java.io.OutputStream; -import java.util.Map; - -import org.apache.commons.lang.StringUtils; -import org.json.JSONArray; -import org.json.JSONObject; -import org.onap.appc.artifact.handler.dbservices.DBService; -import org.onap.appc.artifact.handler.utils.ArtifactHandlerProviderUtil; -import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; -import org.onap.appc.yang.YANGGenerator; -import org.onap.appc.yang.impl.YANGGeneratorFactory; -import org.openecomp.sdnc.config.params.transformer.tosca.ArtifactProcessorImpl; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - - - -public class ArtifactHandlerNode implements SvcLogicJavaPlugin { - - private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerNode.class); - - public void processArtifact(Map inParams, SvcLogicContext ctx) throws Exception { - String responsePrefix = inParams.get("response_prefix"); - try { - if (inParams != null && !inParams.isEmpty() && inParams.get("postData") != null) { - log.info("Received request for process Artifact with params: " + inParams.toString()); - String postData = inParams.get("postData"); - JSONObject input = new JSONObject(postData).getJSONObject("input"); - responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : ""; - storeUpdateSdcArtifacts(input); - } - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - private boolean storeUpdateSdcArtifacts(JSONObject postDataJson) throws Exception { - log.info("Starting processing of SDC Artifacs into Handler with Data : " + postDataJson.toString()); - try { - JSONObject request_information = - (JSONObject) postDataJson.get(SdcArtifactHandlerConstants.REQUEST_INFORMATION); - JSONObject document_information = - (JSONObject) postDataJson.get(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS); - String artifact_name = document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME); - if (artifact_name != null) { - updateStoreArtifacts(request_information, document_information); - if (artifact_name.toLowerCase().startsWith(SdcArtifactHandlerConstants.REFERENCE)) - return storeReferenceData(request_information, document_information); - else if (artifact_name.toLowerCase().startsWith(SdcArtifactHandlerConstants.PD)) - return createDataForPD(request_information, document_information); - - } else - throw new Exception("Missing Artifact Name for Request : " - + request_information.getString(SdcArtifactHandlerConstants.REQUETS_ID)); - } catch (Exception e) { - e.printStackTrace(); - throw new Exception("Error while processing Request ID : " - + ((JSONObject) postDataJson.get(SdcArtifactHandlerConstants.REQUEST_INFORMATION)) - .getString(SdcArtifactHandlerConstants.REQUETS_ID) - + e.getMessage()); - } - return false; - - } - - private boolean createDataForPD(JSONObject request_information, JSONObject document_information) throws Exception { - - String fn = "ArtifactHandlerNode.createReferenceDataForPD"; - String artifact_name = document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME); - log.info(fn + "Received PD File Name: " + artifact_name + " and suffix lenght " - + SdcArtifactHandlerConstants.PD.length()); - try { - - String suffix = artifact_name.substring(SdcArtifactHandlerConstants.PD.length()); - createArtifactRecords(request_information, document_information, suffix); - } catch (Exception e) { - e.printStackTrace(); - throw new Exception("Error while createing PD data records " + e.getMessage()); - } - return true; - } - - private void createArtifactRecords(JSONObject request_information, JSONObject document_information, String suffix) - throws Exception { - - log.info("Creating Tosca Records and storing into SDC Artifacs"); - String[] docs = {"Tosca", "Yang"}; - ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil(); - String PDFileContents = document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS); - - // Tosca generation - OutputStream toscaStream = new ByteArrayOutputStream(); - String toscaContents = null; - ArtifactProcessorImpl toscaGenerator = new ArtifactProcessorImpl(); - toscaGenerator.generateArtifact(PDFileContents, toscaStream); - if (toscaStream != null) - toscaContents = toscaStream.toString(); - log.info("Generated Tosca File : " + toscaContents); - - String yangContents = "YANG generation is in Progress"; - String yangName = null; - - for (String doc : docs) { - document_information.put(SdcArtifactHandlerConstants.ARTIFACT_TYPE, doc.concat("Type")); - document_information.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, doc.concat("Model")); - if (doc.equals("Tosca")) - document_information.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, - ahpUtil.escapeSql(toscaContents)); - else if (doc.equals("Yang")) - document_information.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, - ahpUtil.escapeSql(yangContents)); - document_information.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, doc.concat(suffix)); - yangName = doc.concat(suffix); - updateStoreArtifacts(request_information, document_information); - } - - String artifactId = getArtifactID(yangName); - OutputStream yangStream = new ByteArrayOutputStream(); - YANGGenerator yangGenerator = YANGGeneratorFactory.getYANGGenerator(); - yangGenerator.generateYANG(artifactId, toscaContents, yangStream); - if (yangStream != null) - yangContents = yangStream.toString(); - - if (yangContents != null) { - updateYangContents(artifactId, ahpUtil.escapeSql(yangContents)); - } - - } - - private void updateYangContents(String artifactId, String yangContents) throws SvcLogicException { - SvcLogicContext context = new SvcLogicContext(); - DBService dbservice = DBService.initialise(); - dbservice.updateYangContents(context, artifactId, yangContents); - } - - private String getArtifactID(String yangName) throws SvcLogicException { - SvcLogicContext context = new SvcLogicContext(); - DBService dbservice = DBService.initialise(); - return dbservice.getArtifactID(context, yangName); - } - - protected boolean updateStoreArtifacts(JSONObject request_information, JSONObject document_information) - throws Exception { - log.info("UpdateStoreArtifactsStarted storing of SDC Artifacs "); - - SvcLogicContext context = new SvcLogicContext(); - DBService dbservice = DBService.initialise(); - ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil(); - int intversion = 0; - context.setAttribute("artifact_name", - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME)); - String internal_version = dbservice.getInternalVersionNumber(context, - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME), null); - log.info("Internal Version number received from Database : " + internal_version); - if (internal_version != null) { - intversion = Integer.parseInt(internal_version); - intversion++; - } - context.setAttribute(SdcArtifactHandlerConstants.SERVICE_UUID, - document_information.getString(SdcArtifactHandlerConstants.SERVICE_UUID)); - context.setAttribute(SdcArtifactHandlerConstants.DISTRIBUTION_ID, - document_information.getString(SdcArtifactHandlerConstants.DISTRIBUTION_ID)); - context.setAttribute(SdcArtifactHandlerConstants.SERVICE_NAME, - document_information.getString(SdcArtifactHandlerConstants.SERVICE_NAME)); - context.setAttribute(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, - document_information.getString(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION)); - context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_UUID, - document_information.getString(SdcArtifactHandlerConstants.RESOURCE_UUID)); - context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, - document_information.getString(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME)); - context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_VERSOIN, - document_information.getString(SdcArtifactHandlerConstants.RESOURCE_VERSOIN)); - context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_TYPE, - document_information.getString(SdcArtifactHandlerConstants.RESOURCE_TYPE)); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_UUID, - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_UUID)); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_TYPE, - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_TYPE)); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN, - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN)); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION)); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, - ahpUtil.escapeSql(document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS))); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME, - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME)); - dbservice.saveArtifacts(context, intversion); - return true; - - } - - public boolean storeReferenceData(JSONObject request_information, JSONObject document_information) - throws Exception { - log.info("Started storing of SDC Artifacs into Handler"); - try { - boolean updateRequired = false; - boolean pdFile = false; - String suffix = null; - String categorySuffix = null; - DBService dbservice = DBService.initialise(); - ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil(); - String contentString = - ahpUtil.escapeSql(document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS)); - String artifactName = - ahpUtil.escapeSql(document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME)); - String capabilityArtifactName = - StringUtils.replace(artifactName, SdcArtifactHandlerConstants.ARTIFACT_NAME_REFERENCE, - SdcArtifactHandlerConstants.ARTIFACT_NAME_CAPABILITY); - JSONObject capabilities = new JSONObject(); - JSONArray vnfActionList = new JSONArray(); - JSONArray vfModuleActionList = new JSONArray(); - JSONArray vnfcActionList = new JSONArray(); - JSONArray vmActionList = new JSONArray(); - String vnfType = null; - JSONObject contentObject = new JSONObject(contentString); - JSONArray contentArray = contentObject.getJSONArray("reference_data"); - boolean storeCapabilityArtifact=true; - for (int a = 0; a < contentArray.length(); a++) { - - JSONObject content = (JSONObject) contentArray.get(a); - log.info("contentString =" + content.toString()); - JSONObject scope = content.getJSONObject("scope"); - log.info("scope :" + scope); - SvcLogicContext context = new SvcLogicContext(); - vnfType = scope.getString(SdcArtifactHandlerConstants.VNF_TYPE); - context.setAttribute(SdcArtifactHandlerConstants.VNF_TYPE, - scope.getString(SdcArtifactHandlerConstants.VNF_TYPE)); - context.setAttribute(SdcArtifactHandlerConstants.ACTION, - content.getString(SdcArtifactHandlerConstants.ACTION)); - String actionLevel = content.getString(SdcArtifactHandlerConstants.ACTION_LEVEL); - context.setAttribute(SdcArtifactHandlerConstants.ACTION_LEVEL, - content.getString(SdcArtifactHandlerConstants.ACTION_LEVEL)); - if ((null != actionLevel) - && actionLevel.equalsIgnoreCase(SdcArtifactHandlerConstants.ACTION_LEVEL_VNFC)) { - vnfcActionList.put(content.getString(SdcArtifactHandlerConstants.ACTION)); - } - if (null != actionLevel - && actionLevel.equalsIgnoreCase(SdcArtifactHandlerConstants.ACTION_LEVEL_VF_MODULE)) { - vfModuleActionList.put(content.getString(SdcArtifactHandlerConstants.ACTION)); - } - if (null != actionLevel && actionLevel.equalsIgnoreCase(SdcArtifactHandlerConstants.ACTION_LEVEL_VNF)) { - vnfActionList.put(content.getString(SdcArtifactHandlerConstants.ACTION)); - } - if (null != actionLevel && actionLevel.equalsIgnoreCase(SdcArtifactHandlerConstants.ACTION_LEVEL_VM)) { - vmActionList.put(content.getString(SdcArtifactHandlerConstants.ACTION)); - } - if (scope.has(SdcArtifactHandlerConstants.VNFC_TYPE) - && !scope.isNull(SdcArtifactHandlerConstants.VNFC_TYPE)) { - context.setAttribute(SdcArtifactHandlerConstants.VNFC_TYPE, - scope.getString(SdcArtifactHandlerConstants.VNFC_TYPE)); - String vnfcTypeScope = scope.getString(SdcArtifactHandlerConstants.VNFC_TYPE); - if (StringUtils.isNotBlank(vnfcTypeScope)) { - storeCapabilityArtifact = false; - log.info("No capability Artifact for this reference data as it is at VNFC level!!"); - } - } - else - context.setAttribute(SdcArtifactHandlerConstants.VNFC_TYPE, null); - if (content.has(SdcArtifactHandlerConstants.DEVICE_PROTOCOL)) - context.setAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL, - content.getString(SdcArtifactHandlerConstants.DEVICE_PROTOCOL)); - if (content.has(SdcArtifactHandlerConstants.USER_NAME)) - context.setAttribute(SdcArtifactHandlerConstants.USER_NAME, - content.getString(SdcArtifactHandlerConstants.USER_NAME)); - if (content.has(SdcArtifactHandlerConstants.PORT_NUMBER)) - context.setAttribute(SdcArtifactHandlerConstants.PORT_NUMBER, - content.getString(SdcArtifactHandlerConstants.PORT_NUMBER)); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_TYPE, ""); - if (content.has("artifact-list") && content.get("artifact-list") instanceof JSONArray) { - JSONArray artifactLists = (JSONArray) content.get("artifact-list"); - for (int i = 0; i < artifactLists.length(); i++) { - JSONObject artifact = (JSONObject) artifactLists.get(i); - log.info("artifact is " + artifact); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME, - artifact.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME)); - context.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, - artifact.getString(SdcArtifactHandlerConstants.ARTIFACT_TYPE)); - - if (artifact.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME) != null - && artifact.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME).toLowerCase() - .startsWith(SdcArtifactHandlerConstants.PD)) { - suffix = artifact.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME) - .substring(SdcArtifactHandlerConstants.PD.length()); - categorySuffix = artifact.getString(SdcArtifactHandlerConstants.ARTIFACT_TYPE) - .substring(SdcArtifactHandlerConstants.PD.length()); - pdFile = true; - } - - dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context, - SdcArtifactHandlerConstants.DB_SDC_REFERENCE)); - - cleanArtifactInstanceData(context); - } - - if (pdFile) { - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME, "Tosca".concat(suffix)); - context.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, - SdcArtifactHandlerConstants.TOSCA_MODEL); - dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context, - SdcArtifactHandlerConstants.DB_SDC_REFERENCE)); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME, "Yang".concat(suffix)); - context.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, - SdcArtifactHandlerConstants.PARAMETER_YANG); - dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context, - SdcArtifactHandlerConstants.DB_SDC_REFERENCE)); - } - } - if (content.getString(SdcArtifactHandlerConstants.ACTION).equals("Configure") - || content.getString(SdcArtifactHandlerConstants.ACTION).equals("ConfigModify")) { - if (content.has(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE) - && content.getString(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE).length() > 0) { - context.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, - content.getString(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE)); - dbservice.processDownloadDgReference(context, dbservice.isArtifactUpdateRequired(context, - SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE)); - } - if (StringUtils.isBlank(context.getAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE))) - context.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, - dbservice.getDownLoadDGReference(context)); - dbservice.processConfigActionDg(context, dbservice.isArtifactUpdateRequired(context, - SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG)); - if (content.getString(SdcArtifactHandlerConstants.ACTION).equals("Configure")) { - dbservice.processDeviceInterfaceProtocol(context, dbservice.isArtifactUpdateRequired(context, - SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL)); - dbservice.processDeviceAuthentication(context, dbservice.isArtifactUpdateRequired(context, - SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION)); - } - - } - - - populateProtocolReference(dbservice, content); - - context.setAttribute(SdcArtifactHandlerConstants.VNFC_TYPE, null); - - if (content.has(SdcArtifactHandlerConstants.VM) - && content.get(SdcArtifactHandlerConstants.VM) instanceof JSONArray) { - JSONArray vmList = (JSONArray) content.get(SdcArtifactHandlerConstants.VM); - dbservice.cleanUpVnfcReferencesForVnf(context); - for (int i = 0; i < vmList.length(); i++) { - JSONObject vmInstance = (JSONObject) vmList.get(i); - context.setAttribute(SdcArtifactHandlerConstants.VM_INSTANCE, - String.valueOf(vmInstance.getInt(SdcArtifactHandlerConstants.VM_INSTANCE))); - log.info("VALUE = " + context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE)); - if (vmInstance.get(SdcArtifactHandlerConstants.VNFC) instanceof JSONArray) { - JSONArray vnfcInstanceList = (JSONArray) vmInstance.get(SdcArtifactHandlerConstants.VNFC); - for (int k = 0; k < vnfcInstanceList.length(); k++) { - JSONObject vnfcInstance = (JSONObject) vnfcInstanceList.get(k); - context.setAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE, - String.valueOf(vnfcInstance.getInt(SdcArtifactHandlerConstants.VNFC_INSTANCE))); - context.setAttribute(SdcArtifactHandlerConstants.VNFC_TYPE, - vnfcInstance.getString(SdcArtifactHandlerConstants.VNFC_TYPE)); - context.setAttribute(SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE, - vnfcInstance.getString(SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE)); - if (vnfcInstance.has(SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP)) - context.setAttribute(SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP, - vnfcInstance.getString(SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP)); - if (vnfcInstance.has(SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE)) - context.setAttribute(SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE, - vnfcInstance.getString(SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE)); - if (vnfcInstance.has(SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE)) - context.setAttribute(SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE, - vnfcInstance.getString(SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE)); - if (content.getString(SdcArtifactHandlerConstants.ACTION).equals("Configure")) { - dbservice.processVnfcReference(context,false); - } - cleanVnfcInstance(context); - } - context.setAttribute(SdcArtifactHandlerConstants.VM_INSTANCE, null); - } - } - } - - - } - if (storeCapabilityArtifact) { - capabilities.put("vnf", vnfActionList); - capabilities.put("vf-module", vfModuleActionList); - capabilities.put("vnfc", vnfcActionList); - capabilities.put("vm", vmActionList); - processAndStoreCapablitiesArtifact(dbservice, document_information, capabilities, capabilityArtifactName, - vnfType); - } - - } catch (Exception e) { - e.printStackTrace(); - throw new Exception("Error While Storing : " + e.getMessage()); - } - - return true; - } - - private void cleanArtifactInstanceData(SvcLogicContext context) { - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME, null); - context.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, null); - } - - private void cleanVnfcInstance(SvcLogicContext context) { - - context.setAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE, null); - context.setAttribute(SdcArtifactHandlerConstants.VNFC_TYPE, null); - context.setAttribute(SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE, null); - context.setAttribute(SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP, null); - context.setAttribute(SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE, null); - context.setAttribute(SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE, null); - - } - - private void processAndStoreCapablitiesArtifact(DBService dbservice, JSONObject document_information, - JSONObject capabilities, String capabilityArtifactName, String vnfType) throws Exception { - log.info("Begin-->processAndStoreCapablitiesArtifact "); - - try { - - JSONObject newCapabilitiesObject = new JSONObject(); - newCapabilitiesObject.put("capabilities", capabilities); - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME, capabilityArtifactName); - context.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, SdcArtifactHandlerConstants.CAPABILITY); - context.setAttribute(SdcArtifactHandlerConstants.ACTION, null); - context.setAttribute(SdcArtifactHandlerConstants.VNFC_TYPE, null); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_TYPE, null); - context.setAttribute(SdcArtifactHandlerConstants.VNF_TYPE, vnfType); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, newCapabilitiesObject.toString()); - dbservice.processSdcReferences(context, - dbservice.isArtifactUpdateRequired(context, SdcArtifactHandlerConstants.DB_SDC_REFERENCE)); - int intversion = 0; - - String internal_version = dbservice.getInternalVersionNumber(context, - context.getAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME), null); - log.info("Internal Version number received from Database : " + internal_version); - if (internal_version != null) { - intversion = Integer.parseInt(internal_version); - intversion++; - } - context.setAttribute(SdcArtifactHandlerConstants.SERVICE_UUID, - document_information.getString(SdcArtifactHandlerConstants.SERVICE_UUID)); - context.setAttribute(SdcArtifactHandlerConstants.DISTRIBUTION_ID, - document_information.getString(SdcArtifactHandlerConstants.DISTRIBUTION_ID)); - context.setAttribute(SdcArtifactHandlerConstants.SERVICE_NAME, - document_information.getString(SdcArtifactHandlerConstants.SERVICE_NAME)); - context.setAttribute(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, - document_information.getString(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION)); - context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_UUID, - document_information.getString(SdcArtifactHandlerConstants.RESOURCE_UUID)); - context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, - document_information.getString(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME)); - context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_VERSOIN, - document_information.getString(SdcArtifactHandlerConstants.RESOURCE_VERSOIN)); - context.setAttribute(SdcArtifactHandlerConstants.RESOURCE_TYPE, - document_information.getString(SdcArtifactHandlerConstants.RESOURCE_TYPE)); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_UUID, - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_UUID)); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN, - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN)); - context.setAttribute(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION)); - - - dbservice.saveArtifacts(context, intversion); - return; - } catch (Exception e) { - log.error("Error saving capabilities artifact to DB: " + e.toString()); - throw e; - } finally { - log.info("End-->processAndStoreCapablitiesArtifact "); - } - - } - - private void populateProtocolReference(DBService dbservice, JSONObject content) throws Exception { - log.info("Begin-->populateProtocolReference "); - try { - SvcLogicContext context = new SvcLogicContext(); - JSONObject scope = content.getJSONObject("scope"); - String vnfType = null, protocol = null, action = null, actionLevel = null, template = null; - if (scope.has(SdcArtifactHandlerConstants.VNF_TYPE) && !scope.isNull(SdcArtifactHandlerConstants.VNF_TYPE)) - vnfType = scope.getString(SdcArtifactHandlerConstants.VNF_TYPE); - if (content.has(SdcArtifactHandlerConstants.DEVICE_PROTOCOL)) - protocol = content.getString(SdcArtifactHandlerConstants.DEVICE_PROTOCOL); - if (content.has(SdcArtifactHandlerConstants.ACTION)) - action = content.getString(SdcArtifactHandlerConstants.ACTION); - if (content.has(SdcArtifactHandlerConstants.ACTION_LEVEL)) - actionLevel = content.getString(SdcArtifactHandlerConstants.ACTION_LEVEL); - if (content.has(SdcArtifactHandlerConstants.TEMPLATE) - && !content.isNull(SdcArtifactHandlerConstants.TEMPLATE)) - template = content.getString(SdcArtifactHandlerConstants.TEMPLATE); - boolean isUpdateNeeded=dbservice.isProtocolReferenceUpdateRequired(context, vnfType, protocol, action, actionLevel, template); - if (isUpdateNeeded) - dbservice.updateProtocolReference(context, vnfType, protocol, action, actionLevel, template); - else - dbservice.insertProtocolReference(context, vnfType,protocol,action,actionLevel,template); - } catch (Exception e) { - log.error("Error inserting record into protocolReference: " + e.toString()); - throw e; - } finally { - log.info("End-->populateProtocolReference "); - } - } - -} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java deleted file mode 100644 index 15859178a..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java +++ /dev/null @@ -1,191 +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.artifact.handler.utils; - -import java.io.IOException; -import java.security.SecureRandom; -import java.util.HashMap; - -import org.apache.commons.lang3.StringUtils; -import org.json.JSONException; -import org.json.JSONObject; -import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactInput; -import org.onap.appc.artifact.handler.node.ArtifactHandlerNode; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ArtifactHandlerProviderUtil { - - public UploadartifactInput templateData ; - SvcLogicContext context = null; - private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerProviderUtil.class); - public static void loadProperties() { - // TODO Auto-generated method stub - - } - public enum DistributionStatusEnum { - DOWNLOAD_OK, - DOWNLOAD_ERROR, - ALREADY_DOWNLOADED, - DEPLOY_OK, - DEPLOY_ERROR, - ALREADY_DEPLOYED; - } - - public ArtifactHandlerProviderUtil(){}; - - public ArtifactHandlerProviderUtil(UploadartifactInput input) { - this.templateData = input; - log.info("templateData " + this.templateData); - } - - public void processTemplate(String requestInfo) throws Exception { - if(context == null) - context = new SvcLogicContext(); - - ArtifactHandlerNode node = new ArtifactHandlerNode(); - try { - - HashMap processdata = new HashMap(); - processdata.put("postData", requestInfo); - log.info("Post data = " + requestInfo); - node.processArtifact(processdata, context); - } catch (Exception e) { - // TODO Auto-generated catch block - log.error("Error: " + e.getMessage()); - e.printStackTrace(); - throw e; - } - - } - public String createDummyRequestData() throws JSONException, IOException{ - - - JSONObject info = new JSONObject(this.templateData); - log.info("INFO = " + info); - String artifact_name = templateData.getDocumentParameters().getArtifactName(); - String artifact_version = templateData.getDocumentParameters().getArtifactVersion(); - - JSONObject json = new JSONObject(); - JSONObject requestInfo = new JSONObject(); - String random = getRandom(); - - requestInfo.put(SdcArtifactHandlerConstants.REQUETS_ID, "TLRID-" + random); - requestInfo.put(SdcArtifactHandlerConstants.REQUEST_ACTION, "StoreSdcDocumentRequest"); - requestInfo.put(SdcArtifactHandlerConstants.SOURCE, "TemplateLoader"); - - JSONObject docParams = new JSONObject(); - docParams.put(SdcArtifactHandlerConstants.SERVICE_UUID, "TLSUUID" + templateData.getRequestInformation().getRequestId()); - docParams.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "TLDID" + random); - docParams.put(SdcArtifactHandlerConstants.SERVICE_NAME, "TLServiceName"); - docParams.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "Template Loader Test"); - docParams.put(SdcArtifactHandlerConstants.SERVICE_ARTIFACTS, "[]"); - docParams.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "TLRUID" + random); - docParams.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "TLRIName"); - docParams.put(SdcArtifactHandlerConstants.REOURCE_NAME, "TLResourceName"); - docParams.put(SdcArtifactHandlerConstants.RESOURCE_VERSOIN, "TLResourceVersion"); - docParams.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "TLResourceType"); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "TLAUUID" + random); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_TYPE, "APPC-CONFIG"); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN, templateData.getDocumentParameters().getArtifactVersion()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "SdcTestDescription"); - // String data = IOUtils.toString(TestartifactHandlerNode.class.getClassLoader().getResourceAsStream("template_msrp_msc_a_template.json"), "utf-8"); - // String data = IOUtils.toString(TemplateProcessor.class.getClassLoader().getResourceAsStream("referenceData.json"), "utf-8"); - - // this.templateData = this.templateData.substring(this.templateData.indexOf("}") + 1); - docParams.put("artifact-contents", templateData.getDocumentParameters().getArtifactContents()); - - json.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); - json.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, docParams); - System.out.println("Final data =" + this.templateData); - return String.format("{\"input\": %s}", json.toString()); - } - - private String getRandom() { - SecureRandom random = new SecureRandom(); - int num = random.nextInt(100000); - String formatted = String.format("%05d", num); - return formatted; - } - - public String escapeSql(String str) { - if (str == null) { - return null; - } - String searchList[] = new String[]{"'","\\"}; - String replacementList[] = new String[]{ "''","\\\\"}; - return StringUtils.replaceEach(str,searchList, replacementList); - } - public String createRequestData() throws JSONException, IOException{ - - - JSONObject info = new JSONObject(this.templateData); - log.info("INFO = " + info); - - JSONObject json = new JSONObject(); - JSONObject requestInfo = new JSONObject(); - String random = getRandom(); - - requestInfo.put(SdcArtifactHandlerConstants.REQUETS_ID, templateData.getRequestInformation().getRequestId()); - requestInfo.put(SdcArtifactHandlerConstants.REQUEST_ACTION, "StoreSdcDocumentRequest"); - requestInfo.put(SdcArtifactHandlerConstants.SOURCE, templateData.getRequestInformation().getSource()); - - String serviceDescription = serviceDescriptionData(templateData.getDocumentParameters().getServiceDescription()); - - JSONObject docParams = new JSONObject(); - docParams.put(SdcArtifactHandlerConstants.SERVICE_UUID, templateData.getDocumentParameters().getResourceUuid()); - docParams.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, templateData.getDocumentParameters().getDistributionId()); - docParams.put(SdcArtifactHandlerConstants.SERVICE_NAME, templateData.getDocumentParameters().getServiceName()); - docParams.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION,serviceDescription); - docParams.put(SdcArtifactHandlerConstants.SERVICE_ARTIFACTS, templateData.getDocumentParameters().getServiceArtifacts()); - docParams.put(SdcArtifactHandlerConstants.RESOURCE_UUID, templateData.getDocumentParameters().getResourceUuid()); - docParams.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, templateData.getDocumentParameters().getResourceInstanceName()); - docParams.put(SdcArtifactHandlerConstants.REOURCE_NAME, templateData.getDocumentParameters().getResourceName()); - docParams.put(SdcArtifactHandlerConstants.RESOURCE_VERSOIN, templateData.getDocumentParameters().getResourceVersion()); - docParams.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, templateData.getDocumentParameters().getResourceType()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, templateData.getDocumentParameters().getArtifactUuid()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_TYPE, templateData.getDocumentParameters().getArtifactType()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN, templateData.getDocumentParameters().getArtifactVersion()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, templateData.getDocumentParameters().getArtifactDescription()); - - docParams.put("artifact-contents", templateData.getDocumentParameters().getArtifactContents()); - - json.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); - json.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, docParams); - System.out.println("Final data =" + this.templateData); - return String.format("{\"input\": %s}", json.toString()); - } - - private String serviceDescriptionData(String serviceDescription){ - if(!StringUtils.isBlank(serviceDescription)&&serviceDescription.length()>255){ - serviceDescription = serviceDescription.substring(0, 255); - } - return serviceDescription; - } -} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/EscapeUtils.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/EscapeUtils.java deleted file mode 100644 index ece5cdb24..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/EscapeUtils.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.artifact.handler.utils; - -import org.apache.commons.lang3.StringUtils; - -public class EscapeUtils { - - public EscapeUtils() { - // TODO Auto-generated constructor stub - } - - public static String escapeSql(String str) { - if (str == null) { - return null; - } - String searchList[] = new String[]{"'","\\"}; - String replacementList[] = new String[]{ "''","\\\\"}; - return StringUtils.replaceEach(str,searchList, replacementList); - } -} diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java deleted file mode 100644 index c045ee7d4..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/openecomp/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java +++ /dev/null @@ -1,93 +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.artifact.handler.utils; - -public class SdcArtifactHandlerConstants { - - public static final String DOCUMENT_PARAMETERS = "document-parameters"; - public static final String SERVICE_UUID = "service-uuid"; - public static final String DISTRIBUTION_ID = "distribution-id"; - public static final String REQUETS_ID = "request-id"; - public static final String REQUEST_ACTION = "request-action"; - public static final String SOURCE = "source"; - public static final String SERVICE_NAME = "service-name"; - public static final String SERVICE_DESCRIPTION ="service-description"; - public static final String SERVICE_ARTIFACTS = "service-artifacts"; - public static final String RESOURCE_UUID ="resource-uuid"; - public static final String RESOURCE_INSTANCE_NAME = "resource-instance-name"; - public static final String REOURCE_NAME = "resource-name"; - public static final String RESOURCE_VERSOIN ="resource-version"; - public static final String RESOURCE_TYPE= "resource-type"; - public static final String ARTIFACT_UUID ="artifact-uuid"; - public static final String ARTIFACT_NAME = "artifact-name"; - public static final String ARTIFACT_TYPE = "artifact-type"; - public static final String ARTIFACT_VERSOIN = "artifact-version"; - public static final String ARTIFACT_DESRIPTION = "artifact-description"; - public static final String ARTIFACT_CONTENTS = "artifact-contents"; - public static final String REQUEST_INFORMATION = "request-information"; - public static final String INTERNAL_VERSION = "internal-versoin"; - public static final String FILE_CATEGORY = "file-category"; - public static final String VNF_TYPE = "vnf-type"; - public static final String ACTION = "action"; - public static final String ACTION_LEVEL = "action-level"; - public static final String VNFC_TYPE = "vnfc-type"; - public static final String VM_INSTANCE = "vm-instance"; - public static final String VM = "vm"; - public static final String VNFC = "vnfc"; - public static final String VNFC_FUNCTION_CODE = "vnfc-function-code"; - public static final String GROUP_NOTATION = "group-notation"; - public static final String IPADDRESS_V4_OAM_VIP = "ipaddress-v4-oam-vip"; - public static final String GROUP_NOTATION_TYPE = "group-notation-type"; - public static final String GROUP_NOTATION_VALUE = "group-notation-value"; - public static final String REFERENCE = "reference"; - public static final String VNFC_INSTANCE = "vnfc-instance"; - public static final String DEVICE_PROTOCOL = "device-protocol"; - public static final String DG_RPC = "dg-rpc"; - public static final String MODULE = "module"; - public static final String USER_NAME = "user-name"; - public static final String PORT_NUMBER = "port-number"; - public static final String DOWNLOAD_DG_REFERENCE = "download-dg-reference"; - - - public static final String DB_DOWNLOAD_DG_REFERENCE = "DOWNLOAD_DG_REFERENCE"; - public static final String DB_SDC_REFERENCE = "ASDC_REFERENCE"; - public static final String DB_DEVICE_INTERFACE_PROTOCOL = "DEVICE_INTERFACE_PROTOCOL"; - public static final String DB_DEVICE_AUTHENTICATION = "DEVICE_AUTHENTICATION"; - public static final String DB_VNFC_REFERENCE = "VNFC_REFERENCE"; - public static final String DB_CONFIG_ACTION_DG = "CONFIGURE_ACTION_DG"; - public static final String PD = "pd"; - public static final String PARAMETER_YANG = "parameter_yang"; - public static final String TOSCA_MODEL = "tosca_model"; - public static final String DESIGN_TOOL = "Design-tool"; - public static final String ACTION_LEVEL_VNFC = "VNFC"; - public static final String ACTION_LEVEL_VF_MODULE ="VF-MODULE"; - public static final String ACTION_LEVEL_VNF = "VNF"; - public static final String ACTION_LEVEL_VM = "VM"; - public static final String CAPABILITY = "capability"; - public static final String TEMPLATE = "template"; - public static final String ARTIFACT_NAME_REFERENCE = "reference"; - public static final String ARTIFACT_NAME_CAPABILITY = "capability"; -} - diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/DBServiceTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/DBServiceTest.java new file mode 100644 index 000000000..d5e86a0fc --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/DBServiceTest.java @@ -0,0 +1,298 @@ +/*- + * ============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.artifact.handler.dbservices; + +import java.nio.charset.Charset; +import org.json.JSONObject; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.powermock.reflect.Whitebox; +import static org.junit.Assert.assertEquals; + +public class DBServiceTest { + + @Test + public void testSaveArtifacts() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + int internalVersion = 1; + dbService.saveArtifacts(ctx, internalVersion); + } + + @Test + public void testSaveArtifactsException() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + int internalVersion = 1; + dbService.saveArtifacts(ctx, internalVersion); + } + + @Test + public void testLogData() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String prefix = "test"; + dbService.logData(ctx, prefix); + } + + + @Test + public void testLogDataException() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String prefix = "test"; + dbService.logData(ctx, prefix); + } + + @Test + public void testProcessConfigActionDg() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + ctx.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, "Reference"); + dbService.processConfigActionDg(ctx, isUpdate); + } + + @Test + public void testProcessConfigActionDgException() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + ctx.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, "Reference"); + dbService.processConfigActionDg(ctx, isUpdate); + } + + @Test + public void testGetModelDataInformationbyArtifactName() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String artifactName = "test"; + dbService.getModelDataInformationbyArtifactName(artifactName); + } + + @Test + public void testGetModelDataInformationbyArtifactNameException() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String artifactName = "test"; + dbService.getModelDataInformationbyArtifactName(artifactName); + } + + @Test + public void testUpdateYangContents() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String artifactName = "test"; + String artifactId = "TestArtifact"; + String yangContents = "TestYangContents"; + dbService.updateYangContents(ctx, artifactId, yangContents); + } + + @Test + public void testUpdateYangContentsException() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String artifactName = "test"; + String artifactId = "TestArtifact"; + String yangContents = "TestYangContents"; + dbService.updateYangContents(ctx, artifactId, yangContents); + } + + @Test + public void testInsertProtocolReference() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String vnfType = "testVnf"; + String protocol = "testProtocol"; + String action = "testAction"; + String actionLevel = "testActionLevel"; + String template = "testTemplateData"; + dbService.insertProtocolReference(ctx, vnfType, protocol, action, actionLevel, template); + } + + + @Test + public void testInsertProtocolReferenceException() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String vnfType = "testVnf"; + String protocol = "testProtocol"; + String action = "testAction"; + String actionLevel = "testActionLevel"; + String template = "testTemplateData"; + dbService.insertProtocolReference(ctx, vnfType, protocol, action, actionLevel, template); + } + + @Test + public void testprocessDpwnloadDGReference() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processDownloadDgReference(ctx, isUpdate); + } + + @Test + public void testprocessDpwnloadDGReferenceException() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processDownloadDgReference(ctx, isUpdate); + } + + @Test + public void testProcessVnfcReference() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processVnfcReference(ctx, isUpdate); + } + + @Test + public void testProcessVnfcReferenceException() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processVnfcReference(ctx, isUpdate); + } + + @Test + public void testProcessDeviceAuthentication() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processDeviceAuthentication(ctx, isUpdate); + } + + @Test + public void testProcessDeviceAuthenticationException() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processDeviceAuthentication(ctx, isUpdate); + } + + @Test + public void testProcessDeviceInterfaceProtocol() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processDeviceInterfaceProtocol(ctx, isUpdate); + } + + @Test + public void testProcessDeviceInterfaceProtocolException() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processDeviceInterfaceProtocol(ctx, isUpdate); + } + + @Test + public void testProcessSdcReferences() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + ctx.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, "testCategory"); + boolean isUpdate = true; + dbService.processSdcReferences(ctx, isUpdate); + } + + @Ignore + public void testProcessSdcReferencesException() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processSdcReferences(ctx, isUpdate); + } + + @Test + public void testIsArtifactUpdateRequired() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String db = "db"; + dbService.isArtifactUpdateRequired(ctx, db); + } + + @Test + public void testIsArtifactUpdateRequiredExcetion() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String db = "db"; + dbService.isArtifactUpdateRequired(ctx, db); + } + + + @Test + public void testgetArtifactID() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String db = "db"; + dbService.getArtifactID(ctx, db); + } + + @Test + public void testgetArtifactIDException() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String db = "db"; + dbService.getArtifactID(ctx, db); + } + @Test + public void testGetDownLoadDGReference() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + ctx.setAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL, "CLI"); + assertEquals("TestDG", dbService.getDownLoadDGReference(ctx)); + } +} + diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockDBService.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockDBService.java new file mode 100644 index 000000000..caec09172 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockDBService.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.artifact.handler.dbservices; + +public class MockDBService extends DBService { + private static MockDBService mockDgGeneralDBService = null; + private static MockSvcLogicResource serviceLogic = new MockSvcLogicResource();; + + public MockDBService() { + super(serviceLogic); + if (mockDgGeneralDBService != null) { + mockDgGeneralDBService = new MockDBService(serviceLogic); + } + + } + + public MockDBService(MockSvcLogicResource serviceLogic2) { + super(serviceLogic); + } + + public static MockDBService initialise() { + if (mockDgGeneralDBService == null) { + mockDgGeneralDBService = new MockDBService(serviceLogic); + } + return mockDgGeneralDBService; + } + +} + diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockSvcLogicResource.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockSvcLogicResource.java new file mode 100644 index 000000000..c931ab0f4 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockSvcLogicResource.java @@ -0,0 +1,55 @@ +/*- + * ============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.artifact.handler.dbservices; + +import java.util.Map; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; + +public class MockSvcLogicResource extends SqlResource { + + @Override + public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix, + String orderBy, SvcLogicContext ctx) throws SvcLogicException { + QueryStatus status = QueryStatus.SUCCESS; + ctx.setAttribute("id", "testId"); + ctx.setAttribute("VNF_TYPE", "testvnf"); + ctx.setAttribute("maximum", "1"); + ctx.setAttribute("COUNT(*)", "1"); + ctx.setAttribute("download-config-dg", "TestDG"); + return status; + } + + + @Override + public QueryStatus save(String resource, boolean force, boolean localOnly, String key, Map parms, + String prefix, SvcLogicContext ctx) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java new file mode 100644 index 000000000..42d436e98 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java @@ -0,0 +1,174 @@ +/*- + * ============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.artifact.handler.node; + +import java.io.InputStream; +import java.nio.charset.Charset; +import java.util.Enumeration; +import java.util.Properties; + +import org.apache.commons.io.IOUtils; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.powermock.reflect.Whitebox; +import static org.junit.Assert.assertTrue; +import org.onap.appc.artifact.handler.dbservices.DBService; +import org.onap.appc.artifact.handler.dbservices.MockDBService; +import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; +import org.onap.appc.artifact.handler.utils.ArtifactHandlerProviderUtilTest; + +import java.util.Map; +import java.util.HashMap; + +public class ArtifactHandlerNodeTest { + + @Test + public void testProcessArtifact() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); + Map inParams = new HashMap(); + JSONObject postData = new JSONObject(); + JSONObject input = new JSONObject(); + inParams.put("response_prefix", "prefix"); + JSONObject requestInfo = new JSONObject(); + JSONObject documentInfo = new JSONObject(); + String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() + .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json"); + requestInfo.put("RequestInfo", "testValue"); + input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo); + input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); + postData.put("input", input); + inParams.put("postData", postData.toString()); + ah.processArtifact(inParams, ctx); + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testStoreReferenceData() throws Exception { + MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); + JSONObject documentInfo = new JSONObject(); + String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() + .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json"); + JSONObject requestInfo = new JSONObject(); + requestInfo.put("RequestInfo", "testStoreReferenceData"); + ah.storeReferenceData(requestInfo, documentInfo); + } + + @Test + public void testPopulateProtocolReference() throws Exception { + ArtifactHandlerNode ah = new ArtifactHandlerNode(); + String contentStr = + "{\"action\": \"TestAction\",\"action-level\": \"vnf\",\"scope\": {\"vnf-type\": \"vDBE-I\",\"vnfc-type\": null},\"template\": \"N\",\"device-protocol\": \"REST\"}"; + JSONObject content = new JSONObject(contentStr); + MockDBService dbService = MockDBService.initialise(); + Whitebox.invokeMethod(ah, "populateProtocolReference", dbService, content); + } + + @Test + public void testProcessAndStoreCapablitiesArtifact() throws Exception { + ArtifactHandlerNode ah = new ArtifactHandlerNode(); + JSONObject capabilities = new JSONObject(); + JSONObject documentInfo = new JSONObject(); + MockDBService dbService = MockDBService.initialise(); + documentInfo.put(SdcArtifactHandlerConstants.SERVICE_UUID, "testuid"); + documentInfo.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "testDist"); + documentInfo.put(SdcArtifactHandlerConstants.SERVICE_NAME, "testName"); + documentInfo.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "testDesc"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "testRes"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "testResIns"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_VERSOIN, "testVers"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "testResType"); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "testArtifactUuid"); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN, "testArtifactVers"); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "testArtifactDesc"); + Whitebox.invokeMethod(ah, "processAndStoreCapablitiesArtifact", dbService, documentInfo, capabilities, + "artifactName", "someVnf"); + } + + @Test + public void testCleanVnfcInstance() throws Exception { + ArtifactHandlerNode ah = new ArtifactHandlerNode(); + SvcLogicContext ctx = new SvcLogicContext(); + Whitebox.invokeMethod(ah, "cleanVnfcInstance", ctx); + assertTrue(true); + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testGetArtifactIDException() throws Exception { + ArtifactHandlerNode ah = new ArtifactHandlerNode(); + String yFileName = "yFileName"; + Whitebox.invokeMethod(ah, "getArtifactID", yFileName); + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testStoreUpdateSdcArtifacts() throws Exception { + ArtifactHandlerNode ah = new ArtifactHandlerNode(); + String postDataStr = + "{\"request-information\":{},\"document-parameters\":{\"artifact-name\":\"testArtifact\",\"artifact-contents\":{\"content\":\"TestContent\"}}}"; + JSONObject postData = new JSONObject(postDataStr); + Whitebox.invokeMethod(ah, "storeUpdateSdcArtifacts", postData); + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testUpdateStoreArtifacts() throws Exception { + MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); + JSONObject documentInfo = new JSONObject(); + String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() + .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json"); + JSONObject requestInfo = new JSONObject(); + requestInfo.put("RequestInfo", "testupdateStoreArtifacts"); + ah.updateStoreArtifacts(requestInfo, documentInfo); + } + + @Test + public void testCleanArtifactInstanceData() throws Exception { + MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); + SvcLogicContext ctx = new SvcLogicContext(); + Whitebox.invokeMethod(ah, "cleanArtifactInstanceData", ctx); + } + + @Ignore("Test is taking 60 seconds") + @Test(expected = Exception.class) + public void testUpdateYangContents() throws Exception { + MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); + String artifactId = "1"; + String yangContents = "SomeContent"; + Whitebox.invokeMethod(ah, "updateYangContents", artifactId, yangContents); + } + +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/MockArtifactHandlerNode.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/MockArtifactHandlerNode.java new file mode 100644 index 000000000..39706a282 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/MockArtifactHandlerNode.java @@ -0,0 +1,65 @@ +/*- + * ============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.artifact.handler.node; + +import org.json.JSONObject; +import org.onap.appc.artifact.handler.dbservices.MockDBService; +import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +public class MockArtifactHandlerNode extends ArtifactHandlerNode { + + @Override + public boolean updateStoreArtifacts(JSONObject request_information, JSONObject document_information) + throws Exception { + if (request_information != null && request_information.get("RequestInfo").equals("testupdateStoreArtifacts")) { + super.updateStoreArtifacts(request_information, document_information); + } + SvcLogicContext context = new SvcLogicContext(); + MockDBService dbservice = MockDBService.initialise(); + int intversion = 0; + context.setAttribute("artifact_name", + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME)); + String internal_version = dbservice.getInternalVersionNumber(context, + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME), null); + if (internal_version != null) { + intversion = Integer.parseInt(internal_version); + intversion++; + } + + return true; + + } + + @Override + public boolean storeReferenceData(JSONObject request_information, JSONObject document_information) + throws Exception { + if (request_information != null && request_information.get("RequestInfo").equals("testStoreReferenceData")) { + super.storeReferenceData(request_information, document_information); + } + return true; + } + +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java new file mode 100644 index 000000000..ef6ec6618 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java @@ -0,0 +1,82 @@ +/*- + * ============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.artifact.handler.utils; + +import static org.junit.Assert.assertTrue; +import java.nio.charset.Charset; +import org.apache.commons.io.IOUtils; +import org.json.JSONObject; +import org.junit.Test; +import org.powermock.reflect.Whitebox; + +public class ArtifactHandlerProviderUtilTest { + + @Test(expected = Exception.class) + public void testProcessTemplate() throws Exception { + String artifact_conetent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() + .getResourceAsStream("templates/reference_template.json"), Charset.defaultCharset()); + JSONObject obj = new JSONObject(); + obj.put("artifact-name", "reference_JunitTestArtifact"); + obj.put("artifact-version", "0.01"); + obj.put("artifact-contents", artifact_conetent); + ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); + ahprovider.processTemplate(obj.toString()); + } + + @Test(expected = Exception.class) + public void testcreateDummyRequestData() throws Exception { + String artifact_conetent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() + .getResourceAsStream("templates/reference_template.json"), Charset.defaultCharset()); + JSONObject obj = new JSONObject(); + obj.put("artifact-name", "reference_JunitTestArtifact"); + obj.put("artifact-version", "0.01"); + obj.put("artifact-contents", artifact_conetent); + ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); + String requestInfo = ahprovider.createDummyRequestData(); + } + + @Test + public void testEscapeSql() throws Exception { + String testStr = "Test String is 'test'"; + ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); + ahprovider.escapeSql(testStr); + assertTrue(true); + } + + @Test + public void testGetRandom() throws Exception { + ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); + Whitebox.invokeMethod(ahprovider, "getRandom"); + assertTrue(true); + } + + @Test + public void testEscapeUtils() throws Exception { + String str = "The Test string is 'test'"; + EscapeUtils.escapeSql(str); + assertTrue(true); + } +} + diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/DBServiceTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/DBServiceTest.java deleted file mode 100644 index d5e86a0fc..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/DBServiceTest.java +++ /dev/null @@ -1,298 +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.artifact.handler.dbservices; - -import java.nio.charset.Charset; -import org.json.JSONObject; -import org.junit.Ignore; -import org.junit.Test; -import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.powermock.reflect.Whitebox; -import static org.junit.Assert.assertEquals; - -public class DBServiceTest { - - @Test - public void testSaveArtifacts() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - int internalVersion = 1; - dbService.saveArtifacts(ctx, internalVersion); - } - - @Test - public void testSaveArtifactsException() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - int internalVersion = 1; - dbService.saveArtifacts(ctx, internalVersion); - } - - @Test - public void testLogData() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - String prefix = "test"; - dbService.logData(ctx, prefix); - } - - - @Test - public void testLogDataException() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - String prefix = "test"; - dbService.logData(ctx, prefix); - } - - @Test - public void testProcessConfigActionDg() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - boolean isUpdate = true; - ctx.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, "Reference"); - dbService.processConfigActionDg(ctx, isUpdate); - } - - @Test - public void testProcessConfigActionDgException() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - boolean isUpdate = true; - ctx.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, "Reference"); - dbService.processConfigActionDg(ctx, isUpdate); - } - - @Test - public void testGetModelDataInformationbyArtifactName() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - String artifactName = "test"; - dbService.getModelDataInformationbyArtifactName(artifactName); - } - - @Test - public void testGetModelDataInformationbyArtifactNameException() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - String artifactName = "test"; - dbService.getModelDataInformationbyArtifactName(artifactName); - } - - @Test - public void testUpdateYangContents() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - String artifactName = "test"; - String artifactId = "TestArtifact"; - String yangContents = "TestYangContents"; - dbService.updateYangContents(ctx, artifactId, yangContents); - } - - @Test - public void testUpdateYangContentsException() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - String artifactName = "test"; - String artifactId = "TestArtifact"; - String yangContents = "TestYangContents"; - dbService.updateYangContents(ctx, artifactId, yangContents); - } - - @Test - public void testInsertProtocolReference() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - String vnfType = "testVnf"; - String protocol = "testProtocol"; - String action = "testAction"; - String actionLevel = "testActionLevel"; - String template = "testTemplateData"; - dbService.insertProtocolReference(ctx, vnfType, protocol, action, actionLevel, template); - } - - - @Test - public void testInsertProtocolReferenceException() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - String vnfType = "testVnf"; - String protocol = "testProtocol"; - String action = "testAction"; - String actionLevel = "testActionLevel"; - String template = "testTemplateData"; - dbService.insertProtocolReference(ctx, vnfType, protocol, action, actionLevel, template); - } - - @Test - public void testprocessDpwnloadDGReference() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - boolean isUpdate = true; - dbService.processDownloadDgReference(ctx, isUpdate); - } - - @Test - public void testprocessDpwnloadDGReferenceException() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - boolean isUpdate = true; - dbService.processDownloadDgReference(ctx, isUpdate); - } - - @Test - public void testProcessVnfcReference() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - boolean isUpdate = true; - dbService.processVnfcReference(ctx, isUpdate); - } - - @Test - public void testProcessVnfcReferenceException() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - boolean isUpdate = true; - dbService.processVnfcReference(ctx, isUpdate); - } - - @Test - public void testProcessDeviceAuthentication() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - boolean isUpdate = true; - dbService.processDeviceAuthentication(ctx, isUpdate); - } - - @Test - public void testProcessDeviceAuthenticationException() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - boolean isUpdate = true; - dbService.processDeviceAuthentication(ctx, isUpdate); - } - - @Test - public void testProcessDeviceInterfaceProtocol() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - boolean isUpdate = true; - dbService.processDeviceInterfaceProtocol(ctx, isUpdate); - } - - @Test - public void testProcessDeviceInterfaceProtocolException() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - boolean isUpdate = true; - dbService.processDeviceInterfaceProtocol(ctx, isUpdate); - } - - @Test - public void testProcessSdcReferences() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - ctx.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, "testCategory"); - boolean isUpdate = true; - dbService.processSdcReferences(ctx, isUpdate); - } - - @Ignore - public void testProcessSdcReferencesException() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - boolean isUpdate = true; - dbService.processSdcReferences(ctx, isUpdate); - } - - @Test - public void testIsArtifactUpdateRequired() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - String db = "db"; - dbService.isArtifactUpdateRequired(ctx, db); - } - - @Test - public void testIsArtifactUpdateRequiredExcetion() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - String db = "db"; - dbService.isArtifactUpdateRequired(ctx, db); - } - - - @Test - public void testgetArtifactID() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - String db = "db"; - dbService.getArtifactID(ctx, db); - } - - @Test - public void testgetArtifactIDException() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - String db = "db"; - dbService.getArtifactID(ctx, db); - } - @Test - public void testGetDownLoadDGReference() throws Exception { - MockDBService dbService = MockDBService.initialise(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - ctx.setAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL, "CLI"); - assertEquals("TestDG", dbService.getDownLoadDGReference(ctx)); - } -} - diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/MockDBService.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/MockDBService.java deleted file mode 100644 index caec09172..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/MockDBService.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.artifact.handler.dbservices; - -public class MockDBService extends DBService { - private static MockDBService mockDgGeneralDBService = null; - private static MockSvcLogicResource serviceLogic = new MockSvcLogicResource();; - - public MockDBService() { - super(serviceLogic); - if (mockDgGeneralDBService != null) { - mockDgGeneralDBService = new MockDBService(serviceLogic); - } - - } - - public MockDBService(MockSvcLogicResource serviceLogic2) { - super(serviceLogic); - } - - public static MockDBService initialise() { - if (mockDgGeneralDBService == null) { - mockDgGeneralDBService = new MockDBService(serviceLogic); - } - return mockDgGeneralDBService; - } - -} - diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/MockSvcLogicResource.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/MockSvcLogicResource.java deleted file mode 100644 index c931ab0f4..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/MockSvcLogicResource.java +++ /dev/null @@ -1,55 +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.artifact.handler.dbservices; - -import java.util.Map; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; - -public class MockSvcLogicResource extends SqlResource { - - @Override - public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix, - String orderBy, SvcLogicContext ctx) throws SvcLogicException { - QueryStatus status = QueryStatus.SUCCESS; - ctx.setAttribute("id", "testId"); - ctx.setAttribute("VNF_TYPE", "testvnf"); - ctx.setAttribute("maximum", "1"); - ctx.setAttribute("COUNT(*)", "1"); - ctx.setAttribute("download-config-dg", "TestDG"); - return status; - } - - - @Override - public QueryStatus save(String resource, boolean force, boolean localOnly, String key, Map parms, - String prefix, SvcLogicContext ctx) throws SvcLogicException { - return QueryStatus.SUCCESS; - } - - -} diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNodeTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNodeTest.java deleted file mode 100644 index 42d436e98..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNodeTest.java +++ /dev/null @@ -1,174 +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.artifact.handler.node; - -import java.io.InputStream; -import java.nio.charset.Charset; -import java.util.Enumeration; -import java.util.Properties; - -import org.apache.commons.io.IOUtils; -import org.json.JSONObject; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.powermock.reflect.Whitebox; -import static org.junit.Assert.assertTrue; -import org.onap.appc.artifact.handler.dbservices.DBService; -import org.onap.appc.artifact.handler.dbservices.MockDBService; -import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; -import org.onap.appc.artifact.handler.utils.ArtifactHandlerProviderUtilTest; - -import java.util.Map; -import java.util.HashMap; - -public class ArtifactHandlerNodeTest { - - @Test - public void testProcessArtifact() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("test", "test"); - MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); - Map inParams = new HashMap(); - JSONObject postData = new JSONObject(); - JSONObject input = new JSONObject(); - inParams.put("response_prefix", "prefix"); - JSONObject requestInfo = new JSONObject(); - JSONObject documentInfo = new JSONObject(); - String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() - .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); - documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); - documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json"); - requestInfo.put("RequestInfo", "testValue"); - input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo); - input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); - postData.put("input", input); - inParams.put("postData", postData.toString()); - ah.processArtifact(inParams, ctx); - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testStoreReferenceData() throws Exception { - MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); - JSONObject documentInfo = new JSONObject(); - String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() - .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); - documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); - documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json"); - JSONObject requestInfo = new JSONObject(); - requestInfo.put("RequestInfo", "testStoreReferenceData"); - ah.storeReferenceData(requestInfo, documentInfo); - } - - @Test - public void testPopulateProtocolReference() throws Exception { - ArtifactHandlerNode ah = new ArtifactHandlerNode(); - String contentStr = - "{\"action\": \"TestAction\",\"action-level\": \"vnf\",\"scope\": {\"vnf-type\": \"vDBE-I\",\"vnfc-type\": null},\"template\": \"N\",\"device-protocol\": \"REST\"}"; - JSONObject content = new JSONObject(contentStr); - MockDBService dbService = MockDBService.initialise(); - Whitebox.invokeMethod(ah, "populateProtocolReference", dbService, content); - } - - @Test - public void testProcessAndStoreCapablitiesArtifact() throws Exception { - ArtifactHandlerNode ah = new ArtifactHandlerNode(); - JSONObject capabilities = new JSONObject(); - JSONObject documentInfo = new JSONObject(); - MockDBService dbService = MockDBService.initialise(); - documentInfo.put(SdcArtifactHandlerConstants.SERVICE_UUID, "testuid"); - documentInfo.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "testDist"); - documentInfo.put(SdcArtifactHandlerConstants.SERVICE_NAME, "testName"); - documentInfo.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "testDesc"); - documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "testRes"); - documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "testResIns"); - documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_VERSOIN, "testVers"); - documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "testResType"); - documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "testArtifactUuid"); - documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN, "testArtifactVers"); - documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "testArtifactDesc"); - Whitebox.invokeMethod(ah, "processAndStoreCapablitiesArtifact", dbService, documentInfo, capabilities, - "artifactName", "someVnf"); - } - - @Test - public void testCleanVnfcInstance() throws Exception { - ArtifactHandlerNode ah = new ArtifactHandlerNode(); - SvcLogicContext ctx = new SvcLogicContext(); - Whitebox.invokeMethod(ah, "cleanVnfcInstance", ctx); - assertTrue(true); - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testGetArtifactIDException() throws Exception { - ArtifactHandlerNode ah = new ArtifactHandlerNode(); - String yFileName = "yFileName"; - Whitebox.invokeMethod(ah, "getArtifactID", yFileName); - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testStoreUpdateSdcArtifacts() throws Exception { - ArtifactHandlerNode ah = new ArtifactHandlerNode(); - String postDataStr = - "{\"request-information\":{},\"document-parameters\":{\"artifact-name\":\"testArtifact\",\"artifact-contents\":{\"content\":\"TestContent\"}}}"; - JSONObject postData = new JSONObject(postDataStr); - Whitebox.invokeMethod(ah, "storeUpdateSdcArtifacts", postData); - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testUpdateStoreArtifacts() throws Exception { - MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); - JSONObject documentInfo = new JSONObject(); - String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() - .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); - documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); - documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json"); - JSONObject requestInfo = new JSONObject(); - requestInfo.put("RequestInfo", "testupdateStoreArtifacts"); - ah.updateStoreArtifacts(requestInfo, documentInfo); - } - - @Test - public void testCleanArtifactInstanceData() throws Exception { - MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); - SvcLogicContext ctx = new SvcLogicContext(); - Whitebox.invokeMethod(ah, "cleanArtifactInstanceData", ctx); - } - - @Ignore("Test is taking 60 seconds") - @Test(expected = Exception.class) - public void testUpdateYangContents() throws Exception { - MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); - String artifactId = "1"; - String yangContents = "SomeContent"; - Whitebox.invokeMethod(ah, "updateYangContents", artifactId, yangContents); - } - -} diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/MockArtifactHandlerNode.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/MockArtifactHandlerNode.java deleted file mode 100644 index 39706a282..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/MockArtifactHandlerNode.java +++ /dev/null @@ -1,65 +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.artifact.handler.node; - -import org.json.JSONObject; -import org.onap.appc.artifact.handler.dbservices.MockDBService; -import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -public class MockArtifactHandlerNode extends ArtifactHandlerNode { - - @Override - public boolean updateStoreArtifacts(JSONObject request_information, JSONObject document_information) - throws Exception { - if (request_information != null && request_information.get("RequestInfo").equals("testupdateStoreArtifacts")) { - super.updateStoreArtifacts(request_information, document_information); - } - SvcLogicContext context = new SvcLogicContext(); - MockDBService dbservice = MockDBService.initialise(); - int intversion = 0; - context.setAttribute("artifact_name", - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME)); - String internal_version = dbservice.getInternalVersionNumber(context, - document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME), null); - if (internal_version != null) { - intversion = Integer.parseInt(internal_version); - intversion++; - } - - return true; - - } - - @Override - public boolean storeReferenceData(JSONObject request_information, JSONObject document_information) - throws Exception { - if (request_information != null && request_information.get("RequestInfo").equals("testStoreReferenceData")) { - super.storeReferenceData(request_information, document_information); - } - return true; - } - -} diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java deleted file mode 100644 index ef6ec6618..000000000 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java +++ /dev/null @@ -1,82 +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.artifact.handler.utils; - -import static org.junit.Assert.assertTrue; -import java.nio.charset.Charset; -import org.apache.commons.io.IOUtils; -import org.json.JSONObject; -import org.junit.Test; -import org.powermock.reflect.Whitebox; - -public class ArtifactHandlerProviderUtilTest { - - @Test(expected = Exception.class) - public void testProcessTemplate() throws Exception { - String artifact_conetent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() - .getResourceAsStream("templates/reference_template.json"), Charset.defaultCharset()); - JSONObject obj = new JSONObject(); - obj.put("artifact-name", "reference_JunitTestArtifact"); - obj.put("artifact-version", "0.01"); - obj.put("artifact-contents", artifact_conetent); - ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); - ahprovider.processTemplate(obj.toString()); - } - - @Test(expected = Exception.class) - public void testcreateDummyRequestData() throws Exception { - String artifact_conetent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() - .getResourceAsStream("templates/reference_template.json"), Charset.defaultCharset()); - JSONObject obj = new JSONObject(); - obj.put("artifact-name", "reference_JunitTestArtifact"); - obj.put("artifact-version", "0.01"); - obj.put("artifact-contents", artifact_conetent); - ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); - String requestInfo = ahprovider.createDummyRequestData(); - } - - @Test - public void testEscapeSql() throws Exception { - String testStr = "Test String is 'test'"; - ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); - ahprovider.escapeSql(testStr); - assertTrue(true); - } - - @Test - public void testGetRandom() throws Exception { - ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); - Whitebox.invokeMethod(ahprovider, "getRandom"); - assertTrue(true); - } - - @Test - public void testEscapeUtils() throws Exception { - String str = "The Test string is 'test'"; - EscapeUtils.escapeSql(str); - assertTrue(true); - } -} - diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/ArtifactInfo.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/ArtifactInfo.java new file mode 100644 index 000000000..53f6f02fb --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/ArtifactInfo.java @@ -0,0 +1,42 @@ +/*- + * ============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.design.data; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ArtifactInfo { + + @JsonProperty("artifact-content") + String artifact_content; + + public String getArtifact_content() { + return artifact_content; + } + + public void setArtifact_content(String artifact_content) { + this.artifact_content = artifact_content; + } + +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignInfo.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignInfo.java new file mode 100644 index 000000000..a6d2ba24b --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignInfo.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.design.data; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class DesignInfo{ + + @JsonProperty("vnf-type") + String vnf_type; + + @JsonProperty("vnfc-type") + String vnfc_type; + + @JsonProperty("protocol") + String protocol; + + @JsonProperty("incart") + String inCart; + + @JsonProperty("action") + String action; + + @JsonProperty("artifact-name") + String artifact_name; + + + @JsonProperty("artifact-type") + String artifact_type; + + public String getArtifact_type() { + return artifact_type; + } + + public void setArtifact_type(String artifact_type) { + this.artifact_type = artifact_type; + } + + public String getArtifact_name() { + return artifact_name; + } + + public void setArtifact_name(String artifact_name) { + this.artifact_name = artifact_name; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public String getVnf_type() { + return vnf_type; + } + + public void setVnf_type(String vnf_type) { + this.vnf_type = vnf_type; + } + + public String getVnfc_type() { + return vnfc_type; + } + + public void setVnfc_type(String vnfc_type) { + this.vnfc_type = vnfc_type; + } + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public String getInCart() { + return inCart; + } + + public void setInCart(String inCart) { + this.inCart = inCart; + } + + @Override + public String toString() { + return "DesignInfo [vnf_type=" + vnf_type + ", vnfc_type=" + vnfc_type + ", protocol=" + protocol + ", inCart=" + + inCart + "]"; + } + +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignRequest.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignRequest.java new file mode 100644 index 000000000..d61de0282 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignRequest.java @@ -0,0 +1,132 @@ +/*- + * ============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.design.data; + +import java.io.File; +import java.net.URL; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import javax.sql.rowset.CachedRowSet; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.onap.appc.design.services.util.DesignServiceConstants; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +import org.onap.ccsdk.sli.core.dblib.DbLibService; + +public class DesignRequest{ + + + @JsonProperty("userID") + String userId ; + + @JsonProperty("vnf-type") + String vnf_type; + + @JsonProperty("vnfc-type") + String vnfc_type; + + @JsonProperty("protocol") + String protocol; + + @JsonProperty("action") + String action; + + @JsonProperty("artifact-name") + String artifact_name; + + @JsonProperty("artifact-contents") + String artifact_contents ; + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getVnf_type() { + return vnf_type; + } + + public void setVnf_type(String vnf_type) { + this.vnf_type = vnf_type; + } + + public String getVnfc_type() { + return vnfc_type; + } + + public void setVnfc_type(String vnfc_type) { + this.vnfc_type = vnfc_type; + } + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public String getArtifact_name() { + return artifact_name; + } + + public void setArtifact_name(String artifact_name) { + this.artifact_name = artifact_name; + } + + public String getArtifact_contents() { + return artifact_contents; + } + + public void setArtifact_contents(String artifact_contents) { + this.artifact_contents = artifact_contents; + } + + @Override + public String toString() { + return "DesignRequest [userId=" + userId + ", vnf_type=" + vnf_type + ", vnfc_type=" + vnfc_type + ", protocol=" + + protocol + ", action=" + action + ", artifact_name=" + artifact_name + ", artifact_contents=" + + artifact_contents + "]"; + } + +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignResponse.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignResponse.java new file mode 100644 index 000000000..559620d9e --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignResponse.java @@ -0,0 +1,77 @@ +/*- + * ============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.design.data; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class DesignResponse{ + + + @JsonProperty("userID") + String userId ; + + @JsonProperty("designInfo") + List designInfoList; + + @JsonProperty("statusInfo") + List statusInfoList; + + @JsonProperty("artifactInfo") + List artifactInfo; + + + public List getArtifactInfo() { + return artifactInfo; + } + + public void setArtifactInfo(List artifactInfo) { + this.artifactInfo = artifactInfo; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public List getDesignInfoList() { + return designInfoList; + } + + public void setDesignInfoList(List designInfoList) { + this.designInfoList = designInfoList; + } + + public List getStatusInfoList() { + return statusInfoList; + } + + public void setStatusInfoList(List statusInfoList) { + this.statusInfoList = statusInfoList; + } +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/StatusInfo.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/StatusInfo.java new file mode 100644 index 000000000..6d4b1a5a1 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/StatusInfo.java @@ -0,0 +1,86 @@ +/*- + * ============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.design.data; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class StatusInfo{ + + @JsonProperty("vnf-type") + String vnf_type; + + @JsonProperty("vnfc-type") + String vnfc_type; + + @JsonProperty("action") + String action; + + @JsonProperty("artifact-status") + String artifact_status; + + @JsonProperty("action-status") + String action_status; + + public String getVnf_type() { + return vnf_type; + } + + public void setVnf_type(String vnf_type) { + this.vnf_type = vnf_type; + } + + public String getVnfc_type() { + return vnfc_type; + } + + public void setVnfc_type(String vnfc_type) { + this.vnfc_type = vnfc_type; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public String getArtifact_status() { + return artifact_status; + } + + public void setArtifact_status(String artifact_status) { + this.artifact_status = artifact_status; + } + + public String getAction_status() { + return action_status; + } + + public void setAction_status(String action_status) { + this.action_status = action_status; + } + +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java new file mode 100644 index 000000000..e697a9d4f --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java @@ -0,0 +1,110 @@ +/*- + * ============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.design.dbervices; + +import org.onap.appc.design.services.util.DesignServiceConstants; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class DbResponseProcessor { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(DbResponseProcessor.class); + public String parseResponse(String dbresposne, String action) throws Exception { + + log.info("Starting Parsing the response for action : " + action + "\n data " + dbresposne ); + String response ; + switch (action) { + case DesignServiceConstants.GETDESIGNS: + response = getDesignsResponse(dbresposne); + break; + case DesignServiceConstants.ADDINCART: + response = getAddInCartResponse(dbresposne); + break ; + case DesignServiceConstants.GETARTIFACTREFERENCE: + response= getArtifactReferenceResponse(dbresposne); + break; + case DesignServiceConstants.GETARTIFACT: + response= getArtifactResponse(dbresposne); + break; + case DesignServiceConstants.GETGUIREFERENCE: + response= getGuiReferenceResponse(dbresposne); + break; + case DesignServiceConstants.GETSTATUS: + response= getStatusResponse(dbresposne); + break; + case DesignServiceConstants.UPLOADARTIFACT: + response= getsetStatusResponse(dbresposne); + break; + case DesignServiceConstants.SETPROTOCOLREFERENCE: + response= getsetStatusResponse(dbresposne); + break; + case DesignServiceConstants.SETINCART: + response= getsetStatusResponse(dbresposne); + break; + default: + log.error("Action " + action + " Not Supported by response Parser"); + throw new Exception(" Action " + action + " not found while processing request "); + + } + return response; + + } + + private String getArtifactResponse(String dbresposne) { + // TODO Auto-generated method stub + return dbresposne; + } + + private String getsetStatusResponse(String dbresposne) { + // TODO Auto-generated method stub + return null; + } + + private String getStatusResponse(String dbresposne) { + log.info("Returning reposne from Response Parser " + dbresposne); + return dbresposne; + } + + private String getGuiReferenceResponse(String dbresposne) { + // TODO Auto-generated method stub + return null; + } + + private String getArtifactReferenceResponse(String dbresposne) { + // TODO Auto-generated method stub + return null; + } + + private String getAddInCartResponse(String dbresposne) { + // TODO Auto-generated method stub + return null; + } + + private String getDesignsResponse(String dbresposne) { + return dbresposne; + + } +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbService.java new file mode 100644 index 000000000..a2349196f --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbService.java @@ -0,0 +1,146 @@ +/*- + * ============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.design.dbervices; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Properties; +import java.util.UUID; + +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +import org.onap.ccsdk.sli.core.dblib.DbLibService; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DbService { + + private static final Logger Log = LoggerFactory.getLogger(DbService.class); + private static final String DBLIB_SERVICE = "org.onap.ccsdk.sli.core.dblib.DBResourceManager"; + DbLibService dblibSvc = null; + String errorMsg = null; + + public DbService() throws Exception { + DbLibService dblibSvc = null; + Log.info("Initializing DbService service"); + try + { + dblibSvc = getDbLibService(); + if (dblibSvc == null) { + Log.error("Got Exception While getting DB Connection"); + throw new Exception("Got Exception While getting DB Connection"); + } + this.dblibSvc = dblibSvc; + } + catch (Exception e) { + Log.error(e.getMessage()); + throw e; + } + } + + private static DbLibService getDbLibService() { + + DbLibService dblibSvc = null; + BundleContext bctx = null; + ServiceReference sref = null; + + Bundle bundle = FrameworkUtil.getBundle(SvcLogicService.class); + + if (bundle != null) { + bctx = bundle.getBundleContext(); + } + + if (bctx != null) { + Log.debug("Getting bundle Context"); + sref = bctx.getServiceReference(DBLIB_SERVICE); + } + + if (sref == null) { + Log.warn("Could not find service reference for DBLib service"); + + } else { + dblibSvc = (DbLibService) bctx.getService(sref); + if (dblibSvc == null) { + Log.warn("DBLIB_SERVICE is null"); + } + } + if (dblibSvc == null) { + try { + dblibSvc = new DBResourceManager(System.getProperties()); + } catch (Exception e) { + Log.error("Caught exception trying to create db service", e); + } + + if (dblibSvc == null) { + Log.warn("Could not create new DBResourceManager"); + } + } + return (dblibSvc); + } + + public ResultSet getDBData(String query) throws Exception { + ResultSet resultSet; + StringBuilder sqlBuilder = new StringBuilder(query); + Log.info("Query: " + sqlBuilder.toString()); + try { + resultSet = dblibSvc.getData(sqlBuilder.toString(), null, null); + } catch (Exception e) { + Log.error("SQL query "+sqlBuilder+" :: " + e.getMessage()); + throw e; + } + return resultSet; + } + + public ResultSet getDBData(String query, ArrayList paramList) throws Exception { + ResultSet resultSet; + StringBuilder sqlBuilder = new StringBuilder(query); + Log.info("Query :" + sqlBuilder.toString()); + try { + resultSet = dblibSvc.getData(sqlBuilder.toString(), paramList, null); + } catch (Exception expObj) { + Log.error("query "+sqlBuilder+" :: " + expObj.getMessage()); + throw expObj; + } + return resultSet; + } + + public boolean updateDBData(String query, ArrayList paramList) throws Exception { + boolean update; + StringBuilder sqlBuilder = new StringBuilder(query); + Log.info("Query :" + sqlBuilder.toString()); + try { + update = dblibSvc.writeData(sqlBuilder.toString(), paramList, null); + } catch (Exception expObj) { + Log.error("query "+sqlBuilder+" :: " + expObj.getMessage()); + throw expObj; + } + return update; + } +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java new file mode 100644 index 000000000..64251027f --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java @@ -0,0 +1,645 @@ +/*- + * ============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.design.dbervices; + +import java.io.IOException; +import java.security.SecureRandom; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.onap.appc.design.data.ArtifactInfo; +import org.onap.appc.design.data.DesignInfo; +import org.onap.appc.design.data.DesignResponse; +import org.onap.appc.design.data.StatusInfo; +import org.onap.appc.design.services.util.ArtifactHandlerClient; +import org.onap.appc.design.services.util.DesignServiceConstants; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +public class DesignDBService { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(DesignDBService.class); + private SvcLogicResource serviceLogic; + private static DesignDBService dgGeneralDBService = null; + private static DBResourceManager jdbcDataSource; + + DbService dbservice = null; + private static Properties props; + public static DesignDBService initialise() { + if (dgGeneralDBService == null) { + dgGeneralDBService = new DesignDBService(); + } + return dgGeneralDBService; + } + private DesignDBService() { + if (serviceLogic == null) { + serviceLogic = new SqlResource(); + } + } + + public String execute(String action, String payload, String requestID) throws Exception { + + log.info("Received execute request for action : " + action + " with Payload : "+ payload ); + RequestValidator.validate(action, payload); + String response = null; + dbservice = new DbService(); + switch (action) { + case DesignServiceConstants.GETDESIGNS: + response = getDesigns(payload,requestID ); + break; + case DesignServiceConstants.ADDINCART: + response= setInCart(payload, requestID); + break ; + case DesignServiceConstants.GETARTIFACTREFERENCE: + response= getArtifactReference(payload, requestID); + break; + case DesignServiceConstants.GETARTIFACT: + response= getArtifact(payload, requestID); + break; + case DesignServiceConstants.GETGUIREFERENCE: + response= getGuiReference(payload, requestID); + break; + case DesignServiceConstants.GETSTATUS: + response= getStatus(payload, requestID); + break; + case DesignServiceConstants.SETSTATUS: + response= setStatus(payload, requestID); + break; + case DesignServiceConstants.UPLOADARTIFACT: + response= uploadArtifact(payload, requestID); + break; + case DesignServiceConstants.SETPROTOCOLREFERENCE: + response= setProtocolReference(payload, requestID); + break; + default: + throw new Exception(" Action " + action + " not found while processing request "); + + } + return response; + } + + private String setInCart(String payload, String requestID) throws Exception { + + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + ArrayList argList = new ArrayList<>(); + argList.add(payloadObject.get(DesignServiceConstants.INCART).textValue()); + argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); + + String queryString = "UPDATE DT_ARTIFACT_TRACKING SET INCART= ? WHERE ASDC_REFERENCE_ID IN " + + " (SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE_ID WHERE VNF_TYPE = ? " ; + + if(payloadObject.get(DesignServiceConstants.VNF_TYPE) != null &&! payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) { + queryString = queryString + " AND VNFC_TYPE = ? ) AND USER = ? " ; + argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); + } + else{ + queryString = queryString + " ) AND USER = ? " ; + } + + argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); + + log.info("Query String :" + queryString); + boolean data = dbservice.updateDBData(queryString, argList); + + if(!data) + throw new Exception("Error while updating ProtocolReference"); + + return "{\"update\" : \"success\" } "; + + } + private String setProtocolReference(String payload, String requestID) throws Exception { + + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + ArrayList argList = new ArrayList<>(); + + argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); + argList.add(payloadObject.get(DesignServiceConstants.ACTION_LEVEL).textValue()); + argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); + argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue()); + + String queryString = " DELETE FROM PROTOCOL_REFERENCE WHERE ACTION = ? AND ACTION_LEVEL AND VNF_TYPE= ? AND PROTOCOL = ? " ; + + log.info("Delete Query String :" + queryString); + boolean data = dbservice.updateDBData(queryString, argList); + + log.info("Record Deleted"); + + if((payloadObject.get(DesignServiceConstants.TEMPLATE) != null && !payloadObject.get(DesignServiceConstants.TEMPLATE).textValue().isEmpty())) + argList.add(payloadObject.get(DesignServiceConstants.TEMPLATE).textValue()); + else + argList.add("NO"); + + String insertString = "INSERT INTO PROTOCOL_REFERENCE VALUES (?,?,?,?,?,SYSDATE()) "; + + if(payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && ! payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()){ + queryString = queryString + " AND VNFC_TYPE = ? )" ; + } + else{ + queryString = queryString + " ) "; + } + log.info("Query String :" + queryString); + data = dbservice.updateDBData(queryString, argList); + + if(!data) + throw new Exception("Error while updating ProtocolReference"); + + return "{\"update\" : \"success\" } "; + } + private String uploadArtifact(String payload, String requestID) throws Exception { + + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + log.info("Got upload Aritfact with Payload : " + payloadObject.asText()); + try{ + ArtifactHandlerClient ac = new ArtifactHandlerClient(); + String requestString = ac.createArtifactData(payload, requestID); + ac.execute(requestString, "POST"); + int sdc_artifact_id = getSDCArtifactIDbyRequestID(requestID); + int sdc_reference_id = getSDCReferenceID(payload); + createArtifactTrackingRecord(payload, requestID,sdc_artifact_id, sdc_reference_id ); + String status = getDataFromActionStatus(payload, "STATUS"); + if(status == null || status.isEmpty()) + setActionStatus(payload, "Not Tested"); + linkstatusRelationShip(sdc_artifact_id,sdc_reference_id, payload); + + } + catch(Exception e){ + e.printStackTrace(); + throw e; + } + return "{\"update\" : \"success\" } "; + + } + + private void linkstatusRelationShip(int sdc_artifact_id, int sdc_reference_id, String payload) throws Exception { + + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + ArrayList argList = new ArrayList<>(); + argList.add(String.valueOf(sdc_artifact_id)); + argList.add(String.valueOf(sdc_reference_id)); + argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); + argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); + argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); + + String queryString = "INSERT INTO DT_STATUS_RELATIONSHIP (DT_ARTIFACT_TRACKING_ID,DT_ACTION_STATUS_ID) VALUES " + + "(( SELECT DT_ARTIFACT_TRACKING_ID FROM DT_ARTIFACT_TRACKING WHERE ASDC_ARTIFACTS_ID = ? AND ASDC_REFERENCE_ID = ? ) , " + + "( SELECT DT_ACTION_STATUS_ID FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? " ; + + if(payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && ! payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()){ + queryString = queryString + " AND VNFC_TYPE = ? ) )" ; + } + else{ + queryString = queryString + " ) ) "; + } + log.info("Query String :" + queryString); + boolean data = dbservice.updateDBData(queryString, argList); + + if(!data) + throw new Exception("Error while updating RealtionShip table"); + + } + private int getSDCReferenceID(String payload) throws Exception { + + String vnfc_type = null; + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + ArrayList argList = new ArrayList<>(); + argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); + + argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue()); + argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue()); + + String queryString = " SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE WHERE VNF_TYPE = ? " + + " AND ARTIFACT_TYPE = ? AND ARTIFACT_NAME = ? " ; + + if(payloadObject.get(DesignServiceConstants.ACTION) != null && !payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty()){ + argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); + queryString = queryString + " AND ACTION = ? "; + } + if(payloadObject.get(DesignServiceConstants.VNFC_TYPE) !=null && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()){ + argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); + queryString = queryString + " AND VNFC_TYPE = ? "; + + } + + log.info("Query String :" + queryString); + ResultSet data = dbservice.getDBData(queryString, argList); + int sdc_reference_id = 0; + while(data.next()) { + sdc_reference_id = data.getInt("ASDC_REFERENCE_ID"); + } + log.info("Got sdc_reference_id = " + sdc_reference_id ); + return sdc_reference_id; + + } + + private String getDataFromActionStatus(String payload, String dataValue) throws Exception { + String status = null ; + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + ArrayList argList = new ArrayList<>(); + argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); + argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); + argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); + String queryString = " SELECT " + dataValue + " FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? "; + if(payloadObject.get(DesignServiceConstants.VNFC_TYPE) !=null && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()){ + argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); + queryString = queryString + " AND VNFC_TYPE = ? "; + } + log.info("Query String :" + queryString); + ResultSet data = dbservice.getDBData(queryString, argList); + while(data.next()) { + status = data.getString("STATUS"); + } + log.info("DT_ACTION_STATUS Status = " + status ); + return status; + } + + private boolean setActionStatus(String payload, String status) throws Exception { + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + ArrayList argList = new ArrayList<>(); + argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); + argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); + + + String insertQuery = " INSERT INTO DT_ACTION_STATUS (ACTION, VNF_TYPE, VNFC_TYPE, USER, TECHNOLOGY, UPDATED_DATE, STATUS) VALUES (?,?,?,?,?,sysdate() , ?); "; + if(payloadObject.get(DesignServiceConstants.VNFC_TYPE) !=null && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()){ + argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); + } + else{ + argList.add(null); + } + argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); + if(payloadObject.get(DesignServiceConstants.TECHNOLOGY) !=null && !payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()){ + argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue()); + } + else{ + argList.add(null); + } + argList.add(status); + + boolean updateStatus = dbservice.updateDBData(insertQuery, argList); + if(!updateStatus) + throw new Exception("Error while updating Action Status"); + return updateStatus; + } + + private void createArtifactTrackingRecord(String payload, String requestID, int sdc_artifact_id, int sdc_reference_id) throws Exception { + String vnfc_type = null; + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + + ArrayList argList = new ArrayList<>(); + argList.add(String.valueOf(sdc_artifact_id)); + argList.add(String.valueOf(sdc_reference_id)); + argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); + if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null &&! payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) + argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue()); + else + argList.add(""); + + if (payloadObject.get(DesignServiceConstants.PROTOCOL) != null &&! payloadObject.get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) + argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue()); + else + argList.add(""); + + + String queryString = "INSERT INTO DT_ARTIFACT_TRACKING (ASDC_ARTIFACTS_ID, ASDC_REFERENCE_ID, USER, TECHNOLOGY, CREATION_DATE, UPDATED_DATE, ARTIFACT_STATUS, PROTOCOL, IN_CART) VALUES (? , ? , ?, ?, sysdate() , sysdate(), 'Created', ? ,'N' )" ; + + log.info("Query String :" + queryString); + boolean data = dbservice.updateDBData(queryString, argList); + if(!data) + throw new Exception("Error Updating DT_ARTIFACT_TRACKING "); + + + } + + private int getSDCArtifactIDbyRequestID(String requestID) throws Exception { + log.info("Starting getArtifactIDbyRequestID DB Operation"); + int artifact_id = 0; + try{ + ArrayList argList = new ArrayList<>(); + argList.add("TLSUUID" + requestID); + String queryString = " SELECT ASDC_ARTIFACTS_ID FROM ASDC_ARTIFACTS where SERVICE_UUID = ? "; + log.info("Query String :" + queryString); + ResultSet data = dbservice.getDBData(queryString, argList); + while(data.next()){ + artifact_id = data.getInt("ASDC_ARTIFACTS_ID"); + } + } + catch(Exception e){ + e.printStackTrace(); + throw e; + } + log.info("Got SDC_ARTIFACTS_ID As :" + artifact_id); + return artifact_id; + } + + + private String getArtifact(String payload, String requestID) throws Exception { + String fn = "DBService.getStatus "; + log.info("Starting getArtifact DB Operation"); + try{ + String vnfc_type = null; + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + ArrayList argList = new ArrayList<>(); + argList.add(payloadObject.get("artifact-name").textValue()); + argList.add(payloadObject.get("artifact-type").textValue()); + + String queryString = "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS where " + + " ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ? " ; + + log.info("Query String :" + queryString); + ResultSet data = dbservice.getDBData(queryString, argList); + String artifact_content = null; + int hightestVerion = 0 ; + while(data.next()) { + int version = data.getInt("INTERNAL_VERSION"); + if(hightestVerion < version) + artifact_content = data.getString("ARTIFACT_CONTENT"); + } + + if(artifact_content == null || artifact_content.isEmpty()) + throw new Exception("Sorry !!! I dont have any artifact Named : " + payloadObject.get("artifact-name").textValue()); + DesignResponse designResponse = new DesignResponse(); + designResponse.setUserId(payloadObject.get("userID").textValue()); + List artifactInfoList = new ArrayList(); + ArtifactInfo artifactInfo = new ArtifactInfo(); + artifactInfo.setArtifact_content(artifact_content); + artifactInfoList.add(artifactInfo); + designResponse.setArtifactInfo(artifactInfoList); + + ObjectMapper mapper = new ObjectMapper(); + String jsonString = mapper.writeValueAsString(designResponse); + log.info("Info : " + jsonString); + return jsonString; + } + catch(SQLException e) + { + log.error("Error while DB operation : " + e.getMessage()); + e.printStackTrace(); + throw e; + } + catch(Exception e) + { + log.error("Error while DB operation : " + e.getMessage()); + e.printStackTrace(); + throw e; + } + + } + private String setStatus(String payload, String requestID) throws Exception { + String fn = "DBService.getStatus "; + log.info("Starting getStatus DB Operation"); + try{ + String vnfc_type = null; + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + + + ArrayList argList = new ArrayList<>(); + argList.add(payloadObject.get("artifact_status").textValue()); + argList.add(payloadObject.get("action_status").textValue()); + + argList.add(payloadObject.get("userID").textValue()); + argList.add(payloadObject.get("vnf-type").textValue()); + + String queryString = " UPDATE DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR SET DAT.ARTIFACT_STATUS = ? , DAS.DT_ACTION_STATUS = ? " + + " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID " + + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? " + + " and DAS.VNF_TYPE = ? " ; + + if(payloadObject.get("vnfc-type") !=null && !payloadObject.get("vnfc-type").textValue().isEmpty()){ + argList.add(payloadObject.get("vnfc-type").textValue()); + queryString = queryString + " and DAS.VNFC_TYPE = ? "; + } + + log.info("Query String :" + queryString); + + DesignResponse designResponse = new DesignResponse(); + designResponse.setUserId(payloadObject.get("userID").textValue()); + List statusInfoList = new ArrayList(); + boolean update = dbservice.updateDBData(queryString, argList); + if(!update) + throw new Exception("Sorry .....Something went wrong while updating the Status"); + + ObjectMapper mapper = new ObjectMapper(); + String jsonString = mapper.writeValueAsString(designResponse); + log.info("Info : " + jsonString); + return jsonString; + } + catch(SQLException e) + { + log.error("Error while DB operation : " + e.getMessage()); + e.printStackTrace(); + throw e; + } + catch(Exception e) + { + log.error("Error while DB operation : " + e.getMessage()); + e.printStackTrace(); + throw e; + } + } + private String getStatus(String payload, String requestID) throws Exception { + String fn = "DBService.getStatus "; + log.info("Starting getStatus DB Operation"); + try{ + String vnfc_type = null; + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + String UserID = payloadObject.get("userID").textValue(); + String vnf_type = payloadObject.get("vnf-type").textValue(); + if(payloadObject.get("vnfc-type") != null ) + vnfc_type = payloadObject.get("vnfc-type").textValue(); + ArrayList argList = new ArrayList<>(); + + argList.add(UserID); + argList.add(vnf_type); + + String queryString = "SELECT DAS.VNF_TYPE, DAS.VNFC_TYPE, DAS.STATUS, DAS.ACTION, DAT.ARTIFACT_STATUS " + + "from DT_ACTION_STATUS DAS , DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR " + + " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID " + + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? " + + " and DAS.VNF_TYPE = ? " ; + + if(vnfc_type !=null && ! vnfc_type.isEmpty()){ + argList.add(vnfc_type); + queryString = queryString + " and DAS.VNFC_TYPE = ? "; + } + + log.info("Query String :" + queryString); + + DesignResponse designResponse = new DesignResponse(); + designResponse.setUserId(UserID); + List statusInfoList = new ArrayList(); + ResultSet data = dbservice.getDBData(queryString, argList); + while(data.next()) { + StatusInfo statusInfo = new StatusInfo(); + statusInfo.setAction(data.getString("ACTION")); + statusInfo.setAction_status(data.getString("STATUS")); + statusInfo.setArtifact_status(data.getString("ARTIFACT_STATUS")); + statusInfo.setVnf_type(data.getString("VNF_TYPE")); + statusInfo.setVnfc_type(data.getString("VNFC_TYPE")); + statusInfoList.add(statusInfo); + } + + if(statusInfoList.size() < 1) + throw new Exception("OOPS !!!! No VNF information available for VNF-TYPE : " + vnf_type + " for User : " + UserID); + designResponse.setStatusInfoList(statusInfoList); + ObjectMapper mapper = new ObjectMapper(); + String jsonString = mapper.writeValueAsString(designResponse); + log.info("Info : " + jsonString); + return jsonString; + } + catch(SQLException e) + { + log.error("Error while DB operation : " + e.getMessage()); + e.printStackTrace(); + throw e; + } + catch(Exception e) + { + log.error("Error while DB operation : " + e.getMessage()); + e.printStackTrace(); + throw e; + } + } + private String getGuiReference(String payload, String requestID) { + // TODO Auto-generated method stub + return null; + } + private String getArtifactReference(String payload, String requestID) { + // TODO Auto-generated method stub + return null; + } + private String getAddInCart(String payload, String requestID) { + // TODO Auto-generated method stub + return null; + } + + // private String getDesigns(String payload, String requestID) throws SQLException, JsonProcessingException, IOException, SvcLogicException { + // + // String fn = "DBService.getDesigns "; + // QueryStatus status = null; + // ObjectMapper objectMapper = new ObjectMapper(); + // JsonNode jnode = objectMapper.readTree(payload); + // String UserId = jnode.get("userID").textValue(); + // SvcLogicContext localContext = new SvcLogicContext(); + // localContext.setAttribute("requestID", requestID); + // localContext.setAttribute("userID", UserId); + // if (serviceLogic != null && localContext != null) { + // String queryString = "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART from " + + // DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , " + DesignServiceConstants.DB_SDC_REFERENCE + + // " AR where DAT.SDC_REFERENCE_ID= AR.SDC_REFERENCE_ID and DAT.USER = $userID" ; + // + // log.info(fn + "Query String : " + queryString); + // try { + // status = serviceLogic.query("SQL", true, null, queryString, null, null, localContext); + // } catch (SvcLogicException e1) { + // // TODO Auto-generated catch block + // e1.printStackTrace(); + // } + // + // if(status.toString().equals("FAILURE")) + // throw new SvcLogicException("Error - while getting FlowReferenceData "); + // + // Properties props = localContext.toProperties(); + // log.info("SvcLogicContext contains the following : " + props.toString()); + // for (Enumeration e = props.propertyNames(); e.hasMoreElements() ; ) { + // String propName = (String) e.nextElement(); + // log.info(propName+" = "+props.getProperty(propName)); + // + // } + // } + // return requestID; + // + // } + + private String getDesigns(String payload, String requestID) throws Exception { + + String fn = "DBService.getDesigns "; + log.info("Starting getDesgins DB Operation"); + + + try{ + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + String UserID = payloadObject.get("userID").textValue(); + ArrayList argList = new ArrayList<>(); + argList.add(UserID); + + String queryString = "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from " + + DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , " + DesignServiceConstants.DB_SDC_REFERENCE + + " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? "; + + DesignResponse designResponse = new DesignResponse(); + designResponse.setUserId(UserID); + List designInfoList = new ArrayList(); + ResultSet data = dbservice.getDBData(queryString, argList); + while(data.next()) { + DesignInfo designInfo = new DesignInfo(); + designInfo.setInCart(data.getString("IN_CART")); + designInfo.setProtocol(data.getString("PROTOCOL")); + designInfo.setVnf_type(data.getString("VNF_TYPE")); + designInfo.setVnfc_type(data.getString("VNFC_TYPE")); + designInfo.setAction(data.getString("ACTION")); + designInfo.setArtifact_type(data.getString("ARTIFACT_TYPE")); + designInfo.setArtifact_name(data.getString("ARTIFACT_NAME")); + designInfoList.add(designInfo); + } + if(designInfoList.size() < 1) + throw new Exception(" Welcome to CDT, Looks like you dont have Design Yet... Lets create some...."); + designResponse.setDesignInfoList(designInfoList); + ObjectMapper mapper = new ObjectMapper(); + String jsonString = mapper.writeValueAsString(designResponse); + log.info("Info : " + jsonString); + return jsonString; + } + catch(Exception e) + { + e.printStackTrace(); + throw e; + } + } + +} + + diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java new file mode 100644 index 000000000..c0b710deb --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java @@ -0,0 +1,126 @@ +/*- + * ============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.design.dbervices; + +import org.onap.appc.design.services.util.ArtifactHandlerClient; +import org.onap.appc.design.services.util.DesignServiceConstants; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class RequestValidator { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(RequestValidator.class); + public static void validate(String action, String payload) throws Exception { + log.info("payload" + payload); + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + log.info("payloadObject" + payloadObject.get(DesignServiceConstants.ARTIFACT_CONTENTS)); + + String errorString = null; + switch (action) { + case DesignServiceConstants.GETDESIGNS: + if(payloadObject.get(DesignServiceConstants.USER_ID) == null || payloadObject.get(DesignServiceConstants.USER_ID).textValue().isEmpty()) + errorString = DesignServiceConstants.USER_ID; + break; + case DesignServiceConstants.GETARTIFACT: + if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) + errorString = DesignServiceConstants.VNF_TYPE; + else if(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue().isEmpty()) + errorString = DesignServiceConstants.ARTIFACT_TYPE; + else if(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue().isEmpty()) + errorString = DesignServiceConstants.ARTIFACT_NAME; + break; + case DesignServiceConstants.GETSTATUS: + if(payloadObject.get(DesignServiceConstants.USER_ID) == null || payloadObject.get(DesignServiceConstants.USER_ID).textValue().isEmpty()) + errorString = DesignServiceConstants.USER_ID; + else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) + errorString = DesignServiceConstants.VNF_TYPE; + break; + case DesignServiceConstants.SETSTATUS: + if(payloadObject.get(DesignServiceConstants.USER_ID) == null || payloadObject.get(DesignServiceConstants.USER_ID).textValue().isEmpty()) + errorString = DesignServiceConstants.USER_ID; + else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) + errorString = DesignServiceConstants.VNF_TYPE; + else if(payloadObject.get(DesignServiceConstants.ACTION) == null || payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty()) + errorString = DesignServiceConstants.ACTION; + else if(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue().isEmpty()) + errorString = DesignServiceConstants.ARTIFACT_TYPE; + else if(payloadObject.get(DesignServiceConstants.STATUS) == null || payloadObject.get(DesignServiceConstants.STATUS).textValue().isEmpty()) + errorString = DesignServiceConstants.STATUS; + break; + case DesignServiceConstants.UPLOADARTIFACT: + if(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue().isEmpty()) + errorString = DesignServiceConstants.ARTIFACT_NAME; + else if(! payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue().contains("reference")){ + if(payloadObject.get(DesignServiceConstants.ACTION) == null || payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty()) + errorString = DesignServiceConstants.ACTION; + } + else if(payloadObject.get(DesignServiceConstants.ARTIFACT_VERSOIN) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_VERSOIN).textValue().isEmpty()) + errorString = DesignServiceConstants.ARTIFACT_VERSOIN; + else if(payloadObject.get(DesignServiceConstants.ARTIFACT_CONTENTS) == null) + errorString = DesignServiceConstants.ARTIFACT_CONTENTS; + else if(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue().isEmpty()) + errorString = DesignServiceConstants.ARTIFACT_TYPE; + + else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) + errorString = DesignServiceConstants.VNF_TYPE; + + + break; + case DesignServiceConstants.SETPROTOCOLREFERENCE: + if(payloadObject.get(DesignServiceConstants.ACTION) == null || payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty()) + errorString = DesignServiceConstants.ACTION; + else if(payloadObject.get(DesignServiceConstants.ACTION_LEVEL) == null || payloadObject.get(DesignServiceConstants.ACTION_LEVEL).textValue().isEmpty()) + errorString = DesignServiceConstants.ACTION_LEVEL; + else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) + errorString = DesignServiceConstants.VNF_TYPE; + else if(payloadObject.get(DesignServiceConstants.PROTOCOL) == null || payloadObject.get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) + errorString = DesignServiceConstants.PROTOCOL; + + case DesignServiceConstants.SETINCART: + if(payloadObject.get(DesignServiceConstants.ACTION) == null || payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty()) + errorString = DesignServiceConstants.ACTION; + else if(payloadObject.get(DesignServiceConstants.ACTION_LEVEL) == null || payloadObject.get(DesignServiceConstants.ACTION_LEVEL).textValue().isEmpty()) + errorString = DesignServiceConstants.ACTION_LEVEL; + else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) + errorString = DesignServiceConstants.VNF_TYPE; + else if(payloadObject.get(DesignServiceConstants.PROTOCOL) == null || payloadObject.get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) + errorString = DesignServiceConstants.PROTOCOL; + break; + default: + throw new Exception(" Action " + action + " not found while processing request "); + + } + if(errorString != null) + throw new Exception(" Missing input parameter :-" + errorString + " -:"); + + } + +} + + diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/propertyServices/PropertyUpdateService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/propertyServices/PropertyUpdateService.java new file mode 100644 index 000000000..87e84d495 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/propertyServices/PropertyUpdateService.java @@ -0,0 +1,30 @@ +/*- + * ============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.design.propertyServices; + +public class PropertyUpdateService { + + // to set the properties this placeholder will be used. +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/DesignServiceProvider.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/DesignServiceProvider.java new file mode 100644 index 000000000..f41bbac46 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/DesignServiceProvider.java @@ -0,0 +1,72 @@ +/*- + * ============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.design.services; + +import java.util.concurrent.Future; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.DesignServicesService; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.onap.appc.design.services.impl.DesignServicesImpl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class DesignServiceProvider{ + + private static final EELFLogger log = EELFManager.getInstance().getLogger(DesignServiceProvider.class); + + private final DataBroker dataBroker; + private final RpcProviderRegistry rpcProviderRegistry; + private RpcRegistration serviceRegistration; + + + public DesignServiceProvider(final DataBroker dataBroker, RpcProviderRegistry rpcProviderRegistry) { + this.dataBroker = dataBroker; + this.rpcProviderRegistry = rpcProviderRegistry; + } + + /** + * Method called when the blueprint container is created. + */ + public void init() { + // initialize data broker + this.serviceRegistration = this.rpcProviderRegistry.addRpcImplementation(DesignServicesService.class, new DesignServicesImpl()); + log.info("DesignServicesImpl Session Initiated"); + } + + /** + * Method called when the blueprint container is destroyed. + */ + public void close() { + if(this.serviceRegistration != null){ + this.serviceRegistration.close(); + } + log.info("DesignServicesImpl Closed"); + } + + +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/DesignServicesImpl.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/DesignServicesImpl.java new file mode 100644 index 000000000..1787618e6 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/impl/DesignServicesImpl.java @@ -0,0 +1,160 @@ +/*- + * ============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.design.services.impl; + +import java.util.concurrent.Future; +import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.DbserviceInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.DbserviceOutput; +import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.DbserviceOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.DesignServicesService; +import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.ValidatorInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.ValidatorOutput; +import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.ValidatorOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.XinterfaceserviceInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.XinterfaceserviceOutput; +import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.XinterfaceserviceOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.data.DataBuilder; +import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.status.StatusBuilder; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.onap.appc.design.dbervices.DbResponseProcessor; +import org.onap.appc.design.dbervices.DesignDBService; +import org.onap.appc.design.services.util.DesignServiceConstants; +import org.onap.appc.design.validator.ValidatorResponseProcessor; +import org.onap.appc.design.validator.ValidatorService; +import org.onap.appc.design.xinterface.XInterfaceService; +import org.onap.appc.design.xinterface.XResponseProcessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.collect.Lists; +import com.google.common.util.concurrent.Futures; + +public class DesignServicesImpl implements DesignServicesService { + + private static final Logger log = LoggerFactory.getLogger(DesignServicesImpl.class); + + @Override + public Future> dbservice(DbserviceInput input) { + + log.info("Received Request: " + input.getDesignRequest().getRequestId() + " Action : " + + input.getDesignRequest().getAction() + " with Payload :" + input.getDesignRequest().getPayload()); + + + DbserviceOutputBuilder outputBuilder = new DbserviceOutputBuilder(); + DataBuilder databuilder = new DataBuilder(); + StatusBuilder statusBuilder = new StatusBuilder(); + + try{ + DesignDBService dbservices = DesignDBService.initialise(); + DbResponseProcessor responseProcessor = new DbResponseProcessor(); + String response = responseProcessor.parseResponse(dbservices.execute(input.getDesignRequest().getAction(), input.getDesignRequest().getPayload(), input.getDesignRequest().getRequestId()), input.getDesignRequest().getAction()); + log.info("Response in for Design Service : " + response); + databuilder.setBlock(response); + databuilder.setRequestId(input.getDesignRequest().getRequestId()); + statusBuilder.setCode("400"); + statusBuilder.setMessage("success"); + } + catch(Exception e){ + log.error("Error" + e.getMessage()); + e.printStackTrace(); + statusBuilder.setCode("401"); + statusBuilder.setMessage(e.getMessage()); + } + + outputBuilder.setData(databuilder.build()); + outputBuilder.setStatus(statusBuilder.build()); + + RpcResult result = RpcResultBuilder.status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public Future> xinterfaceservice(XinterfaceserviceInput input) { + log.info("Received Request: " + input.getDesignRequest().getRequestId() + " Action : " + + input.getDesignRequest().getAction() + " with Payload :" + input.getDesignRequest().getPayload()); + XinterfaceserviceOutputBuilder outputBuilder = new XinterfaceserviceOutputBuilder(); + DataBuilder databuilder = new DataBuilder(); + StatusBuilder statusBuilder = new StatusBuilder(); + try { + + XInterfaceService xInterfaceService = new XInterfaceService(); + XResponseProcessor responseProcessor = new XResponseProcessor(); + String response = responseProcessor.parseResponse(xInterfaceService.execute(input.getDesignRequest().getAction(), input.getDesignRequest().getPayload()), input.getDesignRequest().getAction()); + databuilder.setBlock(response); + databuilder.setRequestId(input.getDesignRequest().getRequestId()); + statusBuilder.setCode("400"); + statusBuilder.setMessage("success"); + } catch (Exception e) { + e.printStackTrace(); + statusBuilder.setCode("401"); + statusBuilder.setMessage(e.getMessage()); + } + outputBuilder.setData(databuilder.build()); + outputBuilder.setStatus(statusBuilder.build()); + + RpcResult result = RpcResultBuilder.status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public Future> validator(ValidatorInput input) { + log.info("Received Request: " + input.getDesignRequest().getRequestId() + " Action : " + + input.getDesignRequest().getAction() + " with Payload :" + input.getDesignRequest().getPayload() + " and Data Type = " + input.getDesignRequest().getDataType()); + ValidatorOutputBuilder outputBuilder = new ValidatorOutputBuilder(); + StatusBuilder statusBuilder = new StatusBuilder(); + + + try { + if(input.getDesignRequest().getDataType() == null || input.getDesignRequest().getDataType().isEmpty()) + throw new Exception ("Data Type required for validate Serivce"); + if(input.getDesignRequest().getAction()== null || input.getDesignRequest().getAction().isEmpty()) + throw new Exception ("Action required for validate Serivce"); + + + if(! input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_JSON) && + ! input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_YAML) && + ! input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_XML) && + ! input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_VELOCITY)) + throw new Exception ("Request Data format " + input.getDesignRequest().getDataType() + + " is not supported by validate Service : Supported data types are : XML, YAML, VELOCITY, JSON "); + + ValidatorService validatorService = new ValidatorService(); + ValidatorResponseProcessor responseProcessor = new ValidatorResponseProcessor(); + String response = validatorService.execute(input.getDesignRequest().getAction(), input.getDesignRequest().getPayload(), input.getDesignRequest().getDataType()); + statusBuilder.setCode("400"); + statusBuilder.setMessage(response); + } catch (Exception e) { + e.printStackTrace(); + statusBuilder.setCode("401"); + statusBuilder.setMessage(e.getMessage()); + } + + outputBuilder.setStatus(statusBuilder.build()); + + RpcResult result = RpcResultBuilder.status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java new file mode 100644 index 000000000..b250faca9 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java @@ -0,0 +1,187 @@ +/*- + * ============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.design.services.util; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.charset.Charset; +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Properties; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLContext; +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + + +public class ArtifactHandlerClient { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerClient.class); + private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR"; + Properties props = new Properties(); + public ArtifactHandlerClient() throws Exception { + String propDir = System.getenv(SDNC_CONFIG_DIR_VAR); + if (propDir == null) + throw new Exception(" Cannot find Property file -" + SDNC_CONFIG_DIR_VAR); + String propFile = propDir + "/" + DesignServiceConstants.DESIGN_SERVICE_PROPERTIES; + InputStream propStream = new FileInputStream(propFile); + try{ + props.load(propStream); + } + catch (Exception e){ + throw new Exception("Could not load properties file " + propFile, e); + } + finally{ + try{ + propStream.close(); + } + catch (Exception e){ + log.warn("Could not close FileInputStream", e); + } + } + } + + public String createArtifactData(String payload, String requestID) throws JsonProcessingException, IOException { + + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + + ObjectNode json = objectMapper.createObjectNode(); + + String artifact_name = payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue(); + String artifact_version = payloadObject.get(DesignServiceConstants.ARTIFACT_VERSOIN).textValue(); + String artifact_contents = payloadObject.get(DesignServiceConstants.ARTIFACT_CONTENTS).textValue(); + + ObjectNode requestInfo = objectMapper.createObjectNode(); + + requestInfo.put(DesignServiceConstants.REQUETS_ID, requestID); + requestInfo.put(DesignServiceConstants.REQUEST_ACTION, "StoreSdcDocumentRequest"); + requestInfo.put(DesignServiceConstants.SOURCE, DesignServiceConstants.DESIGN_TOOL); + + String random = getRandom(); + + ObjectNode docParams = objectMapper.createObjectNode(); + + docParams.put(DesignServiceConstants.ARTIFACT_VERSOIN, artifact_version); + docParams.put(DesignServiceConstants.ARTIFACT_NAME, artifact_name); + docParams.put(DesignServiceConstants.ARTIFACT_CONTENTS, artifact_contents); + + + json.put(DesignServiceConstants.REQUEST_INFORMATION, requestInfo); + json.put(DesignServiceConstants.DOCUMENT_PARAMETERS, docParams); + log.info("Final data =" + json.toString()); + return String.format("{\"input\": %s}", json.toString()); + } + + public HashMap execute(String payload, String rpc) throws Exception{ + log.info("Configuring Rest Operation for Payload " + payload + " RPC : " + rpc ); + HashMap outputMessage = new HashMap(); + Client client = null; + WebResource webResource = null; + ClientResponse clientResponse = null; + String responseDataType=MediaType.APPLICATION_JSON; + String requestDataType=MediaType.APPLICATION_JSON; + + try{ + DefaultClientConfig defaultClientConfig = new DefaultClientConfig(); + System.setProperty("jsse.enableSNIExtension", "false"); + SSLContext sslContext = null; + SecureRestClientTrustManager secureRestClientTrustManager = new SecureRestClientTrustManager(); + sslContext = SSLContext.getInstance("SSL"); + sslContext.init(null, new javax.net.ssl.TrustManager[] { secureRestClientTrustManager }, null); + defaultClientConfig.getProperties().put( + com.sun.jersey.client.urlconnection.HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, + new com.sun.jersey.client.urlconnection.HTTPSProperties(getHostnameVerifier(), sslContext)); + client = Client.create(defaultClientConfig); + client.addFilter(new HTTPBasicAuthFilter(props.getProperty("appc.upload.user"), props.getProperty("appc.upload.pass"))); + webResource = client.resource(new URI(props.getProperty("appc.upload.provider.url"))); + webResource.setProperty("Content-Type", "application/json;charset=UTF-8"); + + log.info("Starting Rest Operation....."); + if(HttpMethod.GET.equalsIgnoreCase(rpc)){ + clientResponse = webResource.accept(responseDataType).get(ClientResponse.class); + }else if(HttpMethod.POST.equalsIgnoreCase(rpc)){ + clientResponse = webResource.type(requestDataType).post(ClientResponse.class, payload); + }else if(HttpMethod.PUT.equalsIgnoreCase(rpc)){ + clientResponse = webResource.type(requestDataType).put(ClientResponse.class,payload); + }else if(HttpMethod.DELETE.equalsIgnoreCase(rpc)){ + clientResponse = webResource.delete(ClientResponse.class); + } + + if(!(clientResponse.getStatus() == 200)) + throw new Exception("HTTP error code : " + clientResponse.getStatus()); + + + log.info("Completed Rest Operation....."); + + }catch (Exception e) { + e.printStackTrace(); + log.debug("failed in RESTCONT Action with falut message :"+e.getMessage()); + throw new Exception("Error While Sending Rest Request" + e.getMessage()); + } + finally { + // clean up. + webResource = null; + if(client != null){ + client.destroy(); + client = null; + } + } + + return outputMessage; + } + private String getRandom() { + SecureRandom random = new SecureRandom(); + int num = random.nextInt(100000); + String formatted = String.format("%05d", num); + return formatted; + } + + private HostnameVerifier getHostnameVerifier() { + return new HostnameVerifier() { + @Override + public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) { + return true; + } + }; + } +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java new file mode 100644 index 000000000..9ad5e10ac --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java @@ -0,0 +1,106 @@ +/*- + * ============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.design.services.util; + +public class DesignServiceConstants { + + public static String STRING_ENCODING = "utf-8"; + public static String Y = "Y"; + public static String N = "N"; + public static String DATA_TYPE_TEXT = "TEXT"; + public static String DATA_TYPE_JSON = "JSON"; + public static String DATA_TYPE_XML = "XML"; + public static String DATA_TYPE_YAML = "YAML"; + public static String DATA_TYPE_VELOCITY = "VELOCITY"; + public static String DATA_TYPE_SQL = "SQL"; + + public static final String GETDESIGNS = "getDesigns"; + public static final String UPLOADARTIFACTS = "uploadArtifacts"; + public static final String VALIDATETEMPLATE = "validateTemplate"; + public static final String GETSTATUS = "getStatus"; + public static final String SETSTATUS = "setStatus"; + public static final String GETGUIREFERENCE = "getGUIReference"; + public static final String GETARTIFACTREFERENCE = "getArtifactReference"; + public static final String GETAAIDATA = "getAAIData"; + public static final String GETINSTARDATA = "getInstarData"; + public static final String PUBLISHARTIFACTS = "publishdArtifacts"; + public static final String ADDINCART = "addInCart"; + + public static final String SUCCESS = "success"; + public static final String DESINGTIME = "DesignTime"; + public static final String RUNTIME = "RunTime"; + public static final String APPC_FLOW_CONTROLLER = "/appc-flow-controller.properties"; + public static final String VNF_TYPE = "vnf-type"; + public static final String ACTION = "action"; + public static final String VNFC_TYPE = "vnfc-type"; + public static final String VM_INSTANCE = "vm-instance"; + public static final String VM = "vm"; + public static final String VNFC = "vnfc"; + + public static final String DOCUMENT_PARAMETERS = "document-parameters"; + public static final String SERVICE_UUID = "service-uuid"; + public static final String DISTRIBUTION_ID = "distribution-id"; + + public static final String SERVICE_NAME = "service-name"; + public static final String SERVICE_DESCRIPTION ="service-description"; + public static final String SERVICE_ARTIFACTS = "service-artifacts"; + public static final String RESOURCE_UUID ="resource-uuid"; + public static final String RESOURCE_INSTANCE_NAME = "resource-instance-name"; + public static final String REOURCE_NAME = "resource-name"; + public static final String RESOURCE_VERSOIN ="resource-version"; + public static final String RESOURCE_TYPE= "resource-type"; + public static final String ARTIFACT_UUID ="artifact-uuid"; + public static final String ARTIFACT_NAME = "artifact-name"; + + public static final String ARTIFACT_VERSOIN = "artifact-version"; + public static final String ARTIFACT_DESRIPTION = "artifact-description"; + public static final String ARTIFACT_CONTENTS = "artifact-contents"; + public static final String REQUEST_INFORMATION = "request-information"; + public static final String INTERNAL_VERSION = "internal-versoin"; + + + + public static final String DB_DT_ARTIFACT_TRACKING = "DT_ARTIFACT_TRACKING"; + public static final String DB_SDC_REFERENCE = "ASDC_REFERENCE"; + public static final String SCHEMA_SDNCTL = "SDNCTL"; + public static final String GETARTIFACT = "getArtifact"; + public static final String USER_ID = "userID"; + public static final String ARTIFACT_TYPE = "artifact-type"; + public static final String STATUS = "status"; + public static final String UPLOADARTIFACT = "uploadArtifact"; + public static final String REQUETS_ID = "request-id"; + public static final String REQUEST_ACTION = "request-action"; + public static final String SOURCE = "source"; + public static final String DESIGN_SERVICE_PROPERTIES = "designService.properties"; + public static final String DESIGN_TOOL = "Design-tool"; + public static final String TECHNOLOGY = "technology"; + public static final String PROTOCOL = "protocol"; + public static final String SETPROTOCOLREFERENCE = "setProtocolReference"; + public static final String ACTION_LEVEL = "action-level"; + public static final String TEMPLATE = "template"; + public static final String SETINCART = "setInCart"; + public static final String INCART = "inCart"; + public static final String STOREPASSWORD = "storeProperty"; + } diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/EscapeUtils.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/EscapeUtils.java new file mode 100644 index 000000000..80f756f3a --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/EscapeUtils.java @@ -0,0 +1,44 @@ +/*- + * ============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.design.services.util; + +import org.apache.commons.lang3.StringUtils; + +public class EscapeUtils { + + public EscapeUtils() { + // TODO Auto-generated constructor stub + } + + public static String escapeSql(String str) { + if (str == null) { + return null; + } + String searchList[] = new String[]{"'","\\", "\"" }; + String replacementList[] = new String[]{ "''","\\\\" ,"\\\""}; + return StringUtils.replaceEach(str,searchList, replacementList); + } + +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/SecureRestClientTrustManager.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/SecureRestClientTrustManager.java new file mode 100644 index 000000000..8e31d9540 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/SecureRestClientTrustManager.java @@ -0,0 +1,58 @@ +/*- + * ============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.design.services.util; + +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + +import javax.net.ssl.X509TrustManager; + + +public class SecureRestClientTrustManager implements X509TrustManager { + + @Override + public void checkClientTrusted(X509Certificate[] arg0, String arg1) + throws CertificateException { + } + + @Override + public void checkServerTrusted(X509Certificate[] arg0, String arg1) + throws CertificateException { + } + + @Override + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + + public boolean isClientTrusted(X509Certificate[] arg0) { + return true; + } + + public boolean isServerTrusted(X509Certificate[] arg0) { + return true; + } + +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/validator/ValidatorResponseProcessor.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/validator/ValidatorResponseProcessor.java new file mode 100644 index 000000000..faea6a5ee --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/validator/ValidatorResponseProcessor.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.design.validator; + +import org.onap.appc.design.services.impl.DesignServicesImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ValidatorResponseProcessor { + + private static final Logger log = LoggerFactory.getLogger(ValidatorResponseProcessor.class); + public String parseResponse(Object execute, String action) { + return null; + } + +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/validator/ValidatorService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/validator/ValidatorService.java new file mode 100644 index 000000000..6660dd825 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/validator/ValidatorService.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.design.validator; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.validation.Validator; + +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; +import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.exception.MethodInvocationException; +import org.apache.velocity.exception.ParseErrorException; +import org.apache.velocity.exception.ResourceNotFoundException; +import org.apache.velocity.runtime.resource.loader.StringResourceLoader; +import org.apache.velocity.runtime.resource.util.StringResourceRepository; +import org.onap.appc.design.services.util.DesignServiceConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; +import com.fasterxml.jackson.dataformat.yaml.snakeyaml.introspector.BeanAccess; + +public class ValidatorService { + + private static final Logger log = LoggerFactory.getLogger(ValidatorService.class); + public String execute(String action, String payload, String dataType) throws Exception { + + String validateResponse = null; + log.info("Received validation for action= " + action + "Data :" + payload + " dataType = " + dataType); + if(dataType.equals(DesignServiceConstants.DATA_TYPE_XML)) + validateResponse = validateXML(payload); + else if(dataType.equals(DesignServiceConstants.DATA_TYPE_JSON)) + validateResponse = validateJOSN(payload); + else if(dataType.equals(DesignServiceConstants.DATA_TYPE_VELOCITY)) + validateResponse = validateVelocity(payload); + else if(dataType.equals(DesignServiceConstants.DATA_TYPE_YAML)) + validateResponse = validateYAML(payload); + + return validateResponse; + + } + + private String validateYAML(String payload) throws Exception { + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + try{ + InputStream is = new ByteArrayInputStream(payload.getBytes()); + + Reader in = new InputStreamReader(is); + Yaml yaml = new Yaml(); + yaml.setBeanAccess(BeanAccess.FIELD); + yaml.load(in); + return DesignServiceConstants.SUCCESS; + } + catch(Exception e){ + log.error("Not a Valid YAML Format "); + throw e; + } + + } + + private String validateVelocity(String payload) { + + try{ + VelocityEngine engine = new VelocityEngine(); + engine.setProperty(Velocity.RESOURCE_LOADER, "string"); + engine.addProperty("string.resource.loader.class", StringResourceLoader.class.getName()); + engine.addProperty("string.resource.loader.repository.static", "false"); + engine.init(); + StringResourceRepository repo = (StringResourceRepository) engine.getApplicationAttribute(StringResourceLoader.REPOSITORY_NAME_DEFAULT); + repo.putStringResource("TestTemplate", payload); + //Template t = ve.getTemplate(payload); + Template t = engine.getTemplate("TestTemplate"); + + return DesignServiceConstants.SUCCESS; + } + catch(ResourceNotFoundException e ){ + log.error("Not a Valid Velocity Template "); + throw e; + } + catch(ParseErrorException pe){ + log.error("Not a Valid Velocity Template "); + throw pe; + } + catch(MethodInvocationException mi){ + log.error("Not a Valid Velocity Template "); + throw mi; + } + } + + private String validateJOSN(String payload) throws Exception { + + try{ + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.readTree(payload); + return DesignServiceConstants.SUCCESS; + } catch(JsonProcessingException e){ + log.error("Not a Valid JOSN file "); + throw e; + } + + } + + private String validateXML(String payload) throws IOException, SAXException, ParserConfigurationException { + + try{ + + DocumentBuilderFactory dBF = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = dBF.newDocumentBuilder(); + InputSource is = new InputSource(payload); + builder.parse(new InputSource(new ByteArrayInputStream(payload.getBytes("utf-8")))); + return DesignServiceConstants.SUCCESS; + + } catch(ParserConfigurationException e){ + log.info("Error While parsing Payload : " + e.getMessage()); + throw e; + } + catch(SAXException se){ + log.info("Error While parsing Payload : " + se.getMessage()); + throw se; + } + catch(IOException io){ + log.info("Error While parsing Payload : " + io.getMessage()); + throw io; + } + } +} + diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java new file mode 100644 index 000000000..157e52937 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.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.design.xinterface; + +import java.io.File; +import java.io.IOException; + +import com.google.common.base.Charsets; +import com.google.common.io.Files; + +public class XInterfaceService { + + + public String execute(String action, String payload) throws IOException { + //Remove this once hte interfaces are up and running + File targetFile = new File("/tmp/" + action + "-response.txt" ); + String interfaceResponse = Files.toString(targetFile, Charsets.UTF_8); + return interfaceResponse; + } + +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java new file mode 100644 index 000000000..aa72e2f09 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.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.design.xinterface; + +import java.io.File; +import java.io.IOException; + +import com.google.common.base.Charsets; +import com.google.common.io.Files; + +public class XResponseProcessor { + + public String parseResponse(Object execute, String action) { + return null; + } +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/ArtifactInfo.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/ArtifactInfo.java deleted file mode 100644 index 53f6f02fb..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/ArtifactInfo.java +++ /dev/null @@ -1,42 +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.design.data; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class ArtifactInfo { - - @JsonProperty("artifact-content") - String artifact_content; - - public String getArtifact_content() { - return artifact_content; - } - - public void setArtifact_content(String artifact_content) { - this.artifact_content = artifact_content; - } - -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/DesignInfo.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/DesignInfo.java deleted file mode 100644 index a6d2ba24b..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/DesignInfo.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.design.data; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class DesignInfo{ - - @JsonProperty("vnf-type") - String vnf_type; - - @JsonProperty("vnfc-type") - String vnfc_type; - - @JsonProperty("protocol") - String protocol; - - @JsonProperty("incart") - String inCart; - - @JsonProperty("action") - String action; - - @JsonProperty("artifact-name") - String artifact_name; - - - @JsonProperty("artifact-type") - String artifact_type; - - public String getArtifact_type() { - return artifact_type; - } - - public void setArtifact_type(String artifact_type) { - this.artifact_type = artifact_type; - } - - public String getArtifact_name() { - return artifact_name; - } - - public void setArtifact_name(String artifact_name) { - this.artifact_name = artifact_name; - } - - public String getAction() { - return action; - } - - public void setAction(String action) { - this.action = action; - } - - public String getVnf_type() { - return vnf_type; - } - - public void setVnf_type(String vnf_type) { - this.vnf_type = vnf_type; - } - - public String getVnfc_type() { - return vnfc_type; - } - - public void setVnfc_type(String vnfc_type) { - this.vnfc_type = vnfc_type; - } - - public String getProtocol() { - return protocol; - } - - public void setProtocol(String protocol) { - this.protocol = protocol; - } - - public String getInCart() { - return inCart; - } - - public void setInCart(String inCart) { - this.inCart = inCart; - } - - @Override - public String toString() { - return "DesignInfo [vnf_type=" + vnf_type + ", vnfc_type=" + vnfc_type + ", protocol=" + protocol + ", inCart=" - + inCart + "]"; - } - -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/DesignRequest.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/DesignRequest.java deleted file mode 100644 index d61de0282..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/DesignRequest.java +++ /dev/null @@ -1,132 +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.design.data; - -import java.io.File; -import java.net.URL; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import javax.sql.rowset.CachedRowSet; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import org.onap.appc.design.services.util.DesignServiceConstants; -import org.onap.ccsdk.sli.core.dblib.DBResourceManager; -import org.onap.ccsdk.sli.core.dblib.DbLibService; - -public class DesignRequest{ - - - @JsonProperty("userID") - String userId ; - - @JsonProperty("vnf-type") - String vnf_type; - - @JsonProperty("vnfc-type") - String vnfc_type; - - @JsonProperty("protocol") - String protocol; - - @JsonProperty("action") - String action; - - @JsonProperty("artifact-name") - String artifact_name; - - @JsonProperty("artifact-contents") - String artifact_contents ; - - public String getUserId() { - return userId; - } - - public void setUserId(String userId) { - this.userId = userId; - } - - public String getVnf_type() { - return vnf_type; - } - - public void setVnf_type(String vnf_type) { - this.vnf_type = vnf_type; - } - - public String getVnfc_type() { - return vnfc_type; - } - - public void setVnfc_type(String vnfc_type) { - this.vnfc_type = vnfc_type; - } - - public String getProtocol() { - return protocol; - } - - public void setProtocol(String protocol) { - this.protocol = protocol; - } - - public String getAction() { - return action; - } - - public void setAction(String action) { - this.action = action; - } - - public String getArtifact_name() { - return artifact_name; - } - - public void setArtifact_name(String artifact_name) { - this.artifact_name = artifact_name; - } - - public String getArtifact_contents() { - return artifact_contents; - } - - public void setArtifact_contents(String artifact_contents) { - this.artifact_contents = artifact_contents; - } - - @Override - public String toString() { - return "DesignRequest [userId=" + userId + ", vnf_type=" + vnf_type + ", vnfc_type=" + vnfc_type + ", protocol=" - + protocol + ", action=" + action + ", artifact_name=" + artifact_name + ", artifact_contents=" - + artifact_contents + "]"; - } - -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/DesignResponse.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/DesignResponse.java deleted file mode 100644 index 559620d9e..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/DesignResponse.java +++ /dev/null @@ -1,77 +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.design.data; - -import java.util.List; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class DesignResponse{ - - - @JsonProperty("userID") - String userId ; - - @JsonProperty("designInfo") - List designInfoList; - - @JsonProperty("statusInfo") - List statusInfoList; - - @JsonProperty("artifactInfo") - List artifactInfo; - - - public List getArtifactInfo() { - return artifactInfo; - } - - public void setArtifactInfo(List artifactInfo) { - this.artifactInfo = artifactInfo; - } - - public String getUserId() { - return userId; - } - - public void setUserId(String userId) { - this.userId = userId; - } - - public List getDesignInfoList() { - return designInfoList; - } - - public void setDesignInfoList(List designInfoList) { - this.designInfoList = designInfoList; - } - - public List getStatusInfoList() { - return statusInfoList; - } - - public void setStatusInfoList(List statusInfoList) { - this.statusInfoList = statusInfoList; - } -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/StatusInfo.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/StatusInfo.java deleted file mode 100644 index 6d4b1a5a1..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/data/StatusInfo.java +++ /dev/null @@ -1,86 +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.design.data; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class StatusInfo{ - - @JsonProperty("vnf-type") - String vnf_type; - - @JsonProperty("vnfc-type") - String vnfc_type; - - @JsonProperty("action") - String action; - - @JsonProperty("artifact-status") - String artifact_status; - - @JsonProperty("action-status") - String action_status; - - public String getVnf_type() { - return vnf_type; - } - - public void setVnf_type(String vnf_type) { - this.vnf_type = vnf_type; - } - - public String getVnfc_type() { - return vnfc_type; - } - - public void setVnfc_type(String vnfc_type) { - this.vnfc_type = vnfc_type; - } - - public String getAction() { - return action; - } - - public void setAction(String action) { - this.action = action; - } - - public String getArtifact_status() { - return artifact_status; - } - - public void setArtifact_status(String artifact_status) { - this.artifact_status = artifact_status; - } - - public String getAction_status() { - return action_status; - } - - public void setAction_status(String action_status) { - this.action_status = action_status; - } - -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/DbResponseProcessor.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/DbResponseProcessor.java deleted file mode 100644 index e697a9d4f..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/DbResponseProcessor.java +++ /dev/null @@ -1,110 +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.design.dbervices; - -import org.onap.appc.design.services.util.DesignServiceConstants; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class DbResponseProcessor { - - private static final EELFLogger log = EELFManager.getInstance().getLogger(DbResponseProcessor.class); - public String parseResponse(String dbresposne, String action) throws Exception { - - log.info("Starting Parsing the response for action : " + action + "\n data " + dbresposne ); - String response ; - switch (action) { - case DesignServiceConstants.GETDESIGNS: - response = getDesignsResponse(dbresposne); - break; - case DesignServiceConstants.ADDINCART: - response = getAddInCartResponse(dbresposne); - break ; - case DesignServiceConstants.GETARTIFACTREFERENCE: - response= getArtifactReferenceResponse(dbresposne); - break; - case DesignServiceConstants.GETARTIFACT: - response= getArtifactResponse(dbresposne); - break; - case DesignServiceConstants.GETGUIREFERENCE: - response= getGuiReferenceResponse(dbresposne); - break; - case DesignServiceConstants.GETSTATUS: - response= getStatusResponse(dbresposne); - break; - case DesignServiceConstants.UPLOADARTIFACT: - response= getsetStatusResponse(dbresposne); - break; - case DesignServiceConstants.SETPROTOCOLREFERENCE: - response= getsetStatusResponse(dbresposne); - break; - case DesignServiceConstants.SETINCART: - response= getsetStatusResponse(dbresposne); - break; - default: - log.error("Action " + action + " Not Supported by response Parser"); - throw new Exception(" Action " + action + " not found while processing request "); - - } - return response; - - } - - private String getArtifactResponse(String dbresposne) { - // TODO Auto-generated method stub - return dbresposne; - } - - private String getsetStatusResponse(String dbresposne) { - // TODO Auto-generated method stub - return null; - } - - private String getStatusResponse(String dbresposne) { - log.info("Returning reposne from Response Parser " + dbresposne); - return dbresposne; - } - - private String getGuiReferenceResponse(String dbresposne) { - // TODO Auto-generated method stub - return null; - } - - private String getArtifactReferenceResponse(String dbresposne) { - // TODO Auto-generated method stub - return null; - } - - private String getAddInCartResponse(String dbresposne) { - // TODO Auto-generated method stub - return null; - } - - private String getDesignsResponse(String dbresposne) { - return dbresposne; - - } -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/DbService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/DbService.java deleted file mode 100644 index a2349196f..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/DbService.java +++ /dev/null @@ -1,146 +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.design.dbervices; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Properties; -import java.util.UUID; - -import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService; -import org.onap.ccsdk.sli.core.dblib.DBResourceManager; -import org.onap.ccsdk.sli.core.dblib.DbLibService; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DbService { - - private static final Logger Log = LoggerFactory.getLogger(DbService.class); - private static final String DBLIB_SERVICE = "org.onap.ccsdk.sli.core.dblib.DBResourceManager"; - DbLibService dblibSvc = null; - String errorMsg = null; - - public DbService() throws Exception { - DbLibService dblibSvc = null; - Log.info("Initializing DbService service"); - try - { - dblibSvc = getDbLibService(); - if (dblibSvc == null) { - Log.error("Got Exception While getting DB Connection"); - throw new Exception("Got Exception While getting DB Connection"); - } - this.dblibSvc = dblibSvc; - } - catch (Exception e) { - Log.error(e.getMessage()); - throw e; - } - } - - private static DbLibService getDbLibService() { - - DbLibService dblibSvc = null; - BundleContext bctx = null; - ServiceReference sref = null; - - Bundle bundle = FrameworkUtil.getBundle(SvcLogicService.class); - - if (bundle != null) { - bctx = bundle.getBundleContext(); - } - - if (bctx != null) { - Log.debug("Getting bundle Context"); - sref = bctx.getServiceReference(DBLIB_SERVICE); - } - - if (sref == null) { - Log.warn("Could not find service reference for DBLib service"); - - } else { - dblibSvc = (DbLibService) bctx.getService(sref); - if (dblibSvc == null) { - Log.warn("DBLIB_SERVICE is null"); - } - } - if (dblibSvc == null) { - try { - dblibSvc = new DBResourceManager(System.getProperties()); - } catch (Exception e) { - Log.error("Caught exception trying to create db service", e); - } - - if (dblibSvc == null) { - Log.warn("Could not create new DBResourceManager"); - } - } - return (dblibSvc); - } - - public ResultSet getDBData(String query) throws Exception { - ResultSet resultSet; - StringBuilder sqlBuilder = new StringBuilder(query); - Log.info("Query: " + sqlBuilder.toString()); - try { - resultSet = dblibSvc.getData(sqlBuilder.toString(), null, null); - } catch (Exception e) { - Log.error("SQL query "+sqlBuilder+" :: " + e.getMessage()); - throw e; - } - return resultSet; - } - - public ResultSet getDBData(String query, ArrayList paramList) throws Exception { - ResultSet resultSet; - StringBuilder sqlBuilder = new StringBuilder(query); - Log.info("Query :" + sqlBuilder.toString()); - try { - resultSet = dblibSvc.getData(sqlBuilder.toString(), paramList, null); - } catch (Exception expObj) { - Log.error("query "+sqlBuilder+" :: " + expObj.getMessage()); - throw expObj; - } - return resultSet; - } - - public boolean updateDBData(String query, ArrayList paramList) throws Exception { - boolean update; - StringBuilder sqlBuilder = new StringBuilder(query); - Log.info("Query :" + sqlBuilder.toString()); - try { - update = dblibSvc.writeData(sqlBuilder.toString(), paramList, null); - } catch (Exception expObj) { - Log.error("query "+sqlBuilder+" :: " + expObj.getMessage()); - throw expObj; - } - return update; - } -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/DesignDBService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/DesignDBService.java deleted file mode 100644 index 64251027f..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/DesignDBService.java +++ /dev/null @@ -1,645 +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.design.dbervices; - -import java.io.IOException; -import java.security.SecureRandom; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import org.onap.appc.design.data.ArtifactInfo; -import org.onap.appc.design.data.DesignInfo; -import org.onap.appc.design.data.DesignResponse; -import org.onap.appc.design.data.StatusInfo; -import org.onap.appc.design.services.util.ArtifactHandlerClient; -import org.onap.appc.design.services.util.DesignServiceConstants; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.ccsdk.sli.core.dblib.DBResourceManager; -import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -public class DesignDBService { - - private static final EELFLogger log = EELFManager.getInstance().getLogger(DesignDBService.class); - private SvcLogicResource serviceLogic; - private static DesignDBService dgGeneralDBService = null; - private static DBResourceManager jdbcDataSource; - - DbService dbservice = null; - private static Properties props; - public static DesignDBService initialise() { - if (dgGeneralDBService == null) { - dgGeneralDBService = new DesignDBService(); - } - return dgGeneralDBService; - } - private DesignDBService() { - if (serviceLogic == null) { - serviceLogic = new SqlResource(); - } - } - - public String execute(String action, String payload, String requestID) throws Exception { - - log.info("Received execute request for action : " + action + " with Payload : "+ payload ); - RequestValidator.validate(action, payload); - String response = null; - dbservice = new DbService(); - switch (action) { - case DesignServiceConstants.GETDESIGNS: - response = getDesigns(payload,requestID ); - break; - case DesignServiceConstants.ADDINCART: - response= setInCart(payload, requestID); - break ; - case DesignServiceConstants.GETARTIFACTREFERENCE: - response= getArtifactReference(payload, requestID); - break; - case DesignServiceConstants.GETARTIFACT: - response= getArtifact(payload, requestID); - break; - case DesignServiceConstants.GETGUIREFERENCE: - response= getGuiReference(payload, requestID); - break; - case DesignServiceConstants.GETSTATUS: - response= getStatus(payload, requestID); - break; - case DesignServiceConstants.SETSTATUS: - response= setStatus(payload, requestID); - break; - case DesignServiceConstants.UPLOADARTIFACT: - response= uploadArtifact(payload, requestID); - break; - case DesignServiceConstants.SETPROTOCOLREFERENCE: - response= setProtocolReference(payload, requestID); - break; - default: - throw new Exception(" Action " + action + " not found while processing request "); - - } - return response; - } - - private String setInCart(String payload, String requestID) throws Exception { - - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - ArrayList argList = new ArrayList<>(); - argList.add(payloadObject.get(DesignServiceConstants.INCART).textValue()); - argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); - - String queryString = "UPDATE DT_ARTIFACT_TRACKING SET INCART= ? WHERE ASDC_REFERENCE_ID IN " - + " (SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE_ID WHERE VNF_TYPE = ? " ; - - if(payloadObject.get(DesignServiceConstants.VNF_TYPE) != null &&! payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) { - queryString = queryString + " AND VNFC_TYPE = ? ) AND USER = ? " ; - argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); - } - else{ - queryString = queryString + " ) AND USER = ? " ; - } - - argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); - - log.info("Query String :" + queryString); - boolean data = dbservice.updateDBData(queryString, argList); - - if(!data) - throw new Exception("Error while updating ProtocolReference"); - - return "{\"update\" : \"success\" } "; - - } - private String setProtocolReference(String payload, String requestID) throws Exception { - - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - ArrayList argList = new ArrayList<>(); - - argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); - argList.add(payloadObject.get(DesignServiceConstants.ACTION_LEVEL).textValue()); - argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); - argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue()); - - String queryString = " DELETE FROM PROTOCOL_REFERENCE WHERE ACTION = ? AND ACTION_LEVEL AND VNF_TYPE= ? AND PROTOCOL = ? " ; - - log.info("Delete Query String :" + queryString); - boolean data = dbservice.updateDBData(queryString, argList); - - log.info("Record Deleted"); - - if((payloadObject.get(DesignServiceConstants.TEMPLATE) != null && !payloadObject.get(DesignServiceConstants.TEMPLATE).textValue().isEmpty())) - argList.add(payloadObject.get(DesignServiceConstants.TEMPLATE).textValue()); - else - argList.add("NO"); - - String insertString = "INSERT INTO PROTOCOL_REFERENCE VALUES (?,?,?,?,?,SYSDATE()) "; - - if(payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && ! payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()){ - queryString = queryString + " AND VNFC_TYPE = ? )" ; - } - else{ - queryString = queryString + " ) "; - } - log.info("Query String :" + queryString); - data = dbservice.updateDBData(queryString, argList); - - if(!data) - throw new Exception("Error while updating ProtocolReference"); - - return "{\"update\" : \"success\" } "; - } - private String uploadArtifact(String payload, String requestID) throws Exception { - - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - log.info("Got upload Aritfact with Payload : " + payloadObject.asText()); - try{ - ArtifactHandlerClient ac = new ArtifactHandlerClient(); - String requestString = ac.createArtifactData(payload, requestID); - ac.execute(requestString, "POST"); - int sdc_artifact_id = getSDCArtifactIDbyRequestID(requestID); - int sdc_reference_id = getSDCReferenceID(payload); - createArtifactTrackingRecord(payload, requestID,sdc_artifact_id, sdc_reference_id ); - String status = getDataFromActionStatus(payload, "STATUS"); - if(status == null || status.isEmpty()) - setActionStatus(payload, "Not Tested"); - linkstatusRelationShip(sdc_artifact_id,sdc_reference_id, payload); - - } - catch(Exception e){ - e.printStackTrace(); - throw e; - } - return "{\"update\" : \"success\" } "; - - } - - private void linkstatusRelationShip(int sdc_artifact_id, int sdc_reference_id, String payload) throws Exception { - - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - ArrayList argList = new ArrayList<>(); - argList.add(String.valueOf(sdc_artifact_id)); - argList.add(String.valueOf(sdc_reference_id)); - argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); - argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); - argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); - - String queryString = "INSERT INTO DT_STATUS_RELATIONSHIP (DT_ARTIFACT_TRACKING_ID,DT_ACTION_STATUS_ID) VALUES " + - "(( SELECT DT_ARTIFACT_TRACKING_ID FROM DT_ARTIFACT_TRACKING WHERE ASDC_ARTIFACTS_ID = ? AND ASDC_REFERENCE_ID = ? ) , " - + "( SELECT DT_ACTION_STATUS_ID FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? " ; - - if(payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && ! payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()){ - queryString = queryString + " AND VNFC_TYPE = ? ) )" ; - } - else{ - queryString = queryString + " ) ) "; - } - log.info("Query String :" + queryString); - boolean data = dbservice.updateDBData(queryString, argList); - - if(!data) - throw new Exception("Error while updating RealtionShip table"); - - } - private int getSDCReferenceID(String payload) throws Exception { - - String vnfc_type = null; - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - ArrayList argList = new ArrayList<>(); - argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); - - argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue()); - argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue()); - - String queryString = " SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE WHERE VNF_TYPE = ? " - + " AND ARTIFACT_TYPE = ? AND ARTIFACT_NAME = ? " ; - - if(payloadObject.get(DesignServiceConstants.ACTION) != null && !payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty()){ - argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); - queryString = queryString + " AND ACTION = ? "; - } - if(payloadObject.get(DesignServiceConstants.VNFC_TYPE) !=null && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()){ - argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); - queryString = queryString + " AND VNFC_TYPE = ? "; - - } - - log.info("Query String :" + queryString); - ResultSet data = dbservice.getDBData(queryString, argList); - int sdc_reference_id = 0; - while(data.next()) { - sdc_reference_id = data.getInt("ASDC_REFERENCE_ID"); - } - log.info("Got sdc_reference_id = " + sdc_reference_id ); - return sdc_reference_id; - - } - - private String getDataFromActionStatus(String payload, String dataValue) throws Exception { - String status = null ; - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - ArrayList argList = new ArrayList<>(); - argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); - argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); - argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); - String queryString = " SELECT " + dataValue + " FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? "; - if(payloadObject.get(DesignServiceConstants.VNFC_TYPE) !=null && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()){ - argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); - queryString = queryString + " AND VNFC_TYPE = ? "; - } - log.info("Query String :" + queryString); - ResultSet data = dbservice.getDBData(queryString, argList); - while(data.next()) { - status = data.getString("STATUS"); - } - log.info("DT_ACTION_STATUS Status = " + status ); - return status; - } - - private boolean setActionStatus(String payload, String status) throws Exception { - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - ArrayList argList = new ArrayList<>(); - argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); - argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); - - - String insertQuery = " INSERT INTO DT_ACTION_STATUS (ACTION, VNF_TYPE, VNFC_TYPE, USER, TECHNOLOGY, UPDATED_DATE, STATUS) VALUES (?,?,?,?,?,sysdate() , ?); "; - if(payloadObject.get(DesignServiceConstants.VNFC_TYPE) !=null && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()){ - argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); - } - else{ - argList.add(null); - } - argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); - if(payloadObject.get(DesignServiceConstants.TECHNOLOGY) !=null && !payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()){ - argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue()); - } - else{ - argList.add(null); - } - argList.add(status); - - boolean updateStatus = dbservice.updateDBData(insertQuery, argList); - if(!updateStatus) - throw new Exception("Error while updating Action Status"); - return updateStatus; - } - - private void createArtifactTrackingRecord(String payload, String requestID, int sdc_artifact_id, int sdc_reference_id) throws Exception { - String vnfc_type = null; - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - - ArrayList argList = new ArrayList<>(); - argList.add(String.valueOf(sdc_artifact_id)); - argList.add(String.valueOf(sdc_reference_id)); - argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); - if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null &&! payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) - argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue()); - else - argList.add(""); - - if (payloadObject.get(DesignServiceConstants.PROTOCOL) != null &&! payloadObject.get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) - argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue()); - else - argList.add(""); - - - String queryString = "INSERT INTO DT_ARTIFACT_TRACKING (ASDC_ARTIFACTS_ID, ASDC_REFERENCE_ID, USER, TECHNOLOGY, CREATION_DATE, UPDATED_DATE, ARTIFACT_STATUS, PROTOCOL, IN_CART) VALUES (? , ? , ?, ?, sysdate() , sysdate(), 'Created', ? ,'N' )" ; - - log.info("Query String :" + queryString); - boolean data = dbservice.updateDBData(queryString, argList); - if(!data) - throw new Exception("Error Updating DT_ARTIFACT_TRACKING "); - - - } - - private int getSDCArtifactIDbyRequestID(String requestID) throws Exception { - log.info("Starting getArtifactIDbyRequestID DB Operation"); - int artifact_id = 0; - try{ - ArrayList argList = new ArrayList<>(); - argList.add("TLSUUID" + requestID); - String queryString = " SELECT ASDC_ARTIFACTS_ID FROM ASDC_ARTIFACTS where SERVICE_UUID = ? "; - log.info("Query String :" + queryString); - ResultSet data = dbservice.getDBData(queryString, argList); - while(data.next()){ - artifact_id = data.getInt("ASDC_ARTIFACTS_ID"); - } - } - catch(Exception e){ - e.printStackTrace(); - throw e; - } - log.info("Got SDC_ARTIFACTS_ID As :" + artifact_id); - return artifact_id; - } - - - private String getArtifact(String payload, String requestID) throws Exception { - String fn = "DBService.getStatus "; - log.info("Starting getArtifact DB Operation"); - try{ - String vnfc_type = null; - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - ArrayList argList = new ArrayList<>(); - argList.add(payloadObject.get("artifact-name").textValue()); - argList.add(payloadObject.get("artifact-type").textValue()); - - String queryString = "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS where " + - " ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ? " ; - - log.info("Query String :" + queryString); - ResultSet data = dbservice.getDBData(queryString, argList); - String artifact_content = null; - int hightestVerion = 0 ; - while(data.next()) { - int version = data.getInt("INTERNAL_VERSION"); - if(hightestVerion < version) - artifact_content = data.getString("ARTIFACT_CONTENT"); - } - - if(artifact_content == null || artifact_content.isEmpty()) - throw new Exception("Sorry !!! I dont have any artifact Named : " + payloadObject.get("artifact-name").textValue()); - DesignResponse designResponse = new DesignResponse(); - designResponse.setUserId(payloadObject.get("userID").textValue()); - List artifactInfoList = new ArrayList(); - ArtifactInfo artifactInfo = new ArtifactInfo(); - artifactInfo.setArtifact_content(artifact_content); - artifactInfoList.add(artifactInfo); - designResponse.setArtifactInfo(artifactInfoList); - - ObjectMapper mapper = new ObjectMapper(); - String jsonString = mapper.writeValueAsString(designResponse); - log.info("Info : " + jsonString); - return jsonString; - } - catch(SQLException e) - { - log.error("Error while DB operation : " + e.getMessage()); - e.printStackTrace(); - throw e; - } - catch(Exception e) - { - log.error("Error while DB operation : " + e.getMessage()); - e.printStackTrace(); - throw e; - } - - } - private String setStatus(String payload, String requestID) throws Exception { - String fn = "DBService.getStatus "; - log.info("Starting getStatus DB Operation"); - try{ - String vnfc_type = null; - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - - - ArrayList argList = new ArrayList<>(); - argList.add(payloadObject.get("artifact_status").textValue()); - argList.add(payloadObject.get("action_status").textValue()); - - argList.add(payloadObject.get("userID").textValue()); - argList.add(payloadObject.get("vnf-type").textValue()); - - String queryString = " UPDATE DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR SET DAT.ARTIFACT_STATUS = ? , DAS.DT_ACTION_STATUS = ? " - + " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID " - + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? " - + " and DAS.VNF_TYPE = ? " ; - - if(payloadObject.get("vnfc-type") !=null && !payloadObject.get("vnfc-type").textValue().isEmpty()){ - argList.add(payloadObject.get("vnfc-type").textValue()); - queryString = queryString + " and DAS.VNFC_TYPE = ? "; - } - - log.info("Query String :" + queryString); - - DesignResponse designResponse = new DesignResponse(); - designResponse.setUserId(payloadObject.get("userID").textValue()); - List statusInfoList = new ArrayList(); - boolean update = dbservice.updateDBData(queryString, argList); - if(!update) - throw new Exception("Sorry .....Something went wrong while updating the Status"); - - ObjectMapper mapper = new ObjectMapper(); - String jsonString = mapper.writeValueAsString(designResponse); - log.info("Info : " + jsonString); - return jsonString; - } - catch(SQLException e) - { - log.error("Error while DB operation : " + e.getMessage()); - e.printStackTrace(); - throw e; - } - catch(Exception e) - { - log.error("Error while DB operation : " + e.getMessage()); - e.printStackTrace(); - throw e; - } - } - private String getStatus(String payload, String requestID) throws Exception { - String fn = "DBService.getStatus "; - log.info("Starting getStatus DB Operation"); - try{ - String vnfc_type = null; - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - String UserID = payloadObject.get("userID").textValue(); - String vnf_type = payloadObject.get("vnf-type").textValue(); - if(payloadObject.get("vnfc-type") != null ) - vnfc_type = payloadObject.get("vnfc-type").textValue(); - ArrayList argList = new ArrayList<>(); - - argList.add(UserID); - argList.add(vnf_type); - - String queryString = "SELECT DAS.VNF_TYPE, DAS.VNFC_TYPE, DAS.STATUS, DAS.ACTION, DAT.ARTIFACT_STATUS " - + "from DT_ACTION_STATUS DAS , DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR " + - " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID " - + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? " - + " and DAS.VNF_TYPE = ? " ; - - if(vnfc_type !=null && ! vnfc_type.isEmpty()){ - argList.add(vnfc_type); - queryString = queryString + " and DAS.VNFC_TYPE = ? "; - } - - log.info("Query String :" + queryString); - - DesignResponse designResponse = new DesignResponse(); - designResponse.setUserId(UserID); - List statusInfoList = new ArrayList(); - ResultSet data = dbservice.getDBData(queryString, argList); - while(data.next()) { - StatusInfo statusInfo = new StatusInfo(); - statusInfo.setAction(data.getString("ACTION")); - statusInfo.setAction_status(data.getString("STATUS")); - statusInfo.setArtifact_status(data.getString("ARTIFACT_STATUS")); - statusInfo.setVnf_type(data.getString("VNF_TYPE")); - statusInfo.setVnfc_type(data.getString("VNFC_TYPE")); - statusInfoList.add(statusInfo); - } - - if(statusInfoList.size() < 1) - throw new Exception("OOPS !!!! No VNF information available for VNF-TYPE : " + vnf_type + " for User : " + UserID); - designResponse.setStatusInfoList(statusInfoList); - ObjectMapper mapper = new ObjectMapper(); - String jsonString = mapper.writeValueAsString(designResponse); - log.info("Info : " + jsonString); - return jsonString; - } - catch(SQLException e) - { - log.error("Error while DB operation : " + e.getMessage()); - e.printStackTrace(); - throw e; - } - catch(Exception e) - { - log.error("Error while DB operation : " + e.getMessage()); - e.printStackTrace(); - throw e; - } - } - private String getGuiReference(String payload, String requestID) { - // TODO Auto-generated method stub - return null; - } - private String getArtifactReference(String payload, String requestID) { - // TODO Auto-generated method stub - return null; - } - private String getAddInCart(String payload, String requestID) { - // TODO Auto-generated method stub - return null; - } - - // private String getDesigns(String payload, String requestID) throws SQLException, JsonProcessingException, IOException, SvcLogicException { - // - // String fn = "DBService.getDesigns "; - // QueryStatus status = null; - // ObjectMapper objectMapper = new ObjectMapper(); - // JsonNode jnode = objectMapper.readTree(payload); - // String UserId = jnode.get("userID").textValue(); - // SvcLogicContext localContext = new SvcLogicContext(); - // localContext.setAttribute("requestID", requestID); - // localContext.setAttribute("userID", UserId); - // if (serviceLogic != null && localContext != null) { - // String queryString = "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART from " + - // DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , " + DesignServiceConstants.DB_SDC_REFERENCE + - // " AR where DAT.SDC_REFERENCE_ID= AR.SDC_REFERENCE_ID and DAT.USER = $userID" ; - // - // log.info(fn + "Query String : " + queryString); - // try { - // status = serviceLogic.query("SQL", true, null, queryString, null, null, localContext); - // } catch (SvcLogicException e1) { - // // TODO Auto-generated catch block - // e1.printStackTrace(); - // } - // - // if(status.toString().equals("FAILURE")) - // throw new SvcLogicException("Error - while getting FlowReferenceData "); - // - // Properties props = localContext.toProperties(); - // log.info("SvcLogicContext contains the following : " + props.toString()); - // for (Enumeration e = props.propertyNames(); e.hasMoreElements() ; ) { - // String propName = (String) e.nextElement(); - // log.info(propName+" = "+props.getProperty(propName)); - // - // } - // } - // return requestID; - // - // } - - private String getDesigns(String payload, String requestID) throws Exception { - - String fn = "DBService.getDesigns "; - log.info("Starting getDesgins DB Operation"); - - - try{ - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - String UserID = payloadObject.get("userID").textValue(); - ArrayList argList = new ArrayList<>(); - argList.add(UserID); - - String queryString = "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from " + - DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , " + DesignServiceConstants.DB_SDC_REFERENCE + - " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? "; - - DesignResponse designResponse = new DesignResponse(); - designResponse.setUserId(UserID); - List designInfoList = new ArrayList(); - ResultSet data = dbservice.getDBData(queryString, argList); - while(data.next()) { - DesignInfo designInfo = new DesignInfo(); - designInfo.setInCart(data.getString("IN_CART")); - designInfo.setProtocol(data.getString("PROTOCOL")); - designInfo.setVnf_type(data.getString("VNF_TYPE")); - designInfo.setVnfc_type(data.getString("VNFC_TYPE")); - designInfo.setAction(data.getString("ACTION")); - designInfo.setArtifact_type(data.getString("ARTIFACT_TYPE")); - designInfo.setArtifact_name(data.getString("ARTIFACT_NAME")); - designInfoList.add(designInfo); - } - if(designInfoList.size() < 1) - throw new Exception(" Welcome to CDT, Looks like you dont have Design Yet... Lets create some...."); - designResponse.setDesignInfoList(designInfoList); - ObjectMapper mapper = new ObjectMapper(); - String jsonString = mapper.writeValueAsString(designResponse); - log.info("Info : " + jsonString); - return jsonString; - } - catch(Exception e) - { - e.printStackTrace(); - throw e; - } - } - -} - - diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/RequestValidator.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/RequestValidator.java deleted file mode 100644 index c0b710deb..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/dbervices/RequestValidator.java +++ /dev/null @@ -1,126 +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.design.dbervices; - -import org.onap.appc.design.services.util.ArtifactHandlerClient; -import org.onap.appc.design.services.util.DesignServiceConstants; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class RequestValidator { - - private static final EELFLogger log = EELFManager.getInstance().getLogger(RequestValidator.class); - public static void validate(String action, String payload) throws Exception { - log.info("payload" + payload); - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - log.info("payloadObject" + payloadObject.get(DesignServiceConstants.ARTIFACT_CONTENTS)); - - String errorString = null; - switch (action) { - case DesignServiceConstants.GETDESIGNS: - if(payloadObject.get(DesignServiceConstants.USER_ID) == null || payloadObject.get(DesignServiceConstants.USER_ID).textValue().isEmpty()) - errorString = DesignServiceConstants.USER_ID; - break; - case DesignServiceConstants.GETARTIFACT: - if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) - errorString = DesignServiceConstants.VNF_TYPE; - else if(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue().isEmpty()) - errorString = DesignServiceConstants.ARTIFACT_TYPE; - else if(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue().isEmpty()) - errorString = DesignServiceConstants.ARTIFACT_NAME; - break; - case DesignServiceConstants.GETSTATUS: - if(payloadObject.get(DesignServiceConstants.USER_ID) == null || payloadObject.get(DesignServiceConstants.USER_ID).textValue().isEmpty()) - errorString = DesignServiceConstants.USER_ID; - else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) - errorString = DesignServiceConstants.VNF_TYPE; - break; - case DesignServiceConstants.SETSTATUS: - if(payloadObject.get(DesignServiceConstants.USER_ID) == null || payloadObject.get(DesignServiceConstants.USER_ID).textValue().isEmpty()) - errorString = DesignServiceConstants.USER_ID; - else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) - errorString = DesignServiceConstants.VNF_TYPE; - else if(payloadObject.get(DesignServiceConstants.ACTION) == null || payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty()) - errorString = DesignServiceConstants.ACTION; - else if(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue().isEmpty()) - errorString = DesignServiceConstants.ARTIFACT_TYPE; - else if(payloadObject.get(DesignServiceConstants.STATUS) == null || payloadObject.get(DesignServiceConstants.STATUS).textValue().isEmpty()) - errorString = DesignServiceConstants.STATUS; - break; - case DesignServiceConstants.UPLOADARTIFACT: - if(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue().isEmpty()) - errorString = DesignServiceConstants.ARTIFACT_NAME; - else if(! payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue().contains("reference")){ - if(payloadObject.get(DesignServiceConstants.ACTION) == null || payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty()) - errorString = DesignServiceConstants.ACTION; - } - else if(payloadObject.get(DesignServiceConstants.ARTIFACT_VERSOIN) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_VERSOIN).textValue().isEmpty()) - errorString = DesignServiceConstants.ARTIFACT_VERSOIN; - else if(payloadObject.get(DesignServiceConstants.ARTIFACT_CONTENTS) == null) - errorString = DesignServiceConstants.ARTIFACT_CONTENTS; - else if(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue().isEmpty()) - errorString = DesignServiceConstants.ARTIFACT_TYPE; - - else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) - errorString = DesignServiceConstants.VNF_TYPE; - - - break; - case DesignServiceConstants.SETPROTOCOLREFERENCE: - if(payloadObject.get(DesignServiceConstants.ACTION) == null || payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty()) - errorString = DesignServiceConstants.ACTION; - else if(payloadObject.get(DesignServiceConstants.ACTION_LEVEL) == null || payloadObject.get(DesignServiceConstants.ACTION_LEVEL).textValue().isEmpty()) - errorString = DesignServiceConstants.ACTION_LEVEL; - else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) - errorString = DesignServiceConstants.VNF_TYPE; - else if(payloadObject.get(DesignServiceConstants.PROTOCOL) == null || payloadObject.get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) - errorString = DesignServiceConstants.PROTOCOL; - - case DesignServiceConstants.SETINCART: - if(payloadObject.get(DesignServiceConstants.ACTION) == null || payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty()) - errorString = DesignServiceConstants.ACTION; - else if(payloadObject.get(DesignServiceConstants.ACTION_LEVEL) == null || payloadObject.get(DesignServiceConstants.ACTION_LEVEL).textValue().isEmpty()) - errorString = DesignServiceConstants.ACTION_LEVEL; - else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) - errorString = DesignServiceConstants.VNF_TYPE; - else if(payloadObject.get(DesignServiceConstants.PROTOCOL) == null || payloadObject.get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) - errorString = DesignServiceConstants.PROTOCOL; - break; - default: - throw new Exception(" Action " + action + " not found while processing request "); - - } - if(errorString != null) - throw new Exception(" Missing input parameter :-" + errorString + " -:"); - - } - -} - - diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/propertyServices/PropertyUpdateService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/propertyServices/PropertyUpdateService.java deleted file mode 100644 index 87e84d495..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/propertyServices/PropertyUpdateService.java +++ /dev/null @@ -1,30 +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.design.propertyServices; - -public class PropertyUpdateService { - - // to set the properties this placeholder will be used. -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/DesignServiceProvider.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/DesignServiceProvider.java deleted file mode 100644 index f41bbac46..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/DesignServiceProvider.java +++ /dev/null @@ -1,72 +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.design.services; - -import java.util.concurrent.Future; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; -import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.DesignServicesService; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.onap.appc.design.services.impl.DesignServicesImpl; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class DesignServiceProvider{ - - private static final EELFLogger log = EELFManager.getInstance().getLogger(DesignServiceProvider.class); - - private final DataBroker dataBroker; - private final RpcProviderRegistry rpcProviderRegistry; - private RpcRegistration serviceRegistration; - - - public DesignServiceProvider(final DataBroker dataBroker, RpcProviderRegistry rpcProviderRegistry) { - this.dataBroker = dataBroker; - this.rpcProviderRegistry = rpcProviderRegistry; - } - - /** - * Method called when the blueprint container is created. - */ - public void init() { - // initialize data broker - this.serviceRegistration = this.rpcProviderRegistry.addRpcImplementation(DesignServicesService.class, new DesignServicesImpl()); - log.info("DesignServicesImpl Session Initiated"); - } - - /** - * Method called when the blueprint container is destroyed. - */ - public void close() { - if(this.serviceRegistration != null){ - this.serviceRegistration.close(); - } - log.info("DesignServicesImpl Closed"); - } - - -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/impl/DesignServicesImpl.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/impl/DesignServicesImpl.java deleted file mode 100644 index 1787618e6..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/impl/DesignServicesImpl.java +++ /dev/null @@ -1,160 +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.design.services.impl; - -import java.util.concurrent.Future; -import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.DbserviceInput; -import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.DbserviceOutput; -import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.DbserviceOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.DesignServicesService; -import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.ValidatorInput; -import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.ValidatorOutput; -import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.ValidatorOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.XinterfaceserviceInput; -import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.XinterfaceserviceOutput; -import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.XinterfaceserviceOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.data.DataBuilder; -import org.opendaylight.yang.gen.v1.org.onap.appc.rev170627.status.StatusBuilder; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import org.onap.appc.design.dbervices.DbResponseProcessor; -import org.onap.appc.design.dbervices.DesignDBService; -import org.onap.appc.design.services.util.DesignServiceConstants; -import org.onap.appc.design.validator.ValidatorResponseProcessor; -import org.onap.appc.design.validator.ValidatorService; -import org.onap.appc.design.xinterface.XInterfaceService; -import org.onap.appc.design.xinterface.XResponseProcessor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.Lists; -import com.google.common.util.concurrent.Futures; - -public class DesignServicesImpl implements DesignServicesService { - - private static final Logger log = LoggerFactory.getLogger(DesignServicesImpl.class); - - @Override - public Future> dbservice(DbserviceInput input) { - - log.info("Received Request: " + input.getDesignRequest().getRequestId() + " Action : " + - input.getDesignRequest().getAction() + " with Payload :" + input.getDesignRequest().getPayload()); - - - DbserviceOutputBuilder outputBuilder = new DbserviceOutputBuilder(); - DataBuilder databuilder = new DataBuilder(); - StatusBuilder statusBuilder = new StatusBuilder(); - - try{ - DesignDBService dbservices = DesignDBService.initialise(); - DbResponseProcessor responseProcessor = new DbResponseProcessor(); - String response = responseProcessor.parseResponse(dbservices.execute(input.getDesignRequest().getAction(), input.getDesignRequest().getPayload(), input.getDesignRequest().getRequestId()), input.getDesignRequest().getAction()); - log.info("Response in for Design Service : " + response); - databuilder.setBlock(response); - databuilder.setRequestId(input.getDesignRequest().getRequestId()); - statusBuilder.setCode("400"); - statusBuilder.setMessage("success"); - } - catch(Exception e){ - log.error("Error" + e.getMessage()); - e.printStackTrace(); - statusBuilder.setCode("401"); - statusBuilder.setMessage(e.getMessage()); - } - - outputBuilder.setData(databuilder.build()); - outputBuilder.setStatus(statusBuilder.build()); - - RpcResult result = RpcResultBuilder.status(true).withResult(outputBuilder.build()).build(); - return Futures.immediateFuture(result); - } - - @Override - public Future> xinterfaceservice(XinterfaceserviceInput input) { - log.info("Received Request: " + input.getDesignRequest().getRequestId() + " Action : " + - input.getDesignRequest().getAction() + " with Payload :" + input.getDesignRequest().getPayload()); - XinterfaceserviceOutputBuilder outputBuilder = new XinterfaceserviceOutputBuilder(); - DataBuilder databuilder = new DataBuilder(); - StatusBuilder statusBuilder = new StatusBuilder(); - try { - - XInterfaceService xInterfaceService = new XInterfaceService(); - XResponseProcessor responseProcessor = new XResponseProcessor(); - String response = responseProcessor.parseResponse(xInterfaceService.execute(input.getDesignRequest().getAction(), input.getDesignRequest().getPayload()), input.getDesignRequest().getAction()); - databuilder.setBlock(response); - databuilder.setRequestId(input.getDesignRequest().getRequestId()); - statusBuilder.setCode("400"); - statusBuilder.setMessage("success"); - } catch (Exception e) { - e.printStackTrace(); - statusBuilder.setCode("401"); - statusBuilder.setMessage(e.getMessage()); - } - outputBuilder.setData(databuilder.build()); - outputBuilder.setStatus(statusBuilder.build()); - - RpcResult result = RpcResultBuilder.status(true).withResult(outputBuilder.build()).build(); - return Futures.immediateFuture(result); - } - - @Override - public Future> validator(ValidatorInput input) { - log.info("Received Request: " + input.getDesignRequest().getRequestId() + " Action : " + - input.getDesignRequest().getAction() + " with Payload :" + input.getDesignRequest().getPayload() + " and Data Type = " + input.getDesignRequest().getDataType()); - ValidatorOutputBuilder outputBuilder = new ValidatorOutputBuilder(); - StatusBuilder statusBuilder = new StatusBuilder(); - - - try { - if(input.getDesignRequest().getDataType() == null || input.getDesignRequest().getDataType().isEmpty()) - throw new Exception ("Data Type required for validate Serivce"); - if(input.getDesignRequest().getAction()== null || input.getDesignRequest().getAction().isEmpty()) - throw new Exception ("Action required for validate Serivce"); - - - if(! input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_JSON) && - ! input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_YAML) && - ! input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_XML) && - ! input.getDesignRequest().getDataType().equals(DesignServiceConstants.DATA_TYPE_VELOCITY)) - throw new Exception ("Request Data format " + input.getDesignRequest().getDataType() - + " is not supported by validate Service : Supported data types are : XML, YAML, VELOCITY, JSON "); - - ValidatorService validatorService = new ValidatorService(); - ValidatorResponseProcessor responseProcessor = new ValidatorResponseProcessor(); - String response = validatorService.execute(input.getDesignRequest().getAction(), input.getDesignRequest().getPayload(), input.getDesignRequest().getDataType()); - statusBuilder.setCode("400"); - statusBuilder.setMessage(response); - } catch (Exception e) { - e.printStackTrace(); - statusBuilder.setCode("401"); - statusBuilder.setMessage(e.getMessage()); - } - - outputBuilder.setStatus(statusBuilder.build()); - - RpcResult result = RpcResultBuilder.status(true).withResult(outputBuilder.build()).build(); - return Futures.immediateFuture(result); - } -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/ArtifactHandlerClient.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/ArtifactHandlerClient.java deleted file mode 100644 index b250faca9..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/ArtifactHandlerClient.java +++ /dev/null @@ -1,187 +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.design.services.util; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.nio.charset.Charset; -import java.security.SecureRandom; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Properties; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.ws.rs.HttpMethod; -import javax.ws.rs.core.MediaType; - -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.config.DefaultClientConfig; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - - -public class ArtifactHandlerClient { - - private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerClient.class); - private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR"; - Properties props = new Properties(); - public ArtifactHandlerClient() throws Exception { - String propDir = System.getenv(SDNC_CONFIG_DIR_VAR); - if (propDir == null) - throw new Exception(" Cannot find Property file -" + SDNC_CONFIG_DIR_VAR); - String propFile = propDir + "/" + DesignServiceConstants.DESIGN_SERVICE_PROPERTIES; - InputStream propStream = new FileInputStream(propFile); - try{ - props.load(propStream); - } - catch (Exception e){ - throw new Exception("Could not load properties file " + propFile, e); - } - finally{ - try{ - propStream.close(); - } - catch (Exception e){ - log.warn("Could not close FileInputStream", e); - } - } - } - - public String createArtifactData(String payload, String requestID) throws JsonProcessingException, IOException { - - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - - ObjectNode json = objectMapper.createObjectNode(); - - String artifact_name = payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue(); - String artifact_version = payloadObject.get(DesignServiceConstants.ARTIFACT_VERSOIN).textValue(); - String artifact_contents = payloadObject.get(DesignServiceConstants.ARTIFACT_CONTENTS).textValue(); - - ObjectNode requestInfo = objectMapper.createObjectNode(); - - requestInfo.put(DesignServiceConstants.REQUETS_ID, requestID); - requestInfo.put(DesignServiceConstants.REQUEST_ACTION, "StoreSdcDocumentRequest"); - requestInfo.put(DesignServiceConstants.SOURCE, DesignServiceConstants.DESIGN_TOOL); - - String random = getRandom(); - - ObjectNode docParams = objectMapper.createObjectNode(); - - docParams.put(DesignServiceConstants.ARTIFACT_VERSOIN, artifact_version); - docParams.put(DesignServiceConstants.ARTIFACT_NAME, artifact_name); - docParams.put(DesignServiceConstants.ARTIFACT_CONTENTS, artifact_contents); - - - json.put(DesignServiceConstants.REQUEST_INFORMATION, requestInfo); - json.put(DesignServiceConstants.DOCUMENT_PARAMETERS, docParams); - log.info("Final data =" + json.toString()); - return String.format("{\"input\": %s}", json.toString()); - } - - public HashMap execute(String payload, String rpc) throws Exception{ - log.info("Configuring Rest Operation for Payload " + payload + " RPC : " + rpc ); - HashMap outputMessage = new HashMap(); - Client client = null; - WebResource webResource = null; - ClientResponse clientResponse = null; - String responseDataType=MediaType.APPLICATION_JSON; - String requestDataType=MediaType.APPLICATION_JSON; - - try{ - DefaultClientConfig defaultClientConfig = new DefaultClientConfig(); - System.setProperty("jsse.enableSNIExtension", "false"); - SSLContext sslContext = null; - SecureRestClientTrustManager secureRestClientTrustManager = new SecureRestClientTrustManager(); - sslContext = SSLContext.getInstance("SSL"); - sslContext.init(null, new javax.net.ssl.TrustManager[] { secureRestClientTrustManager }, null); - defaultClientConfig.getProperties().put( - com.sun.jersey.client.urlconnection.HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, - new com.sun.jersey.client.urlconnection.HTTPSProperties(getHostnameVerifier(), sslContext)); - client = Client.create(defaultClientConfig); - client.addFilter(new HTTPBasicAuthFilter(props.getProperty("appc.upload.user"), props.getProperty("appc.upload.pass"))); - webResource = client.resource(new URI(props.getProperty("appc.upload.provider.url"))); - webResource.setProperty("Content-Type", "application/json;charset=UTF-8"); - - log.info("Starting Rest Operation....."); - if(HttpMethod.GET.equalsIgnoreCase(rpc)){ - clientResponse = webResource.accept(responseDataType).get(ClientResponse.class); - }else if(HttpMethod.POST.equalsIgnoreCase(rpc)){ - clientResponse = webResource.type(requestDataType).post(ClientResponse.class, payload); - }else if(HttpMethod.PUT.equalsIgnoreCase(rpc)){ - clientResponse = webResource.type(requestDataType).put(ClientResponse.class,payload); - }else if(HttpMethod.DELETE.equalsIgnoreCase(rpc)){ - clientResponse = webResource.delete(ClientResponse.class); - } - - if(!(clientResponse.getStatus() == 200)) - throw new Exception("HTTP error code : " + clientResponse.getStatus()); - - - log.info("Completed Rest Operation....."); - - }catch (Exception e) { - e.printStackTrace(); - log.debug("failed in RESTCONT Action with falut message :"+e.getMessage()); - throw new Exception("Error While Sending Rest Request" + e.getMessage()); - } - finally { - // clean up. - webResource = null; - if(client != null){ - client.destroy(); - client = null; - } - } - - return outputMessage; - } - private String getRandom() { - SecureRandom random = new SecureRandom(); - int num = random.nextInt(100000); - String formatted = String.format("%05d", num); - return formatted; - } - - private HostnameVerifier getHostnameVerifier() { - return new HostnameVerifier() { - @Override - public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) { - return true; - } - }; - } -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/DesignServiceConstants.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/DesignServiceConstants.java deleted file mode 100644 index 9ad5e10ac..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/DesignServiceConstants.java +++ /dev/null @@ -1,106 +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.design.services.util; - -public class DesignServiceConstants { - - public static String STRING_ENCODING = "utf-8"; - public static String Y = "Y"; - public static String N = "N"; - public static String DATA_TYPE_TEXT = "TEXT"; - public static String DATA_TYPE_JSON = "JSON"; - public static String DATA_TYPE_XML = "XML"; - public static String DATA_TYPE_YAML = "YAML"; - public static String DATA_TYPE_VELOCITY = "VELOCITY"; - public static String DATA_TYPE_SQL = "SQL"; - - public static final String GETDESIGNS = "getDesigns"; - public static final String UPLOADARTIFACTS = "uploadArtifacts"; - public static final String VALIDATETEMPLATE = "validateTemplate"; - public static final String GETSTATUS = "getStatus"; - public static final String SETSTATUS = "setStatus"; - public static final String GETGUIREFERENCE = "getGUIReference"; - public static final String GETARTIFACTREFERENCE = "getArtifactReference"; - public static final String GETAAIDATA = "getAAIData"; - public static final String GETINSTARDATA = "getInstarData"; - public static final String PUBLISHARTIFACTS = "publishdArtifacts"; - public static final String ADDINCART = "addInCart"; - - public static final String SUCCESS = "success"; - public static final String DESINGTIME = "DesignTime"; - public static final String RUNTIME = "RunTime"; - public static final String APPC_FLOW_CONTROLLER = "/appc-flow-controller.properties"; - public static final String VNF_TYPE = "vnf-type"; - public static final String ACTION = "action"; - public static final String VNFC_TYPE = "vnfc-type"; - public static final String VM_INSTANCE = "vm-instance"; - public static final String VM = "vm"; - public static final String VNFC = "vnfc"; - - public static final String DOCUMENT_PARAMETERS = "document-parameters"; - public static final String SERVICE_UUID = "service-uuid"; - public static final String DISTRIBUTION_ID = "distribution-id"; - - public static final String SERVICE_NAME = "service-name"; - public static final String SERVICE_DESCRIPTION ="service-description"; - public static final String SERVICE_ARTIFACTS = "service-artifacts"; - public static final String RESOURCE_UUID ="resource-uuid"; - public static final String RESOURCE_INSTANCE_NAME = "resource-instance-name"; - public static final String REOURCE_NAME = "resource-name"; - public static final String RESOURCE_VERSOIN ="resource-version"; - public static final String RESOURCE_TYPE= "resource-type"; - public static final String ARTIFACT_UUID ="artifact-uuid"; - public static final String ARTIFACT_NAME = "artifact-name"; - - public static final String ARTIFACT_VERSOIN = "artifact-version"; - public static final String ARTIFACT_DESRIPTION = "artifact-description"; - public static final String ARTIFACT_CONTENTS = "artifact-contents"; - public static final String REQUEST_INFORMATION = "request-information"; - public static final String INTERNAL_VERSION = "internal-versoin"; - - - - public static final String DB_DT_ARTIFACT_TRACKING = "DT_ARTIFACT_TRACKING"; - public static final String DB_SDC_REFERENCE = "ASDC_REFERENCE"; - public static final String SCHEMA_SDNCTL = "SDNCTL"; - public static final String GETARTIFACT = "getArtifact"; - public static final String USER_ID = "userID"; - public static final String ARTIFACT_TYPE = "artifact-type"; - public static final String STATUS = "status"; - public static final String UPLOADARTIFACT = "uploadArtifact"; - public static final String REQUETS_ID = "request-id"; - public static final String REQUEST_ACTION = "request-action"; - public static final String SOURCE = "source"; - public static final String DESIGN_SERVICE_PROPERTIES = "designService.properties"; - public static final String DESIGN_TOOL = "Design-tool"; - public static final String TECHNOLOGY = "technology"; - public static final String PROTOCOL = "protocol"; - public static final String SETPROTOCOLREFERENCE = "setProtocolReference"; - public static final String ACTION_LEVEL = "action-level"; - public static final String TEMPLATE = "template"; - public static final String SETINCART = "setInCart"; - public static final String INCART = "inCart"; - public static final String STOREPASSWORD = "storeProperty"; - } diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/EscapeUtils.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/EscapeUtils.java deleted file mode 100644 index 80f756f3a..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/EscapeUtils.java +++ /dev/null @@ -1,44 +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.design.services.util; - -import org.apache.commons.lang3.StringUtils; - -public class EscapeUtils { - - public EscapeUtils() { - // TODO Auto-generated constructor stub - } - - public static String escapeSql(String str) { - if (str == null) { - return null; - } - String searchList[] = new String[]{"'","\\", "\"" }; - String replacementList[] = new String[]{ "''","\\\\" ,"\\\""}; - return StringUtils.replaceEach(str,searchList, replacementList); - } - -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/SecureRestClientTrustManager.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/SecureRestClientTrustManager.java deleted file mode 100644 index 8e31d9540..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/services/util/SecureRestClientTrustManager.java +++ /dev/null @@ -1,58 +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.design.services.util; - -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; - -import javax.net.ssl.X509TrustManager; - - -public class SecureRestClientTrustManager implements X509TrustManager { - - @Override - public void checkClientTrusted(X509Certificate[] arg0, String arg1) - throws CertificateException { - } - - @Override - public void checkServerTrusted(X509Certificate[] arg0, String arg1) - throws CertificateException { - } - - @Override - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - - public boolean isClientTrusted(X509Certificate[] arg0) { - return true; - } - - public boolean isServerTrusted(X509Certificate[] arg0) { - return true; - } - -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/validator/ValidatorResponseProcessor.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/validator/ValidatorResponseProcessor.java deleted file mode 100644 index faea6a5ee..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/validator/ValidatorResponseProcessor.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.design.validator; - -import org.onap.appc.design.services.impl.DesignServicesImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ValidatorResponseProcessor { - - private static final Logger log = LoggerFactory.getLogger(ValidatorResponseProcessor.class); - public String parseResponse(Object execute, String action) { - return null; - } - -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/validator/ValidatorService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/validator/ValidatorService.java deleted file mode 100644 index 6660dd825..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/validator/ValidatorService.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.design.validator; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringWriter; -import java.nio.charset.StandardCharsets; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.validation.Validator; - -import org.apache.velocity.Template; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.Velocity; -import org.apache.velocity.app.VelocityEngine; -import org.apache.velocity.exception.MethodInvocationException; -import org.apache.velocity.exception.ParseErrorException; -import org.apache.velocity.exception.ResourceNotFoundException; -import org.apache.velocity.runtime.resource.loader.StringResourceLoader; -import org.apache.velocity.runtime.resource.util.StringResourceRepository; -import org.onap.appc.design.services.util.DesignServiceConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; -import com.fasterxml.jackson.dataformat.yaml.snakeyaml.introspector.BeanAccess; - -public class ValidatorService { - - private static final Logger log = LoggerFactory.getLogger(ValidatorService.class); - public String execute(String action, String payload, String dataType) throws Exception { - - String validateResponse = null; - log.info("Received validation for action= " + action + "Data :" + payload + " dataType = " + dataType); - if(dataType.equals(DesignServiceConstants.DATA_TYPE_XML)) - validateResponse = validateXML(payload); - else if(dataType.equals(DesignServiceConstants.DATA_TYPE_JSON)) - validateResponse = validateJOSN(payload); - else if(dataType.equals(DesignServiceConstants.DATA_TYPE_VELOCITY)) - validateResponse = validateVelocity(payload); - else if(dataType.equals(DesignServiceConstants.DATA_TYPE_YAML)) - validateResponse = validateYAML(payload); - - return validateResponse; - - } - - private String validateYAML(String payload) throws Exception { - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - try{ - InputStream is = new ByteArrayInputStream(payload.getBytes()); - - Reader in = new InputStreamReader(is); - Yaml yaml = new Yaml(); - yaml.setBeanAccess(BeanAccess.FIELD); - yaml.load(in); - return DesignServiceConstants.SUCCESS; - } - catch(Exception e){ - log.error("Not a Valid YAML Format "); - throw e; - } - - } - - private String validateVelocity(String payload) { - - try{ - VelocityEngine engine = new VelocityEngine(); - engine.setProperty(Velocity.RESOURCE_LOADER, "string"); - engine.addProperty("string.resource.loader.class", StringResourceLoader.class.getName()); - engine.addProperty("string.resource.loader.repository.static", "false"); - engine.init(); - StringResourceRepository repo = (StringResourceRepository) engine.getApplicationAttribute(StringResourceLoader.REPOSITORY_NAME_DEFAULT); - repo.putStringResource("TestTemplate", payload); - //Template t = ve.getTemplate(payload); - Template t = engine.getTemplate("TestTemplate"); - - return DesignServiceConstants.SUCCESS; - } - catch(ResourceNotFoundException e ){ - log.error("Not a Valid Velocity Template "); - throw e; - } - catch(ParseErrorException pe){ - log.error("Not a Valid Velocity Template "); - throw pe; - } - catch(MethodInvocationException mi){ - log.error("Not a Valid Velocity Template "); - throw mi; - } - } - - private String validateJOSN(String payload) throws Exception { - - try{ - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.readTree(payload); - return DesignServiceConstants.SUCCESS; - } catch(JsonProcessingException e){ - log.error("Not a Valid JOSN file "); - throw e; - } - - } - - private String validateXML(String payload) throws IOException, SAXException, ParserConfigurationException { - - try{ - - DocumentBuilderFactory dBF = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = dBF.newDocumentBuilder(); - InputSource is = new InputSource(payload); - builder.parse(new InputSource(new ByteArrayInputStream(payload.getBytes("utf-8")))); - return DesignServiceConstants.SUCCESS; - - } catch(ParserConfigurationException e){ - log.info("Error While parsing Payload : " + e.getMessage()); - throw e; - } - catch(SAXException se){ - log.info("Error While parsing Payload : " + se.getMessage()); - throw se; - } - catch(IOException io){ - log.info("Error While parsing Payload : " + io.getMessage()); - throw io; - } - } -} - diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/xinterface/XInterfaceService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/xinterface/XInterfaceService.java deleted file mode 100644 index 157e52937..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/xinterface/XInterfaceService.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.design.xinterface; - -import java.io.File; -import java.io.IOException; - -import com.google.common.base.Charsets; -import com.google.common.io.Files; - -public class XInterfaceService { - - - public String execute(String action, String payload) throws IOException { - //Remove this once hte interfaces are up and running - File targetFile = new File("/tmp/" + action + "-response.txt" ); - String interfaceResponse = Files.toString(targetFile, Charsets.UTF_8); - return interfaceResponse; - } - -} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/xinterface/XResponseProcessor.java b/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/xinterface/XResponseProcessor.java deleted file mode 100644 index aa72e2f09..000000000 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/openecomp/appc/design/xinterface/XResponseProcessor.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.design.xinterface; - -import java.io.File; -import java.io.IOException; - -import com.google.common.base.Charsets; -import com.google.common.io.Files; - -public class XResponseProcessor { - - public String parseResponse(Object execute, String action) { - return null; - } -} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestArifactHandlerClient.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestArifactHandlerClient.java new file mode 100644 index 000000000..9f6622e36 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestArifactHandlerClient.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.design.validator; + +import org.junit.Before; +import org.junit.Test; +import org.onap.appc.design.services.util.ArtifactHandlerClient; +import junit.framework.Assert; +import static org.mockito.Mockito.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.Properties; +import org.apache.commons.io.FileUtils; + +public class TestArifactHandlerClient { + + @Test + public void testCreateArtifactData(){ + + try{ + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"00000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": " + + content + + " } "; + String requestID ="0000"; + ArtifactHandlerClient ahi = new ArtifactHandlerClient(); + String value = ahi.createArtifactData(payload, requestID); + Assert.assertTrue(!value.isEmpty()); + }catch(Exception e) + { + } + } + + @Test + public void testExecute(){ + + try{ + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"00000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": " + + content + + " } "; + String rpc = "Post"; + ArtifactHandlerClient ahi = new ArtifactHandlerClient(); + ahi.execute(payload, rpc); + }catch(Exception e) + { + } + } +} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDBService.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDBService.java new file mode 100644 index 000000000..ffc2cadce --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDBService.java @@ -0,0 +1,242 @@ +/*- + * ============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.design.validator; + +import java.io.File; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Properties; +import org.apache.commons.io.FileUtils; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.appc.design.dbervices.DbService; +import org.onap.appc.design.dbervices.DesignDBService; +import org.onap.appc.design.propertyServices.PropertyUpdateService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import junit.framework.Assert; +import org.powermock.reflect.Whitebox; + +public class TestDBService { + + private final org.slf4j.Logger logger = LoggerFactory.getLogger(TestDBService.class); + + @Ignore("Test is taking 60 seconds") + @Test + public void testGetDesigns() { + try { + String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\" }"; + DesignDBService dbservice = DesignDBService.initialise(); + dbservice.execute("getDesigns", payload, "1234"); + } catch (Exception e) { + } + } + + @Ignore("Test is taking 120 seconds") + @Test + public void testGetStatus() { + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": "+ content + " } "; + DesignDBService dbservice = DesignDBService.initialise(); + DbService db = new DbService(); + Whitebox.invokeMethod(db, "getDbLibService"); + dbservice.execute("getStatus", payload, "1234"); + } catch (Exception e) { + } + } + + @Ignore("Test is taking 120 seconds") + @Test + public void testUploadArtifact() { + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": "+ content + " } "; + DesignDBService dbservice = DesignDBService.initialise(); + DbService db = new DbService(); + Whitebox.invokeMethod(db, "getDbLibService"); + dbservice.execute("uploadArtifact", payload, "1234"); + } catch (Exception e) { + } + } + + @Ignore("Test is taking 120 seconds") + @Test + public void testGetArtifact() { + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": "+ content + " } "; + DesignDBService design = DesignDBService.initialise(); + DbService db = new DbService(); + Whitebox.invokeMethod(db, "getDbLibService"); + design.execute("getArtifact", payload, "1234"); + } catch (Exception e) { + } + } + + @Ignore("Test is taking 120 seconds") + @Test + public void testSetIncart() { + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\",\"action-level\":\"VNf\",\"protocol\":\"Test\", \"inCart\":\"Y\",\"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": "+ content + " } "; + DesignDBService design = DesignDBService.initialise(); + DbService db = new DbService(); + Whitebox.invokeMethod(db, "getDbLibService"); + design.execute("setInCart", payload, "1234"); + } catch (Exception e) { + } + } + + @Ignore("Test is taking 120 seconds") + @Test + public void testSetProtocolReference() { + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\",\"action-level\":\"VNf\",\"protocol\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": "+ content + " } "; + DesignDBService design = DesignDBService.initialise(); + DbService db = new DbService(); + Whitebox.invokeMethod(db, "getDbLibService"); + design.execute("setProtocolReference", payload, "1234"); + } catch (Exception e) { + } + } + + @Ignore("Test is taking 120 seconds") + @Test + public void testSetStatus() { + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; + DesignDBService design = DesignDBService.initialise(); + DbService db = new DbService(); + Whitebox.invokeMethod(db, "getDbLibService"); + design.execute("setStatus", payload, "1234"); + } catch (Exception e) { + } + } + + @Ignore("Test is taking 120 seconds") + @Test + public void testGetArtifactReference() { + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; + DesignDBService design = DesignDBService.initialise(); + DbService db = new DbService(); + Whitebox.invokeMethod(db, "getDbLibService"); + design.execute("getArtifactReference", payload, "1234"); + } catch (Exception e) { + } + } + + @Ignore("Test is taking 120 seconds") + @Test + public void testGetGuiReference() { + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; + DesignDBService design = DesignDBService.initialise(); + DbService db = new DbService(); + Whitebox.invokeMethod(db, "getDbLibService"); + design.execute("getGuiReference", payload, "1234"); + } catch (Exception e) { + } + } + + @Test + public void testPropertyUpdateService() { + PropertyUpdateService ps = new PropertyUpdateService(); + } + + @Test + public void testLinkstatusRelationShip() { + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; + DesignDBService design = DesignDBService.initialise(); + Whitebox.invokeMethod(design, "linkstatusRelationShip", 1, 1, payload); + } catch (Exception e) { + } + } + + @Test + public void testGetSDCReferenceID() { + + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; + DesignDBService design = DesignDBService.initialise(); + Whitebox.invokeMethod(design, "getSDCReferenceID", payload); + } catch (Exception e) { + } + } + + @Test + public void testGetDataFromActionStatus() { + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; + DesignDBService design = DesignDBService.initialise(); + Whitebox.invokeMethod(design, "getDataFromActionStatus", payload, "Test"); + } catch (Exception e) { + } + } + + @Test + public void testSetActionStatus() { + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; + DesignDBService design = DesignDBService.initialise(); + Whitebox.invokeMethod(design, "setActionStatus", payload, "Accepted"); + } catch (Exception e) { + } + } + + @Test + public void testGetSDCArtifactIDbyRequestID() { + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; + DesignDBService design = DesignDBService.initialise(); + Whitebox.invokeMethod(design, "getSDCArtifactIDbyRequestID", "0"); + } catch (Exception e) { + } + } + + @Test + public void testCreateArtifactTrackingRecord() { + try { + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; + DesignDBService design = DesignDBService.initialise(); + Whitebox.invokeMethod(design, "createArtifactTrackingRecord",payload,"0",1,1); + } catch (Exception e) { + } + } +} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDbResponse.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDbResponse.java new file mode 100644 index 000000000..73e3dfc99 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDbResponse.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.design.validator; + +import java.util.ArrayList; +import org.junit.Test; +import org.onap.appc.design.dbervices.DbResponseProcessor; + +public class TestDbResponse { + + @Test + public void testDbResponse() { + DbResponseProcessor dbResponse = new DbResponseProcessor(); + try { + dbResponse.parseResponse("Test", "getDesigns"); + dbResponse.parseResponse("Test", "addInCart"); + dbResponse.parseResponse("Test", "getArtifactReference"); + dbResponse.parseResponse("Test", "getArtifact"); + dbResponse.parseResponse("Test", "getGUIReference"); + dbResponse.parseResponse("Test", "getStatus"); + dbResponse.parseResponse("Test", "uploadArtifact"); + dbResponse.parseResponse("Test", "setProtocolReference"); + dbResponse.parseResponse("Test", "setInCart"); + dbResponse.parseResponse("Test", "getStatus"); + dbResponse.parseResponse("Test", "Test"); + } catch (Exception e) { + } + } +} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesigndata.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesigndata.java new file mode 100644 index 000000000..f5c4bfffd --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesigndata.java @@ -0,0 +1,102 @@ +/*- + * ============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.design.validator; + +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; +import org.onap.appc.design.data.ArtifactInfo; +import org.onap.appc.design.data.DesignInfo; +import org.onap.appc.design.data.DesignRequest; +import org.onap.appc.design.data.DesignResponse; +import org.onap.appc.design.data.StatusInfo; + +public class TestDesigndata { + + DesignResponse dr = new DesignResponse(); + + @Test + public void testSetUserID() { + dr.setUserId("00000"); + dr.getUserId(); + } + + @Test + public void testSetDesignInfoList() { + DesignInfo di = new DesignInfo(); + List li = new ArrayList(); + di.setAction("TestAction"); + di.setArtifact_name("TestName"); + di.setArtifact_type("TestType"); + di.setInCart("TestCart"); + di.setProtocol("TestProtocol"); + di.setVnf_type("TestVNF"); + di.setVnfc_type("TestVNFC"); + li.add(di); + dr.setDesignInfoList(li); + } + + @Test + public void testSetArtifactInfo() { + ArtifactInfo ai = new ArtifactInfo(); + List li = new ArrayList(); + ai.setArtifact_content("TestContent"); + li.add(ai); + dr.setArtifactInfo(li); + } + + @Test + public void testStatusInfo() { + StatusInfo si = new StatusInfo(); + List li = new ArrayList(); + si.setAction("TestAction"); + si.setAction_status("TestActionStatus"); + si.setArtifact_status("TestArtifactStatus"); + si.setVnf_type("TestVNF"); + si.setVnfc_type("TestVNFC"); + li.add(si); + dr.setStatusInfoList(li); + } + + @Test + public void testDesignRequest() { + DesignRequest dreq = new DesignRequest(); + dreq.setAction("TestAction"); + dreq.setArtifact_contents("TestContent"); + dreq.setArtifact_name("TestName"); + dreq.setProtocol("TestProtocol"); + dreq.setUserId("0000"); + dreq.setVnf_type("testvnf"); + dreq.setVnfc_type("testvnfc"); + dreq.getAction(); + dreq.getArtifact_contents(); + dreq.getArtifact_name(); + dreq.getProtocol(); + dreq.getUserId(); + dreq.getVnf_type(); + dreq.getVnfc_type(); + dreq.toString(); + } +} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestEscapeUtils.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestEscapeUtils.java new file mode 100644 index 000000000..4a99d42e9 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestEscapeUtils.java @@ -0,0 +1,52 @@ +/*- + * ============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.design.validator; + +import java.io.IOException; +import org.junit.Test; +import org.onap.appc.design.services.util.EscapeUtils; +import org.onap.appc.design.xinterface.XInterfaceService; +import org.onap.appc.design.xinterface.XResponseProcessor; +import junit.framework.Assert; + +public class TestEscapeUtils { + + @Test + public void testEscapeUtils() { + + EscapeUtils escapeUtils = new EscapeUtils(); + String str = escapeUtils.escapeSql("\\'Test Data\\'"); + assert (true); + } + + @Test + public void testXResponseProcessor(){ + + XResponseProcessor xr = new XResponseProcessor(); + Object o = new Object(); + xr.parseResponse(o, "Test"); + Assert.assertEquals(null, null); + } +} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestValidatorService.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestValidatorService.java new file mode 100644 index 000000000..622483c66 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestValidatorService.java @@ -0,0 +1,131 @@ +/*- + * ============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.design.validator; + +import java.io.InputStream; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Properties; +import org.junit.Before; +import org.junit.Test; +import org.onap.appc.design.services.util.DesignServiceConstants; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import junit.framework.Assert; + +public class TestValidatorService { + +//Onap Migration + + private final Logger logger = LoggerFactory.getLogger(TestValidatorService.class); + @Test + public void testValidXMLValidation(){ + String response = null; + String xmlString = "" + "create" + "" + "" + + "SDN-GP" + "" + "" + "" + ""; + + ValidatorService vs = new ValidatorService(); + try { + response = vs.execute("", xmlString, "XML"); + } catch (Exception e) { + } + Assert.assertEquals("success", response); + + } + @Test + public void testInvalidXMLValidation() { + String response = null; + String xmlString = "" + "create" + "" + "" + + "SDN-GP" + "" + "" + ""; + + ValidatorService vs = new ValidatorService(); + try { + response = vs.execute("", xmlString, "XML"); + } catch (Exception e) { + } + Assert.assertEquals(null, response); + } + @Test + public void testYAMLValidation() { + String response = null; + String YAMLString = "en:"; + ValidatorService vs = new ValidatorService(); + try { + response = vs.execute("", YAMLString, "YAML"); + } catch (Exception e) { + } + Assert.assertEquals("success", response); + } + @Test + public void testInvalidYAMLValidation() { + String response = null; + String YAMLString = "Test \n A:"; + ValidatorService vs = new ValidatorService(); + try { + response = vs.execute("", YAMLString, "YAML"); + } catch (Exception e) { + } + + Assert.assertEquals(null, response); + } + + @Test + public void testJSONValidation(){ + String response = null; + String YAMLString = "{\"Test\": \"Test1\" }"; + + ValidatorService vs = new ValidatorService(); + try { + response = vs.execute("", YAMLString, "JSON"); + } catch (Exception e) { + } + Assert.assertEquals("success", response); + } + @Test + public void testInvalidJSONValidation(){ + String response = null; + String YAMLString = "{\"Test\" \"Test1\" }"; + ValidatorService vs = new ValidatorService(); + try { + response = vs.execute("", YAMLString, "JSON"); + } catch (Exception e) { + } + Assert.assertEquals(null, response); + } + + @Test + public void testInvalidvalidateVelocity(){ + String response = null; + String validateVelocity = "{\"Test\" \"Test1\" }"; + ValidatorService vs = new ValidatorService(); + try { + response = vs.execute("", validateVelocity, "Velocity"); + } catch (Exception e) { + } + Assert.assertEquals(null, response); + + } +} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestArifactHandlerClient.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestArifactHandlerClient.java deleted file mode 100644 index 9f6622e36..000000000 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestArifactHandlerClient.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.design.validator; - -import org.junit.Before; -import org.junit.Test; -import org.onap.appc.design.services.util.ArtifactHandlerClient; -import junit.framework.Assert; -import static org.mockito.Mockito.*; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Enumeration; -import java.util.Properties; -import org.apache.commons.io.FileUtils; - -public class TestArifactHandlerClient { - - @Test - public void testCreateArtifactData(){ - - try{ - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"00000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": " - + content + - " } "; - String requestID ="0000"; - ArtifactHandlerClient ahi = new ArtifactHandlerClient(); - String value = ahi.createArtifactData(payload, requestID); - Assert.assertTrue(!value.isEmpty()); - }catch(Exception e) - { - } - } - - @Test - public void testExecute(){ - - try{ - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"00000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": " - + content + - " } "; - String rpc = "Post"; - ArtifactHandlerClient ahi = new ArtifactHandlerClient(); - ahi.execute(payload, rpc); - }catch(Exception e) - { - } - } -} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDBService.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDBService.java deleted file mode 100644 index ffc2cadce..000000000 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDBService.java +++ /dev/null @@ -1,242 +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.design.validator; - -import java.io.File; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Properties; -import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.onap.appc.design.dbervices.DbService; -import org.onap.appc.design.dbervices.DesignDBService; -import org.onap.appc.design.propertyServices.PropertyUpdateService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import junit.framework.Assert; -import org.powermock.reflect.Whitebox; - -public class TestDBService { - - private final org.slf4j.Logger logger = LoggerFactory.getLogger(TestDBService.class); - - @Ignore("Test is taking 60 seconds") - @Test - public void testGetDesigns() { - try { - String payload = "{\"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\" }"; - DesignDBService dbservice = DesignDBService.initialise(); - dbservice.execute("getDesigns", payload, "1234"); - } catch (Exception e) { - } - } - - @Ignore("Test is taking 120 seconds") - @Test - public void testGetStatus() { - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": "+ content + " } "; - DesignDBService dbservice = DesignDBService.initialise(); - DbService db = new DbService(); - Whitebox.invokeMethod(db, "getDbLibService"); - dbservice.execute("getStatus", payload, "1234"); - } catch (Exception e) { - } - } - - @Ignore("Test is taking 120 seconds") - @Test - public void testUploadArtifact() { - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": "+ content + " } "; - DesignDBService dbservice = DesignDBService.initialise(); - DbService db = new DbService(); - Whitebox.invokeMethod(db, "getDbLibService"); - dbservice.execute("uploadArtifact", payload, "1234"); - } catch (Exception e) { - } - } - - @Ignore("Test is taking 120 seconds") - @Test - public void testGetArtifact() { - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": "+ content + " } "; - DesignDBService design = DesignDBService.initialise(); - DbService db = new DbService(); - Whitebox.invokeMethod(db, "getDbLibService"); - design.execute("getArtifact", payload, "1234"); - } catch (Exception e) { - } - } - - @Ignore("Test is taking 120 seconds") - @Test - public void testSetIncart() { - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\",\"action-level\":\"VNf\",\"protocol\":\"Test\", \"inCart\":\"Y\",\"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": "+ content + " } "; - DesignDBService design = DesignDBService.initialise(); - DbService db = new DbService(); - Whitebox.invokeMethod(db, "getDbLibService"); - design.execute("setInCart", payload, "1234"); - } catch (Exception e) { - } - } - - @Ignore("Test is taking 120 seconds") - @Test - public void testSetProtocolReference() { - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\",\"action-level\":\"VNf\",\"protocol\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": "+ content + " } "; - DesignDBService design = DesignDBService.initialise(); - DbService db = new DbService(); - Whitebox.invokeMethod(db, "getDbLibService"); - design.execute("setProtocolReference", payload, "1234"); - } catch (Exception e) { - } - } - - @Ignore("Test is taking 120 seconds") - @Test - public void testSetStatus() { - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; - DesignDBService design = DesignDBService.initialise(); - DbService db = new DbService(); - Whitebox.invokeMethod(db, "getDbLibService"); - design.execute("setStatus", payload, "1234"); - } catch (Exception e) { - } - } - - @Ignore("Test is taking 120 seconds") - @Test - public void testGetArtifactReference() { - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; - DesignDBService design = DesignDBService.initialise(); - DbService db = new DbService(); - Whitebox.invokeMethod(db, "getDbLibService"); - design.execute("getArtifactReference", payload, "1234"); - } catch (Exception e) { - } - } - - @Ignore("Test is taking 120 seconds") - @Test - public void testGetGuiReference() { - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; - DesignDBService design = DesignDBService.initialise(); - DbService db = new DbService(); - Whitebox.invokeMethod(db, "getDbLibService"); - design.execute("getGuiReference", payload, "1234"); - } catch (Exception e) { - } - } - - @Test - public void testPropertyUpdateService() { - PropertyUpdateService ps = new PropertyUpdateService(); - } - - @Test - public void testLinkstatusRelationShip() { - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; - DesignDBService design = DesignDBService.initialise(); - Whitebox.invokeMethod(design, "linkstatusRelationShip", 1, 1, payload); - } catch (Exception e) { - } - } - - @Test - public void testGetSDCReferenceID() { - - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; - DesignDBService design = DesignDBService.initialise(); - Whitebox.invokeMethod(design, "getSDCReferenceID", payload); - } catch (Exception e) { - } - } - - @Test - public void testGetDataFromActionStatus() { - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; - DesignDBService design = DesignDBService.initialise(); - Whitebox.invokeMethod(design, "getDataFromActionStatus", payload, "Test"); - } catch (Exception e) { - } - } - - @Test - public void testSetActionStatus() { - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; - DesignDBService design = DesignDBService.initialise(); - Whitebox.invokeMethod(design, "setActionStatus", payload, "Accepted"); - } catch (Exception e) { - } - } - - @Test - public void testGetSDCArtifactIDbyRequestID() { - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; - DesignDBService design = DesignDBService.initialise(); - Whitebox.invokeMethod(design, "getSDCArtifactIDbyRequestID", "0"); - } catch (Exception e) { - } - } - - @Test - public void testCreateArtifactTrackingRecord() { - try { - String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); - String payload = " { \"userID\": \"0000\",\"status\":\"Test\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-status\":\"\",\"artifact-contents\": "+ content + " } "; - DesignDBService design = DesignDBService.initialise(); - Whitebox.invokeMethod(design, "createArtifactTrackingRecord",payload,"0",1,1); - } catch (Exception e) { - } - } -} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDbResponse.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDbResponse.java deleted file mode 100644 index 73e3dfc99..000000000 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDbResponse.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.design.validator; - -import java.util.ArrayList; -import org.junit.Test; -import org.onap.appc.design.dbervices.DbResponseProcessor; - -public class TestDbResponse { - - @Test - public void testDbResponse() { - DbResponseProcessor dbResponse = new DbResponseProcessor(); - try { - dbResponse.parseResponse("Test", "getDesigns"); - dbResponse.parseResponse("Test", "addInCart"); - dbResponse.parseResponse("Test", "getArtifactReference"); - dbResponse.parseResponse("Test", "getArtifact"); - dbResponse.parseResponse("Test", "getGUIReference"); - dbResponse.parseResponse("Test", "getStatus"); - dbResponse.parseResponse("Test", "uploadArtifact"); - dbResponse.parseResponse("Test", "setProtocolReference"); - dbResponse.parseResponse("Test", "setInCart"); - dbResponse.parseResponse("Test", "getStatus"); - dbResponse.parseResponse("Test", "Test"); - } catch (Exception e) { - } - } -} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDesigndata.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDesigndata.java deleted file mode 100644 index f5c4bfffd..000000000 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDesigndata.java +++ /dev/null @@ -1,102 +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.design.validator; - -import java.util.ArrayList; -import java.util.List; -import org.junit.Test; -import org.onap.appc.design.data.ArtifactInfo; -import org.onap.appc.design.data.DesignInfo; -import org.onap.appc.design.data.DesignRequest; -import org.onap.appc.design.data.DesignResponse; -import org.onap.appc.design.data.StatusInfo; - -public class TestDesigndata { - - DesignResponse dr = new DesignResponse(); - - @Test - public void testSetUserID() { - dr.setUserId("00000"); - dr.getUserId(); - } - - @Test - public void testSetDesignInfoList() { - DesignInfo di = new DesignInfo(); - List li = new ArrayList(); - di.setAction("TestAction"); - di.setArtifact_name("TestName"); - di.setArtifact_type("TestType"); - di.setInCart("TestCart"); - di.setProtocol("TestProtocol"); - di.setVnf_type("TestVNF"); - di.setVnfc_type("TestVNFC"); - li.add(di); - dr.setDesignInfoList(li); - } - - @Test - public void testSetArtifactInfo() { - ArtifactInfo ai = new ArtifactInfo(); - List li = new ArrayList(); - ai.setArtifact_content("TestContent"); - li.add(ai); - dr.setArtifactInfo(li); - } - - @Test - public void testStatusInfo() { - StatusInfo si = new StatusInfo(); - List li = new ArrayList(); - si.setAction("TestAction"); - si.setAction_status("TestActionStatus"); - si.setArtifact_status("TestArtifactStatus"); - si.setVnf_type("TestVNF"); - si.setVnfc_type("TestVNFC"); - li.add(si); - dr.setStatusInfoList(li); - } - - @Test - public void testDesignRequest() { - DesignRequest dreq = new DesignRequest(); - dreq.setAction("TestAction"); - dreq.setArtifact_contents("TestContent"); - dreq.setArtifact_name("TestName"); - dreq.setProtocol("TestProtocol"); - dreq.setUserId("0000"); - dreq.setVnf_type("testvnf"); - dreq.setVnfc_type("testvnfc"); - dreq.getAction(); - dreq.getArtifact_contents(); - dreq.getArtifact_name(); - dreq.getProtocol(); - dreq.getUserId(); - dreq.getVnf_type(); - dreq.getVnfc_type(); - dreq.toString(); - } -} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestEscapeUtils.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestEscapeUtils.java deleted file mode 100644 index 4a99d42e9..000000000 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestEscapeUtils.java +++ /dev/null @@ -1,52 +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.design.validator; - -import java.io.IOException; -import org.junit.Test; -import org.onap.appc.design.services.util.EscapeUtils; -import org.onap.appc.design.xinterface.XInterfaceService; -import org.onap.appc.design.xinterface.XResponseProcessor; -import junit.framework.Assert; - -public class TestEscapeUtils { - - @Test - public void testEscapeUtils() { - - EscapeUtils escapeUtils = new EscapeUtils(); - String str = escapeUtils.escapeSql("\\'Test Data\\'"); - assert (true); - } - - @Test - public void testXResponseProcessor(){ - - XResponseProcessor xr = new XResponseProcessor(); - Object o = new Object(); - xr.parseResponse(o, "Test"); - Assert.assertEquals(null, null); - } -} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestValidatorService.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestValidatorService.java deleted file mode 100644 index 622483c66..000000000 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestValidatorService.java +++ /dev/null @@ -1,131 +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.design.validator; - -import java.io.InputStream; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Properties; -import org.junit.Before; -import org.junit.Test; -import org.onap.appc.design.services.util.DesignServiceConstants; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import junit.framework.Assert; - -public class TestValidatorService { - -//Onap Migration - - private final Logger logger = LoggerFactory.getLogger(TestValidatorService.class); - @Test - public void testValidXMLValidation(){ - String response = null; - String xmlString = "" + "create" + "" + "" - + "SDN-GP" + "" + "" + "" + ""; - - ValidatorService vs = new ValidatorService(); - try { - response = vs.execute("", xmlString, "XML"); - } catch (Exception e) { - } - Assert.assertEquals("success", response); - - } - @Test - public void testInvalidXMLValidation() { - String response = null; - String xmlString = "" + "create" + "" + "" - + "SDN-GP" + "" + "" + ""; - - ValidatorService vs = new ValidatorService(); - try { - response = vs.execute("", xmlString, "XML"); - } catch (Exception e) { - } - Assert.assertEquals(null, response); - } - @Test - public void testYAMLValidation() { - String response = null; - String YAMLString = "en:"; - ValidatorService vs = new ValidatorService(); - try { - response = vs.execute("", YAMLString, "YAML"); - } catch (Exception e) { - } - Assert.assertEquals("success", response); - } - @Test - public void testInvalidYAMLValidation() { - String response = null; - String YAMLString = "Test \n A:"; - ValidatorService vs = new ValidatorService(); - try { - response = vs.execute("", YAMLString, "YAML"); - } catch (Exception e) { - } - - Assert.assertEquals(null, response); - } - - @Test - public void testJSONValidation(){ - String response = null; - String YAMLString = "{\"Test\": \"Test1\" }"; - - ValidatorService vs = new ValidatorService(); - try { - response = vs.execute("", YAMLString, "JSON"); - } catch (Exception e) { - } - Assert.assertEquals("success", response); - } - @Test - public void testInvalidJSONValidation(){ - String response = null; - String YAMLString = "{\"Test\" \"Test1\" }"; - ValidatorService vs = new ValidatorService(); - try { - response = vs.execute("", YAMLString, "JSON"); - } catch (Exception e) { - } - Assert.assertEquals(null, response); - } - - @Test - public void testInvalidvalidateVelocity(){ - String response = null; - String validateVelocity = "{\"Test\" \"Test1\" }"; - ValidatorService vs = new ValidatorService(); - try { - response = vs.execute("", validateVelocity, "Velocity"); - } catch (Exception e) { - } - Assert.assertEquals(null, response); - - } -} -- cgit 1.2.3-korg