summaryrefslogtreecommitdiffstats
path: root/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap')
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/ArtifactHandlerProvider.java213
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/SdcArtifactHandlerActivator.java58
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java531
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java533
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java191
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/EscapeUtils.java43
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java93
7 files changed, 1662 insertions, 0 deletions
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<DataChangeListener> dclServices;
+
+ protected BindingAwareBroker.RpcRegistration<ArtifactHandlerService> 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<Void, TransactionCommitFailedException> 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<InstanceIdentifier<?>, 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<UploadartifactOutput> 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<UploadartifactOutput> rpcResult = RpcResultBuilder.<UploadartifactOutput> status(true)
+ .withResult(responseBuilder.build()).build();
+ return rpcResult;
+ }
+
+ @Override
+ public Future<RpcResult<UploadartifactOutput>> uploadartifact(UploadartifactInput input) {
+
+ if (input == null || input.getDocumentParameters() == null || input.getDocumentParameters().getArtifactContents() == null ) {
+ RpcResult<UploadartifactOutput> 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<UploadartifactOutput> rpcResult = RpcResultBuilder.<UploadartifactOutput> 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<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>();
+
+ @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<String, String> modelData = new HashMap<String, String>();
+ 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<String, String> 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<String, String> processdata = new HashMap<String, String>();
+ 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";
+}
+