4.0.0
org.onap.ccsdk.cds.components.cba
blueprint-model
1.1.0-SNAPSHOT
test-blueprint-kotlin-parent
pom
Components Model Catalog - Blueprints Model - Test Kotlin Parent
org.onap.ccsdk.cds.blueprintsprocessor.modules
execution-service
org.onap.ccsdk.cds.blueprintsprocessor.functions
resource-resolution
org.onap.ccsdk.cds.blueprintsprocessor.functions
netconf-executor
org.onap.ccsdk.cds.blueprintsprocessor.functions
restconf-executor
org.onap.ccsdk.cds.blueprintsprocessor.functions
cli-executor
org.onap.ccsdk.cds.blueprintsprocessor.functions
message-prioritizaion
org.jetbrains.kotlin
kotlin-test-junit
test
org.jetbrains.kotlinx
kotlinx-coroutines-test
test
junit
junit
4.12
test
io.mockk
mockk
1.10.0
test
com.squareup.okhttp3
okhttp
3.14.0
${project.basedir}/Scripts/kotlin
${project.basedir}/Tests/kotlin
${project.basedir}/Environments
org.jacoco
jacoco-maven-plugin
pre-unit-test
none
default-prepare-agent
none
post-unit-test
none
default-report
none
pre-integration-test
none
post-integration-test
none
default-check
none
org.jetbrains.kotlin
kotlin-maven-plugin
compile
compile
compile
${project.basedir}/Scripts/kotlin
test-compile
test-compile
test-compile
${project.basedir}/Tests/kotlin
org.apache.maven.plugins
maven-site-plugin
attach-descriptor
none
maven-checkstyle-plugin
check-license
none
check-style
none
maven-assembly-plugin
org.onap.ccsdk.cds.components.cba
cba-assembly-descriptor
${ccsdk.cds.version}
*
*
make-assembly
package
single
cba_zip
deploy-cba
org.codehaus.gmaven
groovy-maven-plugin
com.squareup.okhttp3
okhttp
3.14.0
commons-io
commons-io
${commons-io-version}
deploy-cba
install
execute
import okhttp3.Credentials
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody
import org.apache.commons.io.IOUtils
import java.io.File
target = "${basedir.absolutePath}/target"
userName = throwIfPropMissing('cds.username')
password = throwIfPropMissing('cds.password')
protocol = properties['cds.protocol'] ?: 'http'
host = properties['cds.host'] ?: 'localhost'
port = properties['cds.port'] ?: '8081'
def cba = "${project.artifact.artifactId}-${project.artifact.version}-cba.zip"
def enrichedCba = "${project.artifact.artifactId}-${project.artifact.version}-enriched-cba.zip"
def enrichEndpoint = properties['cds.enrich.endpoint'] ?: 'api/v1/blueprint-model/enrich'
def publishEndpoint = properties['cds.publish.endpoint'] ?: 'api/v1/blueprint-model/publish'
def throwIfPropMissing(prop) {
value = properties[prop]
if (!value || "".equals(value)) {
throw new RuntimeException("Property missing: $prop")
}
return value
}
def buildRequest(endpoint, fileName) {
body = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file",
fileName,
RequestBody.create(MediaType.parse('application/zip'), new File(target, fileName)))
.build()
return new Request.Builder()
.url("$protocol://$host:$port/$endpoint")
.addHeader('Authorization', Credentials.basic(userName, password))
.post(body)
.build()
}
def logAndThrow(msg) {
if(response) {
log.error(response.body().string())
}
throw new RuntimeException(msg)
}
response = null
try {
def client = new OkHttpClient()
response = client.newCall(buildRequest(enrichEndpoint, cba)).execute()
if (!response || !response.isSuccessful()) {
logAndThrow("Failed to enrich CBA")
}
IOUtils.copy(
response.body().byteStream(),
new FileOutputStream(new File(target, enrichedCba))
)
log.info("Created enriched cba: $enrichedCba")
response = client.newCall(buildRequest(publishEndpoint, enrichedCba)).execute()
if (!response || !response.isSuccessful()) {
logAndThrow("Failed to publish CBA")
}
log.info("CBA Deployed")
log.info(response.body().string())
} finally {
if (response) {
response.close()
}
}