diff options
author | Singal, Kapil (ks220y) <ks220y@att.com> | 2020-09-22 12:16:46 -0400 |
---|---|---|
committer | Singal, Kapil (ks220y) <ks220y@att.com> | 2020-09-22 13:49:05 -0400 |
commit | 1072867dfac0df993cbd3e44bcc11a5cac7465fd (patch) | |
tree | 4a821659cf3b50cf946cbb535d528be8508e9fff /ms/blueprintsprocessor/functions/k8s-profile-upload | |
parent | d97021cd756d63402545fdc2e14ac7611c3da118 (diff) |
Enabling Code Formatter
Code Formatter was turned off due to java 11 migation
Issue-ID: CCSDK-2852
Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
Change-Id: I3d02ed3cc7a93d7551fe25356512cfe8db1517d8
Diffstat (limited to 'ms/blueprintsprocessor/functions/k8s-profile-upload')
6 files changed, 58 insertions, 32 deletions
diff --git a/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sPluginApi.kt b/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sPluginApi.kt index dab977db0..d00c47b7f 100644 --- a/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sPluginApi.kt +++ b/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sPluginApi.kt @@ -19,13 +19,13 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.profile.upload -import org.springframework.http.HttpMethod import com.fasterxml.jackson.databind.ObjectMapper import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService -import java.nio.file.Path import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.slf4j.LoggerFactory +import org.springframework.http.HttpMethod +import java.nio.file.Path class K8sPluginApi( val username: String, @@ -34,6 +34,7 @@ class K8sPluginApi( val definition: String?, val definitionVersion: String? ) { + private val service: K8sUploadFileRestClientService // BasicAuthRestClientService private val log = LoggerFactory.getLogger(K8sPluginApi::class.java)!! diff --git a/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfile.kt b/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfile.kt index 87836428e..c9ddf4846 100644 --- a/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfile.kt +++ b/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfile.kt @@ -22,12 +22,16 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.profile.upload import com.fasterxml.jackson.annotation.JsonProperty class K8sProfile { + @get:JsonProperty("rb-name") var rbName: String? = null + @get:JsonProperty("rb-version") var rbVersion: String? = null + @get:JsonProperty("profile-name") var profileName: String? = null + @get:JsonProperty("namespace") var namespace: String? = "default" diff --git a/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfileUploadComponent.kt b/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfileUploadComponent.kt index 337104551..6b575a60a 100644 --- a/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfileUploadComponent.kt +++ b/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfileUploadComponent.kt @@ -46,7 +46,6 @@ import java.io.File import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths -import kotlin.collections.ArrayList @Component("component-k8s-profile-upload") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @@ -58,6 +57,7 @@ open class K8sProfileUploadComponent( AbstractComponentFunction() { companion object { + const val INPUT_K8S_PROFILE_NAME = "k8s-rb-profile-name" const val INPUT_K8S_DEFINITION_NAME = "k8s-rb-definition-name" const val INPUT_K8S_DEFINITION_VERSION = "k8s-rb-definition-version" @@ -152,8 +152,10 @@ open class K8sProfileUploadComponent( val bluePrintContext = bluePrintRuntimeService.bluePrintContext() val artifact: ArtifactDefinition = bluePrintContext.nodeTemplateArtifact(nodeTemplateName, profileSource) if (artifact.type != BluePrintConstants.MODEL_TYPE_ARTIFACT_K8S_PROFILE) - throw BluePrintProcessorException("Unexpected profile artifact type for profile source " + - "$profileSource. Expecting: $artifact.type") + throw BluePrintProcessorException( + "Unexpected profile artifact type for profile source " + + "$profileSource. Expecting: $artifact.type" + ) var profile = K8sProfile() profile.profileName = profileName profile.rbName = definitionName @@ -197,7 +199,7 @@ open class K8sProfileUploadComponent( val bluePrintContext = bluePrintRuntimeService.bluePrintContext() val bluePrintBasePath: String = bluePrintContext.rootPath val profileSourceFileFolderPath: String = bluePrintBasePath.plus(File.separator) - .plus(ks8ProfileLocation) + .plus(ks8ProfileLocation) val profileFilePathTarGz: String = profileSourceFileFolderPath.plus(".tar.gz") val profileFilePathTgz: String = profileSourceFileFolderPath.plus(".tgz") @@ -215,26 +217,37 @@ open class K8sProfileUploadComponent( properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = 1 properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY] = false val resolutionResult: Pair<String, JsonNode> = resourceResolutionService.resolveResources( - bluePrintRuntimeService, - nodeTemplateName, - ks8ProfileSource, - properties) + bluePrintRuntimeService, + nodeTemplateName, + ks8ProfileSource, + properties + ) val tempMainPath: File = createTempDir("k8s-profile-", "") val tempProfilePath: File = createTempDir("content-", "", tempMainPath) try { - val manifestFiles: ArrayList<File>? = readManifestFiles(Paths.get(profileSourceFileFolderPath).toFile(), - tempProfilePath) + val manifestFiles: ArrayList<File>? = readManifestFiles( + Paths.get(profileSourceFileFolderPath).toFile(), + tempProfilePath + ) if (manifestFiles != null) { - templateLocation(Paths.get(profileSourceFileFolderPath).toFile(), resolutionResult.second, - tempProfilePath, manifestFiles) + templateLocation( + Paths.get(profileSourceFileFolderPath).toFile(), resolutionResult.second, + tempProfilePath, manifestFiles + ) } else throw BluePrintProcessorException("Manifest file is missing") // Preparation of the final profile content - val finalProfileFilePath = Paths.get(tempMainPath.toString().plus(File.separator).plus( - "$k8sRbProfileName.tar.gz")) - if (!BluePrintArchiveUtils.compress(tempProfilePath, finalProfileFilePath.toFile(), - ArchiveType.TarGz)) { + val finalProfileFilePath = Paths.get( + tempMainPath.toString().plus(File.separator).plus( + "$k8sRbProfileName.tar.gz" + ) + ) + if (!BluePrintArchiveUtils.compress( + tempProfilePath, finalProfileFilePath.toFile(), + ArchiveType.TarGz + ) + ) { throw BluePrintProcessorException("Profile compression has failed") } FileUtils.deleteDirectory(tempProfilePath) @@ -303,8 +316,10 @@ open class K8sProfileUploadComponent( if (location.extension.toLowerCase() == "vtl") { templateFile(location, params, destinationFolder, manifestFiles) } else { - val finalFilePath = Paths.get(destinationFolder.path.plus(File.separator) - .plus(location.name)).toFile() + val finalFilePath = Paths.get( + destinationFolder.path.plus(File.separator) + .plus(location.name) + ).toFile() if (isFileInTheManifestFiles(finalFilePath, manifestFiles)) { if (!destinationFolder.exists()) Files.createDirectories(destinationFolder.toPath()) @@ -328,13 +343,17 @@ open class K8sProfileUploadComponent( destinationFolder: File, manifestFiles: ArrayList<File> ) { - val finalFile = File(destinationFolder.path.plus(File.separator) - .plus(templatedFile.nameWithoutExtension)) + val finalFile = File( + destinationFolder.path.plus(File.separator) + .plus(templatedFile.nameWithoutExtension) + ) if (!isFileInTheManifestFiles(finalFile, manifestFiles)) return val fileContent = templatedFile.bufferedReader().readText() - val finalFileContent = BluePrintVelocityTemplateService.generateContent(fileContent, - params, true) + val finalFileContent = BluePrintVelocityTemplateService.generateContent( + fileContent, + params, true + ) if (!destinationFolder.exists()) Files.createDirectories(destinationFolder.toPath()) finalFile.bufferedWriter().use { out -> out.write(finalFileContent) } diff --git a/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfileUploadConfiguration.kt b/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfileUploadConfiguration.kt index 193fdda6d..542be8cab 100644 --- a/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfileUploadConfiguration.kt +++ b/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfileUploadConfiguration.kt @@ -45,6 +45,7 @@ open class K8sProfileUploadConfiguration(private var bluePrintPropertiesService: class K8sProfileUploadConstants { companion object { + const val PREFIX_K8S_PLUGIN: String = "blueprintprocessor.k8s.plugin" } } diff --git a/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfileUploadProperties.kt b/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfileUploadProperties.kt index b023a5355..ae277e360 100644 --- a/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfileUploadProperties.kt +++ b/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sProfileUploadProperties.kt @@ -18,6 +18,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.profile.upload open class K8sProfileUploadProperties { + var type: String = K8sProfileUploadConstants.PREFIX_K8S_PLUGIN lateinit var url: String lateinit var username: String diff --git a/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sUploadFileRestClientService.kt b/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sUploadFileRestClientService.kt index 2cd87ad20..5e6a6d7c8 100644 --- a/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sUploadFileRestClientService.kt +++ b/ms/blueprintsprocessor/functions/k8s-profile-upload/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/k8s/profile/upload/K8sUploadFileRestClientService.kt @@ -19,21 +19,21 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.k8s.profile.upload -import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.RestLoggerService import org.apache.commons.io.IOUtils +import org.apache.http.client.ClientProtocolException import org.apache.http.client.entity.EntityBuilder -import org.apache.http.message.BasicHeader import org.apache.http.client.methods.HttpPost import org.apache.http.client.methods.HttpUriRequest -import org.apache.http.client.ClientProtocolException -import java.io.IOException -import java.nio.file.Files -import java.nio.file.Path +import org.apache.http.message.BasicHeader +import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.RestLoggerService import org.springframework.http.HttpHeaders import org.springframework.http.MediaType +import java.io.IOException import java.nio.charset.Charset +import java.nio.file.Files +import java.nio.file.Path import java.util.Base64 class K8sUploadFileRestClientService( |