summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/service/src/main
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-12-14 20:38:44 -0500
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-12-14 20:38:44 -0500
commit8899e7a0f1ba7481cbcbe7ff581c285a9d0e98b6 (patch)
tree1315815d23d4dcb7ef1450a215fc3df7f686c87a /ms/controllerblueprints/modules/service/src/main
parented2e6c9ab708184398718ed0c112806e32a23d05 (diff)
Add multiple path load service.
Change-Id: Ib2e5f60663991d097b7446106bb883a45db1bdb8 Issue-ID: CCSDK-746 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Diffstat (limited to 'ms/controllerblueprints/modules/service/src/main')
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java325
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintCoreConfiguration.kt60
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt68
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogServiceImpl.kt66
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt79
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintLoadConfiguration.kt (renamed from ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoad.kt)18
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt6
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ResourceDictionaryLoadService.kt104
8 files changed, 349 insertions, 377 deletions
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java
deleted file mode 100644
index a4b874eef..000000000
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java
+++ /dev/null
@@ -1,325 +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.apps.controllerblueprints.service;
-
-import com.google.common.base.Preconditions;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.text.StrBuilder;
-import org.jetbrains.annotations.NotNull;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType;
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;
-import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel;
-import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;
-import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;
-import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.boot.context.event.ApplicationReadyEvent;
-import org.springframework.context.event.EventListener;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.ResourcePatternResolver;
-import org.springframework.stereotype.Component;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.util.List;
-
-/**
- * DataBaseInitService.java Purpose: Provide DataBaseInitService Service
- *
- * @author Brinda Santh
- * @version 1.0
- */
-@Deprecated
-@Component
-@ConditionalOnProperty(name = "blueprints.load.initial-data", havingValue = "true")
-public class DataBaseInitService {
-
- private static EELFLogger log = EELFManager.getInstance().getLogger(DataBaseInitService.class);
- private ModelTypeService modelTypeService;
- private ResourceDictionaryService resourceDictionaryService;
- private ConfigModelService configModelService;
- private String updateBySystem = "System";
- private static final String JSON_EXTN= ".json";
- private static final String EXCEPTION= "Exception";
-
- @Value("${load.dataTypePath}")
- private String dataTypePath;
- @Value("${load.nodeTypePath}")
- private String nodeTypePath;
- @Value("${load.artifactTypePath}")
- private String artifactTypePath;
- @Value("${load.resourceDictionaryPath}")
- private String resourceDictionaryPath;
- @Value("${load.blueprintsPath}")
- private String bluePrintsPath;
-
- @Autowired
- private ResourcePatternResolver resourceLoader;
-
- /**
- * This is a DataBaseInitService, used to load the initial data
- *
- * @param modelTypeService modelTypeService
- * @param resourceDictionaryService resourceDictionaryService
- * @param configModelService configModelService
- */
- public DataBaseInitService(ModelTypeService modelTypeService, ResourceDictionaryService resourceDictionaryService,
- ConfigModelService configModelService) {
- this.modelTypeService = modelTypeService;
- this.resourceDictionaryService = resourceDictionaryService;
- this.configModelService = configModelService;
- log.info("DataBaseInitService started...");
-
- }
-
- @SuppressWarnings("unused")
- @EventListener(ApplicationReadyEvent.class)
- private void initDatabase() {
- log.info("loading dataTypePath from DIR : {}", dataTypePath);
- log.info("loading nodeTypePath from DIR : {}", nodeTypePath);
- log.info("loading artifactTypePath from DIR : {}", artifactTypePath);
- log.info("loading resourceDictionaryPath from DIR : {}", resourceDictionaryPath);
- log.info("loading bluePrintsPath from DIR : {}", bluePrintsPath);
-
- loadModelType();
- loadResourceDictionary();
- }
-
- private void loadModelType() {
- log.info(" *************************** loadModelType **********************");
- try {
- Resource[] dataTypefiles = getPathResources(dataTypePath, JSON_EXTN);
- StrBuilder errorBuilder = new StrBuilder();
- for (Resource file : dataTypefiles) {
- if (file != null) {
- loadDataType(file, errorBuilder);
- }
- }
-
- Resource[] nodeTypefiles = getPathResources(nodeTypePath, JSON_EXTN);
- for (Resource file : nodeTypefiles) {
- if (file != null) {
- loadNodeType(file, errorBuilder);
- }
- }
-
-
- Resource[] artifactTypefiles = getPathResources(artifactTypePath, JSON_EXTN);
-
- for (Resource file : artifactTypefiles) {
- if (file != null) {
- loadArtifactType(file, errorBuilder);
- }
- }
-
-
- if (!errorBuilder.isEmpty()) {
- log.error(errorBuilder.toString());
- }
- } catch (Exception e) {
- log.error("Failed in Data type loading", e);
- }
- }
-
- private void loadResourceDictionary() {
- log.info(
- " *************************** loadResourceDictionary **********************");
- try {
- Resource[] dataTypefiles = getPathResources(resourceDictionaryPath, JSON_EXTN);
-
- StrBuilder errorBuilder = new StrBuilder();
- String fileName;
- for (Resource file : dataTypefiles) {
- try {
- fileName = file.getFilename();
- log.trace("Loading : {}", fileName);
- String definitionContent = getResourceContent(file);
- ResourceDefinition resourceDefinition =
- JacksonUtils.readValue(definitionContent, ResourceDefinition.class);
- if (resourceDefinition != null) {
- Preconditions.checkNotNull(resourceDefinition.getProperty(), "Failed to get Property Definition");
- ResourceDictionary resourceDictionary = new ResourceDictionary();
- resourceDictionary.setName(resourceDefinition.getName());
- resourceDictionary.setDefinition(resourceDefinition);
-
- Preconditions.checkNotNull(resourceDefinition.getProperty(), "Property field is missing");
- resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription());
- resourceDictionary.setDataType(resourceDefinition.getProperty().getType());
- if(resourceDefinition.getProperty().getEntrySchema() != null){
- resourceDictionary.setEntrySchema(resourceDefinition.getProperty().getEntrySchema().getType());
- }
- resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy());
- if (StringUtils.isBlank(resourceDefinition.getTags())) {
- resourceDictionary.setTags(
- resourceDefinition.getName() + ", " + resourceDefinition.getUpdatedBy()
- + ", " + resourceDefinition.getUpdatedBy());
-
- } else {
- resourceDictionary.setTags(resourceDefinition.getTags());
- }
- resourceDictionaryService.saveResourceDictionary(resourceDictionary);
-
- log.trace(" Loaded successfully : {}", file.getFilename());
- } else {
- throw new BluePrintException("couldn't get dictionary from content information");
- }
- } catch (Exception e) {
- log.error(EXCEPTION, e);
- errorBuilder.appendln("Dictionary loading Errors : " + file.getFilename() + ":" + e.getMessage());
- }
- }
- if (!errorBuilder.isEmpty()) {
- log.error(errorBuilder.toString());
- }
-
-
- } catch (Exception e) {
- log.error(
- "Failed in Resource dictionary loading", e);
- }
- }
-
- private void loadBlueprints() {
- log.info("*************************** loadServiceTemplate **********************");
- try {
- List<String> serviceTemplateDirs = ConfigModelUtils.getBlueprintNames(bluePrintsPath);
- if (CollectionUtils.isNotEmpty(serviceTemplateDirs)) {
- StrBuilder errorBuilder = new StrBuilder();
- for (String fileName : serviceTemplateDirs) {
- try {
- String bluePrintPath = this.bluePrintsPath.concat("/").concat(fileName);
- log.debug("***** Loading service template : {}", bluePrintPath);
- ConfigModel configModel = ConfigModelUtils.getConfigModel(bluePrintPath);
-
- configModel = this.configModelService.saveConfigModel(configModel);
-
- log.info("Publishing : {}", configModel.getId());
-
- this.configModelService.publishConfigModel(configModel.getId());
-
- log.info("Loaded service template successfully: {}", fileName);
-
- } catch (Exception e) {
- log.error(EXCEPTION, e);
- errorBuilder.appendln("load config model " + fileName + " error : " + e.getMessage());
- }
- }
-
- if (!errorBuilder.isEmpty()) {
- log.error(errorBuilder.toString());
- }
- }
- } catch (Exception e) {
- log.error("Failed in Service Template loading", e);
- }
- }
-
- private void loadNodeType(Resource file, StrBuilder errorBuilder) {
- try {
- log.trace("Loading Node Type : {}", file.getFilename());
- String nodeKey = file.getFilename().replace(JSON_EXTN, "");
- String definitionContent = getResourceContent(file);
- NodeType nodeType = JacksonUtils.readValue(definitionContent, NodeType.class);
- Preconditions.checkNotNull(nodeType, String.format("failed to get node type from file : %s", file.getFilename()));
- ModelType modelType = new ModelType();
- modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE);
- modelType.setDerivedFrom(nodeType.getDerivedFrom());
- modelType.setDescription(nodeType.getDescription());
- modelType.setDefinition(JacksonUtils.jsonNode(definitionContent));
- modelType.setModelName(nodeKey);
- modelType.setVersion(nodeType.getVersion());
- modelType.setUpdatedBy(updateBySystem);
- modelType.setTags(nodeKey + "," + BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE + ","
- + nodeType.getDerivedFrom());
- modelTypeService.saveModel(modelType);
- log.trace("Loaded Node Type successfully : {}", file.getFilename());
- } catch (Exception e) {
- log.error(EXCEPTION, e);
- errorBuilder.appendln("Node type loading error : " + file.getFilename() + ":" + e.getMessage());
- }
- }
-
- private void loadDataType(@NotNull Resource file, StrBuilder errorBuilder) {
- try {
- log.trace("Loading Data Type: {}", file.getFilename());
- String dataKey = file.getFilename().replace(JSON_EXTN, "");
- String definitionContent = getResourceContent(file);
- DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class);
- Preconditions.checkNotNull(dataType, String.format("failed to get data type from file : %s", file.getFilename()));
- ModelType modelType = new ModelType();
- modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);
- modelType.setDerivedFrom(dataType.getDerivedFrom());
- modelType.setDescription(dataType.getDescription());
- modelType.setDefinition(JacksonUtils.jsonNode(definitionContent));
- modelType.setModelName(dataKey);
- modelType.setVersion(dataType.getVersion());
- modelType.setUpdatedBy(updateBySystem);
- modelType.setTags(dataKey + "," + dataType.getDerivedFrom() + ","
- + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);
- modelTypeService.saveModel(modelType);
- log.trace(" Loaded Data Type successfully : {}", file.getFilename());
- } catch (Exception e) {
- log.error(EXCEPTION, e);
- errorBuilder.appendln("Data type loading error : " + file.getFilename() + ":" + e.getMessage());
- }
- }
-
- private void loadArtifactType(Resource file, StrBuilder errorBuilder) {
- try {
- log.trace("Loading Artifact Type: {}", file.getFilename());
- String dataKey = file.getFilename().replace(JSON_EXTN, "");
- String definitionContent = getResourceContent(file);
- ArtifactType artifactType = JacksonUtils.readValue(definitionContent, ArtifactType.class);
- Preconditions.checkNotNull(artifactType, String.format("failed to get artifact type from file : %s", file.getFilename()));
- ModelType modelType = new ModelType();
- modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE);
- modelType.setDerivedFrom(artifactType.getDerivedFrom());
- modelType.setDescription(artifactType.getDescription());
- modelType.setDefinition(JacksonUtils.jsonNode(definitionContent));
- modelType.setModelName(dataKey);
- modelType.setVersion(artifactType.getVersion());
- modelType.setUpdatedBy(updateBySystem);
- modelType.setTags(dataKey + "," + artifactType.getDerivedFrom() + ","
- + BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE);
- modelTypeService.saveModel(modelType);
- log.trace("Loaded Artifact Type successfully : {}", file.getFilename());
- } catch (Exception e) {
- log.error(EXCEPTION, e);
- errorBuilder.appendln("Artifact type loading error : " + file.getFilename() + ":" + e.getMessage());
- }
- }
-
- private Resource[] getPathResources(String path, String extension) throws IOException {
- return resourceLoader.getResources("file:" + path + "/*" + extension);
- }
-
- private String getResourceContent(Resource resource) throws IOException {
- return IOUtils.toString(resource.getInputStream(), Charset.defaultCharset());
- }
-
-}
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintCoreConfiguration.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintCoreConfiguration.kt
new file mode 100644
index 000000000..2e5fc5ba3
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintCoreConfiguration.kt
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.service
+
+import org.onap.ccsdk.apps.controllerblueprints.service.load.BluePrintLoadConfiguration
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.context.properties.bind.Bindable
+import org.springframework.boot.context.properties.bind.Binder
+import org.springframework.boot.context.properties.source.ConfigurationPropertySources
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+import org.springframework.core.env.Environment
+import org.springframework.stereotype.Service
+
+@Configuration
+open class BluePrintCoreConfiguration(private val bluePrintProperties: BluePrintProperties) {
+
+ companion object {
+ const val PREFIX_BLUEPRINT_LOAD_CONFIGURATION = "controllerblueprints"
+ }
+
+ @Bean
+ open fun bluePrintLoadConfiguration(): BluePrintLoadConfiguration {
+ return bluePrintProperties
+ .propertyBeanType(PREFIX_BLUEPRINT_LOAD_CONFIGURATION, BluePrintLoadConfiguration::class.java)
+ }
+}
+
+@Configuration
+open class BlueprintPropertyConfiguration {
+ @Autowired
+ lateinit var environment: Environment
+
+ @Bean
+ open fun bluePrintPropertyBinder(): Binder {
+ val configurationPropertySource = ConfigurationPropertySources.get(environment)
+ return Binder(configurationPropertySource)
+ }
+}
+
+@Service
+open class BluePrintProperties(var bluePrintPropertyBinder: Binder) {
+ fun <T> propertyBeanType(prefix: String, type: Class<T>): T {
+ return bluePrintPropertyBinder.bind(prefix, Bindable.of(type)).get()
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt
new file mode 100644
index 000000000..07ee0a9bb
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.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.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
+import org.springframework.stereotype.Service
+import java.io.File
+
+@Service
+open class BluePrintCatalogLoadService(private val bluePrintCatalogService: BluePrintCatalogService) {
+
+ private val log = EELFManager.getInstance().getLogger(BluePrintCatalogLoadService::class.java)
+
+ open fun loadPathsBluePrintModelCatalog(paths: List<String>) {
+ paths.forEach { loadPathBluePrintModelCatalog(it) }
+ }
+
+ open 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())
+ }
+ }
+ }
+
+ open fun loadBluePrintModelCatalog(errorBuilder: StrBuilder, file: File) {
+ try {
+ bluePrintCatalogService.uploadToDataBase(file.absolutePath)
+ } catch (e: Exception) {
+ errorBuilder.appendln("Couldn't load DataType(${file.name}: ${e.message}")
+ }
+ }
+
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogServiceImpl.kt
new file mode 100644
index 000000000..8cddbb4c9
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogServiceImpl.kt
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.service.load
+
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
+import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
+import org.springframework.stereotype.Service
+import java.io.File
+import java.util.*
+
+@Service
+class BluePrintCatalogServiceImpl(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration,
+ private val bluePrintValidatorService: BluePrintValidatorService) : BluePrintCatalogService {
+
+ override fun uploadToDataBase(file: String): String {
+ val id = UUID.randomUUID().toString()
+ val blueprintFile = File(file)
+ // If the file is directory
+ if (blueprintFile.isDirectory) {
+ val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(id, blueprintFile.absolutePath)
+ val valid = bluePrintValidatorService.validateBluePrints(bluePrintRuntimeService)
+ if (valid) {
+ val zipFile = File("${bluePrintLoadConfiguration.blueprintArchivePath}/${id}.zip")
+ // zip the directory
+ BluePrintArchiveUtils.compress(blueprintFile, zipFile, true)
+
+ // TODO(Upload to the Data Base)
+
+ // After Upload to Database delete the zip file
+ zipFile.deleteOnExit()
+ }
+ } else {
+ // If the file is ZIP
+ // TODO(Upload to the Data Base)
+ }
+ return id
+ }
+
+ override fun downloadFromDataBase(name: String, version: String, path: String): String {
+ // If path ends with zip, then compress otherwise download as extracted folder
+
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun prepareBluePrint(name: String, version: String): String {
+ val preparedPath = "${bluePrintLoadConfiguration.blueprintDeployPath}/$name/$version"
+ downloadFromDataBase(name, version, preparedPath)
+ return preparedPath
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt
new file mode 100644
index 000000000..eeea97c9b
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt
@@ -0,0 +1,79 @@
+/*
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.service.load
+
+import com.att.eelf.configuration.EELFManager
+import org.springframework.boot.context.event.ApplicationReadyEvent
+import org.springframework.context.event.EventListener
+import org.springframework.stereotype.Service
+
+@Service
+open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration,
+ private val modelTypeLoadService: ModelTypeLoadService,
+ private val resourceDictionaryLoadService: ResourceDictionaryLoadService,
+ private val bluePrintCatalogLoadService: BluePrintCatalogLoadService) {
+
+ private val log = EELFManager.getInstance().getLogger(BluePrintDatabaseLoadService::class.java)
+
+
+ @EventListener(ApplicationReadyEvent::class)
+ open fun init() {
+ if (bluePrintLoadConfiguration.loadInitialData) {
+ initModelTypes()
+ initResourceDictionary()
+ initBluePrintCatalog()
+ } else {
+ log.info("Initial data load is disabled")
+ }
+ }
+
+ open fun initModelTypes() {
+ log.info("model types load configuration(${bluePrintLoadConfiguration.loadModelType}) " +
+ "under paths(${bluePrintLoadConfiguration.loadModeTypePaths})")
+
+ if (bluePrintLoadConfiguration.loadModelType) {
+ val paths = bluePrintLoadConfiguration.loadModeTypePaths?.split(",")
+ paths?.let {
+ modelTypeLoadService.loadPathsModelType(paths)
+ }
+ }
+ }
+
+ open fun initResourceDictionary() {
+ log.info("resource dictionary load configuration(${bluePrintLoadConfiguration.loadResourceDictionary}) " +
+ "under paths(${bluePrintLoadConfiguration.loadResourceDictionaryPaths})")
+
+ if (bluePrintLoadConfiguration.loadResourceDictionary) {
+ val paths = bluePrintLoadConfiguration.loadResourceDictionaryPaths?.split(",")
+ paths?.let {
+ resourceDictionaryLoadService.loadPathsResourceDictionary(paths)
+ }
+ }
+ }
+
+ open fun initBluePrintCatalog() {
+ log.info("blueprint load configuration(${bluePrintLoadConfiguration.loadBluePrint}) " +
+ "under paths(${bluePrintLoadConfiguration.loadBluePrintPaths})")
+
+ if (bluePrintLoadConfiguration.loadBluePrint) {
+ val paths = bluePrintLoadConfiguration.loadBluePrintPaths?.split(",")
+ paths?.let {
+ bluePrintCatalogLoadService.loadPathsBluePrintModelCatalog(paths)
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoad.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintLoadConfiguration.kt
index 8a5cc4c6c..cf36a3e5a 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoad.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintLoadConfiguration.kt
@@ -16,13 +16,19 @@
package org.onap.ccsdk.apps.controllerblueprints.service.load
-import org.springframework.stereotype.Service
+open class BluePrintLoadConfiguration {
-@Service
-open class BluePrintCatalogLoad {
+ lateinit var blueprintDeployPath: String
+ lateinit var blueprintArchivePath: String
+ lateinit var blueprintEnrichmentPath: String
- open fun loadBluePrintModelCatalog() {
- // TODO
- }
+ var loadInitialData: Boolean = false
+ var loadBluePrint: Boolean = false
+ var loadBluePrintPaths: String? = null
+ var loadModelType: Boolean = false
+ var loadModeTypePaths: String? = null
+
+ var loadResourceDictionary: Boolean = false
+ var loadResourceDictionaryPaths: String? = null
} \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt
index ac9834b9f..1c5276c8d 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt
@@ -36,11 +36,11 @@ open class ModelTypeLoadService(private val modelTypeService: ModelTypeService)
private val log = EELFManager.getInstance().getLogger(ModelTypeLoadService::class.java)
private val updateBySystem = "System"
- open fun loadModelType(modelTypePaths: List<String>) {
- modelTypePaths.forEach { loadModelType(it) }
+ open fun loadPathsModelType(modelTypePaths: List<String>) {
+ modelTypePaths.forEach { loadPathModelType(it) }
}
- open fun loadModelType(modelTypePath: String) {
+ open fun loadPathModelType(modelTypePath: String) {
log.info(" *************************** loadModelType **********************")
try {
val errorBuilder = StrBuilder()
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ResourceDictionaryLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ResourceDictionaryLoadService.kt
index eddaa1cc2..4bb8a2f3a 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ResourceDictionaryLoadService.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ResourceDictionaryLoadService.kt
@@ -17,6 +17,9 @@
package org.onap.ccsdk.apps.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.StringUtils
import org.apache.commons.lang3.text.StrBuilder
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
@@ -33,55 +36,70 @@ open class ResourceDictionaryLoadService(private val resourceDictionaryService:
private val log = EELFManager.getInstance().getLogger(ResourceDictionaryLoadService::class.java)
- open fun loadResourceDictionary(resourceDictionaryPaths: List<String>) {
- resourceDictionaryPaths.forEach { loadResourceDictionary(it) }
+ open fun loadPathsResourceDictionary(paths: List<String>) {
+ paths.forEach { loadPathResourceDictionary(it) }
}
- open fun loadResourceDictionary(resourceDictionaryPath: String) {
+ open fun loadPathResourceDictionary(path: String) {
log.info(" *************************** loadResourceDictionary **********************")
- val resourceDictionaries = File(resourceDictionaryPath).listFiles()
- val errorBuilder = StrBuilder()
-
- resourceDictionaries.forEach { file ->
- try {
- log.trace("Loading NodeType(${file.name}")
- val definitionContent = file.readText(Charset.defaultCharset())
- val resourceDefinition = JacksonUtils.readValue(definitionContent, ResourceDefinition::class.java)
- if (resourceDefinition != null) {
-
- checkNotNull(resourceDefinition.property) { "Failed to get Property Definition" }
- val resourceDictionary = ResourceDictionary()
- resourceDictionary.name = resourceDefinition.name
- resourceDictionary.definition = resourceDefinition
-
- checkNotNull(resourceDefinition.property) { "Property field is missing" }
- resourceDictionary.description = resourceDefinition.property.description
- resourceDictionary.dataType = resourceDefinition.property.type
-
- if (resourceDefinition.property.entrySchema != null) {
- resourceDictionary.entrySchema = resourceDefinition.property.entrySchema!!.type
- }
- resourceDictionary.updatedBy = resourceDefinition.updatedBy
-
- if (StringUtils.isBlank(resourceDefinition.tags)) {
- resourceDictionary.tags = (resourceDefinition.name + ", " + resourceDefinition.updatedBy
- + ", " + resourceDefinition.updatedBy)
-
- } else {
- resourceDictionary.tags = resourceDefinition.tags
- }
- resourceDictionaryService.saveResourceDictionary(resourceDictionary)
-
- log.trace("Resource dictionary(${file.name}) loaded successfully ")
- } else {
- throw BluePrintException("couldn't get dictionary from content information")
+ val files = File(path).listFiles()
+
+ runBlocking {
+ val errorBuilder = StrBuilder()
+ val deferredResults = mutableListOf<Deferred<Unit>>()
+
+ for (file in files) {
+ deferredResults += async {
+ loadResourceDictionary(errorBuilder, file)
}
- } catch (e: Exception) {
- errorBuilder.appendln("Couldn't load Resource dictionary (${file.name}: ${e.message}")
+ }
+
+ 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) {
+ try {
+ log.trace("Loading NodeType(${file.name}")
+ val definitionContent = file.readText(Charset.defaultCharset())
+ val resourceDefinition = JacksonUtils.readValue(definitionContent, ResourceDefinition::class.java)
+ if (resourceDefinition != null) {
+
+ checkNotNull(resourceDefinition.property) { "Failed to get Property Definition" }
+ val resourceDictionary = ResourceDictionary()
+ resourceDictionary.name = resourceDefinition.name
+ resourceDictionary.definition = resourceDefinition
+
+ checkNotNull(resourceDefinition.property) { "Property field is missing" }
+ resourceDictionary.description = resourceDefinition.property.description
+ resourceDictionary.dataType = resourceDefinition.property.type
+
+ if (resourceDefinition.property.entrySchema != null) {
+ resourceDictionary.entrySchema = resourceDefinition.property.entrySchema!!.type
+ }
+ resourceDictionary.updatedBy = resourceDefinition.updatedBy
+
+ if (StringUtils.isBlank(resourceDefinition.tags)) {
+ resourceDictionary.tags = (resourceDefinition.name + ", " + resourceDefinition.updatedBy
+ + ", " + resourceDefinition.updatedBy)
+
+ } else {
+ resourceDictionary.tags = resourceDefinition.tags
+ }
+ resourceDictionaryService.saveResourceDictionary(resourceDictionary)
+
+ log.trace("Resource dictionary(${file.name}) loaded successfully ")
+ } else {
+ throw BluePrintException("couldn't get dictionary from content information")
+ }
+ } catch (e: Exception) {
+ errorBuilder.appendln("Couldn't load Resource dictionary (${file.name}: ${e.message}")
}
}