2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.apps.controllerblueprints.service.load
19 import com.att.eelf.configuration.EELFManager
20 import kotlinx.coroutines.Deferred
21 import kotlinx.coroutines.async
22 import kotlinx.coroutines.runBlocking
23 import org.apache.commons.lang3.text.StrBuilder
24 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
25 import org.springframework.stereotype.Service
29 open class BluePrintCatalogLoadService(private val bluePrintCatalogService: BluePrintCatalogService) {
31 private val log = EELFManager.getInstance().getLogger(BluePrintCatalogLoadService::class.java)
33 open fun loadPathsBluePrintModelCatalog(paths: List<String>) {
34 paths.forEach { loadPathBluePrintModelCatalog(it) }
37 open fun loadPathBluePrintModelCatalog(path: String) {
39 val files = File(path).listFiles()
41 val errorBuilder = StrBuilder()
42 val deferredResults = mutableListOf<Deferred<Unit>>()
45 deferredResults += async {
46 loadBluePrintModelCatalog(errorBuilder, file)
50 for (deferredResult in deferredResults) {
51 deferredResult.await()
54 if (!errorBuilder.isEmpty) {
55 log.error(errorBuilder.toString())
60 open fun loadBluePrintModelCatalog(errorBuilder: StrBuilder, file: File) {
62 bluePrintCatalogService.saveToDatabase(file)
63 } catch (e: Exception) {
64 errorBuilder.appendln("Couldn't load BlueprintModel(${file.name}: ${e.message}")