diff options
author | Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com> | 2019-03-25 00:31:16 -0400 |
---|---|---|
committer | Alexis de Talhouët <adetalhouet89@gmail.com> | 2019-03-25 14:31:26 -0400 |
commit | 40e79084751b4ef3b6d69189f1edf947fb6af011 (patch) | |
tree | ff9d4bef034580a73687114449a00a102d667f81 /ms/controllerblueprints/modules/service/src/main | |
parent | 3a2872a0d9c01bde8aabcc35d79b40f6c03f1958 (diff) |
Improve initial data load
Change-Id: I5358b4a4900858bfefea429cf0a1e260d2dcd19a
Issue-ID: CCSDK-1137
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/service/src/main')
14 files changed, 260 insertions, 332 deletions
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java deleted file mode 100644 index 9aeee1771..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.cds.controllerblueprints.service.repository; - -import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Optional; - -/** - * ControllerBlueprintModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface ControllerBlueprintModelSearchRepository extends JpaRepository<BlueprintModelSearch, Long> { - - /** - * This is a findById method - * - * @param id id - * @return Optional<BlueprintModelSearch> - */ - @NotNull - Optional<BlueprintModelSearch> findById(@NotNull String id); - - /** - * This is a findAll method - * @return List<BlueprintModelSearch> - */ - @Override - List<BlueprintModelSearch> findAll(); - - /** - * This is a findByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - * @return Optional<AsdcArtifacts> - */ - Optional<BlueprintModelSearch> findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags - * @return Optional<BlueprintModelSearch> - */ - List<BlueprintModelSearch> findByTagsContainingIgnoreCase(String tags); -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.java deleted file mode 100644 index 314ac6a4e..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.controllerblueprints.service.repository; - -import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.Optional; - -/** - * ResourceMappingRepository.java Purpose: Provide Configuration Generator ResourceMappingRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface ResourceDictionaryRepository extends JpaRepository<ResourceDictionary, String> { - - - /** - * This is a findByName method - * - * @param name name - * @return Optional<ResourceMapping> - */ - Optional<ResourceDictionary> findByName(String name); - - /** - * This is a findByNameIn method - * - * @param names names - * @return Optional<ResourceMapping> - */ - List<ResourceDictionary> findByNameIn(List<String> names); - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags tags - * @return Optional<ModelType> - */ - List<ResourceDictionary> findByTagsContainingIgnoreCase(String tags); - - /** - * This is a deleteByName method - * - * @param name name - */ - void deleteByName(String name); - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt index 8ede9f208..e1fa1882d 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt @@ -72,8 +72,8 @@ open class BluePrintRepoFileService(private val modelTypeRepository: ModelTypeRe @Throws(BluePrintException::class) override fun getResourceDefinition(resourceDefinitionName: String): ResourceDefinition { val dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName) - return if (dbResourceDictionary.isPresent) { - dbResourceDictionary.get().definition + return if (dbResourceDictionary != null) { + dbResourceDictionary.definition } else { throw BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)) } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt index 0509e970e..341d63bf0 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +20,7 @@ package org.onap.ccsdk.cds.controllerblueprints.service.controller import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType import org.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler +import kotlinx.coroutines.runBlocking import org.springframework.http.MediaType import org.springframework.web.bind.annotation.* @@ -27,30 +29,30 @@ import org.springframework.web.bind.annotation.* open class ModelTypeController(private val modelTypeHandler: ModelTypeHandler) { @GetMapping(path = arrayOf("/{name}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) - fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? { - return modelTypeHandler.getModelTypeByName(name) + fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? = runBlocking { + modelTypeHandler.getModelTypeByName(name) } @GetMapping(path = arrayOf("/search/{tags}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) - fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> { - return modelTypeHandler.searchModelTypes(tags) + fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> = runBlocking { + modelTypeHandler.searchModelTypes(tags) } @GetMapping(path = arrayOf("/by-definition/{definitionType}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) @ResponseBody - fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> { - return modelTypeHandler.getModelTypeByDefinitionType(definitionType) + fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> = runBlocking { + modelTypeHandler.getModelTypeByDefinitionType(definitionType) } @PostMapping(path = arrayOf(""), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE), consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE)) @ResponseBody @Throws(BluePrintException::class) - fun saveModelType(@RequestBody modelType: ModelType): ModelType { - return modelTypeHandler.saveModel(modelType) + fun saveModelType(@RequestBody modelType: ModelType): ModelType = runBlocking { + modelTypeHandler.saveModel(modelType) } @DeleteMapping(path = arrayOf("/{name}")) - fun deleteModelTypeByName(@PathVariable(value = "name") name: String) { + fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = runBlocking { modelTypeHandler.deleteByModelName(name) } }
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt index e21639715..d728fc229 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt @@ -20,6 +20,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary import org.onap.ccsdk.cds.controllerblueprints.service.handler.ResourceDictionaryHandler +import kotlinx.coroutines.runBlocking import org.springframework.http.MediaType import org.springframework.web.bind.annotation.* @@ -30,39 +31,39 @@ open class ResourceDictionaryController(private val resourceDictionaryHandler: R @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @Throws(BluePrintException::class) - fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary { - return resourceDictionaryHandler.getResourceDictionaryByName(name) + fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary = runBlocking { + resourceDictionaryHandler.getResourceDictionaryByName(name) } @PostMapping(path = [""], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @Throws(BluePrintException::class) - fun saveResourceDictionary(@RequestBody dataDictionary: ResourceDictionary): ResourceDictionary { - return resourceDictionaryHandler.saveResourceDictionary(dataDictionary) + fun saveResourceDictionary(@RequestBody dataDictionary: ResourceDictionary): ResourceDictionary = runBlocking { + resourceDictionaryHandler.saveResourceDictionary(dataDictionary) } @DeleteMapping(path = ["/{name}"]) - fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) { + fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) = runBlocking { resourceDictionaryHandler.deleteResourceDictionary(name) } @PostMapping(path = ["/by-names"], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody - fun searchResourceDictionaryByNames(@RequestBody names: List<String>): List<ResourceDictionary> { - return resourceDictionaryHandler.searchResourceDictionaryByNames(names) + fun searchResourceDictionaryByNames(@RequestBody names: List<String>): List<ResourceDictionary> = runBlocking { + resourceDictionaryHandler.searchResourceDictionaryByNames(names) } @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody - fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List<ResourceDictionary> { - return resourceDictionaryHandler.searchResourceDictionaryByTags(tags) + fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List<ResourceDictionary> = runBlocking { + resourceDictionaryHandler.searchResourceDictionaryByTags(tags) } @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody - fun getResourceSourceMapping(): ResourceSourceMapping { - return resourceDictionaryHandler.getResourceSourceMapping() + fun getResourceSourceMapping(): ResourceSourceMapping = runBlocking { + resourceDictionaryHandler.getResourceSourceMapping() } } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt index 5c1a1652c..f602437ed 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,10 +35,15 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * @param modelTypeName modelTypeName * @return ModelType */ - fun getModelTypeByName(modelTypeName: String): ModelType? { + suspend fun getModelTypeByName(modelTypeName: String): ModelType { log.info("Searching : $modelTypeName") check(modelTypeName.isNotBlank()) { "Model Name Information is missing." } - return modelTypeRepository.findByModelName(modelTypeName) + val modelType = modelTypeRepository.findByModelName(modelTypeName) + return if (modelType != null) { + modelType + } else { + throw BluePrintException("couldn't get modelType($modelTypeName)") + } } @@ -47,7 +53,7 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * @param tags tags * @return List<ModelType> </ModelType> */ - fun searchModelTypes(tags: String): List<ModelType> { + suspend fun searchModelTypes(tags: String): List<ModelType> { check(tags.isNotBlank()) { "No Search Information provide" } return modelTypeRepository.findByTagsContainingIgnoreCase(tags) } @@ -60,7 +66,7 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * @throws BluePrintException BluePrintException */ @Throws(BluePrintException::class) - open fun saveModel(modelType: ModelType): ModelType { + suspend open fun saveModel(modelType: ModelType): ModelType { lateinit var dbModel: ModelType ModelTypeValidator.validateModelType(modelType) val dbModelType: ModelType? = modelTypeRepository.findByModelName(modelType.modelName) @@ -86,7 +92,7 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * * @param modelName modelName */ - open fun deleteByModelName(modelName: String) { + suspend open fun deleteByModelName(modelName: String) { check(modelName.isNotBlank()) { "Model Name Information is missing." } modelTypeRepository.deleteByModelName(modelName) @@ -97,8 +103,8 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * * @param definitionType definitionType * @return List<ModelType> - */ - fun getModelTypeByDefinitionType(definitionType: String): List<ModelType> { + */ + suspend fun getModelTypeByDefinitionType(definitionType: String): List<ModelType> { check(definitionType.isNotBlank()) { "Model definitionType Information is missing." } return modelTypeRepository.findByDefinitionType(definitionType) } @@ -108,8 +114,8 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * * @param derivedFrom derivedFrom * @return List<ModelType> - */ - fun getModelTypeByDerivedFrom(derivedFrom: String): List<ModelType> { + */ + suspend fun getModelTypeByDerivedFrom(derivedFrom: String): List<ModelType> { check(derivedFrom.isNotBlank()) { "Model derivedFrom Information is missing." } return modelTypeRepository.findByDerivedFrom(derivedFrom) } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt index f6e95de2d..df8cffdba 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt @@ -40,11 +40,11 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * @throws BluePrintException BluePrintException */ @Throws(BluePrintException::class) - fun getResourceDictionaryByName(name: String): ResourceDictionary { + suspend fun getResourceDictionaryByName(name: String): ResourceDictionary { Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing.") val resourceDictionaryDb = resourceDictionaryRepository.findByName(name) - return if (resourceDictionaryDb.isPresent) { - resourceDictionaryDb.get() + return if (resourceDictionaryDb != null) { + resourceDictionaryDb } else { throw BluePrintException(String.format("couldn't get resource dictionary for name (%s)", name)) } @@ -56,7 +56,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * @param names names * @return List<ResourceDictionary> </ResourceDictionary> */ - fun searchResourceDictionaryByNames(names: List<String>): List<ResourceDictionary> { + suspend fun searchResourceDictionaryByNames(names: List<String>): List<ResourceDictionary> { Preconditions.checkArgument(CollectionUtils.isNotEmpty(names), "No Search Information provide") return resourceDictionaryRepository.findByNameIn(names) } @@ -67,7 +67,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * @param tags tags * @return List<ResourceDictionary> </ResourceDictionary> */ - fun searchResourceDictionaryByTags(tags: String): List<ResourceDictionary> { + suspend fun searchResourceDictionaryByTags(tags: String): List<ResourceDictionary> { Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No search tag information provide") return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags) } @@ -79,7 +79,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * @return DataDictionary */ @Throws(BluePrintException::class) - fun saveResourceDictionary(resourceDictionary: ResourceDictionary): ResourceDictionary { + suspend fun saveResourceDictionary(resourceDictionary: ResourceDictionary): ResourceDictionary { var resourceDictionary = resourceDictionary val resourceDefinition = resourceDictionary.definition @@ -101,8 +101,8 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour validateResourceDictionary(resourceDictionary) val dbResourceDictionaryData = resourceDictionaryRepository.findByName(resourceDictionary.name) - if (dbResourceDictionaryData.isPresent) { - val dbResourceDictionary = dbResourceDictionaryData.get() + if (dbResourceDictionaryData != null) { + val dbResourceDictionary = dbResourceDictionaryData dbResourceDictionary.name = resourceDictionary.name dbResourceDictionary.definition = resourceDictionary.definition @@ -124,7 +124,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * * @param name name */ - fun deleteResourceDictionary(name: String) { + suspend fun deleteResourceDictionary(name: String) { check(name.isNotBlank()) { "Resource dictionary name is missing." } resourceDictionaryRepository.deleteByName(name) } @@ -132,7 +132,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour /** * This is a getResourceSourceMapping service */ - fun getResourceSourceMapping(): ResourceSourceMapping { + suspend fun getResourceSourceMapping(): ResourceSourceMapping { return ResourceSourceMappingFactory.getRegisterSourceMapping() } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt index bffdccda7..eca7ce1bf 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +18,8 @@ package org.onap.ccsdk.cds.controllerblueprints.service.load import com.att.eelf.configuration.EELFManager -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.async -import kotlinx.coroutines.runBlocking -import org.apache.commons.lang3.text.StrBuilder import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.springframework.stereotype.Service import java.io.File @@ -30,38 +28,28 @@ open class BluePrintCatalogLoadService(private val bluePrintCatalogService: Blue private val log = EELFManager.getInstance().getLogger(BluePrintCatalogLoadService::class.java) - open fun loadPathsBluePrintModelCatalog(paths: List<String>) { + open suspend fun loadPathsBluePrintModelCatalog(paths: List<String>) { paths.forEach { loadPathBluePrintModelCatalog(it) } } - open fun loadPathBluePrintModelCatalog(path: String) { + open suspend fun loadPathBluePrintModelCatalog(path: String) { - val files = File(path).listFiles() - runBlocking { - val errorBuilder = StrBuilder() - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in files) { - deferredResults += async { - loadBluePrintModelCatalog(errorBuilder, file) - } - } - - for (deferredResult in deferredResults) { - deferredResult.await() - } - - if (!errorBuilder.isEmpty) { - log.error(errorBuilder.toString()) - } + val files = normalizedFile(path).listFiles() + val errors = mutableListOf<String>() + files.forEach { + loadBluePrintModelCatalog(errors, it) + } + if (!errors.isEmpty()) { + log.error(errors.joinToString("\n")) } } - open fun loadBluePrintModelCatalog(errorBuilder: StrBuilder, file: File) { + open suspend fun loadBluePrintModelCatalog(errorBuilder: MutableList<String>, file: File) { try { + log.info("loading blueprint cba(${file.absolutePath})") bluePrintCatalogService.saveToDatabase(file) } catch (e: Exception) { - errorBuilder.appendln("Couldn't load BlueprintModel(${file.name}: ${e.message}") + errorBuilder.add("Couldn't load BlueprintModel(${file.name}: ${e.message}") } } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt index e6f6498df..4a3168d65 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +34,7 @@ open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: @EventListener(ApplicationReadyEvent::class) - open fun init() { + open fun init() = runBlocking { if (bluePrintLoadConfiguration.loadInitialData) { initModelTypes() initResourceDictionary() @@ -41,23 +42,22 @@ open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: } else { log.info("Initial data load is disabled") } + } - open fun initModelTypes() { + open suspend fun initModelTypes() { log.info("model types load configuration(${bluePrintLoadConfiguration.loadModelType}) " + "under paths(${bluePrintLoadConfiguration.loadModeTypePaths})") if (bluePrintLoadConfiguration.loadModelType) { val paths = bluePrintLoadConfiguration.loadModeTypePaths?.split(",") paths?.let { - runBlocking { - modelTypeLoadService.loadPathsModelType(paths) - } + modelTypeLoadService.loadPathsModelType(paths) } } } - open fun initResourceDictionary() { + open suspend fun initResourceDictionary() { log.info("resource dictionary load configuration(${bluePrintLoadConfiguration.loadResourceDictionary}) " + "under paths(${bluePrintLoadConfiguration.loadResourceDictionaryPaths})") @@ -69,7 +69,7 @@ open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: } } - open fun initBluePrintCatalog() { + open suspend fun initBluePrintCatalog() { log.info("blueprint load configuration(${bluePrintLoadConfiguration.loadBluePrint}) " + "under paths(${bluePrintLoadConfiguration.loadBluePrintPaths})") diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt index c3533979b..ff87ad465 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,18 +18,21 @@ package org.onap.ccsdk.cds.controllerblueprints.service.load import com.att.eelf.configuration.EELFManager -import kotlinx.coroutines.* +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.coroutineScope import org.apache.commons.io.FilenameUtils import org.apache.commons.lang3.text.StrBuilder import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.data.* +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.readNBText import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType import org.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler import org.springframework.stereotype.Service import java.io.File -import java.nio.charset.Charset @Service open class ModelTypeLoadService(private val modelTypeHandler: ModelTypeHandler) { @@ -37,65 +41,57 @@ open class ModelTypeLoadService(private val modelTypeHandler: ModelTypeHandler) private val updateBySystem = "System" open suspend fun loadPathsModelType(modelTypePaths: List<String>) { - modelTypePaths.forEach { runBlocking { loadPathModelType(it) } } + modelTypePaths.forEach { + loadPathModelType(it) + } } /** * Load the Model Type file content from the defined path, Load of sequencing should be maintained. */ - open suspend fun loadPathModelType(modelTypePath: String) = runBlocking { + open suspend fun loadPathModelType(modelTypePath: String) { log.info(" *************************** loadModelType **********************") try { val errorBuilder = StrBuilder() coroutineScope { - val dataTypeFiles = File("$modelTypePath/data_type").listFiles() - - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in dataTypeFiles) deferredResults += async { - loadModelType(file, DataType::class.java, errorBuilder) + val dataTypeFiles = normalizedFile("$modelTypePath", "data_type").listFiles() + val deferred = dataTypeFiles.map { + async { + loadModelType(it, DataType::class.java, errorBuilder) + } } - - deferredResults.awaitAll() + deferred.awaitAll() } coroutineScope { - val artifactTypeFiles = File("$modelTypePath/artifact_type").listFiles() - - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in artifactTypeFiles) deferredResults += async { - loadModelType(file, - ArtifactType::class.java, errorBuilder) + val artifactTypeFiles = normalizedFile("$modelTypePath", "artifact_type").listFiles() + val deferred = artifactTypeFiles.map { + async { + loadModelType(it, ArtifactType::class.java, errorBuilder) + } } - - deferredResults.awaitAll() + deferred.awaitAll() } coroutineScope { - val relationshipTypeFiles = File("$modelTypePath/relationship_type").listFiles() - - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in relationshipTypeFiles) deferredResults += async { - loadModelType(file, - RelationshipType::class.java, errorBuilder) + val relationshipTypeFiles = normalizedFile("$modelTypePath", "relationship_type").listFiles() + val deferred = relationshipTypeFiles.map { + async { + loadModelType(it, RelationshipType::class.java, errorBuilder) + } } - - deferredResults.awaitAll() + deferred.awaitAll() } coroutineScope { - val nodeTypeFiles = File("$modelTypePath/node_type").listFiles() - - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in nodeTypeFiles) deferredResults += async { - loadModelType(file, - NodeType::class.java, errorBuilder) + val nodeTypeFiles = normalizedFile("$modelTypePath", "node_type").listFiles() + val deferred = nodeTypeFiles.map { + async { + loadModelType(it, NodeType::class.java, errorBuilder) + } } - deferredResults.awaitAll() + deferred.awaitAll() } if (!errorBuilder.isEmpty) { @@ -106,11 +102,11 @@ open class ModelTypeLoadService(private val modelTypeHandler: ModelTypeHandler) } } - private inline fun <reified T> loadModelType(file: File, classType: Class<T>, errorBuilder: StrBuilder) { + private suspend inline fun <reified T> loadModelType(file: File, classType: Class<T>, errorBuilder: StrBuilder) { try { log.trace("Loading ${classType.name} (${file.name})") val dataKey = FilenameUtils.getBaseName(file.name) - val definitionContent = file.readText(Charset.defaultCharset()) + val definitionContent = file.readNBText() val definition = JacksonUtils.readValue(definitionContent, classType) as EntityType //checkNotNull(definition) { "failed to get data type from file : ${file.name}" } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt index e07552592..69b7c643c 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,57 +18,56 @@ package org.onap.ccsdk.cds.controllerblueprints.service.load import com.att.eelf.configuration.EELFManager -import kotlinx.coroutines.Deferred import kotlinx.coroutines.async -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.coroutineScope import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.text.StrBuilder import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.readNBText import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary import org.onap.ccsdk.cds.controllerblueprints.service.handler.ResourceDictionaryHandler import org.springframework.stereotype.Service import java.io.File -import java.nio.charset.Charset @Service open class ResourceDictionaryLoadService(private val resourceDictionaryHandler: ResourceDictionaryHandler) { private val log = EELFManager.getInstance().getLogger(ResourceDictionaryLoadService::class.java) - open fun loadPathsResourceDictionary(paths: List<String>) { - paths.forEach { loadPathResourceDictionary(it) } + open suspend fun loadPathsResourceDictionary(paths: List<String>) { + paths.forEach { + loadPathResourceDictionary(it) + } } - open fun loadPathResourceDictionary(path: String) { + open suspend fun loadPathResourceDictionary(path: String) { log.info(" *************************** loadResourceDictionary **********************") - val files = File(path).listFiles() - - runBlocking { - val errorBuilder = StrBuilder() - val deferredResults = mutableListOf<Deferred<Unit>>() + val files = normalizedFile(path).listFiles() + val errorBuilder = StrBuilder() - for (file in files) { - deferredResults += async { - loadResourceDictionary(errorBuilder, file) + coroutineScope() { + val deferred = files.map { + async { + loadResourceDictionary(errorBuilder, it) } } + deferred.awaitAll() + } - for (deferredResult in deferredResults) { - deferredResult.await() - } - - if (!errorBuilder.isEmpty) { - log.error(errorBuilder.toString()) - } + if (!errorBuilder.isEmpty) { + log.error(errorBuilder.toString()) } + } - private fun loadResourceDictionary(errorBuilder: StrBuilder, file: File) { + private suspend fun loadResourceDictionary(errorBuilder: StrBuilder, file: File) { try { - log.trace("Loading NodeType(${file.name}") - val definitionContent = file.readText(Charset.defaultCharset()) + log.trace("Loading NodeType(${file.name}}") + val definitionContent = file.readNBText() val resourceDefinition = JacksonUtils.readValue(definitionContent, ResourceDefinition::class.java) if (resourceDefinition != null) { diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.kt new file mode 100644 index 000000000..bf77af66c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.kt @@ -0,0 +1,63 @@ +/* + * Copyright © 2019 IBM. + * + * 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.controllerblueprints.service.repository + +import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository +import java.util.* + +/** + * ControllerBlueprintModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +interface ControllerBlueprintModelSearchRepository : JpaRepository<BlueprintModelSearch, Long> { + + /** + * This is a findById method + * + * @param id id + * @return Optional<BlueprintModelSearch> + </BlueprintModelSearch> */ + fun findById(id: String): Optional<BlueprintModelSearch> + + /** + * This is a findAll method + * @return List<BlueprintModelSearch> + </BlueprintModelSearch> */ + override fun findAll(): List<BlueprintModelSearch> + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return Optional<AsdcArtifacts> + </AsdcArtifacts> */ + fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): Optional<BlueprintModelSearch> + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags + * @return Optional<BlueprintModelSearch> + </BlueprintModelSearch> */ + fun findByTagsContainingIgnoreCase(tags: String): List<BlueprintModelSearch> +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt deleted file mode 100644 index 5758fb7fb..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright © 2018 IBM. - * - * 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.controllerblueprints.service.repository - -import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary -import org.springframework.stereotype.Service -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono -import reactor.core.scheduler.Schedulers - -/** - * ResourceDictionaryReactRepository. - * - * @author Brinda Santh - */ -@Service -open class ResourceDictionaryReactRepository(private val resourceDictionaryRepository: ResourceDictionaryRepository) { - - fun save(resourceDictionary: ResourceDictionary): Mono<ResourceDictionary> { - return Mono.justOrEmpty(resourceDictionaryRepository.save(resourceDictionary)) - } - - fun findByName(name: String): Mono<ResourceDictionary> { - return Mono.justOrEmpty(resourceDictionaryRepository.findByName(name)) - } - - fun findByNameIn(names: List<String>): Flux<ResourceDictionary> { - return Flux.fromIterable(resourceDictionaryRepository.findByNameIn(names)) - .subscribeOn(Schedulers.elastic()) - } - - fun findByTagsContainingIgnoreCase(tags: String): Flux<ResourceDictionary> { - return Flux.fromIterable(resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags)) - .subscribeOn(Schedulers.elastic()) - } - - fun deleteByName(name: String): Mono<Void> { - resourceDictionaryRepository.deleteByName(name) - return Mono.empty() - } - -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.kt new file mode 100644 index 000000000..b1b633a10 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.kt @@ -0,0 +1,66 @@ +/* + * Copyright © 2019 IBM. + * + * 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.controllerblueprints.service.repository + +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + + +/** + * ResourceMappingRepository.java Purpose: Provide Configuration Generator ResourceMappingRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +interface ResourceDictionaryRepository : JpaRepository<ResourceDictionary, String> { + + + /** + * This is a findByName method + * + * @param name name + * @return Optional<ResourceMapping> + </ResourceMapping> */ + fun findByName(name: String): ResourceDictionary? + + /** + * This is a findByNameIn method + * + * @param names names + * @return Optional<ResourceMapping> + </ResourceMapping> */ + fun findByNameIn(names: List<String>): List<ResourceDictionary> + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags tags + * @return Optional<ModelType> + </ModelType> */ + fun findByTagsContainingIgnoreCase(tags: String): List<ResourceDictionary> + + /** + * This is a deleteByName method + * + * @param name name + */ + fun deleteByName(name: String) + + +} |