diff options
34 files changed, 964 insertions, 679 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfo.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfo.java index c6e29d05d7..d2b3334c8c 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfo.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfo.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2018 Nokia. + * ================================================================================ * 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. @@ -20,166 +22,78 @@ package org.onap.so.cloudify.beans; -import java.util.HashMap; import java.util.Map; -import org.onap.so.cloudify.v3.model.Deployment; -import org.onap.so.cloudify.v3.model.DeploymentOutputs; -import org.onap.so.cloudify.v3.model.Execution; - /* * This Java bean class relays Heat stack status information to ActiveVOS processes. - * + * * This bean is returned by all Heat-specific adapter operations (create, query, delete) */ -public class DeploymentInfo { - // Set defaults for everything - private String id = ""; - private DeploymentStatus status = DeploymentStatus.NOTFOUND; - private Map<String,Object> outputs = new HashMap<String,Object>(); - private Map<String,Object> inputs = new HashMap<String,Object>(); - private String lastAction; - private String actionStatus; - private String errorMessage; - - public DeploymentInfo () { - } - - public DeploymentInfo (String id, Map<String,Object> outputs) { - this.id = id; - if (outputs != null) this.outputs = outputs; - } - - public DeploymentInfo (String id) { - this.id = id; - } - - public DeploymentInfo (String id, DeploymentStatus status) { - this.id = id; - this.status = status; - } - - public DeploymentInfo (Deployment deployment) { - this(deployment, null, null); - } - - /** - * Construct a DeploymentInfo object from a deployment and the latest Execution action - * @param deployment - * @param execution - */ - public DeploymentInfo (Deployment deployment, DeploymentOutputs outputs, Execution execution) - { - if (deployment == null) { - this.id = null; - return; - } - - this.id = deployment.getId(); - - if (outputs != null) - this.outputs = outputs.getOutputs(); - - if (deployment.getInputs() != null) - this.inputs = deployment.getInputs(); - - if (execution != null) { - this.lastAction = execution.getWorkflowId(); - this.actionStatus = execution.getStatus(); - this.errorMessage = execution.getError(); - - // Compute the status based on the last workflow - if (lastAction.equals("install")) { - if (actionStatus.equals("terminated")) - this.status = DeploymentStatus.INSTALLED; - else if (actionStatus.equals("failed")) - this.status = DeploymentStatus.FAILED; - else if (actionStatus.equals("started") || actionStatus.equals("pending")) - this.status = DeploymentStatus.INSTALLING; - else - this.status = DeploymentStatus.UNKNOWN; - } - else if (lastAction.equals("uninstall")) { - if (actionStatus.equals("terminated")) - this.status = DeploymentStatus.CREATED; - else if (actionStatus.equals("failed")) - this.status = DeploymentStatus.FAILED; - else if (actionStatus.equals("started") || actionStatus.equals("pending")) - this.status = DeploymentStatus.UNINSTALLING; - else - this.status = DeploymentStatus.UNKNOWN; - } - else { - // Could have more cases in the future for different actions. - this.status = DeploymentStatus.UNKNOWN; - } - } - else { - this.status = DeploymentStatus.CREATED; - } - } - - public String getId() { - return id; - } - - public void setId (String id) { - this.id = id; - } - - public DeploymentStatus getStatus() { - return status; - } - - public void setStatus (DeploymentStatus status) { - this.status = status; - } - - public Map<String,Object> getOutputs () { - return outputs; - } - - public void setOutputs (Map<String,Object> outputs) { - this.outputs = outputs; - } - - public Map<String,Object> getInputs () { - return inputs; - } - - public void setInputs (Map<String,Object> inputs) { - this.inputs = inputs; - } - - public String getLastAction() { - return lastAction; - } - - public String getActionStatus() { - return actionStatus; - } - - public String getErrorMessage() { - return errorMessage; - } - - public void saveExecutionStatus (Execution execution) { - this.lastAction = execution.getWorkflowId(); - this.actionStatus = execution.getStatus(); - this.errorMessage = execution.getError(); - } - - @Override +public final class DeploymentInfo { + + private final String id; + private final DeploymentStatus status; + private final Map<String, Object> outputs; + private final Map<String, Object> inputs; + private final String lastAction; + private final String actionStatus; + private final String errorMessage; + + DeploymentInfo(String id, DeploymentStatus deploymentStatus, + Map<String, Object> deploymentOutputs, + Map<String, Object> deploymentInputs, + String lastAction, + String actionStatus, + String errorMessage) { + + this.id = id; + this.status = deploymentStatus; + this.outputs = deploymentOutputs; + this.inputs = deploymentInputs; + this.lastAction = lastAction; + this.actionStatus = actionStatus; + this.errorMessage = errorMessage; + } + + public String getId() { + return id; + } + + public DeploymentStatus getStatus() { + return status; + } + + public Map<String, Object> getOutputs() { + return outputs; + } + + public Map<String, Object> getInputs() { + return inputs; + } + + public String getLastAction() { + return lastAction; + } + + public String getActionStatus() { + return actionStatus; + } + + public String getErrorMessage() { + return errorMessage; + } + + @Override public String toString() { return "DeploymentInfo {" + - "id='" + id + '\'' + - ", inputs='" + inputs + '\'' + - ", outputs='" + outputs + '\'' + - ", lastAction='" + lastAction + '\'' + - ", status='" + status + '\'' + - ", errorMessage='" + errorMessage + '\'' + - '}'; + "id='" + id + '\'' + + ", inputs='" + inputs + '\'' + + ", outputs='" + outputs + '\'' + + ", lastAction='" + lastAction + '\'' + + ", status='" + status + '\'' + + ", errorMessage='" + errorMessage + '\'' + + '}'; } } diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfoBuilder.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfoBuilder.java new file mode 100644 index 0000000000..2e12869c95 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfoBuilder.java @@ -0,0 +1,118 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 Nokia. + * ============================================================================= + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.so.cloudify.beans; + +import java.util.HashMap; +import java.util.Map; +import org.onap.so.cloudify.v3.model.Execution; + +public final class DeploymentInfoBuilder { + + private String id = ""; + private DeploymentStatus deploymentStatus = DeploymentStatus.NOTFOUND; + private Map<String, Object> deploymentOutputs = new HashMap<>(); + private Map<String, Object> deploymentInputs = new HashMap<>(); + private String lastAction; + private String actionStatus; + private String errorMessage; + + public DeploymentInfoBuilder withId(String id) { + this.id = id; + return this; + } + + public DeploymentInfoBuilder withStatus(DeploymentStatus deploymentStatus) { + this.deploymentStatus = deploymentStatus; + return this; + } + + public DeploymentInfoBuilder withDeploymentOutputs(Map<String, Object> deploymentOutputs) { + this.deploymentOutputs = deploymentOutputs; + return this; + } + + public DeploymentInfoBuilder withDeploymentInputs(Map<String, Object> deploymentInputs) { + this.deploymentInputs = deploymentInputs; + return this; + } + + public DeploymentInfoBuilder withLastAction(String lastAction) { + this.lastAction = lastAction; + return this; + } + + public DeploymentInfoBuilder withActionStatus(String actionStatus) { + this.actionStatus = actionStatus; + return this; + } + + public DeploymentInfoBuilder withErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + return this; + } + + public DeploymentInfoBuilder fromExecution(Execution execution) { + if (execution != null) { + this.lastAction = execution.getWorkflowId(); + this.actionStatus = execution.getStatus(); + this.errorMessage = execution.getError(); + + // Compute the status based on the last workflow + if (lastAction.equals("install")) { + if (actionStatus.equals("terminated")) { + this.deploymentStatus = DeploymentStatus.INSTALLED; + } else if (actionStatus.equals("failed")) { + this.deploymentStatus = DeploymentStatus.FAILED; + } else if (actionStatus.equals("started") || actionStatus.equals("pending")) { + this.deploymentStatus = DeploymentStatus.INSTALLING; + } else { + this.deploymentStatus = DeploymentStatus.UNKNOWN; + } + } else if (lastAction.equals("uninstall")) { + if (actionStatus.equals("terminated")) { + this.deploymentStatus = DeploymentStatus.CREATED; + } else if (actionStatus.equals("failed")) { + this.deploymentStatus = DeploymentStatus.FAILED; + } else if (actionStatus.equals("started") || actionStatus.equals("pending")) { + this.deploymentStatus = DeploymentStatus.UNINSTALLING; + } else { + this.deploymentStatus = DeploymentStatus.UNKNOWN; + } + } else { + // Could have more cases in the future for different actions. + this.deploymentStatus = DeploymentStatus.UNKNOWN; + } + } else { + this.deploymentStatus = DeploymentStatus.CREATED; + } + + return this; + } + + public DeploymentInfo build() { + return new DeploymentInfo(id, + deploymentStatus, + deploymentOutputs, + deploymentInputs, + lastAction, + actionStatus, + errorMessage); + } +} diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java index 677f6395ff..85abf9403c 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2018 Nokia. + * ================================================================================ * 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 @@ -20,6 +22,9 @@ package org.onap.so.cloudify.utils; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -30,7 +35,6 @@ import java.util.Map; import java.util.Optional; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; - import org.onap.so.adapters.vdu.CloudInfo; import org.onap.so.adapters.vdu.PluginAction; import org.onap.so.adapters.vdu.VduArtifact; @@ -42,14 +46,13 @@ import org.onap.so.adapters.vdu.VduPlugin; import org.onap.so.adapters.vdu.VduStateType; import org.onap.so.adapters.vdu.VduStatus; import org.onap.so.cloud.CloudConfig; -import org.onap.so.db.catalog.beans.CloudSite; -import org.onap.so.db.catalog.beans.CloudifyManager; import org.onap.so.cloudify.base.client.CloudifyBaseException; import org.onap.so.cloudify.base.client.CloudifyClientTokenProvider; import org.onap.so.cloudify.base.client.CloudifyConnectException; import org.onap.so.cloudify.base.client.CloudifyRequest; import org.onap.so.cloudify.base.client.CloudifyResponseException; import org.onap.so.cloudify.beans.DeploymentInfo; +import org.onap.so.cloudify.beans.DeploymentInfoBuilder; import org.onap.so.cloudify.beans.DeploymentStatus; import org.onap.so.cloudify.exceptions.MsoCloudifyException; import org.onap.so.cloudify.exceptions.MsoCloudifyManagerNotFound; @@ -77,6 +80,8 @@ import org.onap.so.cloudify.v3.model.Executions; import org.onap.so.cloudify.v3.model.OpenstackConfig; import org.onap.so.cloudify.v3.model.StartExecutionParams; import org.onap.so.config.beans.PoConfig; +import org.onap.so.db.catalog.beans.CloudSite; +import org.onap.so.db.catalog.beans.CloudifyManager; import org.onap.so.db.catalog.beans.HeatTemplateParam; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoAlarmLogger; @@ -93,10 +98,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - @Component public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin{ @@ -155,7 +156,6 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin{ * @param inputs A map of key/value inputs * @param pollForCompletion Indicator that polling should be handled in Java vs. in the client * @param timeoutMinutes Timeout after which the "install" will be cancelled - * @param environment An optional yaml-format string to specify environmental parameters * @param backout Flag to delete deployment on install Failure - defaulted to True * @return A DeploymentInfo object * @throws MsoCloudifyException Thrown if the Cloudify API call returns an exception. @@ -256,7 +256,12 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin{ // Success! // Create and return a DeploymentInfo structure. Include the Runtime outputs DeploymentOutputs outputs = getDeploymentOutputs (cloudify, deploymentId); - return new DeploymentInfo (deployment, outputs, installWorkflow); + return new DeploymentInfoBuilder() + .withId(deployment.getId()) + .withDeploymentInputs(deployment.getInputs()) + .withDeploymentOutputs(outputs.getOutputs()) + .fromExecution(installWorkflow) + .build(); } else { // The workflow completed with errors. Must try to back it out. @@ -538,7 +543,6 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin{ * * @param tenantId The Openstack ID of the tenant in which to query * @param cloudSiteId The cloud identifier (may be a region) in which to query - * @param stackName The name of the stack to query (may be simple or canonical) * @return A StackInfo object * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception. */ @@ -556,7 +560,7 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin{ Cloudify cloudify = getCloudifyClient (cloudSite.get()); // Build and send the Cloudify request - Deployment deployment = null; + Deployment deployment = new Deployment(); DeploymentOutputs outputs = null; try { GetDeployment queryDeployment = cloudify.deployments().byId(deploymentId); @@ -573,10 +577,18 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin{ // If no executions, does this give NOT_FOUND or empty set? if (executions.getItems().isEmpty()) { - return new DeploymentInfo (deployment); + return new DeploymentInfoBuilder() + .withId(deployment.getId()) + .withDeploymentInputs(deployment.getInputs()) + .build(); } else { - return new DeploymentInfo (deployment, outputs, executions.getItems().get(0)); + return new DeploymentInfoBuilder() + .withId(deployment.getId()) + .withDeploymentInputs(deployment.getInputs()) + .withDeploymentOutputs(outputs.getOutputs()) + .fromExecution(executions.getItems().get(0)) + .build(); } } catch (CloudifyConnectException ce) { @@ -589,10 +601,14 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin{ // Got a NOT FOUND error. React differently based on deployment vs. execution if (deployment != null) { // Got NOT_FOUND on the executions. Assume this is a valid "empty" set - return new DeploymentInfo (deployment, outputs, null); + return new DeploymentInfoBuilder() + .withId(deployment.getId()) + .withDeploymentInputs(deployment.getInputs()) + .withDeploymentOutputs(outputs.getOutputs()) + .build(); } else { // Deployment not found. Default status of a DeploymentInfo object is NOTFOUND - return new DeploymentInfo (deploymentId); + return new DeploymentInfoBuilder().withId(deploymentId).build(); } } throw new MsoCloudifyException (re.getStatus(), re.getMessage(), re.getLocalizedMessage(), re); @@ -615,8 +631,6 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin{ * * @param tenantId The Openstack ID of the tenant in which to perform the delete * @param cloudSiteId The cloud identifier (may be a region) from which to delete the stack. - * @param stackName The name/id of the stack to delete. May be simple or canonical - * @param pollForCompletion Indicator that polling should be handled in Java vs. in the client * @return A StackInfo object * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception. * @throws MsoCloudSiteNotFound @@ -651,7 +665,10 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin{ // Deployment doesn't exist. Return a "NOTFOUND" DeploymentInfo object // TODO: Should return NULL? LOGGER.debug("Deployment requested for deletion does not exist: " + deploymentId); - return new DeploymentInfo (deploymentId, DeploymentStatus.NOTFOUND); + return new DeploymentInfoBuilder() + .withId(deploymentId) + .withStatus(DeploymentStatus.NOTFOUND) + .build(); } else { // Convert the CloudifyResponseException to an MsoOpenstackException LOGGER.debug("ERROR STATUS = " + e.getStatus() + ",\n" + e.getMessage() + "\n" + e.getLocalizedMessage()); @@ -741,7 +758,12 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin{ } // Return the deleted deployment info (with runtime outputs) along with the completed uninstall workflow status - return new DeploymentInfo (deployment, outputs, uninstallWorkflow); + return new DeploymentInfoBuilder() + .withId(deployment.getId()) + .withDeploymentInputs(deployment.getInputs()) + .withDeploymentOutputs(outputs.getOutputs()) + .fromExecution(uninstallWorkflow) + .build(); } diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/beans/DeploymentInfoBuilderTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/beans/DeploymentInfoBuilderTest.java new file mode 100644 index 0000000000..8f172b79ca --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/beans/DeploymentInfoBuilderTest.java @@ -0,0 +1,168 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 Nokia. + * ============================================================================= + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.so.cloudify.beans; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.common.collect.ImmutableMap; +import org.junit.Test; +import org.onap.so.cloudify.v3.model.Execution; + +public class DeploymentInfoBuilderTest { + + private static final String ERROR_MESSAGE = "something went wrong"; + private static final String INSTALL_WORKFLOW_ID = "install"; + private static final String UNINSTALL_WORKFLOW_ID = "uninstall"; + + @Test + public void shouldConstructDeploymentInfo_withBasicValues() { + DeploymentInfo deploymentInfo = new DeploymentInfoBuilder() + .withId("id") + .withStatus(DeploymentStatus.CREATED) + .withDeploymentOutputs(ImmutableMap.of()) + .withDeploymentInputs(ImmutableMap.of()) + .withActionStatus("started") + .withLastAction(INSTALL_WORKFLOW_ID) + .withErrorMessage(ERROR_MESSAGE) + .build(); + + assertThat(deploymentInfo.getId()).isEqualTo("id"); + assertThat(deploymentInfo.getStatus()).isEqualTo(DeploymentStatus.CREATED); + assertThat(deploymentInfo.getOutputs()).isEqualTo(ImmutableMap.of()); + assertThat(deploymentInfo.getInputs()).isEqualTo(ImmutableMap.of()); + assertThat(deploymentInfo.getActionStatus()).isEqualTo("started"); + assertThat(deploymentInfo.getLastAction()).isEqualTo(INSTALL_WORKFLOW_ID); + assertThat(deploymentInfo.getErrorMessage()).isEqualTo(ERROR_MESSAGE); + } + + @Test + public void shouldConstructDeploymentInfo_withCreateDeploymentStatus_fromNullExecution() { + DeploymentInfo deploymentInfo = new DeploymentInfoBuilder() + .fromExecution(null) + .build(); + + assertThat(deploymentInfo.getStatus()).isEqualTo(DeploymentStatus.CREATED); + } + + @Test + public void shouldConstructDeploymentInfo_withInstalledDeploymentStatus_fromTerminatedExecution() { + String workflowIdLastAction = INSTALL_WORKFLOW_ID; + String status = "terminated"; + DeploymentStatus expectedDeploymentStatus = DeploymentStatus.INSTALLED; + verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); + } + + @Test + public void shouldConstructDeploymentInfo_withFailedDeploymentStatus_fromFailedInstallExecution() { + String workflowIdLastAction = INSTALL_WORKFLOW_ID; + String status = "failed"; + DeploymentStatus expectedDeploymentStatus = DeploymentStatus.FAILED; + verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); + } + + @Test + public void shouldConstructDeploymentInfo_withInstallingDeploymentStatus_fromStartedExecution() { + String workflowIdLastAction = INSTALL_WORKFLOW_ID; + String status = "started"; + DeploymentStatus expectedDeploymentStatus = DeploymentStatus.INSTALLING; + verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); + } + + @Test + public void shouldConstructDeploymentInfo_withInstallingDeploymentStatus_fromPendingExecution() { + String workflowIdLastAction = INSTALL_WORKFLOW_ID; + String status = "pending"; + DeploymentStatus expectedDeploymentStatus = DeploymentStatus.INSTALLING; + verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); + } + + @Test + public void shouldConstructDeploymentInfo_withUnknownDeploymentStatus_fromUnmappableExecution() { + String workflowIdLastAction = INSTALL_WORKFLOW_ID; + String status = "strangeStatus"; + DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNKNOWN; + verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); + } + + @Test + public void shouldConstructDeploymentInfo_withCreatedDeploymentStatus_fromTerminatedExecution() { + String workflowIdLastAction = UNINSTALL_WORKFLOW_ID; + String status = "terminated"; + DeploymentStatus expectedDeploymentStatus = DeploymentStatus.CREATED; + verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); + } + + @Test + public void shouldConstructDeploymentInfo_withFailedDeploymentStatus_fromFailedUninstallExecution() { + String workflowIdLastAction = UNINSTALL_WORKFLOW_ID; + String status = "failed"; + DeploymentStatus expectedDeploymentStatus = DeploymentStatus.FAILED; + verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); + } + + @Test + public void shouldConstructDeploymentInfo_withUninstallingDeploymentStatus_fromStartedUninstallExecution() { + String workflowIdLastAction = UNINSTALL_WORKFLOW_ID; + String status = "started"; + DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNINSTALLING; + verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); + } + + @Test + public void shouldConstructDeploymentInfo_withUninstallingDeploymentStatus_fromPendingUninstallExecution() { + String workflowIdLastAction = UNINSTALL_WORKFLOW_ID; + String status = "pending"; + DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNINSTALLING; + verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); + } + + @Test + public void shouldConstructDeploymentInfo_withUnknownDeploymentStatus_fromUnmappableUninstallExecution() { + String workflowIdLastAction = UNINSTALL_WORKFLOW_ID; + String status = "strangeStatus"; + DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNKNOWN; + verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); + } + + @Test + public void shouldConstructDeploymentInfo_withUnknownDeploymentStatus_forUnknownExecutionWorkflowId() { + String workflowIdLastAction = "strangeWorkflowIdLastAction"; + String status = "strangeStatus"; + DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNKNOWN; + verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); + } + + private void verifyDeploymentInfoConstruction(String workflowIdLastAction, String actionStatus, + DeploymentStatus expectedDeploymentStatus) { + + Execution execution = new Execution(); + execution.setWorkflowId(workflowIdLastAction); + execution.setStatus(actionStatus); + execution.setError(ERROR_MESSAGE); + DeploymentInfo deploymentInfo = new DeploymentInfoBuilder() + .fromExecution(execution) + .build(); + + assertThat(deploymentInfo.getLastAction()).isEqualTo(workflowIdLastAction); + assertThat(deploymentInfo.getActionStatus()).isEqualTo(actionStatus); + assertThat(deploymentInfo.getErrorMessage()).isEqualTo(ERROR_MESSAGE); + assertThat(deploymentInfo.getStatus()).isEqualTo(expectedDeploymentStatus); + } +}
\ No newline at end of file diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/beans/DeploymentInfoTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/beans/DeploymentInfoTest.java deleted file mode 100644 index e200f9aa96..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/beans/DeploymentInfoTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* -* ============LICENSE_START======================================================= - * ONAP : SO - * ================================================================================ - * Copyright (C) 2018 TechMahindra - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= -*/ - -package org.onap.so.cloudify.beans; - -import static org.mockito.Mockito.mock; -import java.util.HashMap; -import java.util.Map; -import org.junit.Test; -import org.mockito.Mock; -import org.onap.so.cloudify.v3.model.Deployment; -import org.onap.so.cloudify.v3.model.DeploymentOutputs; -import org.onap.so.cloudify.v3.model.Execution; -import org.powermock.api.mockito.PowerMockito; - -public class DeploymentInfoTest { - - @Mock - DeploymentStatus status; - - @Mock - DeploymentOutputs out; - - @Mock - Execution execution; - - @Mock - Deployment deployment; - - @Test - public void test() { - Deployment deployment=mock(Deployment.class); - Map<String,Object> dep=new HashMap(); - Map<String,Object> outputs = new HashMap<String,Object>(); - Map<String,Object> inputs = new HashMap<String,Object>(); - inputs.put("id",dep); - status=DeploymentStatus.CREATED; - outputs.put("id", out); - dep.put("id", outputs); - DeploymentInfo dinfo=new DeploymentInfo(deployment); - DeploymentInfo dinfi=new DeploymentInfo("id"); - DeploymentInfo din=new DeploymentInfo("id",outputs); - DeploymentInfo dfo=new DeploymentInfo("id", status); - DeploymentInfo dfoi=new DeploymentInfo(deployment, out, execution); - dinfo=PowerMockito.spy(new DeploymentInfo()); - dinfo.setId("id"); - dinfi.setInputs(inputs); - din.setStatus(status); - din.setOutputs(outputs); - assert(din.toString()!=null); - assert(din.getOutputs().equals(outputs)); - assert(din.getId().equals("id")); - assert(din.getStatus().equals(status)); - din.getLastAction(); - din.getErrorMessage(); - din.getActionStatus(); - } - -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest2.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest2.java index 96202c5122..c7aecd90be 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest2.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest2.java @@ -2,14 +2,16 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2018 Nokia. * ================================================================================ * 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. @@ -17,7 +19,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.onap.so.cloudify.utils; import static com.shazam.shazamcrest.MatcherAssert.assertThat; @@ -42,6 +43,7 @@ import org.onap.so.adapters.vdu.VduModelInfo; import org.onap.so.adapters.vdu.VduStateType; import org.onap.so.adapters.vdu.VduStatus; import org.onap.so.cloud.CloudConfig; +import org.onap.so.cloudify.beans.DeploymentInfoBuilder; import org.onap.so.db.catalog.beans.CloudIdentity; import org.onap.so.db.catalog.beans.CloudSite; import org.onap.so.cloudify.beans.DeploymentInfo; @@ -82,9 +84,10 @@ public class MsoCloudifyUtilsTest2 { List<VduArtifact> artifacts = new ArrayList<>(); artifacts.add(artifact); vduModel.setArtifacts(artifacts); - DeploymentInfo deployment = new DeploymentInfo(); - deployment.setId("id"); - deployment.setStatus(DeploymentStatus.INSTALLED); + DeploymentInfo deployment = new DeploymentInfoBuilder() + .withId("id") + .withStatus(DeploymentStatus.INSTALLED) + .build(); Map<String, byte[]> blueprintFiles = new HashMap<>(); blueprintFiles.put(artifact.getName(), artifact.getContent()); String instanceName = "instanceName"; @@ -118,9 +121,10 @@ public class MsoCloudifyUtilsTest2 { CloudInfo cloudInfo = new CloudInfo(); cloudInfo.setCloudSiteId("cloudSiteId"); cloudInfo.setTenantId("tenantId"); - DeploymentInfo deployment = new DeploymentInfo(); - deployment.setId("id"); - deployment.setStatus(DeploymentStatus.INSTALLED); + DeploymentInfo deployment = new DeploymentInfoBuilder() + .withId("id") + .withStatus(DeploymentStatus.INSTALLED) + .build(); String instanceId = "instanceId"; MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class); @@ -148,14 +152,12 @@ public class MsoCloudifyUtilsTest2 { cloudInfo.setTenantId("tenantId"); String instanceId = "instanceId"; int timeoutMinutes = 1; - DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class); - deployment.setId("id"); - deployment.setStatus(DeploymentStatus.CREATED); - when(deployment.getId()).thenReturn("id"); - when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED); - when(deployment.getLastAction()).thenReturn("deleting"); + DeploymentInfo deploymentInfo = new DeploymentInfoBuilder() + .withId("id") + .withStatus(DeploymentStatus.CREATED) + .withLastAction("deleting").build(); MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class); - doReturn(deployment).when(cloudify).uninstallAndDeleteDeployment(cloudInfo.getCloudSiteId(), + doReturn(deploymentInfo).when(cloudify).uninstallAndDeleteDeployment(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(), instanceId, timeoutMinutes); VduInstance actual = cloudify.deleteVdu(cloudInfo, instanceId, timeoutMinutes); @@ -173,16 +175,14 @@ public class MsoCloudifyUtilsTest2 { status.setLastAction(new PluginAction("deleting", null, null)); expected.setStatus(status); - DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class); - deployment.setId("id"); - deployment.setStatus(DeploymentStatus.CREATED); - when(deployment.getId()).thenReturn("id"); - when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED); - when(deployment.getLastAction()).thenReturn("deleting"); + DeploymentInfo deploymentInfo = new DeploymentInfoBuilder() + .withId("id") + .withStatus(DeploymentStatus.CREATED) + .withLastAction("deleting").build(); MsoCloudifyUtils cloudify = new MsoCloudifyUtils(); - VduInstance actual = cloudify.deploymentInfoToVduInstance(deployment); + VduInstance actual = cloudify.deploymentInfoToVduInstance(deploymentInfo); assertThat(actual, sameBeanAs(expected)); } @@ -193,16 +193,14 @@ public class MsoCloudifyUtilsTest2 { expected.setState(VduStateType.DELETING); expected.setLastAction(new PluginAction("deleting", null, null)); - DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class); - deployment.setId("id"); - deployment.setStatus(DeploymentStatus.CREATED); - when(deployment.getId()).thenReturn("id"); - when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED); - when(deployment.getLastAction()).thenReturn("deleting"); + DeploymentInfo deploymentInfo = new DeploymentInfoBuilder() + .withId("id") + .withStatus(DeploymentStatus.CREATED) + .withLastAction("deleting").build(); MsoCloudifyUtils cloudify = new MsoCloudifyUtils(); - VduStatus actual = cloudify.deploymentStatusToVduStatus(deployment); + VduStatus actual = cloudify.deploymentStatusToVduStatus(deploymentInfo); assertThat(actual, sameBeanAs(expected)); } diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java index 4ec5839cb6..3783a51689 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java @@ -38,6 +38,7 @@ import org.onap.so.db.catalog.beans.VnfComponentsRecipe; import org.onap.so.db.catalog.beans.VnfRecipe; import org.onap.so.db.catalog.beans.VnfResource; import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; @@ -63,6 +64,18 @@ public class CatalogDbClientTest { } @Test + public void testGetRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(){ + RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep("AssignServiceInstanceBB", "*", "*", "*", "*"); + Assert.assertEquals("Rollback", rainyDayHandlerStatus.getPolicy()); + } + + @Test + public void testGetRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStepRecordNotFound(){ + RainyDayHandlerStatus rainyDayHandlerStatus = client.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(UUID.randomUUID().toString(), "*", "*", "*", "*"); + Assert.assertNull(rainyDayHandlerStatus); + } + + @Test public void testGetCloudSiteHappyPath() throws Exception { CloudSite cloudSite = client.getCloudSite(MTN13); Assert.assertNotNull(cloudSite); diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java index f1269f412b..7c037e4885 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java @@ -7,9 +7,9 @@ * 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. @@ -26,6 +26,9 @@ import org.junit.runner.RunWith; import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.beans.OperationStatus; +import org.onap.so.db.request.beans.OperationalEnvDistributionStatus; +import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus; +import org.onap.so.db.request.beans.RequestProcessingData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; @@ -41,6 +44,8 @@ import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertFalse; @RunWith(SpringRunner.class) @SpringBootTest(classes = MSORequestDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -90,6 +95,7 @@ public class RequestsDbClientTest { assertThat(request, sameBeanAs(response).ignoring("operateAt").ignoring("finishedAt")); } + private void verifyInfraActiveRequests(InfraActiveRequests infraActiveRequestsResponse) { assertThat(infraActiveRequestsResponse, sameBeanAs(infraActiveRequests).ignoring("modifyTime").ignoring("log")); } @@ -189,4 +195,37 @@ public class RequestsDbClientTest { assertNull(requestsDbClient.getOneByServiceIdAndOperationId(UUID.randomUUID().toString(),operationStatus.getOperationId())); } + + + @Test + public void getRequestProcessingDataBySoRequestIdTest(){ + List<RequestProcessingData> requestProcessingDataList = requestsDbClient + .getRequestProcessingDataBySoRequestId("00032ab7-na18-42e5-965d-8ea592502018"); + assertNotNull(requestProcessingDataList); + assertFalse(requestProcessingDataList.isEmpty()); + assertEquals(2,requestProcessingDataList.size()); + } + + @Test + public void findOneByOperationalEnvIdAndServiceModelVersionIdTest(){ + OperationalEnvServiceModelStatus operationalEnvServiceModelStatus =requestsDbClient.findOneByOperationalEnvIdAndServiceModelVersionId("1234","TEST1234"); + assertNotNull(operationalEnvServiceModelStatus); + assertEquals("1234",operationalEnvServiceModelStatus.getOperationalEnvId()); + assertEquals("TEST1234",operationalEnvServiceModelStatus.getServiceModelVersionId()); + } + + @Test + public void getAllByOperationalEnvIdAndRequestId(){ + List<OperationalEnvServiceModelStatus> operationalEnvServiceModelStatuses =requestsDbClient.getAllByOperationalEnvIdAndRequestId("1234","00032ab7-3fb3-42e5-965d-8ea592502017"); + assertNotNull(operationalEnvServiceModelStatuses); + assertFalse(operationalEnvServiceModelStatuses.isEmpty()); + assertEquals(2,operationalEnvServiceModelStatuses.size()); + } + + @Test + public void getDistributionStatusByIdTest(){ + OperationalEnvDistributionStatus operationalEnvDistributionStatus =requestsDbClient.getDistributionStatusById("111"); + assertNotNull(operationalEnvDistributionStatus); + assertEquals("111",operationalEnvDistributionStatus.getDistributionId()); + } } diff --git a/adapters/mso-requests-db-adapter/src/test/resources/db/migration/afterMigrate.sql b/adapters/mso-requests-db-adapter/src/test/resources/db/migration/afterMigrate.sql index ae5f5e9124..fcfd1483da 100644 --- a/adapters/mso-requests-db-adapter/src/test/resources/db/migration/afterMigrate.sql +++ b/adapters/mso-requests-db-adapter/src/test/resources/db/migration/afterMigrate.sql @@ -36,3 +36,14 @@ VALUES (1, '00032ab7-na18-42e5-965d-8ea592502018', '7d2e8c07-4d10-456d-bddc-37abf38ca714', 'requestAction', 'assign', 'pincFabricConfigRequest'), (2, '00032ab7-na18-42e5-965d-8ea592502018', '7d2e8c07-4d10-456d-bddc-37abf38ca715', 'configurationId', '52234bc0-d6a6-41d4-a901-79015e4877e2', 'pincFabricConfigRequest'), (3, '5ffbabd6-b793-4377-a1ab-082670fbc7ac', '5ffbabd6-b793-4377-a1ab-082670fbc7ac', 'configId', '52234bc0-d6a6-41d4-a901-79015e4877e2', 'pincFabricConfig'); + +INSERT INTO activate_operational_env_service_model_distribution_status (OPERATIONAL_ENV_ID, SERVICE_MODEL_VERSION_ID, REQUEST_ID,SERVICE_MOD_VER_FINAL_DISTR_STATUS,RECOVERY_ACTION,RETRY_COUNT_LEFT,WORKLOAD_CONTEXT, CREATE_TIME, MODIFY_TIME) +VALUES +('1234', 'TEST1234', '00032ab7-3fb3-42e5-965d-8ea592502017', "Test", "Test", 1, 'DEFAULT', '2018-08-14 16:50:59', '2018-08-14 16:50:59'); +INSERT INTO activate_operational_env_service_model_distribution_status (OPERATIONAL_ENV_ID, SERVICE_MODEL_VERSION_ID, REQUEST_ID,SERVICE_MOD_VER_FINAL_DISTR_STATUS,RECOVERY_ACTION,RETRY_COUNT_LEFT,WORKLOAD_CONTEXT, CREATE_TIME, MODIFY_TIME) +VALUES +('1234', 'TEST1235', '00032ab7-3fb3-42e5-965d-8ea592502017', "Test", "Test", 2, 'DEFAULT', '2018-08-14 16:50:59', '2018-08-14 16:50:59'); + +INSERT INTO `activate_operational_env_per_distributionid_status` (`DISTRIBUTION_ID`, `DISTRIBUTION_ID_STATUS`, `DISTRIBUTION_ID_ERROR_REASON`, `CREATE_TIME`, `MODIFY_TIME`, `OPERATIONAL_ENV_ID`, `SERVICE_MODEL_VERSION_ID`, `REQUEST_ID`) +VALUES +('111', 'TEST', 'ERROR', '2018-09-12 19:29:24', '2018-09-12 19:29:25', '1234', 'TEST1234', '00032ab7-3fb3-42e5-965d-8ea592502017');
\ No newline at end of file diff --git a/asdc-controller/pom.xml b/asdc-controller/pom.xml index b5cb596ea0..9ea397701c 100644 --- a/asdc-controller/pom.xml +++ b/asdc-controller/pom.xml @@ -196,12 +196,12 @@ <dependency> <groupId>org.onap.sdc.sdc-tosca</groupId> <artifactId>sdc-tosca</artifactId> - <version>1.4.1</version> + <version>1.4.4</version> </dependency> <dependency> <groupId>org.onap.sdc.jtosca</groupId> <artifactId>jtosca</artifactId> - <version>1.4.1</version> + <version>1.4.4</version> </dependency> <dependency> <groupId>org.onap.so</groupId> diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java index 970cb0bf50..f77a48a1f8 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java @@ -488,21 +488,24 @@ public class ToscaResourceInstaller { .getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID); IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata(); - logger.debug("Comparing VFModuleMetadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID()); + logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID()); Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream() .peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID " + group.getMetadata().getValue("vfModuleModelCustomizationUUID"))) - .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID())). - findFirst(); + .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID())) + .findFirst(); if(matchingObject.isPresent()){ VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct, vfResourceStructure,vfMetadata, vnfResource, service, existingCvnfcSet, existingVnfcSet); vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources()); }else - throw new Exception("Cannot find matching VFModule Customization for VF Module Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID()); + throw new Exception("Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID()); } service.getVnfCustomizations().add(vnfResource); + } else{ + logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " + + "Tosca VF Customization UUID: " + vfCustomizationUUID); } } } @@ -1150,7 +1153,7 @@ public class ToscaResourceInstaller { vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); - vfcInstanceGroup.setToscaNodeType(group.getType()); + vfcInstanceGroup.setToscaNodeType(group.getType()); vfcInstanceGroup.setRole("SUB-INTERFACE"); // Set Role vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type @@ -1201,7 +1204,7 @@ public class ToscaResourceInstaller { if(vfModule==null) vfModule=createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata); - vfModuleCustomization = createVfModuleCustomzation(group, toscaResourceStructure, vfModule, vfModuleData); + vfModuleCustomization = createVfModuleCustomization(group, toscaResourceStructure, vfModule, vfModuleData); setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization, vfMetadata); vfModuleCustomization.setVfModule(vfModule); @@ -1416,7 +1419,7 @@ public class ToscaResourceInstaller { return vfModule; } - protected VfModuleCustomization createVfModuleCustomzation(Group group, + protected VfModuleCustomization createVfModuleCustomization(Group group, ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) { VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); @@ -1691,6 +1694,8 @@ public class ToscaResourceInstaller { testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES))); vnfResource.setAicVersionMin( testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES))); + vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY)); + vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)); return vnfResource; } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java b/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java index ab9c359b7f..9df9ffc7af 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java @@ -203,11 +203,11 @@ public class ASDCNotificationLogging { List<NodeTemplate> vfNodeTemplatesList = toscaResourceStructure.getSdcCsarHelper().getServiceVfList(); for (NodeTemplate vfNodeTemplate : vfNodeTemplatesList) { - + + buffer.append(System.lineSeparator()); buffer.append(System.lineSeparator()); buffer.append("VNF Properties:"); - buffer.append(System.lineSeparator()); - + buffer.append(System.lineSeparator()); buffer.append("Model Name:"); buffer.append(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); buffer.append(System.lineSeparator()); @@ -262,6 +262,7 @@ public class ASDCNotificationLogging { for (Group group : groupList) { Metadata instanceMetadata = group.getMetadata(); + buffer.append(System.lineSeparator()); buffer.append(System.lineSeparator()); buffer.append("VNFC Instance Group Properties:"); buffer.append(System.lineSeparator()); @@ -277,18 +278,19 @@ public class ASDCNotificationLogging { buffer.append(System.lineSeparator()); buffer.append("InvariantUuid:"); buffer.append(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - buffer.append(System.lineSeparator()); + buffer.append(System.lineSeparator()); } } - + List<Group> vfGroups = toscaResourceStructure.getSdcCsarHelper().getVfModulesByVf(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))); for(Group group : vfGroups){ Metadata vfMetadata = group.getMetadata(); + buffer.append(System.lineSeparator()); buffer.append(System.lineSeparator()); buffer.append("VF Module Properties:"); buffer.append(System.lineSeparator()); @@ -306,13 +308,14 @@ public class ASDCNotificationLogging { buffer.append(System.lineSeparator()); buffer.append("Description:"); buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); - buffer.append(System.lineSeparator()); + buffer.append(System.lineSeparator()); } List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(vfNodeTemplate, SdcTypes.CVFC); for(NodeTemplate cvfcTemplate : cvfcList) { + buffer.append(System.lineSeparator()); buffer.append(System.lineSeparator()); buffer.append("CVNFC Properties:"); buffer.append(System.lineSeparator()); @@ -339,6 +342,7 @@ public class ASDCNotificationLogging { List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC); for(NodeTemplate vfcTemplate : vfcList) { + buffer.append(System.lineSeparator()); buffer.append(System.lineSeparator()); buffer.append("VNFC Properties:"); buffer.append(System.lineSeparator()); @@ -370,13 +374,13 @@ public class ASDCNotificationLogging { List<NodeTemplate> nodeTemplatesVLList = toscaResourceStructure.getSdcCsarHelper().getServiceVlList(); if(nodeTemplatesVLList != null){ - - buffer.append(System.lineSeparator()); - buffer.append("NETWORK Level Properties:"); - buffer.append(System.lineSeparator()); - + for(NodeTemplate vlNode : nodeTemplatesVLList){ + buffer.append(System.lineSeparator()); + buffer.append(System.lineSeparator()); + buffer.append("NETWORK Level Properties:"); + buffer.append(System.lineSeparator()); buffer.append("Model Name:"); buffer.append(testNull(vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); buffer.append(System.lineSeparator()); @@ -414,6 +418,7 @@ public class ASDCNotificationLogging { if (networkCollectionList != null) { for (NodeTemplate crNode : networkCollectionList) { + buffer.append(System.lineSeparator()); buffer.append("Model Name:"); buffer.append(crNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); buffer.append(System.lineSeparator()); @@ -448,6 +453,7 @@ public class ASDCNotificationLogging { Metadata vlMetadata = vlNodeTemplate.getMetaData(); + buffer.append(System.lineSeparator()); buffer.append(System.lineSeparator()); buffer.append("Network CR VL Properties:"); buffer.append(System.lineSeparator()); @@ -481,7 +487,8 @@ public class ASDCNotificationLogging { if(groupList != null){ for (Group group : groupList) { Metadata instanceMetadata = group.getMetadata(); - buffer.append(System.lineSeparator()); + buffer.append(System.lineSeparator()); + buffer.append(System.lineSeparator()); buffer.append("Network Instance Group Properties:"); buffer.append(System.lineSeparator()); diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/util/YamlEditor.java b/asdc-controller/src/main/java/org/onap/so/asdc/util/YamlEditor.java index 32f512b0f0..3418ee3295 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/util/YamlEditor.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/util/YamlEditor.java @@ -50,6 +50,10 @@ public class YamlEditor { public YamlEditor (byte[] body) { init (body); } + + public YamlEditor (Yaml yaml) { + this.yaml = yaml; + } @SuppressWarnings("unchecked") protected synchronized void init (byte[] body) { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java index 7a56ab88ab..70d523eab4 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildingBlockRainyDay.java @@ -42,7 +42,7 @@ public class ExecuteBuildingBlockRainyDay { @Autowired private CatalogDbClient catalogDbClient; - private static final String ASTERISK = "ASTERISK"; + private static final String ASTERISK = "*"; public void setRetryTimer(DelegateExecution execution) { try { diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java index 2144f1c69a..0c2a95f5d1 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java @@ -53,6 +53,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { private GenericVnf vnf; private BuildingBlock buildingBlock; private ExecuteBuildingBlock executeBuildingBlock; + private static final String ASTERISK = "*"; @Before public void before() { @@ -99,7 +100,7 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { rainyDayHandlerStatus.setServiceType("st1"); rainyDayHandlerStatus.setVnfType("vnft1"); rainyDayHandlerStatus.setPolicy("Rollback"); - rainyDayHandlerStatus.setWorkStep("ASTERISK"); + rainyDayHandlerStatus.setWorkStep(ASTERISK); doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep("AssignServiceInstanceBB", "st1", "vnft1", "7000", "*"); @@ -115,15 +116,15 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { vnf.setVnfType("vnft1"); RainyDayHandlerStatus rainyDayHandlerStatus = new RainyDayHandlerStatus(); - rainyDayHandlerStatus.setErrorCode("ASTERISK"); + rainyDayHandlerStatus.setErrorCode(ASTERISK); rainyDayHandlerStatus.setFlowName("AssignServiceInstanceBB"); - rainyDayHandlerStatus.setServiceType("ASTERISK"); - rainyDayHandlerStatus.setVnfType("ASTERISK"); + rainyDayHandlerStatus.setServiceType(ASTERISK); + rainyDayHandlerStatus.setVnfType(ASTERISK); rainyDayHandlerStatus.setPolicy("Rollback"); - rainyDayHandlerStatus.setWorkStep("ASTERISK"); + rainyDayHandlerStatus.setWorkStep(ASTERISK); - doReturn(null).when(MOCK_catalogDbClient).getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep("AssignServiceInstanceBB", "st1", "vnft1", "7000", "ASTERISK"); - doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep("AssignServiceInstanceBB", "ASTERISK", "ASTERISK", "ASTERISK", "ASTERISK"); + doReturn(null).when(MOCK_catalogDbClient).getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep("AssignServiceInstanceBB", "st1", "vnft1", "7000", ASTERISK); + doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep("AssignServiceInstanceBB", ASTERISK, ASTERISK, ASTERISK, ASTERISK); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution); diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ActivateSDNCNetworkResource.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ActivateSDNCNetworkResource.bpmn index e3b5e7997e..fe2c8928d8 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ActivateSDNCNetworkResource.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ActivateSDNCNetworkResource.bpmn @@ -171,4 +171,4 @@ dcsi.prepareSDNCRequest(execution)</bpmn:script> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> -</bpmn:definitions>
\ No newline at end of file +</bpmn:definitions> diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateVcpeResCustService_simplified.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateVcpeResCustService_simplified.bpmn index f975ffbcd6..3b1c56628e 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateVcpeResCustService_simplified.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateVcpeResCustService_simplified.bpmn @@ -4,7 +4,7 @@ <bpmn2:scriptTask id="sendSyncAckResponse_ScriptTask" name="Send Sync Ack Response" scriptFormat="groovy"> <bpmn2:incoming>SequenceFlow_7</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_3</bpmn2:outgoing> - <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.vcpe.scripts.* + <bpmn2:script><![CDATA[import org.onap.so.bpmn.vcpe.scripts.* def CreateVcpeResCustService = new CreateVcpeResCustService() CreateVcpeResCustService.sendSyncResponse(execution)]]></bpmn2:script> </bpmn2:scriptTask> @@ -16,7 +16,7 @@ CreateVcpeResCustService.sendSyncResponse(execution)]]></bpmn2:script> <bpmn2:scriptTask id="preProcessRequest_ScriptTask" name="PreProcess Incoming Request" scriptFormat="groovy"> <bpmn2:incoming>SequenceFlow_1</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_7</bpmn2:outgoing> - <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.vcpe.scripts.* + <bpmn2:script><![CDATA[import org.onap.so.bpmn.vcpe.scripts.* def CreateVcpeResCustService = new CreateVcpeResCustService() CreateVcpeResCustService.preProcessRequest(execution) ]]></bpmn2:script> @@ -29,7 +29,7 @@ CreateVcpeResCustService.preProcessRequest(execution) <bpmn2:scriptTask id="postProcessAndCompletionRequest_ScriptTask" name="Post Process & Completion Request" scriptFormat="groovy"> <bpmn2:incoming>SequenceFlow_0afe2pg</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_29</bpmn2:outgoing> - <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.vcpe.scripts.* + <bpmn2:script><![CDATA[import org.onap.so.bpmn.vcpe.scripts.* def CreateVcpeResCustService = new CreateVcpeResCustService() CreateVcpeResCustService.postProcessResponse(execution)]]></bpmn2:script> </bpmn2:scriptTask> @@ -72,7 +72,7 @@ execution.setVariable("CreateVcpeResCustServiceSuccessIndicator", true)]]></bpmn <bpmn2:scriptTask id="ScriptTask_1" name="Log / Print Unexpected Error" scriptFormat="groovy"> <bpmn2:incoming>SequenceFlow_2</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_5</bpmn2:outgoing> - <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.common.scripts.* + <bpmn2:script><![CDATA[import org.onap.so.bpmn.common.scripts.* ExceptionUtil ex = new ExceptionUtil() ex.processJavaException(execution)]]></bpmn2:script> </bpmn2:scriptTask> @@ -124,7 +124,7 @@ ex.processJavaException(execution)]]></bpmn2:script> <bpmn2:scriptTask id="ScriptTask_0yk02h3" name="Prepare FalloutHandler" scriptFormat="groovy"> <bpmn2:incoming>SequenceFlow_0jg47xm</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_0807ukc</bpmn2:outgoing> - <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.vcpe.scripts.* + <bpmn2:script><![CDATA[import org.onap.so.bpmn.vcpe.scripts.* def CreateVcpeResCustService = new CreateVcpeResCustService() CreateVcpeResCustService.prepareFalloutRequest(execution)]]></bpmn2:script> </bpmn2:scriptTask> @@ -176,14 +176,14 @@ CreateVcpeResCustService.prepareFalloutRequest(execution)]]></bpmn2:script> <bpmn2:scriptTask id="ScriptTask_17doerz" name="Pre Process Rollback" scriptFormat="groovy"> <bpmn2:incoming>SequenceFlow_02o4yqx</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_0ftzjjm</bpmn2:outgoing> - <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.vcpe.scripts.* + <bpmn2:script><![CDATA[import org.onap.so.bpmn.vcpe.scripts.* def CreateVcpeResCustService= new CreateVcpeResCustService() CreateVcpeResCustService.preProcessRollback(execution)]]></bpmn2:script> </bpmn2:scriptTask> <bpmn2:scriptTask id="ScriptTask_0wyub4x" name="Post Process Rollback" scriptFormat="groovy"> <bpmn2:incoming>SequenceFlow_0dvsqpp</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_1rabks0</bpmn2:outgoing> - <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.vcpe.scripts.* + <bpmn2:script><![CDATA[import org.onap.so.bpmn.vcpe.scripts.* def CreateVcpeResCustService= new CreateVcpeResCustService() CreateVcpeResCustService.postProcessRollback(execution)]]></bpmn2:script> </bpmn2:scriptTask> @@ -332,7 +332,7 @@ CreateVcpeResCustService.postProcessRollback(execution)]]></bpmn2:script> <bpmn2:scriptTask id="ScriptTask_0cdtchu" name="Prepare Decompose Service " scriptFormat="groovy"> <bpmn2:incoming>SequenceFlow_1eu60rt</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_00h6hmd</bpmn2:outgoing> - <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.vcpe.scripts.* + <bpmn2:script><![CDATA[import org.onap.so.bpmn.vcpe.scripts.* def CreateVcpeResCustService = new CreateVcpeResCustService() CreateVcpeResCustService.prepareDecomposeService(execution)]]></bpmn2:script> </bpmn2:scriptTask> @@ -350,7 +350,7 @@ CreateVcpeResCustService.prepareDecomposeService(execution)]]></bpmn2:script> <bpmn2:scriptTask id="ScriptTask_0lpv2da" name="PostProcess Decompose Service " scriptFormat="groovy"> <bpmn2:incoming>SequenceFlow_17g05fd</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_11efpvh</bpmn2:outgoing> - <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.vcpe.scripts.* + <bpmn2:script><![CDATA[import org.onap.so.bpmn.vcpe.scripts.* def CreateVcpeResCustService = new CreateVcpeResCustService() CreateVcpeResCustService.processDecomposition(execution)]]></bpmn2:script> </bpmn2:scriptTask> diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeActivateSDNCNetworkResource.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeActivateSDNCNetworkResource.bpmn index 09d8e35258..eaf37191d5 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeActivateSDNCNetworkResource.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeActivateSDNCNetworkResource.bpmn @@ -180,4 +180,4 @@ csi.sendSyncResponse(execution)</bpmn:script> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> -</bpmn:definitions>
\ No newline at end of file +</bpmn:definitions> diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeleteSDNCNetworkResource.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeleteSDNCNetworkResource.bpmn index da17fee16e..80fcc1762e 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeleteSDNCNetworkResource.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeleteSDNCNetworkResource.bpmn @@ -296,4 +296,4 @@ dcsi.prepareUpdateAfterDeleteSDNCResource(execution)</bpmn:script> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> -</bpmn:definitions>
\ No newline at end of file +</bpmn:definitions> diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasks.java index 39f4c7822a..5f263e8b4b 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasks.java @@ -7,9 +7,9 @@ * 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. @@ -73,7 +73,7 @@ public class SDNCAssignTasks { public void assignVnf(BuildingBlockExecution execution) { try { - GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); + GeneralBuildingBlock gBBInput = execution.getVariable("generalBuildingBlock"); RequestContext requestContext = gBBInput.getRequestContext(); ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); @@ -85,7 +85,7 @@ public class SDNCAssignTasks { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } } - + public void assignVfModule(BuildingBlockExecution execution) { try { GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); @@ -101,14 +101,14 @@ public class SDNCAssignTasks { } Customer customer = gBBInput.getCustomer(); CloudRegion cloudRegion = gBBInput.getCloudRegion(); - - String response = sdncVfModuleResources.assignVfModule(vfModule, volumeGroup, vnf, serviceInstance, customer, cloudRegion, requestContext); + + String response = sdncVfModuleResources.assignVfModule(vfModule, volumeGroup, vnf, serviceInstance, customer, cloudRegion, requestContext); execution.setVariable("SDNCAssignResponse_"+ vfModule.getVfModuleId(), response); - } catch (Exception ex) { + } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } } - + /** * BPMN access method to perform Assign action on SDNC for L3Network * @param execution @@ -117,14 +117,14 @@ public class SDNCAssignTasks { public void assignNetwork(BuildingBlockExecution execution) { try { GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); - + L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID)); ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); - + Customer customer = gBBInput.getCustomer(); RequestContext requestContext = gBBInput.getRequestContext(); CloudRegion cloudRegion = gBBInput.getCloudRegion(); - + sdncNetworkResources.assignNetwork(l3network, serviceInstance, customer, requestContext, cloudRegion); } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java index 9e4b01eea5..d3f817c2a5 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java @@ -221,7 +221,7 @@ public class WorkflowActionBBTasks { } public void checkRetryStatus(DelegateExecution execution) { - if (execution.getVariable("handlingCode") == "Retry") { + if (execution.getVariable("handlingCode").equals("Retry")) { int currSequence = (int) execution.getVariable("gCurrentSequence"); currSequence--; execution.setVariable("gCurrentSequence", currSequence); @@ -239,8 +239,9 @@ public class WorkflowActionBBTasks { List<ExecuteBuildingBlock> flowsToExecute = (List<ExecuteBuildingBlock>) execution .getVariable("flowsToExecute"); List<ExecuteBuildingBlock> rollbackFlows = new ArrayList(); - int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE) - 1; - for (int i = flowsToExecute.size() - 1; i >= 0; i--) { + int currentSequence = (int) execution.getVariable(G_CURRENT_SEQUENCE) + 1; + int listSize = flowsToExecute.size(); + for (int i = listSize - 1; i >= 0; i--) { if (i >= currentSequence) { flowsToExecute.remove(i); } else { @@ -248,11 +249,13 @@ public class WorkflowActionBBTasks { BuildingBlock bb = flowsToExecute.get(i).getBuildingBlock(); String flowName = flowsToExecute.get(i).getBuildingBlock().getBpmnFlowName(); if (flowName.contains("Assign")) { - flowName = "Unassign" + flowName.substring(7, flowName.length()); + flowName = "Unassign" + flowName.substring(6, flowName.length()); } else if (flowName.contains("Create")) { flowName = "Delete" + flowName.substring(6, flowName.length()); } else if (flowName.contains("Activate")) { flowName = "Deactivate" + flowName.substring(8, flowName.length()); + }else{ + continue; } flowsToExecute.get(i).getBuildingBlock().setBpmnFlowName(flowName); rollbackFlows.add(flowsToExecute.get(i)); @@ -262,7 +265,6 @@ public class WorkflowActionBBTasks { execution.setVariable("isRollbackNeeded", false); else execution.setVariable("isRollbackNeeded", true); - execution.setVariable("flowsToExecute", rollbackFlows); execution.setVariable("handlingCode", "PreformingRollback"); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SdnCommonTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SdnCommonTasks.java index aefb84c606..ee1d432b6f 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SdnCommonTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SdnCommonTasks.java @@ -26,21 +26,14 @@ import java.util.List; import org.apache.commons.lang.StringUtils; import org.apache.http.HttpStatus; -import org.json.JSONObject; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.MapperException; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; -import org.onap.so.logging.jaxrs.filter.SpringClientFilter; -import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.http.client.BufferingClientHttpRequestFactory; -import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; -import org.springframework.web.client.RestTemplate; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; @@ -99,24 +92,32 @@ public class SdnCommonTasks { * @return * @throws BadResponseException */ - public String validateSDNResponse(LinkedHashMap<?, ?> output) throws BadResponseException { - if (CollectionUtils.isEmpty(output)) { - msoLogger.error(MessageEnum.RA_RESPONSE_FROM_SDNC, NO_RESPONSE_FROM_SDNC, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, NO_RESPONSE_FROM_SDNC); - throw new BadResponseException(NO_RESPONSE_FROM_SDNC); + public String validateSDNResponse(LinkedHashMap<?, ?> output) throws BadResponseException { + if (CollectionUtils.isEmpty(output)) { + msoLogger.error(MessageEnum.RA_RESPONSE_FROM_SDNC, NO_RESPONSE_FROM_SDNC, "BPMN", + MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, NO_RESPONSE_FROM_SDNC); + throw new BadResponseException(NO_RESPONSE_FROM_SDNC); + } + LinkedHashMap<?, ?> embeddedResponse =(LinkedHashMap<?, ?>) output.get("output"); + String responseCode = ""; + String responseMessage = ""; + if (embeddedResponse != null) { + responseCode = (String) embeddedResponse.get(RESPONSE_CODE); + responseMessage = (String) embeddedResponse.get(RESPONSE_MESSAGE); } - String responseCode = (String) output.get(RESPONSE_CODE); - String responseMessage = (String) output.get(RESPONSE_MESSAGE); - msoLogger.info("ResponseCode: " + responseCode + " ResponseMessage: " + responseMessage); - int code = StringUtils.isNotEmpty(responseCode) ? Integer.parseInt(responseCode) : 0; - if (isHttpCodeSuccess(code)) { - msoLogger.info("Successful Response from SDNC"); - return responseMessage; - } else { - String errorMessage = String.format(SDNC_CODE_NOT_0_OR_IN_200_299, responseMessage); - msoLogger.error(MessageEnum.RA_RESPONSE_FROM_SDNC, errorMessage, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.DataError, errorMessage); - throw new BadResponseException(errorMessage); - } - } + + msoLogger.info("ResponseCode: " + responseCode + " ResponseMessage: " + responseMessage); + int code = StringUtils.isNotEmpty(responseCode) ? Integer.parseInt(responseCode) : 0; + if (isHttpCodeSuccess(code)) { + msoLogger.info("Successful Response from SDNC"); + return responseMessage; + } else { + String errorMessage = String.format(SDNC_CODE_NOT_0_OR_IN_200_299, responseMessage); + msoLogger.error(MessageEnum.RA_RESPONSE_FROM_SDNC, errorMessage, "BPMN", MsoLogger.getServiceName(), + MsoLogger.ErrorCode.DataError, errorMessage); + throw new BadResponseException(errorMessage); + } + } /*** * diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java index fb9533091b..b5bb0bed94 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java @@ -7,9 +7,9 @@ * 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. @@ -58,6 +58,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding; import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink; import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.License; import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; @@ -88,20 +89,20 @@ public class TestDataSetup{ private int volumeGroupCounter; private int vpnBindingCounter; private int vpnBondingLinkCounter; - + protected BuildingBlockExecution execution; - + protected GeneralBuildingBlock gBBInput; - + protected HashMap<ResourceKey, String> lookupKeyMap; - + protected ExtractPojosForBB extractPojosForBB = new ExtractPojosForBB(); - + @Rule public ExpectedException expectedException = ExpectedException.none(); - + protected DelegateExecution delegateExecution; - + @Before public void buildingBlockTestDataSetupBefore() { collectionCounter = 0; @@ -120,183 +121,183 @@ public class TestDataSetup{ volumeGroupCounter = 0; vpnBindingCounter = 0; vpnBondingLinkCounter = 0; - + execution = new DelegateExecutionImpl(new ExecutionImpl()); execution.setVariable("testProcessKey", "testProcessKeyValue"); - + gBBInput = new GeneralBuildingBlock(); execution.setVariable("gBBInput", gBBInput); - + lookupKeyMap = new HashMap<ResourceKey, String>(); execution.setVariable("lookupKeyMap", lookupKeyMap); - + ExecutionImpl mockExecutionImpl = mock(ExecutionImpl.class); doReturn("test").when(mockExecutionImpl).getProcessInstanceId(); - + ExecutionImpl executionImpl = new ExecutionImpl(); executionImpl.setProcessInstance(mockExecutionImpl); - + delegateExecution = (DelegateExecution) executionImpl; delegateExecution.setVariable("testProcessKey", "testProcessKeyValue"); } - + public Map<String, String> buildUserInput() { Map<String, String> userInput = new HashMap<>(); userInput.put("testUserInputKey", "testUserInputValue"); - + return userInput; } - + public Map<String, String> setUserInput() { Map<String, String> userInput = buildUserInput(); - + gBBInput.setUserInput(userInput); - + return userInput; } - + public RequestContext buildRequestContext() { RequestContext requestContext = new RequestContext(); requestContext.setMsoRequestId(UUID.randomUUID().toString()); requestContext.setProductFamilyId("testProductFamilyId"); requestContext.setRequestorId("testRequestorId"); - + requestContext.setUserParams(new HashMap<>()); - + Map<String,Object> dataMap = new HashMap<>(); dataMap.put("vpnId","testVpnId"); dataMap.put("vpnRegion","testVpnRegion"); dataMap.put("vpnRt","testVpnRt"); dataMap.put("vpnName","vpnName"); dataMap.put("vpnRegion", Arrays.asList(new String[] {"USA", "EMEA", "APAC"})); - + HashMap<String,Object> userParams = new HashMap<>(); userParams.put("vpnData",dataMap); - + List<Map<String,Object>> userParamsList = new ArrayList<>(); userParamsList.add(userParams); - + RequestParameters requestParameters = new RequestParameters(); requestParameters.setUserParams(userParamsList); requestContext.setRequestParameters(requestParameters); - + return requestContext; } - + public RequestContext setRequestContext() { RequestContext requestContext = buildRequestContext(); - + gBBInput.setRequestContext(requestContext); - + return requestContext; } - + public CloudRegion buildCloudRegion() { CloudRegion cloudRegion = new CloudRegion(); cloudRegion.setLcpCloudRegionId("testLcpCloudRegionId"); cloudRegion.setTenantId("testTenantId"); cloudRegion.setCloudOwner("testCloudOwner"); - + return cloudRegion; } - + public CloudRegion setCloudRegion() { CloudRegion cloudRegion = buildCloudRegion(); - + gBBInput.setCloudRegion(cloudRegion); - + return cloudRegion; } - + public OrchestrationContext buildOrchestrationContext() { OrchestrationContext orchestrationContext = new OrchestrationContext(); - + return orchestrationContext; } - + public OrchestrationContext setOrchestrationContext() { OrchestrationContext orchestrationContext = buildOrchestrationContext(); - + gBBInput.setOrchContext(orchestrationContext); - + return orchestrationContext; } - + public Collection buildCollection() { collectionCounter++; - + Collection collection = new Collection(); collection.setId("testId" + collectionCounter); collection.setInstanceGroup(buildInstanceGroup()); - + return collection; } - + public Configuration buildConfiguration() { configurationCounter++; - + Configuration configuration = new Configuration(); configuration.setConfigurationId("testConfigurationId" + configurationCounter); configuration.setConfigurationName("testConfigurationName" + configurationCounter); - + ModelInfoConfiguration modelInfoConfiguration = new ModelInfoConfiguration(); modelInfoConfiguration.setModelVersionId("testModelVersionId" + configurationCounter); modelInfoConfiguration.setModelInvariantId("testModelInvariantId" + configurationCounter); modelInfoConfiguration.setModelCustomizationId("testModelCustomizationId" + configurationCounter); - + configuration.setModelInfoConfiguration(modelInfoConfiguration); - + return configuration; } - + public OwningEntity buildOwningEntity() { owningEntityCounter++; - + OwningEntity owningEntity = new OwningEntity(); owningEntity.setOwningEntityId("testOwningEntityId" + owningEntityCounter); owningEntity.setOwningEntityName("testOwningEntityName" + owningEntityCounter); - + return owningEntity; } - + public Project buildProject() { projectCounter++; - + Project project = new Project(); project.setProjectName("testProjectName" + projectCounter); - + return project; } - + public ServiceSubscription buildServiceSubscription() { serviceSubscriptionCounter++; - + ServiceSubscription serviceSubscription = new ServiceSubscription(); serviceSubscription.setTempUbSubAccountId("testTempUbSubAccountId" + serviceSubscriptionCounter); serviceSubscription.setServiceType("testServiceType" + serviceSubscriptionCounter); - + return serviceSubscription; } - + public Customer buildCustomer() { customerCounter++; - + Customer customer = new Customer(); customer.setGlobalCustomerId("testGlobalCustomerId" + customerCounter); customer.setSubscriberType("testSubscriberType" + customerCounter); customer.setServiceSubscription(buildServiceSubscription()); - + return customer; } - + public ServiceInstance buildServiceInstance() { serviceInstanceCounter++; - + ServiceInstance serviceInstance = new ServiceInstance(); serviceInstance.setServiceInstanceId("testServiceInstanceId" + serviceInstanceCounter); serviceInstance.setServiceInstanceName("testServiceInstanceName" + serviceInstanceCounter); - + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); modelInfoServiceInstance.setModelInvariantUuid("testModelInvariantUUID" + serviceInstanceCounter); modelInfoServiceInstance.setModelUuid("testModelUUID" + serviceInstanceCounter); @@ -304,30 +305,30 @@ public class TestDataSetup{ modelInfoServiceInstance.setModelName("testModelName" + serviceInstanceCounter); modelInfoServiceInstance.setServiceType("testServiceType" + serviceInstanceCounter); serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); - + serviceInstance.setProject(buildProject()); - + serviceInstance.setOwningEntity(buildOwningEntity()); - + serviceInstance.setCollection(buildCollection()); - + serviceInstance.getConfigurations().add(buildConfiguration()); - + return serviceInstance; } - + public ServiceInstance setServiceInstance() { ServiceInstance serviceInstance = buildServiceInstance(); - + if(gBBInput.getCustomer() == null) { gBBInput.setCustomer(buildCustomer()); } gBBInput.getCustomer().getServiceSubscription().getServiceInstances().add(serviceInstance); lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstance.getServiceInstanceId()); - + return serviceInstance; } - + public Customer setCustomer() { if(gBBInput.getCustomer() != null) return gBBInput.getCustomer(); Customer customer = new Customer(); @@ -337,64 +338,64 @@ public class TestDataSetup{ customer.setServiceSubscription(buildServiceSubscription()); gBBInput.setCustomer(customer); - + return customer; } - + public Collection setCollection() { Collection collection = new Collection(); collection.setId("testId"); - + ServiceInstance serviceInstance = null; - + try { serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); } catch(BBObjectNotFoundException e) { serviceInstance = setServiceInstance(); } - + serviceInstance.setCollection(collection); - + return collection; } - + public InstanceGroup setInstanceGroup() { InstanceGroup instanceGroup = new InstanceGroup(); instanceGroup.setId("testId"); instanceGroup.setInstanceGroupFunction("testInstanceGroupFunction"); - + Collection collection = null; - + try { ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); collection = serviceInstance.getCollection(); - + if (collection == null) { collection = setCollection(); } } catch(BBObjectNotFoundException e) { collection = setCollection(); } - + collection.setInstanceGroup(instanceGroup); - + return instanceGroup; } - + public VpnBinding buildVpnBinding() { vpnBindingCounter++; - + VpnBinding vpnBinding = new VpnBinding(); vpnBinding.setVpnId("testVpnId" + vpnBindingCounter); vpnBinding.setVpnName("testVpnName" + vpnBindingCounter); vpnBinding.setCustomerVpnId("testCustomerVpnId" + vpnBindingCounter); - + return vpnBinding; } - + public VpnBinding setVpnBinding() { VpnBinding vpnBinding = buildVpnBinding(); - + Customer customer = gBBInput.getCustomer(); if(customer == null){ @@ -403,72 +404,72 @@ public class TestDataSetup{ customer.getVpnBindings().add(vpnBinding); lookupKeyMap.put(ResourceKey.VPN_ID, vpnBinding.getVpnId()); - + return vpnBinding; } - + public InstanceGroup buildInstanceGroup() { instanceGroupCounter++; - + InstanceGroup instanceGroup = new InstanceGroup(); instanceGroup.setId("testId" + instanceGroupCounter); instanceGroup.setInstanceGroupFunction("testInstanceGroupFunction" + instanceGroupCounter); - + return instanceGroup; } - + public L3Network buildL3Network() { l3NetworkCounter++; - + L3Network network = new L3Network(); network.setNetworkId("testNetworkId" + l3NetworkCounter); network.setNetworkName("testNetworkName" + l3NetworkCounter); network.setNetworkType("testNetworkType" + l3NetworkCounter); - + ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); modelInfoNetwork.setModelInvariantUUID("testModelInvariantUUID" + l3NetworkCounter); modelInfoNetwork.setModelName("testModelName" + l3NetworkCounter); modelInfoNetwork.setModelVersion("testModelVersion" + l3NetworkCounter); modelInfoNetwork.setModelUUID("testModelUUID" + l3NetworkCounter); network.setModelInfoNetwork(modelInfoNetwork); - + return network; } - + public L3Network setL3Network() { L3Network network = buildL3Network(); - + ServiceInstance serviceInstance = null; - + try { serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); } catch(BBObjectNotFoundException e) { serviceInstance = setServiceInstance(); } - + serviceInstance.getNetworks().add(network); lookupKeyMap.put(ResourceKey.NETWORK_ID, network.getNetworkId()); - + return network; } - + public GenericVnf buildGenericVnf() { genericVnfCounter++; - + GenericVnf genericVnf = new GenericVnf(); genericVnf.setVnfId("testVnfId" + genericVnfCounter); genericVnf.setVnfName("testVnfName" + genericVnfCounter); genericVnf.setVnfType("testVnfType" + genericVnfCounter); genericVnf.setIpv4OamAddress("10.222.22.2"); - + Platform platform = new Platform(); platform.setPlatformName("testPlatformName"); genericVnf.setPlatform(platform); - + LineOfBusiness lob = new LineOfBusiness(); lob.setLineOfBusinessName("testLineOfBusinessName"); genericVnf.setLineOfBusiness(lob); - + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); modelInfoGenericVnf.setModelName("testModelName" + genericVnfCounter); modelInfoGenericVnf.setModelCustomizationUuid("testModelCustomizationUUID" + genericVnfCounter); @@ -476,34 +477,40 @@ public class TestDataSetup{ modelInfoGenericVnf.setModelVersion("testModelVersion" + genericVnfCounter); modelInfoGenericVnf.setModelUuid("testModelUUID" + genericVnfCounter); genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); - + + License license = new License(); + List<String> array = new ArrayList<String>(); + array.add("testPoolUuid"); + license.setEntitlementPoolUuids(array); + genericVnf.setLicense(license); + return genericVnf; } - + public GenericVnf setGenericVnf() { GenericVnf genericVnf = buildGenericVnf(); - + ServiceInstance serviceInstance = null; - + try { serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); } catch(BBObjectNotFoundException e) { serviceInstance = setServiceInstance(); } - + serviceInstance.getVnfs().add(genericVnf); lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, genericVnf.getVnfId()); - + return genericVnf; } - + public VfModule buildVfModule() { vfModuleCounter++; - + VfModule vfModule = new VfModule(); vfModule.setVfModuleId("testVfModuleId" + vfModuleCounter); vfModule.setVfModuleName("testVfModuleName" + vfModuleCounter); - + ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); modelInfoVfModule.setModelInvariantUUID("testModelInvariantUUID" + vfModuleCounter); modelInfoVfModule.setModelVersion("testModelVersion" + vfModuleCounter); @@ -511,128 +518,128 @@ public class TestDataSetup{ modelInfoVfModule.setModelName("testModelName" + vfModuleCounter); modelInfoVfModule.setModelCustomizationUUID("testModelCustomizationUUID" + vfModuleCounter); vfModule.setModelInfoVfModule(modelInfoVfModule); - + return vfModule; } - + public VfModule setVfModule() { VfModule vfModule = buildVfModule(); - + GenericVnf genericVnf = null; - + try { genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); } catch(BBObjectNotFoundException e) { genericVnf = setGenericVnf(); } - + genericVnf.getVfModules().add(vfModule); lookupKeyMap.put(ResourceKey.VF_MODULE_ID, vfModule.getVfModuleId()); - + return vfModule; } - + public VolumeGroup buildVolumeGroup() { volumeGroupCounter++; - + VolumeGroup volumeGroup = new VolumeGroup(); volumeGroup.setVolumeGroupId("testVolumeGroupId" + volumeGroupCounter); volumeGroup.setVolumeGroupName("testVolumeGroupName" + volumeGroupCounter); volumeGroup.setHeatStackId("testHeatStackId" + volumeGroupCounter); - + return volumeGroup; } - + public VolumeGroup setVolumeGroup() { VolumeGroup volumeGroup = buildVolumeGroup(); - + GenericVnf genericVnf = null; - + try { genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); } catch(BBObjectNotFoundException e) { genericVnf = setGenericVnf(); } - + genericVnf.getVolumeGroups().add(volumeGroup); lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, volumeGroup.getVolumeGroupId()); - + return volumeGroup; } - + public Pnf buildPnf() { pnfCounter++; - + Pnf pnf = new Pnf(); pnf.setPnfId("testPnfId" + pnfCounter); pnf.setPnfName("testPnfName" + pnfCounter); - + return pnf; } - + public ServiceProxy buildServiceProxy() { serviceProxyCounter++; - + ServiceProxy serviceProxy = new ServiceProxy(); serviceProxy.setServiceInstance(buildServiceInstance()); serviceProxy.getServiceInstance().getVnfs().add(buildGenericVnf()); - + Pnf primaryPnf = buildPnf(); primaryPnf.setRole("Primary"); serviceProxy.getServiceInstance().getPnfs().add(primaryPnf); - + Pnf secondaryPnf = buildPnf(); secondaryPnf.setRole("Secondary"); serviceProxy.getServiceInstance().getPnfs().add(secondaryPnf); - + return serviceProxy; } - + public VpnBondingLink buildVpnBondingLink() { vpnBondingLinkCounter++; - + VpnBondingLink vpnBondingLink = new VpnBondingLink(); vpnBondingLink.setVpnBondingLinkId("testVpnBondingLinkId" + vpnBondingLinkCounter); - + Configuration vnrConfiguration = buildConfiguration(); - vnrConfiguration.setNetwork(buildL3Network()); + vnrConfiguration.setNetwork(buildL3Network()); vpnBondingLink.setVnrConfiguration(vnrConfiguration); vpnBondingLink.setVrfConfiguration(buildConfiguration()); - + vpnBondingLink.setInfrastructureServiceProxy(buildServiceProxy()); - + vpnBondingLink.setTransportServiceProxy(buildServiceProxy()); - + return vpnBondingLink; } - + public VpnBondingLink setVpnBondingLink() { VpnBondingLink vpnBondingLink = buildVpnBondingLink(); - + ServiceInstance serviceInstance = null; - + try { serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); } catch(BBObjectNotFoundException e) { serviceInstance = setServiceInstance(); } - + serviceInstance.getVpnBondingLinks().add(vpnBondingLink); lookupKeyMap.put(ResourceKey.VPN_BONDING_LINK_ID, vpnBondingLink.getVpnBondingLinkId()); return vpnBondingLink; } - + public Customer setAvpnCustomer() { Customer customer = buildCustomer(); - + gBBInput.setCustomer(customer); - + return customer; } - + public ServiceProxy setServiceProxy(String uniqueIdentifier, String type) { ServiceProxy serviceProxy = new ServiceProxy(); serviceProxy.setId("testProxyId" + uniqueIdentifier); @@ -658,12 +665,12 @@ public class TestDataSetup{ modelInfo.setModelName("testProxyModelName" + uniqueIdentifier); modelInfo.setModelUuid("testProxyModelUuid" + uniqueIdentifier); modelInfo.setModelVersion("testProxyModelVersion" + uniqueIdentifier); - + ar.setModelInfoAllottedResource(modelInfo); - + return ar; } - + public Configuration setConfiguration () { Configuration config = new Configuration(); config.setConfigurationId("testConfigurationId"); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasksTest.java index 6a40db3eaa..cc96326563 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasksTest.java @@ -7,9 +7,9 @@ * 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. @@ -44,7 +44,7 @@ import org.springframework.beans.factory.annotation.Autowired; public class SDNCAssignTasksTest extends BaseTaskTest{ @Autowired private SDNCAssignTasks sdncAssignTasks; - + private L3Network network; private ServiceInstance serviceInstance; private RequestContext requestContext; @@ -53,7 +53,7 @@ public class SDNCAssignTasksTest extends BaseTaskTest{ private VfModule vfModule; private VolumeGroup volumeGroup; private Customer customer; - + @Before public void before() { customer = setCustomer(); @@ -66,7 +66,7 @@ public class SDNCAssignTasksTest extends BaseTaskTest{ volumeGroup = setVolumeGroup(); } - + @Test public void assignServiceInstanceTest() throws Exception { doReturn("response").when(sdncServiceInstanceResources).assignServiceInstance(serviceInstance, customer, requestContext); @@ -76,35 +76,36 @@ public class SDNCAssignTasksTest extends BaseTaskTest{ verify(sdncServiceInstanceResources, times(1)).assignServiceInstance(serviceInstance, customer, requestContext); assertTrue(execution.getVariable("SDNCResponse").equals("response")); } - + @Test public void assignServiceInstanceExceptionTest() throws Exception { expectedException.expect(BpmnError.class); - + doThrow(Exception.class).when(sdncServiceInstanceResources).assignServiceInstance(serviceInstance, customer, requestContext); sdncAssignTasks.assignServiceInstance(execution); } - + @Test public void assignVnfTest() throws Exception { doReturn("response").when(sdncVnfResources).assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext, false); + execution.setVariable("generalBuildingBlock", gBBInput); sdncAssignTasks.assignVnf(execution); verify(sdncVnfResources, times(1)).assignVnf(genericVnf, serviceInstance,customer, cloudRegion, requestContext, false); assertTrue(execution.getVariable("SDNCResponse").equals("response")); } - + @Test public void assignVnfExceptionTest() throws Exception { expectedException.expect(BpmnError.class); - + doThrow(Exception.class).when(sdncVnfResources).assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext, false); - + sdncAssignTasks.assignVnf(execution); } - + @Test public void assignVfModuleTest() throws Exception { doReturn("response").when(sdncVfModuleResources).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext); @@ -114,16 +115,16 @@ public class SDNCAssignTasksTest extends BaseTaskTest{ verify(sdncVfModuleResources, times(1)).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext); assertTrue(execution.getVariable("SDNCAssignResponse_" + vfModule.getVfModuleId()).equals("response")); } - + @Test public void assignVfModuleExceptionTest() throws Exception { expectedException.expect(BpmnError.class); - + doThrow(Exception.class).when(sdncVfModuleResources).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext); sdncAssignTasks.assignVfModule(execution); } - + @Test public void assignNetworkTest() throws Exception { doReturn("response").when(sdncNetworkResources).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion); @@ -132,11 +133,11 @@ public class SDNCAssignTasksTest extends BaseTaskTest{ verify(sdncNetworkResources, times(1)).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion); } - + @Test public void assignNetworkExceptionTest() throws Exception { expectedException.expect(BpmnError.class); - + doThrow(Exception.class).when(sdncNetworkResources).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion); sdncAssignTasks.assignNetwork(execution); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java index 27173b7502..6cac238482 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java @@ -153,55 +153,56 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); BuildingBlock bb1 = new BuildingBlock(); - bb1.setBpmnFlowName("CreateNetworkBB"); + bb1.setBpmnFlowName("AssignVfModuleBB"); flowsToExecute.add(ebb1); ebb1.setBuildingBlock(bb1); ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock(); BuildingBlock bb2 = new BuildingBlock(); - bb2.setBpmnFlowName("ActivateNetworkBB"); + bb2.setBpmnFlowName("CreateVfModuleBB"); + flowsToExecute.add(ebb2); + ebb2.setBuildingBlock(bb2); + ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock(); + BuildingBlock bb3 = new BuildingBlock(); + bb3.setBpmnFlowName("ActivateVfModuleBB"); + flowsToExecute.add(ebb3); + ebb3.setBuildingBlock(bb3); + + execution.setVariable("flowsToExecute", flowsToExecute); + execution.setVariable("gCurrentSequence", 2); + + workflowActionBBTasks.rollbackExecutionPath(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateVfModuleBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB"); + assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"UnassignVfModuleBB"); + } + + @Test + public void rollbackExecutionPathUnfinishedFlowTest(){ + List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); + ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); + BuildingBlock bb1 = new BuildingBlock(); + bb1.setBpmnFlowName("AssignVfModuleBB"); + flowsToExecute.add(ebb1); + ebb1.setBuildingBlock(bb1); + ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock(); + BuildingBlock bb2 = new BuildingBlock(); + bb2.setBpmnFlowName("CreateVfModuleBB"); flowsToExecute.add(ebb2); ebb2.setBuildingBlock(bb2); ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock(); BuildingBlock bb3 = new BuildingBlock(); - bb3.setBpmnFlowName("CreateVolumeGroupBB"); + bb3.setBpmnFlowName("ActivateVfModuleBB"); flowsToExecute.add(ebb3); ebb3.setBuildingBlock(bb3); - ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock(); - BuildingBlock bb4 = new BuildingBlock(); - bb4.setBpmnFlowName("ActivateVolumeGroupBB"); - flowsToExecute.add(ebb4); - ebb4.setBuildingBlock(bb4); - ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock(); - BuildingBlock bb5 = new BuildingBlock(); - bb5.setBpmnFlowName("CreateVfModuleBB"); - flowsToExecute.add(ebb5); - ebb5.setBuildingBlock(bb5); - ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock(); - BuildingBlock bb6 = new BuildingBlock(); - bb6.setBpmnFlowName("ActivateVfModuleBB"); - flowsToExecute.add(ebb6); - ebb6.setBuildingBlock(bb6); - ExecuteBuildingBlock ebb7 = new ExecuteBuildingBlock(); - BuildingBlock bb7 = new BuildingBlock(); - bb7.setBpmnFlowName("ActivateVnfBB"); - ebb7.setBuildingBlock(bb7); - flowsToExecute.add(ebb7); - ExecuteBuildingBlock ebb8 = new ExecuteBuildingBlock(); - BuildingBlock bb8 = new BuildingBlock(); - bb8.setBpmnFlowName("ActivateServiceInstance"); - ebb8.setBuildingBlock(bb8); - flowsToExecute.add(ebb8); execution.setVariable("flowsToExecute", flowsToExecute); - execution.setVariable("gCurrentSequence", 6); + execution.setVariable("gCurrentSequence", 1); workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB"); - assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"DeactivateVolumeGroupBB"); - assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"DeleteVolumeGroupBB"); - assertEquals(ebbs.get(3).getBuildingBlock().getBpmnFlowName(),"DeactivateNetworkBB"); - assertEquals(ebbs.get(4).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"UnassignVfModuleBB"); } @Test diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java index eb17ad0ff9..e30fe660c3 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java @@ -20,6 +20,8 @@ package org.onap.so.client.sdn.common; +import static org.junit.Assert.assertEquals; + import java.util.LinkedHashMap; import org.junit.Assert; @@ -58,10 +60,12 @@ public class SdnCommonTasksTest{ @Test public void validateSDNResponseTest() throws BadResponseException { - LinkedHashMap responseMap = new LinkedHashMap(); - responseMap.put("response-code", "0"); - responseMap.put("response-message", "success"); - Assert.assertNotNull(sdnCommonTasks.validateSDNResponse(responseMap)); + LinkedHashMap<String, Object> responseMap = new LinkedHashMap<>(); + LinkedHashMap<String, Object> output = new LinkedHashMap<>(); + output.put("response-code", "0"); + output.put("response-message", "success"); + responseMap.put("output", output); + assertEquals("success", sdnCommonTasks.validateSDNResponse(responseMap)); } @Test @@ -74,10 +78,12 @@ public class SdnCommonTasksTest{ @Test public void validateSDNResponseTestRespCodeNot200() throws BadResponseException { expectedException.expect(BadResponseException.class); - LinkedHashMap responseMap = new LinkedHashMap(); - responseMap.put("response-code", "300"); - responseMap.put("response-message", "Failed"); - Assert.assertNotNull(sdnCommonTasks.validateSDNResponse(responseMap)); + LinkedHashMap<String, Object> responseMap = new LinkedHashMap<>(); + LinkedHashMap<String, Object> output = new LinkedHashMap<>(); + output.put("response-code", "300"); + output.put("response-message", "Failed"); + responseMap.put("output", output); + sdnCommonTasks.validateSDNResponse(responseMap); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientTest.java index 2492638520..e24ca339a3 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientTest.java @@ -22,7 +22,9 @@ package org.onap.so.client.sdnc; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import java.io.IOException; @@ -34,6 +36,7 @@ import org.junit.Test; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.MapperException; +import org.onap.so.client.sdnc.endpoint.SDNCTopology; import org.skyscreamer.jsonassert.JSONAssert; import com.github.tomakehurst.wiremock.junit.WireMockRule; @@ -55,4 +58,31 @@ public class SDNCClientTest extends BaseTaskTest { String response = SPY_sdncClient.get(queryLink); JSONAssert.assertEquals(responseJson, response, false); } + + @Test(expected = BadResponseException.class) + public void post404Test() throws BadResponseException, MapperException, IOException { + String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut404Response.json"))); + + String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; + + wireMockRule.stubFor(post(urlMatching(queryLink)) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json").withBody(responseJson))); + + SPY_sdncClient.post("", SDNCTopology.NETWORK); + } + + @Test + public void post200Test() throws BadResponseException, MapperException, IOException { + String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut200Response.json"))); + + String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; + + wireMockRule.stubFor(post(urlMatching(queryLink)) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json").withBody(responseJson))); + + String response = SPY_sdncClient.post("", SDNCTopology.NETWORK); + JSONAssert.assertEquals("", response, false); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientPut200Response.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientPut200Response.json new file mode 100644 index 0000000000..286ce4c844 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientPut200Response.json @@ -0,0 +1,15 @@ +{ + "output": { + "svc-request-id": "5d24d40e-4c77-4c06-94a3-6d168c47a57c", + "network-response-information": { + "instance-id": "4063e0aa-af13-4872-8473-b40c94f9316b", + "object-path": "restconf/config/GENERIC-RESOURCE-API:services/service/2c9c7996-75a7-4f92-becc-9e13e8bd288a/service-data/networks/network/4063e0aa-af13-4872-8473-b40c94f9316b/network-data/network-topology/" + }, + "response-code": "200", + "service-response-information": { + "instance-id": "2c9c7996-75a7-4f92-becc-9e13e8bd288a" + }, + "response-message": "", + "ack-final-indicator": "Y" + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientPut404Response.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientPut404Response.json new file mode 100644 index 0000000000..cf0254886d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientPut404Response.json @@ -0,0 +1,8 @@ +{ + "output": { + "svc-request-id": "086a7a09-1470-4977-8b3e-307488b8811a", + "response-code": "404", + "response-message": "invalid input: the service-instance does not have any service data in SDNC", + "ack-final-indicator": "Y" + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java index 9a5334081f..29fa1a34b3 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java @@ -76,8 +76,8 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{ private final int retryCountThree = 3; private final int retryCountTwo = 2; private final int retryCountZero = 0; + private final String sdcDistributionId1 = "TEST_distributionId1"; private final String sdcDistributionId = "TEST_distributionId"; - private final String sdcDistributionId1 = "TEST_distributionId1"; private final String statusOk = Status.DISTRIBUTION_COMPLETE_OK.toString(); private final String statusError = DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString(); private final String statusSent = "SENT"; @@ -221,12 +221,12 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{ .withBody(mapper.writeValueAsString(iar)) .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/")) - .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"recoveryAction\":\"RETRY\",\"retryCount\":0,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}")) + .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"recoveryAction\":\"RETRY\",\"retryCount\":0,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null}")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/")) - .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}")) + .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null}")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); @@ -290,12 +290,11 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{ .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/")) - .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId1\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"SENT\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null}")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/")) - .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"SENT\",\"recoveryAction\":\"RETRY\",\"retryCount\":2,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}")) + .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"SENT\",\"recoveryAction\":\"RETRY\",\"retryCount\":2,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null}")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); @@ -491,12 +490,12 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{ .withBody(mapper.writeValueAsString(iar)) .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/")) - .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"recoveryAction\":\"SKIP\",\"retryCount\":0,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}")) + .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"recoveryAction\":\"SKIP\",\"retryCount\":0,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null}")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/")) - .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}")) + .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null}")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/data.sql b/mso-api-handlers/mso-api-handler-infra/src/test/resources/data.sql index 70c0791055..afcd7330f3 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/data.sql +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/data.sql @@ -275,7 +275,16 @@ VALUES ('vfModule', 'replaceInstance', '1', 'Gr api recipe to replace vf-module', '/mso/async/services/WorkflowActionBB', 180, 'GR-API-DEFAULT'), ('vfModule', 'deactivateAndCloudDelete', '1', 'Gr api recipe to deactivateAndCloudDelete vf-module', '/mso/async/services/WorkflowActionBB', 180, 'GR-API-DEFAULT'), ('vfModule', 'scaleOut', '1', 'Gr api recipe to scale out vfModule', '/mso/async/services/WorkflowActionBB', '180', 'GR-API-DEFAULT'); +INSERT INTO requestdb.activate_operational_env_service_model_distribution_status (OPERATIONAL_ENV_ID, SERVICE_MODEL_VERSION_ID, REQUEST_ID,SERVICE_MOD_VER_FINAL_DISTR_STATUS,RECOVERY_ACTION,RETRY_COUNT_LEFT,WORKLOAD_CONTEXT, CREATE_TIME, MODIFY_TIME) +VALUES +('1234', 'TEST1234', '00032ab7-3fb3-42e5-965d-8ea592502017', "Test", "Test", 1, 'DEFAULT', '2018-08-14 16:50:59', '2018-08-14 16:50:59'); +INSERT INTO requestdb.activate_operational_env_service_model_distribution_status (OPERATIONAL_ENV_ID, SERVICE_MODEL_VERSION_ID, REQUEST_ID,SERVICE_MOD_VER_FINAL_DISTR_STATUS,RECOVERY_ACTION,RETRY_COUNT_LEFT,WORKLOAD_CONTEXT, CREATE_TIME, MODIFY_TIME) +VALUES +('1234', 'TEST1235', '00032ab7-3fb3-42e5-965d-8ea592502017', "Test", "Test", 2, 'DEFAULT', '2018-08-14 16:50:59', '2018-08-14 16:50:59'); +INSERT INTO requestdb.activate_operational_env_per_distributionid_status (DISTRIBUTION_ID, DISTRIBUTION_ID_STATUS, DISTRIBUTION_ID_ERROR_REASON, CREATE_TIME, MODIFY_TIME, OPERATIONAL_ENV_ID, SERVICE_MODEL_VERSION_ID, REQUEST_ID) +VALUES +('111', 'TEST', 'ERROR', '2018-09-12 19:29:24', '2018-09-12 19:29:25', '1234', 'TEST1234', '00032ab7-3fb3-42e5-965d-8ea592502017'); UPDATE vnf_components_recipe SET vf_module_model_uuid = 'VNF-API-DEFAULT' diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java index 6ab92853d1..e68bdb3772 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java @@ -36,36 +36,29 @@ import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest; import org.onap.so.logging.jaxrs.filter.SpringClientFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.http.HttpRequest; import org.springframework.http.client.BufferingClientHttpRequestFactory; -import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestFactory; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Component; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; -import uk.co.blackpepper.bowman.Client; import uk.co.blackpepper.bowman.ClientFactory; import uk.co.blackpepper.bowman.Configuration; -import uk.co.blackpepper.bowman.RestTemplateConfigurer; import javax.annotation.PostConstruct; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; -import java.io.IOException; import java.net.URI; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Iterator; @Component("RequestsDbClient") @Primary @@ -74,14 +67,10 @@ public class RequestsDbClient { private static final String SERVICE_ID = "SERVICE_ID"; private static final String OPERATION_ID = "OPERATION_ID"; private static final String SO_REQUEST_ID = "SO_REQUEST_ID"; - private static final String GROUPING_ID = "GROUPING_ID"; private static final String REQUEST_ID = "REQUEST_ID"; - private static final String OPERATIONAL_ENVIRONMENT_ID = "OPERATIONAL_ENVIRONMENT_ID"; + private static final String OPERATIONAL_ENVIRONMENT_ID = "OPERATIONAL_ENV_ID"; private static final String SERVICE_MODEL_VERSION_ID = "SERVICE_MODEL_VERSION_ID"; - private static final String NAME = "NAME"; - private static final String VALUE = "VALUE"; - private static final String TAG = "TAG"; - + @Value("${mso.adapters.requestDb.endpoint}") protected String endpoint; @@ -112,9 +101,7 @@ public class RequestsDbClient { private String requestProcessingDataURI = "/requestProcessingData"; - private String findOneBySoRequestIdAndGroupingIdAndNameAndTagURI = "/requestProcessingData/search/findOneBySoRequestIdAndGroupingIdAndNameAndTag/"; - - private String findBySoRequestIdOrderByGroupingIdDesc = "/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/"; + private final String findBySoRequestIdOrderByGroupingIdDesc = "/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc"; @Autowired @@ -137,8 +124,8 @@ public class RequestsDbClient { findAllByOperationalEnvIdAndRequestIdURI = endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findAllByOperationalEnvIdAndRequestIdURI; } - public ClientFactory getClientFactory(){ - URI baseUri = UriBuilder.fromUri(endpoint).build(); + private ClientFactory getClientFactory(){ + URI baseUri = UriBuilder.fromUri(endpoint).build(); ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory()); return Configuration.builder().setBaseUri(baseUri).setClientHttpRequestFactory(factory).setRestTemplateConfigurer(restTemplate -> { @@ -152,11 +139,10 @@ public class RequestsDbClient { }).build().buildClientFactory(); } - + public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive(Map<String, String> orchestrationMap){ URI uri = getUri(cloudOrchestrationFiltersFromInfraActive); - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); + HttpHeaders headers = getHttpHeaders(); HttpEntity<Map> entity = new HttpEntity<>(orchestrationMap, headers); try{ return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {}).getBody(); @@ -170,10 +156,8 @@ public class RequestsDbClient { public InfraActiveRequests getInfraActiveRequestbyRequestId(String requestId) { try { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); - HttpEntity<?> entity = new HttpEntity<>(headers); - InfraActiveRequests infraActiveRequests = restTemplate.exchange(getUri(endpoint + "/infraActiveRequests/" + requestId), HttpMethod.GET, entity, InfraActiveRequests.class).getBody(); + HttpEntity<?> entity = getHttpEntity(); + InfraActiveRequests infraActiveRequests = restTemplate.exchange(getUri(endpoint + "/infraActiveRequests/" + requestId), HttpMethod.GET, entity, InfraActiveRequests.class).getBody(); if (infraActiveRequests != null) { infraActiveRequests.setRequestId(requestId); } @@ -187,24 +171,20 @@ public class RequestsDbClient { } public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive(Map<String, List<String>> orchestrationMap) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); + HttpHeaders headers = getHttpHeaders(); URI uri = getUri(getOrchestrationFilterURI); HttpEntity<Map<String, List<String>>> entity = new HttpEntity<>(orchestrationMap, headers); return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {}).getBody(); } public InfraActiveRequests checkVnfIdStatus(String operationalEnvironmentId) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); - HttpEntity<?> entity = new HttpEntity<>(headers); + HttpEntity<?> entity = getHttpEntity(); URI uri = getUri(checkVnfIdStatus + operationalEnvironmentId); return restTemplate.exchange(uri, HttpMethod.GET, entity, InfraActiveRequests.class).getBody(); } public InfraActiveRequests checkInstanceNameDuplicate(HashMap<String, String> instanceIdMap, String instanceName, String requestScope) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); + HttpHeaders headers = getHttpHeaders(); URI uri = getUri(checkInstanceNameDuplicate); HttpEntity<InstanceNameDuplicateCheckRequest> entity = new HttpEntity<>(new InstanceNameDuplicateCheckRequest(instanceIdMap, instanceName, requestScope), headers); try{ @@ -220,13 +200,11 @@ public class RequestsDbClient { public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId) { try { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); - HttpEntity<?> entity = new HttpEntity<>(headers); - OperationStatus operationStatus = restTemplate.exchange(UriBuilder.fromUri(getUri(findOneByServiceIdAndOperationIdURI)) + HttpEntity<?> entity = getHttpEntity(); + OperationStatus operationStatus = restTemplate.exchange(getUri(UriBuilder.fromUri(getUri(findOneByServiceIdAndOperationIdURI)) .queryParam(SERVICE_ID, serviceId) .queryParam(OPERATION_ID, operationId) - .build(), HttpMethod.GET, entity, OperationStatus.class).getBody(); + .build().toString()), HttpMethod.GET, entity, OperationStatus.class).getBody(); if (operationStatus != null) { operationStatus.setServiceId(serviceId); operationStatus.setOperationId(operationId); @@ -240,27 +218,49 @@ public class RequestsDbClient { throw e; } } - + public OperationalEnvServiceModelStatus findOneByOperationalEnvIdAndServiceModelVersionId(String operationalEnvironmentId, String serviceModelVersionId) { - return this.getSingleOperationalEnvServiceModelStatus(UriBuilder.fromUri(findOneByOperationalEnvIdAndServiceModelVersionIdURI) - .queryParam(OPERATIONAL_ENVIRONMENT_ID,operationalEnvironmentId) - .queryParam(SERVICE_MODEL_VERSION_ID,serviceModelVersionId) - .build()); + try { + HttpEntity<?> entity = getHttpEntity(); + OperationalEnvServiceModelStatus modelStatus = restTemplate.exchange(getUri(UriBuilder.fromUri(findOneByOperationalEnvIdAndServiceModelVersionIdURI) + .queryParam(OPERATIONAL_ENVIRONMENT_ID, operationalEnvironmentId) + .queryParam(SERVICE_MODEL_VERSION_ID, serviceModelVersionId) + .build().toString()), HttpMethod.GET, entity, OperationalEnvServiceModelStatus.class).getBody(); + if (null != modelStatus) { + modelStatus.setOperationalEnvId(operationalEnvironmentId); + modelStatus.setServiceModelVersionId(serviceModelVersionId); + } + return modelStatus; + }catch(HttpClientErrorException e){ + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + return null; + } + throw e; + } } public List<OperationalEnvServiceModelStatus> getAllByOperationalEnvIdAndRequestId(String operationalEnvironmentId, String requestId){ - return this.getMultipleOperationalEnvServiceModelStatus(UriBuilder.fromUri(findAllByOperationalEnvIdAndRequestIdURI) + return this.getMultipleOperationalEnvServiceModelStatus(getUri(UriBuilder.fromUri(findAllByOperationalEnvIdAndRequestIdURI) .queryParam(OPERATIONAL_ENVIRONMENT_ID,operationalEnvironmentId) .queryParam(REQUEST_ID,requestId) - .build()); + .build().toString())); } public OperationalEnvDistributionStatus getDistributionStatusById(String distributionId){ - return this.getSingleOperationalEnvDistributionStatus(UriBuilder.fromUri(operationalEnvDistributionStatusURI+distributionId).build()); - } - - private OperationalEnvServiceModelStatus getSingleOperationalEnvServiceModelStatus(URI uri){ - return getClientFactory().create(OperationalEnvServiceModelStatus.class).get(uri); + try { + HttpEntity<?> entity = getHttpEntity(); + OperationalEnvDistributionStatus distributionStatus = restTemplate.exchange(getUri(operationalEnvDistributionStatusURI + distributionId), + HttpMethod.GET, entity, OperationalEnvDistributionStatus.class).getBody(); + if(null != distributionStatus){ + distributionStatus.setDistributionId(distributionId); + } + return distributionStatus; + }catch(HttpClientErrorException e){ + if(HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()){ + return null; + } + throw e; + } } private List<OperationalEnvServiceModelStatus> getMultipleOperationalEnvServiceModelStatus(URI uri){ @@ -270,32 +270,23 @@ public class RequestsDbClient { statusIterator.forEachRemaining(serviceModelStatuses::add); return serviceModelStatuses; } - + public void save(InfraActiveRequests infraActiveRequests) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); + HttpHeaders headers = getHttpHeaders(); URI uri = getUri(infraActiveRequestURI); HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(infraActiveRequests, headers); restTemplate.postForLocation(uri, entity); } public <T> void save(T object){ - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); + HttpHeaders headers = getHttpHeaders(); URI uri = getUri(endpoint+classURLMapper.getURI(object.getClass())); HttpEntity<T> entity = new HttpEntity<>(object, headers); restTemplate.postForLocation(uri, entity); } - private OperationalEnvDistributionStatus getSingleOperationalEnvDistributionStatus(URI uri){ - return getClientFactory().create(OperationalEnvDistributionStatus.class).get(uri); - } - - public void updateInfraActiveRequests(InfraActiveRequests request) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); - headers.set(HttpHeaders.CONTENT_TYPE,"application/json"); - headers.set(HttpHeaders.ACCEPT, "application/json"); + public void updateInfraActiveRequests(InfraActiveRequests request) { + HttpHeaders headers = getHttpHeaders(); URI uri = getUri(infraActiveRequestURI+request.getRequestId()); HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(request, headers); restTemplate.put(uri, entity); @@ -306,32 +297,18 @@ public class RequestsDbClient { } public void saveRequestProcessingData(RequestProcessingData requestProcessingData) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); + HttpHeaders headers = getHttpHeaders(); URI uri = getUri(endpoint + requestProcessingDataURI); HttpEntity<RequestProcessingData> entity = new HttpEntity<>(requestProcessingData, headers); restTemplate.postForLocation(uri, entity); } - - public RequestProcessingData getRequestProcessingDataBySoRequestIdAndGroupingIdAndNameAndTag(String soRequestId, - String groupingId, String name, String tag) { - return this.getSingleRequestProcessingData(UriBuilder.fromUri(endpoint + findOneBySoRequestIdAndGroupingIdAndNameAndTagURI) - .queryParam(SO_REQUEST_ID,soRequestId) - .queryParam(GROUPING_ID,groupingId) - .queryParam(NAME,name) - .queryParam(TAG,tag) - .build()); - } + public List<RequestProcessingData> getRequestProcessingDataBySoRequestId(String soRequestId) { - return this.getRequestProcessingData(UriBuilder.fromUri(endpoint + findBySoRequestIdOrderByGroupingIdDesc) + return this.getRequestProcessingData(getUri(UriBuilder.fromUri(endpoint + findBySoRequestIdOrderByGroupingIdDesc) .queryParam(SO_REQUEST_ID,soRequestId) - .build()); + .build().toString())); } - - public RequestProcessingData getSingleRequestProcessingData(URI uri){ - return getClientFactory().create(RequestProcessingData.class).get(uri); - } - + private List<RequestProcessingData> getRequestProcessingData(URI uri) { Iterable<RequestProcessingData> requestProcessingDataIterator = getClientFactory().create(RequestProcessingData.class).getAll(uri); List<RequestProcessingData> requestProcessingDataList = new ArrayList<>(); @@ -339,15 +316,6 @@ public class RequestsDbClient { it.forEachRemaining(requestProcessingDataList::add); return requestProcessingDataList; } - - public List<RequestProcessingData> getAllRequestProcessingData() { - - return (List<RequestProcessingData>) this.getAllRequestProcessingData(UriBuilder.fromUri(endpoint + "/requestProcessingData").build()); - } - - private Iterable<RequestProcessingData> getAllRequestProcessingData(URI uri) { - return getClientFactory().create(RequestProcessingData.class).getAll(uri); - } @Component static class ClassURLMapper { @@ -385,4 +353,18 @@ public class RequestsDbClient { public void removePortFromEndpoint() { endpoint = endpoint.substring(0, endpoint.lastIndexOf(':') + 1); } + + private HttpHeaders getHttpHeaders() { + HttpHeaders headers = new HttpHeaders(); + headers.set(HttpHeaders.AUTHORIZATION, msoAdaptersAuth); + headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); + return headers; + } + + private HttpEntity<?> getHttpEntity() { + HttpHeaders headers = getHttpHeaders(); + return new HttpEntity<>(headers); + } + } diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java index 84e4156efa..9a03f8fb07 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java @@ -422,11 +422,11 @@ public class CatalogDbClient { public RainyDayHandlerStatus getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep( String flowName, String serviceType, String vnfType, String errorCode, String workStep) { - return this.getSingleResource(rainyDayHandlerStatusClient, UriBuilder + return this.getSingleResource(rainyDayHandlerStatusClient, getUri(UriBuilder .fromUri(findOneByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep) .queryParam(FLOW_NAME, flowName).queryParam(SERVICE_TYPE, serviceType) .queryParam(VNF_TYPE, vnfType).queryParam(ERROR_CODE, errorCode).queryParam(WORK_STEP, workStep) - .build()); + .build().toString())); } public ServiceRecipe getFirstByServiceModelUUIDAndAction(String modelUUID, String action){ @@ -724,7 +724,7 @@ <dependency> <groupId>org.yaml</groupId> <artifactId>snakeyaml</artifactId> - <version>1.15</version> + <version>1.23</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> |