diff options
author | Kavitha P <pkavitha@aarnanetworks.com> | 2021-08-25 16:12:18 +0530 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2021-08-27 16:58:22 +0000 |
commit | 35481027b3fdf251a3b520ab5b1ae89c7d2d0e34 (patch) | |
tree | 8fe9d3fe117005d54b31e1a136ad334e419268e4 /ms/blueprintsprocessor/functions | |
parent | 6b6f2360e4e60d681a5ba0fc05477f9ac9bea051 (diff) |
CCSDK-3434 CBA workflow status store
Change-Id: Iaeac6fa534c569bbc152e6c8a78c2dd23b6c4b1a
Signed-off-by: Kavitha P <pkavitha@aarnanetworks.com>
Issue-ID: CCSDK-3434
Diffstat (limited to 'ms/blueprintsprocessor/functions')
15 files changed, 1262 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/pom.xml b/ms/blueprintsprocessor/functions/blueprint-audit-status/pom.xml new file mode 100644 index 000000000..ec2e72c61 --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/pom.xml @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Copyright © 2017-2018 AT&T Intellectual Property. + ~ + ~ 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. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> + <artifactId>blueprintsprocessor-functions</artifactId> + <version>1.2.0-SNAPSHOT</version> + </parent> + + <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId> + <artifactId>blueprint-audit-status</artifactId> + <packaging>jar</packaging> + + <name>MS Blueprints Processor Functions - Blueprint Audit status</name> + <description>Blueprints Processor Function - Blueprint Audit status</description> + + <dependencies> + <dependency> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor.modules</groupId> + <artifactId>db-lib</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-testing</artifactId> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/DatabaseStoreAuditConstants.kt b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/DatabaseStoreAuditConstants.kt new file mode 100644 index 000000000..1ca8d1b30 --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/DatabaseStoreAuditConstants.kt @@ -0,0 +1,27 @@ +/* + * Copyright © 2021 Aarna Networks, Inc. + * All rights reserved. + * 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.cds.blueprintsprocessor.functions.workflow.audit + +/** + * Contants file + */ +object DatabaseStoreAuditConstants { + + const val WORKFLOW_STATUS_INPROGRESS = "In Progress" + const val WORKFLOW_STATUS_COMPLETED = "Completed" + const val WORKFLOW_STATUS_UPDATEDBY = "CBA" +} diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/DatabaseStoreAuditService.kt b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/DatabaseStoreAuditService.kt new file mode 100644 index 000000000..ecfb269f0 --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/DatabaseStoreAuditService.kt @@ -0,0 +1,243 @@ +/* + * Copyright © 2021 Aarna Networks, Inc. + * All rights reserved. + * 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.cds.blueprintsprocessor.functions.workflow.audit + +import com.fasterxml.jackson.databind.ObjectMapper +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput +import org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.db.BlueprintAuditStatusRepository +import org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.db.BlueprintWorkflowAuditStatus +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.controllerDate +import org.slf4j.LoggerFactory +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty +import org.springframework.dao.DataIntegrityViolationException +import org.springframework.stereotype.Service +import java.util.Date + +/** + * Workflow request and response details are persisted to database + */ +@ConditionalOnProperty( + name = ["blueprintsprocessor.workflow.self-service-api.audit.storeEnable"], + havingValue = "true" +) +@Service +class DatabaseStoreAuditService( + private val blueprintAuditStatusRepository: BlueprintAuditStatusRepository +) : StoreAuditService { + + private val log = + LoggerFactory.getLogger(DatabaseStoreAuditService::class.toString()) + + /** + * store the blueprint workflow input details to database + * @param executionServiceInput {@link ExecutionServiceInput} + * @throws {@link BluePrintException} + */ + override suspend fun storeExecutionInput( + executionServiceInput: ExecutionServiceInput + ): Long { + log.info( + "storeExecutionInput called to store the Workflow action " + + "input details " + ) + var storedAuditStatus: BlueprintWorkflowAuditStatus = BlueprintWorkflowAuditStatus() + + storedAuditStatus = write( + 0, executionServiceInput.commonHeader.originatorId, + executionServiceInput.commonHeader.requestId, + executionServiceInput.commonHeader.subRequestId, + executionServiceInput.actionIdentifiers.actionName, + executionServiceInput.actionIdentifiers.blueprintName, + executionServiceInput.actionIdentifiers.blueprintVersion, + executionServiceInput.payload.toString(), + DatabaseStoreAuditConstants.WORKFLOW_STATUS_INPROGRESS, controllerDate(), + controllerDate(), controllerDate(), + DatabaseStoreAuditConstants.WORKFLOW_STATUS_UPDATEDBY, + executionServiceInput.actionIdentifiers.mode, "" + ) + + return storedAuditStatus.id + } + + /** + * store the blueprint workflow output to database + * @param auditStoreId + * @param correlationUUID + * @param executionServiceOutput {@link ExecutionServiceOutput} + * @throws {@link BluePrintException} + */ + override suspend fun storeExecutionOutput( + auditStoreId: Long, + correlationUUID: String, + executionServiceOutput: ExecutionServiceOutput + ) { + log.info( + "storeExecutionOutput called to store the Workflow action " + + "output details correlationUUID $correlationUUID " + + "auditStoreId $auditStoreId" + ) + try { + var storedAuditStatus: BlueprintWorkflowAuditStatus + + storedAuditStatus = + blueprintAuditStatusRepository.findById(auditStoreId) + if (storedAuditStatus == null) { + throw BluePrintException("Record not found exception") + } + storedAuditStatus.endDate = controllerDate() + storedAuditStatus.status = DatabaseStoreAuditConstants.WORKFLOW_STATUS_COMPLETED + storedAuditStatus.updatedDate = controllerDate() + ObjectMapper().writeValueAsString(executionServiceOutput.status) + storedAuditStatus.workflowResponseContent = ObjectMapper() + .writeValueAsString(executionServiceOutput) + + log.info( + "Update the Audit status record Id ${storedAuditStatus.id} " + + "bluePrintName ${storedAuditStatus.blueprintName}" + ) + blueprintAuditStatusRepository.saveAndFlush(storedAuditStatus) + } catch (ex: DataIntegrityViolationException) { + log.error( + "Error writing out BLUEPRINT_WORKFLOW_AUDIT_STATUS result: " + + "bpName:" + + " $auditStoreId" + + "correlationUUID $correlationUUID error: {}", + ex.message + ) + throw BluePrintException("Failed to store resource api result.", ex) + } + } + + /** + * retrive workflow records based on request ID + * @param requestId + * @return list of {@link BlueprintWorkflowAuditStatus} + */ + override suspend fun getWorkflowStatusByRequestId( + requestId: String + ): List<BlueprintWorkflowAuditStatus> { + log.info( + "getWorkflowStatusByRequestId called to retrieve all the records " + + "based on request Id" + ) + + var results: List<BlueprintWorkflowAuditStatus> = + blueprintAuditStatusRepository.findByRequestId(requestId) + log.info( + "getWorkflowStatusByRequestId results count " + + "${results.size}" + ) + return results + } + + /** + * Retrive workflow records based on request ID and sub request ID + * @param requestId + * @param subRequestId + * @return list of {@link BlueprintWorkflowAuditStatus} + */ + override suspend fun getWorkflowStatusByRequestIdAndSubRequestId( + requestId: String, + subRequestId: String + ): List<BlueprintWorkflowAuditStatus> { + log.info( + "getWorkflowStatusByRequestIdAndSubRequestId called to retrieve all the records " + + "based on request Id" + ) + + var results: List<BlueprintWorkflowAuditStatus> = + blueprintAuditStatusRepository.findByRequestIdAndSubRequestId(requestId, subRequestId) + log.info( + "getWorkflowStatusByRequestIdAndSubRequestId results count " + + "${results.size}" + ) + return results + } + + /** + * method to save input details to database + */ + suspend fun write( + id: Long, + originatorId: String, + requestId: String, + subRequestId: String, + workflowName: String, + blueprintName: String, + blueprintVersion: String, + workflowTaskContent: String, + status: String, + startDate: Date, + endDate: Date, + updatedDate: Date, + updatedBy: String, + requestMode: String, + workflowResponseContent: String + ): BlueprintWorkflowAuditStatus = + withContext(Dispatchers.IO) { + + val blueprintAuditStatusResult = BlueprintWorkflowAuditStatus() + + blueprintAuditStatusResult.originatorId = originatorId + blueprintAuditStatusResult.requestId = requestId + blueprintAuditStatusResult.subRequestId = subRequestId + blueprintAuditStatusResult.workflowName = workflowName + blueprintAuditStatusResult.blueprintName = blueprintName + blueprintAuditStatusResult.blueprintVersion = blueprintVersion + blueprintAuditStatusResult.workflowTaskContent = workflowTaskContent + blueprintAuditStatusResult.status = status + blueprintAuditStatusResult.startDate = startDate + blueprintAuditStatusResult.endDate = endDate + blueprintAuditStatusResult.updatedDate = updatedDate + blueprintAuditStatusResult.updatedBy = updatedBy + blueprintAuditStatusResult.requestMode = requestMode + blueprintAuditStatusResult.workflowResponseContent = + workflowResponseContent + + var storedAuditStatus: BlueprintWorkflowAuditStatus + try { + log.info( + "Writing out BLUEPRINT_AUDIT_STATUS result: bpName: " + + "$blueprintName bpVer $blueprintVersion " + + "id:$id" + + " (originatorId: $originatorId requestId: " + + "$requestId) subRequestId:$subRequestId" + ) + storedAuditStatus = blueprintAuditStatusRepository.saveAndFlush( + blueprintAuditStatusResult + ) + } catch (ex: DataIntegrityViolationException) { + log.error( + "Error writing out BLUEPRINT_AUDIT_STATUS result: bpName:" + + " $blueprintName bpVer $blueprintVersion " + + "id:$id" + + " (originatorId: $originatorId requestId:" + + " $requestId) subRequestId:$subRequestId error: {}", + ex.message + ) + throw BluePrintException( + "Failed to store resource api result.", + ex + ) + } + storedAuditStatus + } +} diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/NoStoreAuditService.kt b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/NoStoreAuditService.kt new file mode 100644 index 000000000..230e67852 --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/NoStoreAuditService.kt @@ -0,0 +1,118 @@ +/* + * Copyright © 2021 Aarna Networks, Inc. + * All rights reserved. + * 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.cds.blueprintsprocessor.functions.workflow.audit + +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput +import org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.db.BlueprintAuditStatusRepository +import org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.db.BlueprintWorkflowAuditStatus +import org.slf4j.LoggerFactory +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty +import org.springframework.stereotype.Service +import javax.annotation.PostConstruct + +/** + * Workflow request and response details are persisted to database + */ +@ConditionalOnProperty( + name = ["blueprintsprocessor.workflow.self-service-api.audit.storeEnable"], + havingValue = "false" +) +@Service +class NoStoreAuditService( + private val blueprintAuditStatusRepository: BlueprintAuditStatusRepository +) : StoreAuditService { + + private val log = + LoggerFactory.getLogger(NoStoreAuditService::class.toString()) + + @PostConstruct + fun init() { + log.info("Workflow Audit store is disabled") + } + /** + * store the blueprint workflow input details to database + * @param executionServiceInput {@link ExecutionServiceInput} + * @throws {@link BluePrintException} + */ + override suspend fun storeExecutionInput( + executionServiceInput: ExecutionServiceInput + ): Long { + log.info( + "storeExecutionInput called not to store the Workflow action " + + "input details " + ) + val resturnId: Long = -1 + return resturnId + } + + /** + * store the blueprint workflow output to database + * @param auditStoreId + * @param correlationUUID + * @param executionServiceOutput {@link ExecutionServiceOutput} + * @throws {@link BluePrintException} + */ + override suspend fun storeExecutionOutput( + auditStoreId: Long, + correlationUUID: String, + executionServiceOutput: ExecutionServiceOutput + ) { + log.info( + "storeExecutionOutput called not to store the Workflow action " + + "output details correlationUUID $correlationUUID " + + "auditStoreId $auditStoreId" + ) + } + + /** + * retrive workflow records based on request ID + * @param requestId + * @return list of {@link BlueprintWorkflowAuditStatus} + */ + override suspend fun getWorkflowStatusByRequestId( + requestId: String + ): List<BlueprintWorkflowAuditStatus> { + log.info( + "getWorkflowStatusByRequestId placeholer , this doesn't return " + + "any records" + ) + + var results: List<BlueprintWorkflowAuditStatus> = ArrayList<BlueprintWorkflowAuditStatus>() + return results + } + + /** + * Retrive workflow records based on request ID and sub request ID + * @param requestId + * @param subRequestId + * @return list of {@link BlueprintWorkflowAuditStatus} + */ + override suspend fun getWorkflowStatusByRequestIdAndSubRequestId( + requestId: String, + subRequestId: String + ): List<BlueprintWorkflowAuditStatus> { + log.info( + "getWorkflowStatusByRequestIdAndSubRequestId placeholer , this doesn't return " + + "any records" + ) + + var results: List<BlueprintWorkflowAuditStatus> = ArrayList<BlueprintWorkflowAuditStatus>() + + return results + } +} diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/StoreAuditService.kt b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/StoreAuditService.kt new file mode 100644 index 000000000..a2bfc1121 --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/StoreAuditService.kt @@ -0,0 +1,69 @@ +/* + * Copyright © 2021 Aarna Networks, Inc. + * All rights reserved. + * 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.cds.blueprintsprocessor.functions.workflow.audit + +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput +import org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.db.BlueprintWorkflowAuditStatus + +/** + * Workflow request and response details are persisted to database + */ + +interface StoreAuditService { + + /** + * store the blueprint workflow input details to database + * @param executionServiceInput {@link ExecutionServiceInput} + * @throws {@link BluePrintException} + */ + suspend fun storeExecutionInput( + executionServiceInput: ExecutionServiceInput + ): Long + + /** + * store the blueprint workflow output to database + * @param auditStoreId + * @param correlationUUID + * @param executionServiceOutput {@link ExecutionServiceOutput} + */ + suspend fun storeExecutionOutput( + auditStoreId: Long, + correlationUUID: String, + executionServiceOutput: ExecutionServiceOutput + ) + + /** + * retrive workflow records based on request ID + * @param requestId + * @return list of {@link BlueprintWorkflowAuditStatus} + */ + suspend fun getWorkflowStatusByRequestId( + requestId: String + ): List<BlueprintWorkflowAuditStatus> + + /** + * Retrive workflow records based on request ID and sub request ID + * @param requestId + * @param subRequestId + * @return list of {@link BlueprintWorkflowAuditStatus} + */ + suspend fun getWorkflowStatusByRequestIdAndSubRequestId( + requestId: String, + subRequestId: String + ): List<BlueprintWorkflowAuditStatus> +} diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/db/BlueprintAuditStatusRepository.kt b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/db/BlueprintAuditStatusRepository.kt new file mode 100644 index 000000000..8e7304654 --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/db/BlueprintAuditStatusRepository.kt @@ -0,0 +1,107 @@ +/* + * Copyright © 2021 Aarna Networks, Inc. + * All rights reserved. + * 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.cds.blueprintsprocessor.functions.workflow.audit.db + +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository +import javax.transaction.Transactional + +/** + * JPA repository managing {@link BlueprintWorkflowAuditStatus} table. + */ +@Repository +interface BlueprintAuditStatusRepository : + JpaRepository<BlueprintWorkflowAuditStatus, String> { + + /** + * retireve records based on primary key ID. + * @param id + * @return {@link BlueprintWorkflowAuditStatus} + */ + fun findById(id: Long): BlueprintWorkflowAuditStatus + + /** + * retrieve records based on request ID + * @param requestId + * @return list {@link BlueprintWorkflowAuditStatus} + */ + fun findByRequestId( + requestId: String + ): List<BlueprintWorkflowAuditStatus> + + /** + * retrieve records based on request ID and subrequest ID + * @param requestId + * @param subRequestId + * @return list {@link BlueprintWorkflowAuditStatus} + */ + fun findByRequestIdAndSubRequestId( + requestId: String, + subRequestId: String + ): List<BlueprintWorkflowAuditStatus> + + /** + * retrieve records based on request id, blueprint name , blueprint version + * @param requestId + * @param blueprintName + * @param blueprintVersion + * @return {@link BlueprintWorkflowAuditStatus} + */ + fun findByRequestIdAndBlueprintNameAndBlueprintVersion( + requestId: String, + blueprintName: String?, + blueprintVersion: String? + ): BlueprintWorkflowAuditStatus + + /** + * retrieve records based on request id, blueprint name , blueprint version + * @return {@link BlueprintWorkflowAuditStatus} + */ + fun findByOriginatorIdAndRequestIdAndSubRequestIdAndWorkflowNameAndBlueprintNameAndBlueprintVersion( + originatorId: String, + requestId: String?, + subRequestId: String?, + workflowName: String, + blueprintName: String?, + blueprintVersion: String? + ): BlueprintWorkflowAuditStatus + + /** + * retrieve records based on request id, subrequest, originator, workflow, + * blueprint version, blueprint Name + * @return {@link BlueprintWorkflowAuditStatus} + */ + fun findByIdAndOriginatorIdAndRequestIdAndSubRequestIdAndWorkflowNameAndBlueprintNameAndBlueprintVersion( + id: Long, + originatorId: String, + requestId: String?, + subRequestId: String?, + workflowName: String, + blueprintName: String?, + blueprintVersion: String? + ): BlueprintWorkflowAuditStatus + + @Transactional + fun deleteByIdAndBlueprintNameAndBlueprintVersionAndOriginatorIdAndRequestIdAndSubRequestId( + id: Long, + blueprintName: String?, + blueprintVersion: String?, + originatorId: String, + requestId: String?, + subRequestId: String? + ) +} diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/db/BlueprintWorkflowAuditStatus.kt b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/db/BlueprintWorkflowAuditStatus.kt new file mode 100644 index 000000000..d9f0269f1 --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/db/BlueprintWorkflowAuditStatus.kt @@ -0,0 +1,136 @@ +/* + * Copyright © 2021 Aarna Networks, Inc. + * All rights reserved. + * 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.cds.blueprintsprocessor.functions.workflow.audit.db + +import com.fasterxml.jackson.annotation.JsonFormat +import io.swagger.annotations.ApiModelProperty +import org.hibernate.annotations.Proxy +import org.springframework.data.annotation.LastModifiedDate +import java.io.Serializable +import java.util.Date +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.GenerationType +import javax.persistence.GeneratedValue +import javax.persistence.Id +import javax.persistence.Lob +import javax.persistence.Table +import javax.persistence.Temporal +import javax.persistence.TemporalType + +/** + * BlueprintWorkflowAuditStatus Model. + * Records stored and retrieved in table BLUEPRINT_WORKFLOW_AUDIT_STATUS is + * done through this entity. + */ +@Entity +@Table(name = "BLUEPRINT_WORKFLOW_AUDIT_STATUS") +@Proxy(lazy = false) +class BlueprintWorkflowAuditStatus : Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "workflow_audit_id") + var id: Long = 0 + + @get:ApiModelProperty(value = "Workflow payload.", required = true) + @Lob + @Column(name = "workflow_task_content", nullable = false) + @ApiModelProperty(required = true) + lateinit var workflowTaskContent: String + + @get:ApiModelProperty(value = "request originator Id", required = true) + @Column(name = "originator_Id", nullable = false) + @ApiModelProperty(required = true) + lateinit var originatorId: String + + @get:ApiModelProperty(value = "request Id", required = true) + @Column(name = "request_Id", nullable = false) + @ApiModelProperty(required = true) + lateinit var requestId: String + + @get:ApiModelProperty(value = "sub request Id", required = true) + @Column(name = "subRequest_Id", nullable = false) + @ApiModelProperty(required = true) + lateinit var subRequestId: String + + @get:ApiModelProperty(value = "workflow name", required = true) + @Column(name = "workflow_name", nullable = false) + @ApiModelProperty(required = true) + lateinit var workflowName: String + + @get:ApiModelProperty(value = "status", required = true) + @Column(name = "status", nullable = true) + @ApiModelProperty(required = true) + lateinit var status: String + + @get:ApiModelProperty( + value = "start time when request process started", required = true + ) + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "start_time") + var startDate: Date = Date() + + @get:ApiModelProperty( + value = "end time when request process completed", required = true + ) + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "end_time") + var endDate: Date = Date() + + @get:ApiModelProperty(value = "current date time", required = true) + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "updated_date") + var updatedDate: Date = Date() + + @get:ApiModelProperty(value = "updated by", required = true) + @Column(name = "updated_by", nullable = true) + @ApiModelProperty(required = true) + lateinit var updatedBy: String + + @get:ApiModelProperty(value = "blueprint version", required = true) + @Column(name = "blueprint_version", nullable = false) + @ApiModelProperty(required = true) + lateinit var blueprintVersion: String + + @get:ApiModelProperty(value = "blueprint name", required = true) + @Column(name = "blueprint_name", nullable = false) + @ApiModelProperty(required = true) + lateinit var blueprintName: String + + @get:ApiModelProperty(value = "request mode", required = true) + @Column(name = "request_mode", nullable = true) + @ApiModelProperty(required = true) + lateinit var requestMode: String + + @get:ApiModelProperty(value = "workflow response content", required = false) + @Lob + @Column(name = "workflow_response_content", nullable = true) + @ApiModelProperty(required = false) + lateinit var workflowResponseContent: String + + @get:ApiModelProperty(value = "bluprint model uuid", required = true) + @Column(name = "blueprint_uuid", nullable = true) + @ApiModelProperty(required = false) + var blueprintUuid: String = "" +} diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/DatabaseStoreAuditServiceTest.kt b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/DatabaseStoreAuditServiceTest.kt new file mode 100644 index 000000000..cd4fc75a7 --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/DatabaseStoreAuditServiceTest.kt @@ -0,0 +1,270 @@ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit + +import io.mockk.every +import io.mockk.mockk +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput +import org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.db.BlueprintAuditStatusRepository +import org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.db.BlueprintWorkflowAuditStatus +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import java.util.Date +import kotlin.collections.ArrayList +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration( + classes = [TestDatabaseConfiguration::class] +) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) +@EnableAutoConfiguration +class DatabaseStoreAuditServiceTest { + + private val blueprintAuditStatusRepository = + mockk<BlueprintAuditStatusRepository>() + + private val databaseStoreAuditService = DatabaseStoreAuditService(blueprintAuditStatusRepository) + + @Test + fun storeExecutionInputTest() { + val executionServiceInput = JacksonUtils.readValueFromClassPathFile( + "exec-serv-input/multistep-input.json", + ExecutionServiceInput::class.java + )!! + val wfAudit1 = createWorkflowAuditStatusRecord(1000) + var testOuput: Long = 0 + runBlocking { + every { blueprintAuditStatusRepository.saveAndFlush(any<BlueprintWorkflowAuditStatus>()) } returns wfAudit1 + testOuput = databaseStoreAuditService.storeExecutionInput(executionServiceInput) + assertNotNull(testOuput, "failed to resolve the resources") + } + } + + @Test + fun storeExecutionOutputTest() { + val executionServiceOutput = JacksonUtils.readValueFromClassPathFile( + "exec-serv-output/multistep-output.json", + ExecutionServiceOutput::class.java + )!! + val inputAudit = createWorkflowAuditStatusRecord(1001) + val outputAudit = createWorkflowAuditStatusOutputRecord(1001) + + var testOutput: Long = 1001 + runBlocking { + every { blueprintAuditStatusRepository.findById(testOutput) } returns inputAudit + every { blueprintAuditStatusRepository.saveAndFlush(any<BlueprintWorkflowAuditStatus>()) } returns outputAudit + databaseStoreAuditService.storeExecutionOutput( + testOutput, + "12345", executionServiceOutput + ) + } + } + + @Test(expected = Exception::class) + fun storeExecutionOutputErrorTest() { + val executionServiceOutput = JacksonUtils.readValueFromClassPathFile( + "exec-serv-output/multistep-output.json", + ExecutionServiceOutput::class.java + )!! + // val inputAudit = createWorkflowAuditStatusRecord(1001) + val outputAudit = createWorkflowAuditStatusOutputRecord(1001) + + var testOutput: Long = -1 + runBlocking { + every { blueprintAuditStatusRepository.findById(-1) } returns null + every { blueprintAuditStatusRepository.saveAndFlush(any<BlueprintWorkflowAuditStatus>()) } returns outputAudit + databaseStoreAuditService.storeExecutionOutput( + testOutput, + "12345", executionServiceOutput + ) + } + } + + @Test + fun getWorkflowStatusByRequestIdAndSubRequestIdTest() { + val inputAudit = createWorkflowAuditStatusList(1003) + val testRequestId: String = "ab543-3asd4" + val testSubRequestId: String = "81c9-4910" + runBlocking { + every { + blueprintAuditStatusRepository.findByRequestIdAndSubRequestId(testRequestId, testSubRequestId) + } returns inputAudit + assertNotNull( + inputAudit.get(0).blueprintName, "Blueprint Name should not be null" + ) + assertNotNull( + inputAudit.get(0).blueprintVersion, "Blueprint should not be null" + ) + assertNotNull( + inputAudit.get(0).requestId, "Request ID should not be null" + ) + assertNotNull( + inputAudit.get(0).subRequestId, "Subrequest ID should not be null" + ) + assertNotNull( + inputAudit.get(0).status, "Status should not be null" + ) + assertNotNull( + inputAudit.get(0).startDate, "Start Date should not be null" + ) + assertNotNull( + inputAudit.get(0).updatedBy, "Updatedby should not be null" + ) + assertNotNull( + inputAudit.get(0).updatedDate, "updated Date should not be null" + ) + assertNotNull( + inputAudit.get(0).originatorId, "Originator ID should not be null" + ) + assertNotNull( + inputAudit.get(0).requestMode, "Request Mode should not be null" + ) + assertNotNull( + inputAudit.get(0).id, "ID should not be null" + ) + databaseStoreAuditService.getWorkflowStatusByRequestIdAndSubRequestId(testRequestId, testSubRequestId) + } + } + + @Test + fun getWorkflowStatusByRequestIdTest() { + val inputAudit = createWorkflowAuditStatusList(1004) + val testRequestId: String = "ab543-3asd4" + runBlocking { + every { blueprintAuditStatusRepository.findByRequestId(testRequestId) } returns inputAudit + databaseStoreAuditService.getWorkflowStatusByRequestId(testRequestId) + } + } + + private fun createWorkflowAuditStatusRecord( + id: Long + ): BlueprintWorkflowAuditStatus { + + var blueprintWorkflowAuditStatus: BlueprintWorkflowAuditStatus = + BlueprintWorkflowAuditStatus() + blueprintWorkflowAuditStatus.id = id + blueprintWorkflowAuditStatus.originatorId = "SDNC_DG" + blueprintWorkflowAuditStatus.requestMode = "sync" + blueprintWorkflowAuditStatus.requestId = "ab543-3asd4" + blueprintWorkflowAuditStatus.subRequestId = "81c9-4910" + blueprintWorkflowAuditStatus.status = "In progress" + blueprintWorkflowAuditStatus.blueprintName = "multi-steps" + blueprintWorkflowAuditStatus.blueprintVersion = "1.0.0" + blueprintWorkflowAuditStatus.workflowName = "multi-steps-workflow" + blueprintWorkflowAuditStatus.updatedBy = DatabaseStoreAuditConstants.WORKFLOW_STATUS_UPDATEDBY + blueprintWorkflowAuditStatus.endDate = Date() + blueprintWorkflowAuditStatus.requestMode = "sync" + blueprintWorkflowAuditStatus.workflowTaskContent = "{\n" + + " \"multi-steps-workflow-request\": {\n" + + " \"multi-steps-workflow-properties\": {\n" + + " \"prop1\": \"testing\",\n" + + " \"prop2\": \"testing description\",\n" + + " \"prop3\": \"user name \",\n" + + " \"prop4\" : \"test project\"\n" + + " }\n" + + " }\n" + + " }" + blueprintWorkflowAuditStatus.workflowResponseContent = " " + return blueprintWorkflowAuditStatus + } + + private fun createWorkflowAuditStatusOutputRecord( + id: Long + ): BlueprintWorkflowAuditStatus { + + var blueprintWorkflowAuditStatus: BlueprintWorkflowAuditStatus = + BlueprintWorkflowAuditStatus() + blueprintWorkflowAuditStatus.id = id + blueprintWorkflowAuditStatus.originatorId = "SDNC_DG" + blueprintWorkflowAuditStatus.requestMode = "sync" + blueprintWorkflowAuditStatus.requestId = "ab543-3asd4" + blueprintWorkflowAuditStatus.subRequestId = "81c9-4910" + blueprintWorkflowAuditStatus.status = DatabaseStoreAuditConstants.WORKFLOW_STATUS_INPROGRESS + blueprintWorkflowAuditStatus.blueprintName = "multi-steps" + blueprintWorkflowAuditStatus.blueprintVersion = "1.0.0" + blueprintWorkflowAuditStatus.workflowName = "multi-steps-workflow" + blueprintWorkflowAuditStatus.updatedBy = "CBA" + blueprintWorkflowAuditStatus.requestMode = "sync" + blueprintWorkflowAuditStatus.workflowTaskContent = "{\n" + + " \"multi-steps-workflow-request\": {\n" + + " \"multi-steps-workflow-properties\": {\n" + + " \"prop1\": \"testing\",\n" + + " \"prop2\": \"testing description\",\n" + + " \"prop3\": \"user name \",\n" + + " \"prop4\" : \"test project\"\n" + + " }\n" + + " }\n" + + " }" + blueprintWorkflowAuditStatus.workflowResponseContent = "{\n" + + " \"correlationUUID\": null,\n" + + " \"commonHeader\": {\n" + + " \"timestamp\": \"2021-08-05T08:18:35.690Z\",\n" + + " \"originatorId\": \"SDNC_DG\",\n" + + " \"requestId\": \"ab543-3asd4\",\n" + + " \"subRequestId\": \"81c9-4910\",\n" + + " \"flags\": null\n" + + " },\n" + + " \"actionIdentifiers\": {\n" + + " \"blueprintName\": \"multi-steps\",\n" + + " \"blueprintVersion\": \"1.0.0\",\n" + + " \"actionName\": \"multi-steps-workflow\",\n" + + " \"mode\": \"sync\"\n" + + " },\n" + + " \"status\": {\n" + + " \"code\": 200,\n" + + " \"eventType\": \"EVENT_COMPONENT_EXECUTED\",\n" + + " \"timestamp\": \"2021-08-05T08:18:35.727Z\",\n" + + " \"errorMessage\": null,\n" + + " \"message\": \"success\"\n" + + " },\n" + + " \"payload\": {\n" + + " \"multi-steps-workflow-response\": {}\n" + + " }\n" + + "} " + return blueprintWorkflowAuditStatus + } + + private fun createWorkflowAuditStatusList( + id: Long + ): List<BlueprintWorkflowAuditStatus> { + + var blueprintWorkflowAuditStatus: BlueprintWorkflowAuditStatus = + BlueprintWorkflowAuditStatus() + blueprintWorkflowAuditStatus.id = id + blueprintWorkflowAuditStatus.originatorId = "SDNC_DG" + blueprintWorkflowAuditStatus.requestMode = "sync" + blueprintWorkflowAuditStatus.requestId = "ab543-3asd4" + blueprintWorkflowAuditStatus.subRequestId = "81c9-4910" + blueprintWorkflowAuditStatus.status = DatabaseStoreAuditConstants.WORKFLOW_STATUS_INPROGRESS + blueprintWorkflowAuditStatus.blueprintName = "multi-steps" + blueprintWorkflowAuditStatus.blueprintVersion = "1.0.0" + blueprintWorkflowAuditStatus.workflowName = "multi-steps-workflow" + blueprintWorkflowAuditStatus.updatedBy = DatabaseStoreAuditConstants.WORKFLOW_STATUS_UPDATEDBY + blueprintWorkflowAuditStatus.requestMode = "sync" + blueprintWorkflowAuditStatus.workflowTaskContent = "{\n" + + " \"multi-steps-workflow-request\": {\n" + + " \"multi-steps-workflow-properties\": {\n" + + " \"prop1\": \"testing\",\n" + + " \"prop2\": \"testing description\",\n" + + " \"prop3\": \"user name \",\n" + + " \"prop4\" : \"test project\"\n" + + " }\n" + + " }\n" + + " }" + blueprintWorkflowAuditStatus.workflowResponseContent = " " + var testList: ArrayList<BlueprintWorkflowAuditStatus> = ArrayList<BlueprintWorkflowAuditStatus>() + testList.add(blueprintWorkflowAuditStatus) + return testList + } +} + +private infix fun Any.returns(nothing: Nothing?) { +} diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/NoStoreAuditServiceTest.kt b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/NoStoreAuditServiceTest.kt new file mode 100644 index 000000000..16abe95d3 --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/NoStoreAuditServiceTest.kt @@ -0,0 +1,81 @@ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit + +import io.mockk.mockk +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput +import org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.db.BlueprintAuditStatusRepository +import org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.db.BlueprintWorkflowAuditStatus +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration( + classes = [TestDatabaseConfiguration::class] +) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) +@EnableAutoConfiguration +class NoStoreAuditServiceTest { + + private val blueprintAuditStatusRepository = + mockk<BlueprintAuditStatusRepository>() + + private val storeAuditService = NoStoreAuditService(blueprintAuditStatusRepository) + + @Test + fun storeExecutionInputTest() { + val executionServiceInput = JacksonUtils.readValueFromClassPathFile( + "exec-serv-input/multistep-input.json", + ExecutionServiceInput::class.java + )!! + var testOuput: Long = 0 + runBlocking { + testOuput = storeAuditService.storeExecutionInput(executionServiceInput) + assertEquals(-1, testOuput, "Failed to resolve the workflow") + } + } + + @Test + fun storeExecutionOutputTest() { + val executionServiceOutput = JacksonUtils.readValueFromClassPathFile( + "exec-serv-output/multistep-output.json", + ExecutionServiceOutput::class.java + )!! + var testOutput: Long = -1 + runBlocking { + storeAuditService.storeExecutionOutput( + testOutput, "12345", executionServiceOutput + ) + } + } + + @Test + fun getWorkflowStatusByRequestIdAndSubRequestIdTest() { + val testRequestId: String = "ab543-3asd4" + val testSubRequestId: String = "81c9-4910" + var testList: List<BlueprintWorkflowAuditStatus>? = null + runBlocking { + testList = storeAuditService.getWorkflowStatusByRequestIdAndSubRequestId(testRequestId, testSubRequestId) + assertNotNull(testList, " Returned null instead of empty list ") + } + } + + @Test + fun getWorkflowStatusByRequestIdTest() { + val testRequestId: String = "ab543-3asd4" + var testList: List<BlueprintWorkflowAuditStatus>? = null + runBlocking { + testList = storeAuditService.getWorkflowStatusByRequestId(testRequestId) + assertNotNull(testList, " Returned null instead of empty list ") + } + } +} diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/TestDatabaseConfiguration.kt b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/TestDatabaseConfiguration.kt new file mode 100644 index 000000000..682b89155 --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/TestDatabaseConfiguration.kt @@ -0,0 +1,62 @@ +/* + * Copyright © 2021 Aarna Networks, Inc. + * All rights reserved. + * 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.cds.blueprintsprocessor.functions.workflow.audit + +import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDataSourceProperties +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.PrimaryDatabaseConfiguration +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Import +import org.springframework.data.jpa.repository.config.EnableJpaAuditing +import org.springframework.data.jpa.repository.config.EnableJpaRepositories +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean +import org.springframework.transaction.PlatformTransactionManager +import javax.sql.DataSource + +@Configuration +@Import(BluePrintDBLibConfiguration::class) +@EnableJpaRepositories( + basePackages = [ + "org.onap.ccsdk.cds.blueprintsprocessor.db.primary", + "org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit" + ], + entityManagerFactoryRef = "primaryEntityManager", + transactionManagerRef = "primaryTransactionManager" +) +@EnableJpaAuditing +open class TestDatabaseConfiguration(primaryDataSourceProperties: PrimaryDataSourceProperties) : + PrimaryDatabaseConfiguration(primaryDataSourceProperties) { + + @Bean("primaryEntityManager") + open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean { + return primaryEntityManager( + "org.onap.ccsdk.cds.blueprintsprocessor.db.primary", + "org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.db" + ) + } + + @Bean("primaryDataSource") + override fun primaryDataSource(): DataSource { + return super.primaryDataSource() + } + + @Bean("primaryTransactionManager") + override fun primaryTransactionManager(): PlatformTransactionManager { + return super.primaryTransactionManager() + } +} diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/db/BlueprintAuditStatusRepositoryTest.kt b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/db/BlueprintAuditStatusRepositoryTest.kt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/workflow/audit/db/BlueprintAuditStatusRepositoryTest.kt diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/resources/application-test.properties b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/resources/application-test.properties new file mode 100644 index 000000000..6a707b08e --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/resources/application-test.properties @@ -0,0 +1,36 @@ +# +# Copyright © 2021 Aarna Networks, Inc. +# All rights reserved. +# 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. +# +blueprintsprocessor.db.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 +blueprintsprocessor.db.username=sa +blueprintsprocessor.db.password= +blueprintsprocessor.db.driverClassName=org.h2.Driver +blueprintsprocessor.db.hibernateHbm2ddlAuto=create-drop +blueprintsprocessor.db.hibernateDDLAuto=update +blueprintsprocessor.db.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy +blueprintsprocessor.db.hibernateDialect=org.hibernate.dialect.H2Dialect +# Controller Blueprints Core Configuration +blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy +blueprintsprocessor.blueprintWorkingPath=./target/blueprints/work +blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive + +# Error Managements +error.catalog.applicationId=cds +error.catalog.type=properties +error.catalog.errorDefinitionDir=./../../../application/src/test/resources/ + +# Python executor +blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints +blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/resources/exec-serv-input/multistep-input.json b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/resources/exec-serv-input/multistep-input.json new file mode 100644 index 000000000..8e2552c00 --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/resources/exec-serv-input/multistep-input.json @@ -0,0 +1,23 @@ +{ + "actionIdentifiers": { + "mode": "sync", + "blueprintName": "multi-steps", + "blueprintVersion": "1.0.0", + "actionName": "multi-steps-workflow" + }, + "payload": { + "multi-steps-workflow-request": { + "multi-steps-workflow-properties": { + "prop1": "testing", + "prop2": "testing description", + "prop3": "user name ", + "prop4" : "test project" + } + } + }, + "commonHeader": { + "subRequestId": "81c9-4910", + "requestId": "ab543-3asd4", + "originatorId": "SDNC_DG" + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/resources/exec-serv-output/multistep-output.json b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/resources/exec-serv-output/multistep-output.json new file mode 100644 index 000000000..ca12b893d --- /dev/null +++ b/ms/blueprintsprocessor/functions/blueprint-audit-status/src/test/resources/exec-serv-output/multistep-output.json @@ -0,0 +1,26 @@ +{ + "correlationUUID": null, + "commonHeader": { + "timestamp": "2021-08-05T08:18:35.690Z", + "originatorId": "SDNC_DG", + "requestId": "ab543-3asd4", + "subRequestId": "81c9-4910", + "flags": null + }, + "actionIdentifiers": { + "blueprintName": "multi-steps", + "blueprintVersion": "1.0.0", + "actionName": "multi-steps-workflow", + "mode": "sync" + }, + "status": { + "code": 200, + "eventType": "EVENT_COMPONENT_EXECUTED", + "timestamp": "2021-08-05T08:18:35.727Z", + "errorMessage": null, + "message": "success" + }, + "payload": { + "multi-steps-workflow-response": {} + } +} diff --git a/ms/blueprintsprocessor/functions/pom.xml b/ms/blueprintsprocessor/functions/pom.xml index a1a4daad4..a019c6266 100755 --- a/ms/blueprintsprocessor/functions/pom.xml +++ b/ms/blueprintsprocessor/functions/pom.xml @@ -42,6 +42,7 @@ <module>config-snapshots</module> <module>message-prioritization</module> <module>k8s-connection-plugin</module> + <module>blueprint-audit-status</module> </modules> <dependencies> |