diff options
Diffstat (limited to 'ms')
12 files changed, 118 insertions, 139 deletions
diff --git a/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintGRPCServer.java b/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintGRPCServer.java index 16eb4182e..6bb6a2697 100644 --- a/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintGRPCServer.java +++ b/ms/blueprintsprocessor/application/src/main/java/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintGRPCServer.java @@ -61,7 +61,7 @@ public class BlueprintGRPCServer implements ApplicationListener<ContextRefreshed log.info("Blueprint Processor GRPC server started and ready to serve on port({})...", server.getPort()); server.awaitTermination(); } catch (Exception e) { - e.printStackTrace(); + log.error("*** Error ***", e); } } } diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt index c45fb881f..fa5d882b0 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt @@ -79,16 +79,8 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic val argsNode = getOptionalOperationInput(INPUT_ARGUMENT_PROPERTIES)?.returnNullIfMissing() // This prevents unescaping values, as well as quoting the each parameter, in order to allow for spaces in values - var args = "" - argsNode?.fields()?.forEach { - if (it.value.isValueNode) { - args = "$args ${it.value}" - } else { - it.value.fields().forEach { item -> - args = "$args ${item.value}" - } - } - } + val args = getOptionalOperationInput(INPUT_ARGUMENT_PROPERTIES)?.returnNullIfMissing() + ?.rootFieldsToMap()?.toSortedMap()?.values?.joinToString(" ") { formatNestedJsonNode(it) } val command = getOperationInput(INPUT_COMMAND).asText() var scriptCommand = command.replace(pythonScript.name, pythonScript.absolutePath) @@ -141,4 +133,14 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic bluePrintRuntimeService.getBluePrintError() .addError("Failed in ComponentJythonExecutor : ${runtimeException.message}") } + + private fun formatNestedJsonNode(node: JsonNode): String { + val sb = StringBuilder() + if (node.isValueNode) { + sb.append(" $node") + } else { + node.forEach { sb.append(" $it") } + } + return sb.toString() + } } diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt index 8ae128d4b..fcf0558c7 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt @@ -44,6 +44,10 @@ open class BluePrintWorkflowExecutionServiceImpl( val workflowName = executionServiceInput.actionIdentifiers.actionName // Assign Workflow inputs + //check if request structure exists + if (!executionServiceInput.payload.has("$workflowName-request")) { + throw BluePrintProcessorException("Input request missing the expected '$workflowName-request' block!") + } val input = executionServiceInput.payload.get("$workflowName-request") bluePrintRuntimeService.assignWorkflowInputs(workflowName, input) @@ -80,4 +84,4 @@ open class BluePrintWorkflowExecutionServiceImpl( return executionServiceOutput } -}
\ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt index 59be9406e..c15c054db 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt @@ -22,6 +22,7 @@ import org.junit.runner.RunWith import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils @@ -29,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.junit4.SpringRunner import kotlin.test.assertEquals +import kotlin.test.assertFailsWith import kotlin.test.assertNotNull @@ -43,18 +45,33 @@ class BluePrintWorkflowExecutionServiceImplTest { fun testBluePrintWorkflowExecutionService() { runBlocking { val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", - "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", - ExecutionServiceInput::class.java)!! - + ExecutionServiceInput::class.java)!! val executionServiceOutput = bluePrintWorkflowExecutionService - .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf()) + .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf()) assertNotNull(executionServiceOutput, "failed to get response") assertEquals(BluePrintConstants.STATUS_SUCCESS, executionServiceOutput.status.message, - "failed to get successful response") + "failed to get successful response") + } + } + + @Test + fun `Blueprint fails on missing workflowName-parameters with a useful message`() { + assertFailsWith(exceptionClass = BluePrintProcessorException::class) { + runBlocking { + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + //service input will have a mislabeled input params, we are expecting to get an error when that happens with a useful error message + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input-missing-resource_assignment_request.json", + ExecutionServiceInput::class.java)!! + + val executionServiceOutput = bluePrintWorkflowExecutionService + .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf()) + } } } diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/execution-input/resource-assignment-input-missing-resource_assignment_request.json b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/execution-input/resource-assignment-input-missing-resource_assignment_request.json new file mode 100644 index 000000000..a44e171a3 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/execution-input/resource-assignment-input-missing-resource_assignment_request.json @@ -0,0 +1,23 @@ +{ + "commonHeader": { + "originatorId": "System", + "requestId": "1234", + "subRequestId": "1234-12234" + }, + "actionIdentifiers": { + "blueprintName": "baseconfiguration", + "blueprintVersion": "1.0.0", + "actionName": "resource-assignment", + "mode": "sync" + }, + "payload": { + "resource-assignment-mislabeled-request": { + "resource-assignment-properties": { + "request-id": "1234", + "action-name": "resource-assignment", + "scope-type": "vnf-type", + "hostname": "localhost" + } + } + } +} diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/cds/controllerblueprints/filters/ApplicationLoggingFilter.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/cds/controllerblueprints/filters/ApplicationLoggingFilter.java deleted file mode 100644 index 60837e8a7..000000000 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/cds/controllerblueprints/filters/ApplicationLoggingFilter.java +++ /dev/null @@ -1,98 +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.cds.controllerblueprints.filters; - -import com.google.common.base.Preconditions; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.MDC; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpHeaders; -import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.web.server.ServerWebExchange; -import org.springframework.web.server.WebFilter; -import org.springframework.web.server.WebFilterChain; -import reactor.core.publisher.Mono; - -import java.time.ZoneOffset; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.UUID; - -/** - * ApplicationLoggingFilter - * - * @author Brinda Santh 8/14/2018 - */ -@Configuration -@SuppressWarnings("unused") -public class ApplicationLoggingFilter implements WebFilter { - private static Logger log = LoggerFactory.getLogger(ApplicationLoggingFilter.class); - - @SuppressWarnings("unused") - @Value("${appVersion}") - private String appVersion; - - @Override - public Mono<Void> filter(ServerWebExchange serverWebExchange, WebFilterChain webFilterChain) { - try { - - ServerHttpRequest request = serverWebExchange.getRequest(); - ServerHttpResponse response = serverWebExchange.getResponse(); - - String[] tokens = StringUtils.split(appVersion, '.'); - Preconditions.checkNotNull(tokens, "failed to split application versions"); - Preconditions.checkArgument(tokens.length == 3, "failed to tokenize application versions"); - HttpHeaders header = response.getHeaders(); - - String requestID = defaultToUUID(request.getHeaders().getFirst("X-ONAP-RequestID")); - String invocationID = defaultToUUID(request.getHeaders().getFirst("X-ONAP-InvocationID")); - String partnerName = defaultToEmpty(request.getHeaders().getFirst("X-ONAP-PartnerName")); - MDC.put("InvokeTimestamp", ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); - MDC.put("RequestID", requestID); - MDC.put("InvocationID", invocationID); - MDC.put("PartnerName", partnerName); - MDC.put("ClientIPAddress", defaultToEmpty(request.getRemoteAddress().getAddress())); - MDC.put("ServerFQDN", defaultToEmpty(request.getRemoteAddress().getHostString())); - - header.add(BluePrintConstants.RESPONSE_HEADER_TRANSACTION_ID, requestID); - header.add(BluePrintConstants.RESPONSE_HEADER_MINOR_VERSION, tokens[1]); - header.add(BluePrintConstants.RESPONSE_HEADER_PATCH_VERSION, tokens[2]); - header.add(BluePrintConstants.RESPONSE_HEADER_LATEST_VERSION, appVersion); - } catch (Exception e) { - e.printStackTrace(); - } - - return webFilterChain.filter(serverWebExchange); - - } - - private static String defaultToUUID(String in) { - return in == null ? UUID.randomUUID().toString() : in; - } - - private static String defaultToEmpty(Object in) { - return in == null ? "" : in.toString(); - } - - -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt index 42ff8827d..4832970f3 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt @@ -147,7 +147,7 @@ fun <T : JsonNode> T?.isNotNull(): Boolean { */ fun JsonNode.rootFieldsToMap(): MutableMap<String, JsonNode> { if (this is ObjectNode) { - val propertyMap: MutableMap<String, JsonNode> = hashMapOf() + val propertyMap: MutableMap<String, JsonNode> = linkedMapOf() this.fields().forEach { propertyMap[it.key] = it.value } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeService.kt index a7ed72dfa..e6f3f71ca 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -382,7 +382,7 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl val nodeTemplate = bluePrintContext.nodeTemplateByName(nodeTemplateName) return nodeTemplate.artifacts?.get(artifactName) - ?: throw BluePrintProcessorException("failed to get artifat definition($artifactName) from the node " + + ?: throw BluePrintProcessorException("failed to get artifact definition($artifactName) from the node " + "template") } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SwaggerGenerator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SwaggerGenerator.java index abf774981..38216a616 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SwaggerGenerator.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SwaggerGenerator.java @@ -155,19 +155,16 @@ public class SwaggerGenerator { defProperty = new StringProperty(); } } else if (BluePrintTypes.validCollectionTypes().contains(propertyDefinition.getType())) { - ArrayProperty arrayProperty = new ArrayProperty(); + Optional<Property> innerType = Optional.empty(); if (propertyDefinition.getEntrySchema() != null) { String entrySchema = propertyDefinition.getEntrySchema().getType(); if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema)) { - Property innerType = new RefProperty("#/definitions/" + entrySchema); - arrayProperty.setItems(innerType); - } else { - Property innerType = new StringProperty(); - arrayProperty.setItems(innerType); + innerType = Optional.of(new RefProperty("#/definitions/" + entrySchema)); } - defProperty = arrayProperty; } - + ArrayProperty arrayProperty = new ArrayProperty(); + arrayProperty.setItems(innerType.orElseGet(StringProperty::new)); + defProperty = arrayProperty; } else { defProperty = new RefProperty("#/definitions/" + propertyDefinition.getType()); } diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java index 148d0c028..77f3ea536 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java @@ -119,7 +119,9 @@ public class ListenerServiceImpl implements ListenerService { File targetZipFile = new File(targetLocation.toString()); try { - targetZipFile.createNewFile(); + if (! targetZipFile.createNewFile()) { + LOGGER.warn("Overwriting zip file {}", targetLocation); + } } catch (IOException e) { LOGGER.error("Could not able to create file {}", targetZipFile, e); } diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessage.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessage.java index 7a959692a..4f31003b0 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessage.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessage.java @@ -21,17 +21,17 @@ import org.onap.sdc.utils.DistributionStatusEnum; public class ComponentStatusMessage implements IComponentDoneStatusMessage, IDistributionStatusMessage { - public String componentName; + private String componentName; - public String consumerID; + private String consumerID; - public String distributionID; + private String distributionID; - public DistributionStatusEnum status; + private DistributionStatusEnum status; - public long timeStamp; + private long timeStamp; - public String artifactUrl; + private String artifactUrl; @Override public String getDistributionID() { @@ -55,11 +55,43 @@ public class ComponentStatusMessage implements IComponentDoneStatusMessage, IDi @Override public String getArtifactURL() { - return artifactUrl; + return getArtifactUrl(); } @Override public long getTimestamp() { + return getTimeStamp(); + } + + public void setComponentName(String componentName) { + this.componentName = componentName; + } + + public void setConsumerID(String consumerID) { + this.consumerID = consumerID; + } + + public void setDistributionID(String distributionID) { + this.distributionID = distributionID; + } + + public void setStatus(DistributionStatusEnum status) { + this.status = status; + } + + public long getTimeStamp() { return timeStamp; } + + public void setTimeStamp(long timeStamp) { + this.timeStamp = timeStamp; + } + + public String getArtifactUrl() { + return artifactUrl; + } + + public void setArtifactUrl(String artifactUrl) { + this.artifactUrl = artifactUrl; + } } diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/SdcListenerStatus.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/SdcListenerStatus.java index 446fdc068..a8e60c29a 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/SdcListenerStatus.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/SdcListenerStatus.java @@ -93,12 +93,12 @@ public class SdcListenerStatus { private ComponentStatusMessage buildStatusMessage(String distributionId, DistributionStatusEnum status, String url, String componentName) { return new BuilderUtil<>(new ComponentStatusMessage()).build(builder -> { - builder.distributionID = distributionId; - builder.status = status; - builder.consumerID = consumerId; - builder.componentName = componentName; - builder.timeStamp = System.currentTimeMillis(); - builder.artifactUrl = url; + builder.setDistributionID(distributionId); + builder.setStatus(status); + builder.setConsumerID(consumerId); + builder.setComponentName(componentName); + builder.setTimeStamp(System.currentTimeMillis()); + builder.setArtifactUrl(url); }).create(); } |