summaryrefslogtreecommitdiffstats
path: root/appc-asdc-listener
diff options
context:
space:
mode:
authorMasal, Sushil (sm588m) <sushil.masal@amdocs.com>2017-08-13 19:10:02 +0530
committerPatrick Brady <pb071s@att.com>2017-08-16 18:10:03 +0000
commit0500d5dbb363e74983d758288f1ac53ae763683d (patch)
tree54b33039f8b7cb107e6d9d6ce861ab55baa3c05e /appc-asdc-listener
parent833fe6d45ceb8c0f4534972d6422ce568598da89 (diff)
Create and store Dependency model from Tosca
Updated asdc listerner bundle to create dependency model from tosca artifact reveived from SDC.This dependency model will be in JSON format and will be stored to ASDC_ARTIFACT table as new artifact. Also ASDC_REFERENCE table will be updated to with new artifact details. This commit also include bug fix for MDSALStore to handle all http code for successful rest calls Issue ID: APPC-32 Change-Id: Iaef6cdee67475917968a4bcdec131cd1bc4c4f41 Signed-off-by: Masal, Sushil (sm588m) <sushil.masal@amdocs.com>
Diffstat (limited to 'appc-asdc-listener')
-rw-r--r--appc-asdc-listener/appc-asdc-listener-bundle/pom.xml61
-rw-r--r--appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/helper/ArtifactStorageService.java250
-rw-r--r--appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/helper/Constants.java72
-rw-r--r--appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/helper/DependencyModelGenerator.java97
-rw-r--r--appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/impl/ToscaCsarArtifactProcessor.java57
-rw-r--r--appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/object/SDCReference.java94
-rw-r--r--appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/object/Vnfc.java78
-rw-r--r--appc-asdc-listener/appc-yang-generator/pom.xml5
8 files changed, 626 insertions, 88 deletions
diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/pom.xml b/appc-asdc-listener/appc-asdc-listener-bundle/pom.xml
index 35b9b3180..316cfdda0 100644
--- a/appc-asdc-listener/appc-asdc-listener-bundle/pom.xml
+++ b/appc-asdc-listener/appc-asdc-listener-bundle/pom.xml
@@ -9,7 +9,8 @@
</parent>
<properties>
- <snakeyaml.version>1.12</snakeyaml.version>
+ <jackson-yaml-version>2.8.1</jackson-yaml-version>
+ <snakeyaml.version>1.15</snakeyaml.version>
</properties>
<artifactId>appc-asdc-listener-bundle</artifactId>
@@ -39,11 +40,11 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4</artifactId>
- <version>1.6.2</version>
- <scope>test</scope>
- </dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.6.2</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
@@ -127,12 +128,6 @@
<artifactId>gson</artifactId>
</dependency>
- <dependency>
- <groupId>org.openecomp.sdc.common</groupId>
- <artifactId>openecomp-tosca-datatype</artifactId>
- <version>${toscalib.version}</version>
- </dependency>
-
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
@@ -155,16 +150,51 @@
<artifactId>ietf-yang-types</artifactId>
<version>${odl.ietf-yang-types.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-dg-dependency-model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
- <version>${jackson.yml.version}</version>
+ <version>${jackson-yaml-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-dg-domain-model-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>${jackson-yaml-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson-yaml-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>${jackson-yaml-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>${snakeyaml.version}</version>
</dependency>
+
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
- </dependencies>
+
+
+
+ </dependencies>
<build>
@@ -201,7 +231,8 @@
<Embed-Dependency>
sdc-distribution-client,snakeyaml,
saClientLibrary,cambriaClient,saToolkit,
- functionaljava,httpcore,httpclient,gson;
+ functionaljava,httpcore,httpclient,gson,appc-dg-dependency-model,appc-dg-domain-model-lib,
+ jackson-core,jackson-databind,jackson-annotations,jackson-dataformat-yaml;
scope=compile|runtime;inline=false
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/helper/ArtifactStorageService.java b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/helper/ArtifactStorageService.java
index 6bae9695a..ed5e16525 100644
--- a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/helper/ArtifactStorageService.java
+++ b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/helper/ArtifactStorageService.java
@@ -27,6 +27,7 @@ package org.openecomp.appc.sdc.artifacts.helper;
import org.openecomp.appc.exceptions.APPCException;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import org.openecomp.appc.sdc.artifacts.object.SDCReference;
import org.openecomp.sdnc.sli.resource.dblib.DbLibService;
import org.openecomp.appc.sdc.artifacts.object.SDCArtifact;
import org.osgi.framework.BundleContext;
@@ -37,8 +38,8 @@ import javax.sql.rowset.CachedRowSet;
import java.sql.SQLException;
import java.util.ArrayList;
-import static org.openecomp.appc.licmgr.Constants.ASDC_ARTIFACTS;
-import static org.openecomp.appc.licmgr.Constants.ASDC_ARTIFACTS_FIELDS.*;
+import static org.openecomp.appc.sdc.artifacts.helper.Constants.COMMA;
+import static org.openecomp.appc.sdc.artifacts.helper.Constants.AND;
/**
* Provides methods for storing sdc artifacts into app-c database
@@ -47,40 +48,71 @@ public class ArtifactStorageService {
private DbLibService dbLibService;
- private static final String COMMA = " , ";
- private static final String QUERY_PLACEHOLDER = " = ? ";
-
private static final String SCHEMA = "sdnctl";
- private static final String SELECT_QUERY = "SELECT * FROM " + ASDC_ARTIFACTS +
- " WHERE " + RESOURCE_NAME + QUERY_PLACEHOLDER +
- " AND " + RESOURCE_VERSION + QUERY_PLACEHOLDER +
- " AND " + ARTIFACT_TYPE + QUERY_PLACEHOLDER;
-
- private static final String INSERT_QUERY = "INSERT INTO " + ASDC_ARTIFACTS +
- " ( " + SERVICE_UUID + COMMA +
- DISTRIBUTION_ID + COMMA +
- SERVICE_NAME + COMMA +
- SERVICE_DESCRIPTION + COMMA +
- RESOURCE_UUID + COMMA +
- RESOURCE_INSTANCE_NAME + COMMA +
- RESOURCE_NAME + COMMA +
- RESOURCE_VERSION + COMMA +
- RESOURCE_TYPE + COMMA +
- ARTIFACT_UUID + COMMA +
- ARTIFACT_TYPE + COMMA +
- ARTIFACT_VERSION + COMMA +
- ARTIFACT_DESCRIPTION + COMMA +
- CREATION_DATE + COMMA +
- ARTIFACT_NAME +COMMA +
- ARTIFACT_CONTENT + " ) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+ private static final String SELECT_QUERY = Constants.SELECT_FROM + Constants.ASDC_ARTIFACTS +
+ Constants.WHERE + Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_NAME + Constants.QUERY_PLACEHOLDER +
+ AND + Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_VERSION + Constants.QUERY_PLACEHOLDER +
+ AND + Constants.ARTIFACT_TYPE + Constants.QUERY_PLACEHOLDER;
+
+ private static final String SELECT_QUERY_SDC_REFERENCE = Constants.SELECT_FROM + Constants.ASDC_REFERENCE +
+ Constants.WHERE + Constants.ASDC_REFERENCE_FIELDS.VNF_TYPE + Constants.QUERY_PLACEHOLDER +
+ AND + Constants.ASDC_REFERENCE_FIELDS.FILE_CATEGORY + Constants.QUERY_PLACEHOLDER ;
+
+ private static final String INSERT_QUERY = Constants.INSERT + Constants.ASDC_ARTIFACTS +
+ " ( " + Constants.ASDC_ARTIFACTS_FIELDS.SERVICE_UUID + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.DISTRIBUTION_ID + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.SERVICE_NAME + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.SERVICE_DESCRIPTION + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_UUID + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_INSTANCE_NAME + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_NAME + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_VERSION + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_TYPE + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.ARTIFACT_UUID + COMMA +
+ Constants.ARTIFACT_TYPE + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.ARTIFACT_VERSION + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.ARTIFACT_DESCRIPTION + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.CREATION_DATE + COMMA +
+ Constants.ARTIFACT_NAME +COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.ARTIFACT_CONTENT + " ) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+
+ private static final String INSERT_QUERY_WITH_INT_VER = Constants.INSERT + Constants.ASDC_ARTIFACTS +
+ " ( " + Constants.ASDC_ARTIFACTS_FIELDS.SERVICE_UUID + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.DISTRIBUTION_ID + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.SERVICE_NAME + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.SERVICE_DESCRIPTION + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_UUID + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_INSTANCE_NAME + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_NAME + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_VERSION + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_TYPE + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.ARTIFACT_UUID + COMMA +
+ Constants.ARTIFACT_TYPE + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.ARTIFACT_VERSION + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.ARTIFACT_DESCRIPTION + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.CREATION_DATE + COMMA +
+ Constants.ARTIFACT_NAME + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.ARTIFACT_CONTENT + COMMA +
+ Constants.ASDC_ARTIFACTS_FIELDS.INTERNAL_VERSION + " ) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+
+ private static final String ASDC_REF_INSERT_QUERY = Constants.INSERT + Constants.ASDC_REFERENCE +
+ "( "+ Constants.ASDC_REFERENCE_FIELDS.VNF_TYPE + COMMA +
+ Constants.ASDC_REFERENCE_FIELDS.VNFC_TYPE+ COMMA +
+ Constants.ASDC_REFERENCE_FIELDS.FILE_CATEGORY +COMMA +
+ Constants.ASDC_REFERENCE_FIELDS.ACTION +COMMA +
+ Constants.ARTIFACT_TYPE + COMMA +
+ Constants.ARTIFACT_NAME + " ) values (?,?,?,?,?,?)";
+
+ private static final String SELECT_MAX_INT_VERSION = "SELECT coalesce(max(" + Constants.ASDC_ARTIFACTS_FIELDS.INTERNAL_VERSION + ")+1,1) as " + Constants.ASDC_ARTIFACTS_FIELDS.INTERNAL_VERSION +
+ " FROM " + Constants.ASDC_ARTIFACTS + Constants.WHERE + Constants.ARTIFACT_NAME + Constants.QUERY_PLACEHOLDER;
private final EELFLogger logger = EELFManager.getInstance().getLogger(ArtifactStorageService.class);
/**
* Stores Artifact received from SDC into APP-C database
- * @param artifact
+ * @param artifact - SDC Artifact object
* @throws APPCException
*/
public void storeASDCArtifact(SDCArtifact artifact) throws APPCException {
@@ -100,6 +132,71 @@ public class ArtifactStorageService {
}
}
+ /**
+ * Stores Artifact received from SDC and its Reference into APP-C database if it does not exist
+ * @param artifact - SDC Artifact object
+ * @param reference - SDC reference object
+ * @throws APPCException
+ */
+ public void storeASDCArtifactWithReference(SDCArtifact artifact , SDCReference reference) throws APPCException {
+ if(logger.isDebugEnabled()){
+ logger.debug("Entering storeASDCArtifactWithReference with : " + artifact.toString());
+ }
+ try {
+ initializeDBLibService();
+ SDCArtifact existingArtifact = retrieveSDCArtifact(artifact.getResourceName(), artifact.getResourceVersion(),artifact.getArtifactType());
+ if (existingArtifact ==null) { // new resource
+ logger.debug(String.format("Artifact not found for vnfType = %s, version = %s and artifactType = %s. Inserting data." ,
+ artifact.getResourceName(),artifact.getResourceVersion() ,artifact.getArtifactType()));
+ ArrayList<String> arguments = prepareArguments(artifact);
+ Integer version = getNextInternalVersion(artifact.getArtifactName());
+ arguments.add(version.toString());
+ dbLibService.writeData(INSERT_QUERY_WITH_INT_VER,arguments,SCHEMA);
+ } else { // duplicate
+ logger.debug(String.format("Artifact of type '%s' already deployed for resource_type='%s' and resource_version='%s'",
+ artifact.getArtifactType() , artifact.getResourceName() , artifact.getResourceVersion()));
+ }
+
+ SDCReference existingReference = retrieveSDCReference(reference.getVnfType(),reference.getFileCategory());
+ if(existingReference == null){
+ logger.debug("Inserting SDC Reference data: " +reference.toString());
+ ArrayList<String> arguments = prepareReferenceArguments(reference);
+ dbLibService.writeData(ASDC_REF_INSERT_QUERY,arguments,SCHEMA);
+ }else{
+ logger.debug("Artifact reference already exists for: " +reference.toString());
+ }
+ } catch (SQLException e) {
+ logger.error("Error storing artifact to database: " + artifact.toString(),e);
+ throw new APPCException(e.getMessage(),e);
+ }
+ if(logger.isDebugEnabled()){
+ logger.debug("Exiting storeASDCArtifactWithReference");
+ }
+ }
+
+ private Integer getNextInternalVersion(String artifactName) throws APPCException {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Entering getNextInternalVersion with artifactName:" + artifactName);
+ }
+ Integer version = 1;
+ try {
+ initializeDBLibService();
+ ArrayList<String> arguments = new ArrayList<>();
+ arguments.add(artifactName);
+ CachedRowSet rowSet = dbLibService.getData(SELECT_MAX_INT_VERSION, arguments, SCHEMA);
+ if (rowSet.first()) {
+ version = rowSet.getInt(Constants.ASDC_ARTIFACTS_FIELDS.INTERNAL_VERSION .toString());
+ }
+ }catch (SQLException e) {
+ logger.error("Error getting internal version for artifact name " + artifactName , e);
+ throw new APPCException(e);
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("Exiting getNextInternalVersion with retrieved version:" + version.toString());
+ }
+ return version;
+ }
+
private void initializeDBLibService() {
if(dbLibService == null){
BundleContext context = FrameworkUtil.getBundle(DbLibService.class).getBundleContext();
@@ -108,6 +205,17 @@ public class ArtifactStorageService {
}
}
+ private ArrayList<String> prepareReferenceArguments(SDCReference reference) {
+ ArrayList<String> arguments = new ArrayList<>();
+ arguments.add(reference.getVnfType());
+ arguments.add(reference.getVnfcType());
+ arguments.add(reference.getFileCategory());
+ arguments.add(reference.getAction());
+ arguments.add(reference.getArtifactType());
+ arguments.add(reference.getArtifactName());
+ return arguments;
+ }
+
private ArrayList<String> prepareArguments(SDCArtifact artifact) {
ArrayList<String> arguments = new ArrayList<>();
arguments.add(artifact.getServiceUUID());
@@ -130,11 +238,11 @@ public class ArtifactStorageService {
}
/**
- * reads the SDC artifact from APP-C database
- * @param resourceName
- * @param resourceVersion
- * @param artifactType
- * @return
+ * Reads the SDC artifact from APP-C database
+ * @param resourceName - resource Name from ASDC Artifact
+ * @param resourceVersion - resource version from ASDC Artifact
+ * @param artifactType artifact type from ASDC Artifact
+ * @return - ASDC_ARTIFACT record if data exists
* @throws APPCException
*/
public SDCArtifact retrieveSDCArtifact(String resourceName, String resourceVersion, String artifactType) throws APPCException {
@@ -148,33 +256,65 @@ public class ArtifactStorageService {
CachedRowSet rowSet = dbLibService.getData(SELECT_QUERY, arguments, SCHEMA);
if (rowSet.first()) {
artifact = new SDCArtifact();
- artifact.setArtifactUUID(rowSet.getString(ARTIFACT_UUID.toString()));
- artifact.setArtifactName(rowSet.getString(ARTIFACT_NAME.toString()));
- artifact.setArtifactType(rowSet.getString(ARTIFACT_TYPE.toString()));
- artifact.setArtifactVersion(rowSet.getString(ARTIFACT_VERSION.toString()));
- artifact.setArtifactDescription(rowSet.getString(ARTIFACT_DESCRIPTION.toString()));
- artifact.setArtifactContent(rowSet.getString(ARTIFACT_CONTENT.toString()));
-
- artifact.setResourceUUID(rowSet.getString(RESOURCE_UUID.toString()));
- artifact.setResourceName(rowSet.getString(RESOURCE_NAME.toString()));
- artifact.setResourceType(rowSet.getString(RESOURCE_TYPE.toString()));
- artifact.setResourceVersion(rowSet.getString(RESOURCE_VERSION.toString()));
- artifact.setResourceInstanceName(rowSet.getString(RESOURCE_INSTANCE_NAME.toString()));
-
- artifact.setServiceUUID(rowSet.getString(SERVICE_UUID.toString()));
- artifact.setServiceName(rowSet.getString(SERVICE_NAME.toString()));
- artifact.setServiceDescription(rowSet.getString(SERVICE_DESCRIPTION.toString()));
-
- artifact.setCreationDate(rowSet.getString(CREATION_DATE.toString()));
- artifact.setDistributionId(rowSet.getString(DISTRIBUTION_ID.toString()));
+ artifact.setArtifactUUID(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.ARTIFACT_UUID.toString()));
+ artifact.setArtifactName(rowSet.getString(Constants.ARTIFACT_NAME));
+ artifact.setArtifactType(rowSet.getString(Constants.ARTIFACT_TYPE));
+ artifact.setArtifactVersion(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.ARTIFACT_VERSION.toString()));
+ artifact.setArtifactDescription(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.ARTIFACT_DESCRIPTION.toString()));
+ artifact.setArtifactContent(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.ARTIFACT_CONTENT.toString()));
+
+ artifact.setResourceUUID(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_UUID.toString()));
+ artifact.setResourceName(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_NAME.toString()));
+ artifact.setResourceType(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_TYPE.toString()));
+ artifact.setResourceVersion(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_VERSION.toString()));
+ artifact.setResourceInstanceName(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_INSTANCE_NAME.toString()));
+
+ artifact.setServiceUUID(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.SERVICE_UUID.toString()));
+ artifact.setServiceName(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.SERVICE_NAME.toString()));
+ artifact.setServiceDescription(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.SERVICE_DESCRIPTION.toString()));
+
+ artifact.setCreationDate(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.CREATION_DATE.toString()));
+ artifact.setDistributionId(rowSet.getString(Constants.ASDC_ARTIFACTS_FIELDS.DISTRIBUTION_ID.toString()));
}
} catch (SQLException e) {
- logger.error("Error query artifact for " + RESOURCE_NAME + " = " + resourceName +
- RESOURCE_VERSION + " = " + resourceVersion +
- ARTIFACT_TYPE + " = " + artifactType, e);
+ logger.error("Error query artifact for " + Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_NAME + " = " + resourceName +
+ Constants.ASDC_ARTIFACTS_FIELDS.RESOURCE_VERSION + " = " + resourceVersion +
+ Constants.ARTIFACT_TYPE + " = " + artifactType, e);
throw new APPCException(e);
}
return artifact;
}
+
+ /**
+ * Reads the SDC reference from APP-C database
+ * @param vnfType - vnf Type from ASDC reference
+ * @param fileCategory - file category from ASDC reference
+ * @return - ASDC_ARTIFACT record if data exists
+ * @throws APPCException
+ */
+ public SDCReference retrieveSDCReference(String vnfType, String fileCategory) throws APPCException {
+ SDCReference reference = null;
+ try {
+ initializeDBLibService();
+ ArrayList<String> arguments = new ArrayList<>();
+ arguments.add(vnfType);
+ arguments.add(fileCategory);
+ CachedRowSet rowSet = dbLibService.getData(SELECT_QUERY_SDC_REFERENCE, arguments, SCHEMA);
+ if (rowSet.first()) {
+ reference = new SDCReference();
+ reference.setVnfType(rowSet.getString(Constants.ASDC_REFERENCE_FIELDS.VNF_TYPE.toString()));
+ reference.setVnfcType(rowSet.getString(Constants.ASDC_REFERENCE_FIELDS.VNFC_TYPE.toString()));
+ reference.setFileCategory(rowSet.getString(Constants.ASDC_REFERENCE_FIELDS.FILE_CATEGORY.toString()));
+ reference.setAction(rowSet.getString(Constants.ASDC_REFERENCE_FIELDS.ACTION.toString()));
+ reference.setArtifactType(rowSet.getString(Constants.ARTIFACT_TYPE));
+ reference.setArtifactName(rowSet.getString(Constants.ARTIFACT_NAME));
+ }
+ } catch (SQLException e) {
+ logger.error("Error querying ASDC_REFERENCE for " + Constants.ASDC_REFERENCE_FIELDS.VNF_TYPE + " = " + vnfType +
+ Constants.ASDC_REFERENCE_FIELDS.FILE_CATEGORY + " = " + fileCategory , e);
+ throw new APPCException(e);
+ }
+ return reference;
+ }
}
diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/helper/Constants.java b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/helper/Constants.java
new file mode 100644
index 000000000..67f8025d2
--- /dev/null
+++ b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/helper/Constants.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.openecomp.appc.sdc.artifacts.helper;
+
+/**
+ * Constants required in ASDC listener module
+ */
+public class Constants {
+ static final String ASDC_ARTIFACTS = "ASDC_ARTIFACTS";
+ static final String ASDC_REFERENCE = "ASDC_REFERENCE";
+
+ static final String AND = " AND ";
+
+ static final String ARTIFACT_TYPE = "ARTIFACT_TYPE";
+ static final String ARTIFACT_NAME = "ARTIFACT_NAME";
+
+ static final String VF_LICENSE = "VF_LICENSE";
+
+ public enum ASDC_ARTIFACTS_FIELDS {
+ SERVICE_UUID,
+ DISTRIBUTION_ID,
+ SERVICE_NAME,
+ SERVICE_DESCRIPTION,
+ RESOURCE_UUID,
+ RESOURCE_INSTANCE_NAME,
+ RESOURCE_NAME,
+ RESOURCE_VERSION,
+ RESOURCE_TYPE,
+ ARTIFACT_UUID,
+ ARTIFACT_VERSION,
+ ARTIFACT_DESCRIPTION,
+ INTERNAL_VERSION,
+ CREATION_DATE,
+ ARTIFACT_CONTENT
+ }
+
+ public enum ASDC_REFERENCE_FIELDS{
+ ASDC_REFERENCE_ID,
+ VNF_TYPE,
+ VNFC_TYPE,
+ FILE_CATEGORY,
+ ACTION
+ }
+
+ static final String COMMA = " , ";
+ static final String QUERY_PLACEHOLDER = " = ? ";
+ static final String SELECT_FROM = "SELECT * FROM " ;
+ static final String WHERE = " WHERE ";
+ static final String INSERT = "INSERT INTO ";
+}
diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/helper/DependencyModelGenerator.java b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/helper/DependencyModelGenerator.java
new file mode 100644
index 000000000..0f8065a30
--- /dev/null
+++ b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/helper/DependencyModelGenerator.java
@@ -0,0 +1,97 @@
+/*-
+ * ============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.openecomp.appc.sdc.artifacts.helper;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.MapperFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import org.openecomp.appc.dg.dependencymanager.helper.DependencyModelParser;
+import org.openecomp.appc.dg.objects.Node;
+import org.openecomp.appc.dg.objects.VnfcDependencyModel;
+import org.openecomp.appc.domainmodel.Vnfc;
+import org.openecomp.appc.exceptions.APPCException;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Provides method for genrating Dependency JSON from Tosca model
+ */
+public class DependencyModelGenerator {
+
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(DependencyModelGenerator.class);
+
+ /**
+ *
+ * @param tosca - tosca string from SDC
+ * @param vnfType - Vnf Type from tosca
+ * @return - Dependency JSON in String format
+ * @throws APPCException is thrown if error occurs
+ */
+ public String getDependencyModel(String tosca, String vnfType) throws APPCException {
+ logger.debug(String.format("Generating dependency model for vnfType : %s , TOSCA: %s ", vnfType ,tosca));
+ String dependencyJson;
+ DependencyModelParser dependencyModelParser = new DependencyModelParser();
+ VnfcDependencyModel vnfcDependencyModel = dependencyModelParser.generateDependencyModel(tosca, vnfType);
+
+ if (vnfcDependencyModel != null && !vnfcDependencyModel.getDependencies().isEmpty()) {
+ logger.debug(String.format("Dependency Model generated : %s ", vnfcDependencyModel.toString()));
+ List<org.openecomp.appc.sdc.artifacts.object.Vnfc> vnfcs = new ArrayList<>();
+
+ for (Node<Vnfc> node : vnfcDependencyModel.getDependencies()) {
+ org.openecomp.appc.sdc.artifacts.object.Vnfc vnfc = new org.openecomp.appc.sdc.artifacts.object.Vnfc();
+ vnfc.setVnfcType(node.getChild().getVnfcType());
+ vnfc.setMandatory(node.getChild().isMandatory());
+ vnfc.setResilienceType(node.getChild().getResilienceType());
+ if (node.getParents() != null && !node.getParents().isEmpty()) {
+ List<String> parents = new ArrayList<>();
+ for (Vnfc parentNode : node.getParents()) {
+ parents.add(parentNode.getVnfcType());
+ }
+ vnfc.setParents(parents);
+ }
+ vnfcs.add(vnfc);
+ }
+ ObjectMapper objectMapper = new ObjectMapper();
+
+ ObjectWriter writer = objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL).configure
+ (MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true).writer().withRootName("vnfcs");
+ try {
+ dependencyJson = writer.writeValueAsString(vnfcs);
+ } catch (JsonProcessingException e) {
+ logger.error("Error converting dependency model to JSON");
+ throw new APPCException("Error converting dependency model to JSON",e);
+ }
+ } else {
+ logger.error("Error generating dependency model from tosca. Empty dependency model");
+ throw new APPCException("Error generating dependency model from tosca. Empty dependency model");
+ }
+ return dependencyJson;
+ }
+}
diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/impl/ToscaCsarArtifactProcessor.java b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/impl/ToscaCsarArtifactProcessor.java
index 5379d463e..085902187 100644
--- a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/impl/ToscaCsarArtifactProcessor.java
+++ b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/impl/ToscaCsarArtifactProcessor.java
@@ -33,8 +33,10 @@ import org.apache.commons.lang.StringUtils;
import org.openecomp.appc.adapter.message.EventSender;
import org.openecomp.appc.exceptions.APPCException;
import org.openecomp.appc.licmgr.Constants;
+import org.openecomp.appc.sdc.artifacts.helper.DependencyModelGenerator;
import org.openecomp.appc.sdc.artifacts.object.Resource;
import org.openecomp.appc.sdc.artifacts.object.SDCArtifact;
+import org.openecomp.appc.sdc.artifacts.object.SDCReference;
import org.openecomp.sdc.api.IDistributionClient;
import org.openecomp.sdc.api.notification.IArtifactInfo;
import org.openecomp.sdc.api.notification.INotificationData;
@@ -52,9 +54,12 @@ public class ToscaCsarArtifactProcessor extends AbstractArtifactProcessor{
private final EELFLogger logger = EELFManager.getInstance().getLogger(ToscaCsarArtifactProcessor.class);
+ private DependencyModelGenerator dependencyModelGenerator;
+
public ToscaCsarArtifactProcessor(IDistributionClient client, EventSender eventSender, INotificationData notification, IResourceInstance resource,
- IArtifactInfo artifact, URI storeUri){
+ IArtifactInfo artifact, URI storeUri){
super(client,eventSender,notification,resource,artifact,storeUri);
+ dependencyModelGenerator = new DependencyModelGenerator();
}
@Override
@@ -94,7 +99,7 @@ public class ToscaCsarArtifactProcessor extends AbstractArtifactProcessor{
resources = readResources (serviceTemplateContent);
} catch (Exception e) {
logger.error("Error reading resources from " + ", serviceFileName = " + serviceFileName
- + ", TOSCA Metadata = " + csarFiles.get("TOSCA-Metadata/TOSCA.meta"),e);
+ + ", TOSCA Metadata = " + csarFiles.get("TOSCA-Metadata/TOSCA.meta"),e);
throw new APPCException(e);
}
@@ -188,23 +193,49 @@ public class ToscaCsarArtifactProcessor extends AbstractArtifactProcessor{
logger.error(errStr);
throw new APPCException(errStr);
}
-
try {
- SDCArtifact existingArtifact = artifactStorageService.retrieveSDCArtifact(vnfType, version,artifact.getArtifactType());
-
- if (existingArtifact ==null) { // new resource
- logger.debug("Artifact not found for vnfType = " + vnfType + " , version = " + version + " , artifactType = " + artifact.getArtifactType());
- artifactStorageService.storeASDCArtifact(artifact);
- } else { // duplicate
- logger.debug("Artifact retrieved from database = " + existingArtifact);
- logger.warn(String.format("Artifact of type '%s' already deployed for resource_type='%s' and resource_version='%s'", Constants.VF_LICENSE, vnfType, version));
- }
-
+ SDCReference reference = new SDCReference();
+ reference.setVnfType(vnfType);
+ reference.setFileCategory("tosca_model");
+ reference.setArtifactName(artifact.getArtifactName());
+ logger.debug("Storing TOSCA to ASDC Artifact");
+ artifactStorageService.storeASDCArtifactWithReference(artifact,reference);
+
+ SDCArtifact dependencyArtifact = getDependencyArtifact(artifact);
+ SDCReference dependencyReference = new SDCReference();
+ dependencyReference.setVnfType(vnfType);
+ dependencyReference.setFileCategory("tosca_dependency_model");
+ dependencyReference.setArtifactName(dependencyArtifact.getArtifactName());
+ logger.debug("Storing Dependency to ASDC Artifact");
+ artifactStorageService.storeASDCArtifactWithReference(dependencyArtifact,dependencyReference);
} catch (Exception e) {
logger.error("Error processing artifact : " + artifact.toString() );
throw new APPCException(e.getMessage(),e);
}
}
+ private SDCArtifact getDependencyArtifact(SDCArtifact toscaArtifact) throws APPCException {
+ SDCArtifact artifact = new SDCArtifact();
+ artifact.setArtifactName("dependency_"+toscaArtifact.getArtifactName());
+ String dependencyModel = dependencyModelGenerator.getDependencyModel(toscaArtifact.getArtifactContent(),toscaArtifact.getResourceName());
+ artifact.setArtifactContent(dependencyModel);
+ artifact.setArtifactType("DEPENDENCY_MODEL");
+
+ artifact.setArtifactUUID(toscaArtifact.getArtifactUUID());
+ artifact.setArtifactVersion(toscaArtifact.getArtifactVersion());
+ artifact.setArtifactDescription(toscaArtifact.getArtifactDescription());
+ artifact.setCreationDate(super.getCurrentDateTime());
+ artifact.setDistributionId(toscaArtifact.getDistributionId());
+ artifact.setServiceUUID(toscaArtifact.getServiceUUID());
+ artifact.setServiceName(toscaArtifact.getServiceName());
+ artifact.setServiceDescription(toscaArtifact.getServiceDescription());
+ artifact.setResourceName(toscaArtifact.getResourceName());
+ artifact.setResourceType(toscaArtifact.getResourceType());
+ artifact.setResourceVersion(toscaArtifact.getResourceVersion());
+ artifact.setResourceUUID(toscaArtifact.getResourceUUID());
+ artifact.setResourceInstanceName(toscaArtifact.getResourceInstanceName());
+ return artifact;
+ }
+
}
diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/object/SDCReference.java b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/object/SDCReference.java
new file mode 100644
index 000000000..b9d630026
--- /dev/null
+++ b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/object/SDCReference.java
@@ -0,0 +1,94 @@
+/*-
+ * ============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.openecomp.appc.sdc.artifacts.object;
+
+public class SDCReference {
+
+ private String vnfType;
+ private String vnfcType;
+ private String fileCategory;
+ private String action;
+ private String artifactType;
+ private String artifactName;
+
+ public String getVnfType() {
+ return vnfType;
+ }
+
+ public void setVnfType(String vnfType) {
+ this.vnfType = vnfType;
+ }
+
+ public String getVnfcType() {
+ return vnfcType;
+ }
+
+ public void setVnfcType(String vnfcType) {
+ this.vnfcType = vnfcType;
+ }
+
+ public String getFileCategory() {
+ return fileCategory;
+ }
+
+ public void setFileCategory(String fileCategory) {
+ this.fileCategory = fileCategory;
+ }
+
+ public String getAction() {
+ return action;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ public String getArtifactType() {
+ return artifactType;
+ }
+
+ public void setArtifactType(String artifactType) {
+ this.artifactType = artifactType;
+ }
+
+ public String getArtifactName() {
+ return artifactName;
+ }
+
+ public void setArtifactName(String artifactName) {
+ this.artifactName = artifactName;
+ }
+ @Override
+ public String toString() {
+ return "vnfType = " + vnfType+
+ ", vnfType = " + vnfType+
+ ", fileCategory = " + fileCategory+
+ ", action = " + action+
+ ", artifactType = " + artifactType+
+ ", artifactName = " + artifactName+
+ ", vnfType = " + vnfType;
+ }
+
+}
diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/object/Vnfc.java b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/object/Vnfc.java
new file mode 100644
index 000000000..47d5f4516
--- /dev/null
+++ b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/artifacts/object/Vnfc.java
@@ -0,0 +1,78 @@
+/*-
+ * ============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.openecomp.appc.sdc.artifacts.object;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+import java.util.List;
+
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonPropertyOrder({"vnfc-type","mandatory","resilience","parents"})
+public class Vnfc {
+
+ @JsonProperty("vnfc-type")
+ private String vnfcType;
+ @JsonProperty("mandatory")
+ private boolean mandatory;
+ @JsonProperty("resilience")
+ private String resilienceType;
+ @JsonProperty("parents")
+ private List<String> parents;
+
+ public String getVnfcType() {
+ return vnfcType;
+ }
+
+ public void setVnfcType(String vnfcType) {
+ this.vnfcType = vnfcType;
+ }
+ public boolean isMandatory() {
+ return mandatory;
+ }
+
+ public void setMandatory(boolean mandatory) {
+ this.mandatory = mandatory;
+ }
+
+ public String getResilienceType() {
+ return resilienceType;
+ }
+
+ public void setResilienceType(String resilienceType) {
+ this.resilienceType = resilienceType;
+ }
+
+ public List<String> getParents() {
+ return parents;
+ }
+
+ public void setParents(List<String> parents) {
+ this.parents = parents;
+ }
+}
diff --git a/appc-asdc-listener/appc-yang-generator/pom.xml b/appc-asdc-listener/appc-yang-generator/pom.xml
index 473524104..11b5b9d76 100644
--- a/appc-asdc-listener/appc-yang-generator/pom.xml
+++ b/appc-asdc-listener/appc-yang-generator/pom.xml
@@ -37,11 +37,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-tosca-lib</artifactId>
- <version>${toscalib.version}</version>
- </dependency>
- <dependency>
<groupId>org.openecomp.sdc.common</groupId>
<artifactId>openecomp-tosca-datatype</artifactId>
<version>${toscalib.version}</version>