diff options
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core')
4 files changed, 80 insertions, 16 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt index 462935d6..121dfa26 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/CustomFunctions.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. @@ -20,8 +21,6 @@ import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.node.* import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.slf4j.helpers.MessageFormatter -import java.io.File -import java.io.InputStream import kotlin.reflect.KClass /** @@ -160,9 +159,3 @@ fun returnNotEmptyOrThrow(value: String?, lazyMessage: () -> Any): String { } } -fun InputStream.toFile(path: String): File { - val file = File(path) - file.outputStream().use { this.copyTo(it) } - return file -} - diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt new file mode 100644 index 00000000..a433a31b --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt @@ -0,0 +1,74 @@ +/* + * 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.apps.controllerblueprints.core + +import org.apache.commons.io.FileUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils +import java.io.File +import java.io.InputStream +import java.nio.file.Paths + +fun InputStream.toFile(path: String): File { + val file = File(path) + file.outputStream().use { this.copyTo(it) } + return file +} + +fun File.reCreateDirs(): File { + if (this.exists()) { + this.deleteRecursively() + } + // this.mkdirs() + FileUtils.forceMkdir(this) + check(this.exists()) { + throw BluePrintException("failed to re create dir(${this.absolutePath})") + } + return this +} + +fun File.compress(targetZipFileName: String): File { + return this.compress(Paths.get(targetZipFileName).toFile()) +} + +/** + * Compress the current Dir to the target zip file and return the target zip file + */ +fun File.compress(targetZipFile: File): File { + BluePrintArchiveUtils.compress(this, targetZipFile, true) + return targetZipFile +} + +fun File.deCompress(targetFileName: String): File { + return this.deCompress(Paths.get(targetFileName).toFile()) +} + +/** + * De-Compress the current zip file to the target file and return the target file + */ +fun File.deCompress(targetFile: File): File { + BluePrintArchiveUtils.deCompress(this, targetFile.path) + return targetFile +} + +fun deleteDir(path: String) { + Paths.get(path).toFile().deleteRecursively() +} + + +fun normalizedFile(path: String): File { + return Paths.get(path).toFile().normalize() +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt index f6bde1cc..1176f713 100755 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt @@ -17,12 +17,9 @@ package org.onap.ccsdk.apps.controllerblueprints.core.utils -import kotlinx.coroutines.async -import kotlinx.coroutines.runBlocking import org.apache.commons.compress.archivers.zip.ZipArchiveEntry import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream import org.apache.commons.io.IOUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException import org.slf4j.LoggerFactory import java.io.BufferedInputStream @@ -52,7 +49,7 @@ class BluePrintArchiveUtils { recurseFiles(source, source, it, absolute) } } catch (e: Exception) { - log.error("Fail to compress folder($source) to path(${destination.path}", e) + log.error("Fail to compress folder($source) to path(${destination.path})", e) return false } return true diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt index c34a769e..ce11d97e 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt @@ -21,7 +21,6 @@ package org.onap.ccsdk.apps.controllerblueprints.core.utils import com.att.eelf.configuration.EELFLogger import com.att.eelf.configuration.EELFManager import com.fasterxml.jackson.databind.JsonNode -import org.apache.commons.io.FileUtils import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData @@ -31,6 +30,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeSer import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService import java.io.File import java.nio.charset.Charset +import java.nio.file.Paths import java.util.* class BluePrintMetadataUtils { @@ -73,7 +73,7 @@ class BluePrintMetadataUtils { fun toscaMetaDataFromMetaFile(metaFilePath: String): ToscaMetaData { val toscaMetaData = ToscaMetaData() - val lines: MutableList<String> = FileUtils.readLines(File(metaFilePath), Charset.defaultCharset()) + val lines = Paths.get(metaFilePath).toFile().readLines(Charset.defaultCharset()) lines.forEach { line -> if (line.contains(":")) { val keyValue = line.split(":") @@ -118,8 +118,8 @@ class BluePrintMetadataUtils { fun getBluePrintRuntime(id: String, blueprintBasePath: String, executionContext: MutableMap<String, JsonNode>): BluePrintRuntimeService<MutableMap<String, JsonNode>> { val bluePrintContext: BluePrintContext = getBluePrintContext(blueprintBasePath) val bluePrintRuntimeService = DefaultBluePrintRuntimeService(id, bluePrintContext) - executionContext.forEach{ - bluePrintRuntimeService.put(it.key,it.value) + executionContext.forEach { + bluePrintRuntimeService.put(it.key, it.value) } bluePrintRuntimeService.setExecutionContext(executionContext) |