aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin
diff options
context:
space:
mode:
authorAlexis de Talhouët <adetalhouet89@gmail.com>2019-01-07 16:33:02 -0500
committerAlexis de Talhouët <alexis.de_talhouet@bell.ca>2019-01-09 22:11:43 +0000
commit3ce735a660cd4d387affe1e301471d3bd765e21c (patch)
treef7e4d1671857a507a26c345e378975e6d0c0b66c /ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin
parentfcafafe29cf0ff4bc60cae063483deed709c79de (diff)
Add support for blueprintprocessor runtime DB
- created db-resources module to store controller blueprint related controller blueprint repository and entities. Also create an abstract BlueprintCatalogServiceImpl so it can be used both by controllerblueprint and blueprintprocessor - created blueprint-validation to store the implementation of the validation interface. - change controllerblueprint service to levrage db-resources - implement CatalogService for blueprintprocessor db-lib by using db-resources. Change-Id: I0539e414e4ff3b7a6edf0f6304d6cbc5e6eac404 Issue-ID: CCSDK-664 Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin')
-rwxr-xr-xms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt86
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt3
-rwxr-xr-xms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt93
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt101
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt22
-rw-r--r--ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt21
6 files changed, 324 insertions, 2 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt
new file mode 100755
index 00000000..7c0eb6b6
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt
@@ -0,0 +1,86 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 Bell Canada.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.db
+
+import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel
+import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModelContent
+import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.repository.BlueprintProcessorModelContentRepository
+import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.repository.BlueprintProcessorModelRepository
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants
+import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.onap.ccsdk.apps.controllerblueprints.db.resources.BlueprintCatalogServiceImpl
+import org.springframework.stereotype.Service
+import java.io.File
+import java.nio.file.Files
+
+/**
+Similar/Duplicate implementation in [org.onap.ccsdk.apps.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl]
+ */
+@Service
+class BlueprintProcessorCatalogServiceImpl(bluePrintLoadConfiguration: BluePrintLoadConfiguration,
+ private val bluePrintValidatorService: BluePrintValidatorService,
+ private val blueprintModelContentRepository: BlueprintProcessorModelContentRepository,
+ private val blueprintModelRepository: BlueprintProcessorModelRepository)
+ : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration) {
+
+ override fun saveToDataBase(extractedDirectory: File, id: String, archiveFile: File, checkValidity: Boolean?) {
+ var valid = false
+ val firstItem = BluePrintArchiveUtils.getFirstItemInDirectory(extractedDirectory)
+ val blueprintBaseDirectory = extractedDirectory.absolutePath + "/" + firstItem
+ // Validate Blueprint
+ val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(id, blueprintBaseDirectory)
+
+ // Check Validity of blueprint
+ if (checkValidity!!) {
+ valid = bluePrintValidatorService.validateBluePrints(bluePrintRuntimeService)
+ }
+
+ if ((valid && checkValidity!!) || (!valid && !checkValidity!!)) {
+ val metaData = bluePrintRuntimeService.bluePrintContext().metadata!!
+ // FIXME("Check Duplicate for Artifact Name and Artifact Version")
+ val blueprintModel = BlueprintProcessorModel()
+ blueprintModel.id = id
+ blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL
+ blueprintModel.published = ApplicationConstants.ACTIVE_N
+ blueprintModel.artifactName = metaData[BluePrintConstants.METADATA_TEMPLATE_NAME]
+ blueprintModel.artifactVersion = metaData[BluePrintConstants.METADATA_TEMPLATE_VERSION]
+ blueprintModel.updatedBy = metaData[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]
+ blueprintModel.tags = metaData[BluePrintConstants.METADATA_TEMPLATE_TAGS]
+ blueprintModel.artifactDescription = "Controller Blueprint for ${blueprintModel.artifactName}:${blueprintModel.artifactVersion}"
+
+ val blueprintModelContent = BlueprintProcessorModelContent()
+ blueprintModelContent.id = id // For quick access both id's are same.always have one to one mapping.
+ blueprintModelContent.contentType = "CBA_ZIP"
+ blueprintModelContent.name = "${blueprintModel.artifactName}:${blueprintModel.artifactVersion}"
+ blueprintModelContent.description = "(${blueprintModel.artifactName}:${blueprintModel.artifactVersion} CBA Zip Content"
+ blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath())
+
+ // Set the Blueprint Model into blueprintModelContent
+ blueprintModelContent.blueprintModel = blueprintModel
+
+ // Set the Blueprint Model Content into blueprintModel
+ blueprintModel.blueprintModelContent = blueprintModelContent
+
+ blueprintModelRepository.saveAndFlush(blueprintModel)
+ }
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt
index bf76e213..98b6221d 100644
--- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt
@@ -45,8 +45,7 @@ open class PrimaryDatabaseConfiguration(private val primaryDataSourceProperties:
open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean {
val em = LocalContainerEntityManagerFactoryBean()
em.dataSource = primaryDataSource()
- em.setPackagesToScan(
- "org.onap.ccsdk.apps.blueprintsprocessor.db.primary")
+ em.setPackagesToScan("org.onap.ccsdk.apps.blueprintsprocessor.db.primary")
val vendorAdapter = HibernateJpaVendorAdapter()
em.jpaVendorAdapter = vendorAdapter
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt
new file mode 100755
index 00000000..00d4830e
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModel.kt
@@ -0,0 +1,93 @@
+/*
+ * Copyright © 2019 Bell Canada
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain
+
+import com.fasterxml.jackson.annotation.JsonFormat
+import io.swagger.annotations.ApiModelProperty
+import javax.persistence.Entity
+import javax.persistence.EntityListeners
+import javax.persistence.Table
+import org.hibernate.annotations.Proxy
+import org.springframework.data.annotation.LastModifiedDate
+import org.springframework.data.jpa.domain.support.AuditingEntityListener
+import java.io.Serializable
+import java.util.*
+import javax.persistence.CascadeType
+import javax.persistence.Column
+import javax.persistence.FetchType
+import javax.persistence.Id
+import javax.persistence.Lob
+import javax.persistence.OneToOne
+import javax.persistence.Temporal
+import javax.persistence.TemporalType
+
+@EntityListeners(AuditingEntityListener::class)
+@Entity
+@Table(name = "BLUEPRINT_RUNTIME")
+@Proxy(lazy = false)
+class BlueprintProcessorModel : Serializable {
+ @Id
+ @Column(name = "config_model_id")
+ var id: String? = null
+
+ @Column(name = "artifact_uuid")
+ var artifactUUId: String? = null
+
+ @Column(name = "artifact_type")
+ var artifactType: String? = null
+
+ @Column(name = "artifact_version", nullable = false)
+ @ApiModelProperty(required = true)
+ var artifactVersion: String? = null
+
+ @Lob
+ @Column(name = "artifact_description")
+ var artifactDescription: String? = null
+
+ @Column(name = "internal_version")
+ var internalVersion: Int? = null
+
+ @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+ @LastModifiedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ @Column(name = "creation_date")
+ var createdDate = Date()
+
+ @Column(name = "artifact_name", nullable = false)
+ @ApiModelProperty(required = true)
+ var artifactName: String? = null
+
+ @Column(name = "published", nullable = false)
+ @ApiModelProperty(required = true)
+ var published: String? = null
+
+ @Column(name = "updated_by", nullable = false)
+ @ApiModelProperty(required = true)
+ var updatedBy: String? = null
+
+ @Lob
+ @Column(name = "tags", nullable = false)
+ @ApiModelProperty(required = true)
+ var tags: String? = null
+
+ @OneToOne(mappedBy = "blueprintModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = [CascadeType.ALL])
+ var blueprintModelContent: BlueprintProcessorModelContent? = null
+
+ companion object {
+ private const val serialVersionUID = 1L
+ }
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt
new file mode 100644
index 00000000..d012af58
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/domain/BlueprintProcessorModelContent.kt
@@ -0,0 +1,101 @@
+/*
+ * Copyright © 2019 Bell Canada
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain
+
+import com.fasterxml.jackson.annotation.JsonFormat
+import io.swagger.annotations.ApiModelProperty
+import java.io.Serializable
+import java.util.Date
+import java.util.Objects
+import javax.persistence.Column
+import javax.persistence.Entity
+import javax.persistence.EntityListeners
+import javax.persistence.Id
+import javax.persistence.JoinColumn
+import javax.persistence.Lob
+import javax.persistence.OneToOne
+import javax.persistence.Table
+import javax.persistence.Temporal
+import javax.persistence.TemporalType
+import org.springframework.data.annotation.LastModifiedDate
+import org.springframework.data.jpa.domain.support.AuditingEntityListener
+
+@EntityListeners(AuditingEntityListener::class)
+@Entity
+@Table(name = "BLUEPRINT_CONTENT_RUNTIME")
+class BlueprintProcessorModelContent : Serializable {
+
+ @Id
+ @Column(name = "config_model_content_id")
+ var id: String? = null
+
+ @Column(name = "name", nullable = false)
+ @ApiModelProperty(required = true)
+ var name: String? = null
+
+ @Column(name = "content_type", nullable = false)
+ @ApiModelProperty(required = true)
+ var contentType: String? = null
+
+ @OneToOne
+ @JoinColumn(name = "config_model_id")
+ var blueprintModel: BlueprintProcessorModel? = null
+
+ @Lob
+ @Column(name = "description")
+ var description: String? = null
+
+ @Lob
+ @Column(name = "content", nullable = false)
+ @ApiModelProperty(required = true)
+ var content: ByteArray? = null
+
+ @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+ @LastModifiedDate
+ @Temporal(TemporalType.TIMESTAMP)
+ @Column(name = "updated_date")
+ var creationDate = Date()
+
+ override fun toString(): String {
+ return "[" + "id = " + id +
+ ", name = " + name +
+ ", contentType = " + contentType +
+ "]"
+ }
+
+ override fun equals(o: Any?): Boolean {
+
+ if (o === this) {
+ return true
+ }
+ if (o !is BlueprintProcessorModelContent) {
+ return false
+ }
+ val blueprintModelContent = o as BlueprintProcessorModelContent?
+ return (id == blueprintModelContent!!.id && name == blueprintModelContent.name
+ && contentType == blueprintModelContent.contentType)
+ }
+
+ override fun hashCode(): Int {
+ return Objects.hash(id, name, contentType)
+ }
+
+ companion object {
+ private const val serialVersionUID = 1L
+ }
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt
new file mode 100644
index 00000000..e614544e
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelContentRepository.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2019 Bell Canada.
+ *
+ * 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.
+ */
+package org.onap.ccsdk.apps.blueprintsprocessor.db.primary.repository
+
+import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel
+import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModelContent
+import org.onap.ccsdk.apps.controllerblueprints.db.resources.repository.ModelContentRepository
+
+interface BlueprintProcessorModelContentRepository : ModelContentRepository<BlueprintProcessorModel, BlueprintProcessorModelContent> \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt
new file mode 100644
index 00000000..25f3dac9
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/db/primary/repository/BlueprintProcessorModelRepository.kt
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2019 Bell Canada.
+ *
+ * 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.
+ */
+package org.onap.ccsdk.apps.blueprintsprocessor.db.primary.repository
+
+import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.domain.BlueprintProcessorModel
+import org.onap.ccsdk.apps.controllerblueprints.db.resources.repository.ModelRepository
+
+interface BlueprintProcessorModelRepository : ModelRepository<BlueprintProcessorModel>