aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl
diff options
context:
space:
mode:
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>2022-06-30 08:54:30 +0100
committerrameshiyer27 <ramesh.murugan.iyer@est.tech>2022-06-30 15:39:36 +0100
commite50b122534039adf8227bae1739793e53c397f64 (patch)
tree8724362dea546382aaa03f1164e4a6b52ac65830 /participant/participant-impl
parenta49eb94567481ccdaa41bacbc9522da247ba4f59 (diff)
Fix CSIt failure in CLAMP test case
Policy participant always updates the state of AC element to PASSIVE, irrespective of success/failure scenarios in policy creation and deployment. This causes inconsistency in AC overall state and CSIT validation fails. Verifying the response code from api and pap before updating the AC element state from policy participant. Issue-ID: POLICY-4270 Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech> Change-Id: I0ecf770d9803e520401ba49cd47c22ac6e4f9c17
Diffstat (limited to 'participant/participant-impl')
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java50
1 files changed, 31 insertions, 19 deletions
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
index 42d7526f8..e020d209e 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
@@ -27,7 +27,9 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
+import javax.ws.rs.core.Response;
import lombok.Setter;
+import org.apache.http.HttpStatus;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.acm.participant.policy.client.PolicyApiHttpClient;
@@ -98,14 +100,14 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
automationCompositionElementId, orderedState, AutomationCompositionState.UNINITIALISED,
ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
} catch (PfModelRuntimeException e) {
- LOGGER.debug("Undeploying/Deleting policy failed {}", automationCompositionElementId, e);
+ LOGGER.error("Undeploying/Deleting policy failed {}", automationCompositionElementId, e);
}
break;
case PASSIVE:
try {
undeployPolicies(automationCompositionElementId);
} catch (PfModelRuntimeException e) {
- LOGGER.debug("Undeploying policies failed - no policies to undeploy {}",
+ LOGGER.error("Undeploying policies failed - no policies to undeploy {}",
automationCompositionElementId);
}
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
@@ -133,26 +135,30 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
apiHttpClient.deletePolicyType(policyType.getKey(), policyType.getValue());
}
policyTypeMap.clear();
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, newState, AutomationCompositionState.UNINITIALISED,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
}
private void deployPolicies(ToscaConceptIdentifier automationCompositionId, UUID automationCompositionElementId,
AutomationCompositionOrderedState newState) {
+ var deployFailure = false;
// Deploy all policies of this automationComposition from Policy Framework
if (!policyMap.entrySet().isEmpty()) {
for (Entry<String, String> policy : policyMap.entrySet()) {
- papHttpClient.handlePolicyDeployOrUndeploy(policy.getKey(), policy.getValue(),
- DeploymentSubGroup.Action.POST);
+ var deployPolicyResp = papHttpClient.handlePolicyDeployOrUndeploy(policy.getKey(), policy.getValue(),
+ DeploymentSubGroup.Action.POST).getStatus();
+ if (deployPolicyResp != HttpStatus.SC_ACCEPTED) {
+ deployFailure = true;
+ }
}
- LOGGER.debug("Policies deployed to {} successfully", automationCompositionElementId);
+ LOGGER.info("Policies deployed to {} successfully", automationCompositionElementId);
} else {
LOGGER.debug("No policies to deploy to {}", automationCompositionElementId);
}
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, newState, AutomationCompositionState.PASSIVE,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
+ if (! deployFailure) {
+ // Update the AC element state
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
+ automationCompositionElementId, newState, AutomationCompositionState.PASSIVE,
+ ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
+ }
}
private void undeployPolicies(UUID automationCompositionElementId) {
@@ -180,18 +186,18 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
AutomationCompositionElement element,
ToscaNodeTemplate acElementDefinition)
throws PfModelException {
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- element.getOrderedState(),
- AutomationCompositionState.PASSIVE, ParticipantMessageType.AUTOMATION_COMPOSITION_UPDATE);
+ var createPolicyTypeResp = HttpStatus.SC_OK;
+ var createPolicyResp = HttpStatus.SC_OK;
+
ToscaServiceTemplate automationCompositionDefinition = element.getToscaServiceTemplateFragment();
if (automationCompositionDefinition.getToscaTopologyTemplate() != null) {
if (automationCompositionDefinition.getPolicyTypes() != null) {
for (ToscaPolicyType policyType : automationCompositionDefinition.getPolicyTypes().values()) {
policyTypeMap.put(policyType.getName(), policyType.getVersion());
}
- LOGGER.debug("Found Policy Types in automation composition definition: {} , Creating Policy Types",
+ LOGGER.info("Found Policy Types in automation composition definition: {} , Creating Policy Types",
automationCompositionDefinition.getName());
- apiHttpClient.createPolicyType(automationCompositionDefinition);
+ createPolicyTypeResp = apiHttpClient.createPolicyType(automationCompositionDefinition).getStatus();
}
if (automationCompositionDefinition.getToscaTopologyTemplate().getPolicies() != null) {
for (Map<String, ToscaPolicy> gotPolicyMap : automationCompositionDefinition.getToscaTopologyTemplate()
@@ -200,12 +206,18 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
policyMap.put(policy.getName(), policy.getVersion());
}
}
- LOGGER.debug("Found Policies in automation composition definition: {} , Creating Policies",
+ LOGGER.info("Found Policies in automation composition definition: {} , Creating Policies",
automationCompositionDefinition.getName());
- apiHttpClient.createPolicy(automationCompositionDefinition);
+ createPolicyResp = apiHttpClient.createPolicy(automationCompositionDefinition).getStatus();
+ }
+ if (createPolicyTypeResp == HttpStatus.SC_OK && createPolicyResp == HttpStatus.SC_OK) {
+ LOGGER.info("PolicyTypes/Policies for the automation composition element : {} are created "
+ + "successfully", element.getId());
+ deployPolicies(automationCompositionId, element.getId(), element.getOrderedState());
+ } else {
+ LOGGER.error("Creation of PolicyTypes/Policies failed. Policies will not be deployed.");
}
}
- deployPolicies(automationCompositionId, element.getId(), element.getOrderedState());
}
/**