summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/main/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-27 10:52:06 -0400
committerJim Hahn <jrh3@att.com>2019-06-27 18:00:21 -0400
commitd0932a1a2339a02dab04eedefa0480535e68d31c (patch)
treedc6bcde6b279e5dd7a4a332b0494ab108096f173 /controlloop/common/eventmanager/src/main/java
parentd8118c6638bb2440f89eae9d3f979bdfb0e013c3 (diff)
Fix some sonar issues in drools-applications
Added coverage to: - feature-controlloop-management Fixed sonar issues, but didn't add coverage to: - feature-controlloop-trans - eventmanager - guard Change-Id: I12f09c4a533e838c6fb9762ba56194e51ce864eb Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/eventmanager/src/main/java')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java76
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java405
2 files changed, 251 insertions, 230 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
index b82a5f8e5..57df6b3f4 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
@@ -24,13 +24,19 @@ import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
+import java.util.Set;
import java.util.UUID;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.aai.AaiGetVnfResponse;
import org.onap.policy.aai.AaiGetVserverResponse;
@@ -90,6 +96,16 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventManager.class);
private static final long serialVersionUID = -1216568161322872641L;
+
+ private static final Set<String> VALID_TARGETS;
+
+ static {
+ VALID_TARGETS = Collections.unmodifiableSet(new HashSet<>(
+ Arrays.asList(VM_NAME, VNF_NAME, VSERVER_VSERVER_NAME,
+ GENERIC_VNF_VNF_ID, GENERIC_VNF_VNF_NAME)
+ .stream().map(String::toLowerCase).collect(Collectors.toList())));
+ }
+
public final String closedLoopControlName;
private final UUID requestId;
@@ -308,18 +324,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
* @throws ControlLoopException if an error occurs
*/
public VirtualControlLoopNotification isControlLoopFinal() throws ControlLoopException {
- //
- // Check if they activated us
- //
- if (!this.isActivated) {
- throw new ControlLoopException("ControlLoopEventManager MUST be activated first.");
- }
- //
- // Make sure we are expecting this call.
- //
- if (this.onset == null) {
- throw new ControlLoopException("No onset event for ControlLoopEventManager.");
- }
+ validateFinalControlLoop();
//
// Ok, start creating the notification
//
@@ -374,14 +379,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
return notification;
}
- /**
- * Process the control loop.
- *
- * @return a ControlLoopOperationManager
- * @throws ControlLoopException if an error occurs
- * @throws AaiException if an error occurs retrieving information from A&AI
- */
- public ControlLoopOperationManager processControlLoop() throws ControlLoopException, AaiException {
+ private void validateFinalControlLoop() throws ControlLoopException {
//
// Check if they activated us
//
@@ -394,6 +392,17 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
if (this.onset == null) {
throw new ControlLoopException("No onset event for ControlLoopEventManager.");
}
+ }
+
+ /**
+ * Process the control loop.
+ *
+ * @return a ControlLoopOperationManager
+ * @throws ControlLoopException if an error occurs
+ * @throws AaiException if an error occurs retrieving information from A&AI
+ */
+ public ControlLoopOperationManager processControlLoop() throws ControlLoopException, AaiException {
+ validateFinalControlLoop();
//
// Is there a current operation?
//
@@ -692,12 +701,8 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
* @throws ControlLoopException if an error occurs
*/
public void checkEventSyntax(VirtualControlLoopEvent event) throws ControlLoopException {
- if (event.getClosedLoopEventStatus() == null
- || (event.getClosedLoopEventStatus() != ControlLoopEventStatus.ONSET
- && event.getClosedLoopEventStatus() != ControlLoopEventStatus.ABATED)) {
- throw new ControlLoopException("Invalid value in closedLoopEventStatus");
- }
- if (event.getClosedLoopControlName() == null || event.getClosedLoopControlName().length() < 1) {
+ validateStatus(event);
+ if (StringUtils.isBlank(event.getClosedLoopControlName())) {
throw new ControlLoopException("No control loop name");
}
if (event.getRequestId() == null) {
@@ -706,14 +711,23 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
if (event.getClosedLoopEventStatus() == ControlLoopEventStatus.ABATED) {
return;
}
- if (event.getTarget() == null || event.getTarget().length() < 1) {
+ if (StringUtils.isBlank(event.getTarget())) {
throw new ControlLoopException("No target field");
- } else if (!VM_NAME.equalsIgnoreCase(event.getTarget()) && !VNF_NAME.equalsIgnoreCase(event.getTarget())
- && !VSERVER_VSERVER_NAME.equalsIgnoreCase(event.getTarget())
- && !GENERIC_VNF_VNF_ID.equalsIgnoreCase(event.getTarget())
- && !GENERIC_VNF_VNF_NAME.equalsIgnoreCase(event.getTarget())) {
+ } else if (!VALID_TARGETS.contains(event.getTarget().toLowerCase())) {
throw new ControlLoopException("target field invalid - expecting VM_NAME or VNF_NAME");
}
+ validateAaiData(event);
+ }
+
+ private void validateStatus(VirtualControlLoopEvent event) throws ControlLoopException {
+ if (event.getClosedLoopEventStatus() == null
+ || (event.getClosedLoopEventStatus() != ControlLoopEventStatus.ONSET
+ && event.getClosedLoopEventStatus() != ControlLoopEventStatus.ABATED)) {
+ throw new ControlLoopException("Invalid value in closedLoopEventStatus");
+ }
+ }
+
+ private void validateAaiData(VirtualControlLoopEvent event) throws ControlLoopException {
if (event.getAai() == null) {
throw new ControlLoopException("AAI is null");
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
index 3ff5c260e..006899efe 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
@@ -62,6 +62,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ControlLoopOperationManager implements Serializable {
+ private static final String SUCCESS_MSG = " Success";
+ private static final String FAILED_MSG = " Failed";
+ private static final String AAI_CUSTOM_QUERY = "aai.customQuery";
private static final long serialVersionUID = -3773199283624595410L;
private static final Logger logger = LoggerFactory.getLogger(ControlLoopOperationManager.class);
@@ -110,28 +113,7 @@ public class ControlLoopOperationManager implements Serializable {
//
switch (policy.getActor()) {
case "APPC":
- if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) {
- /*
- * The target vnf-id may not be the same as the source vnf-id specified in the yaml, the target
- * vnf-id is retrieved by a named query to A&AI.
- */
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) {
- GenericVnf genvnf = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset)
- .getGenericVnfByModelInvariantId(policy.getTarget().getResourceID());
- if (genvnf == null) {
- logger.info("Target entity could not be found");
- throw new AaiException("Target vnf-id could not be found");
- }
- this.targetEntity = genvnf.getVnfId();
-
- } else {
- this.targetEntity =
- AppcLcmActorServiceProvider.vnfNamedQuery(policy.getTarget().getResourceID(),
- this.targetEntity, PolicyEngine.manager.getEnvironmentProperty("aai.url"),
- PolicyEngine.manager.getEnvironmentProperty("aai.username"),
- PolicyEngine.manager.getEnvironmentProperty("aai.password"));
- }
- }
+ initAppc(onset, policy);
break;
case "SO":
break;
@@ -147,6 +129,32 @@ public class ControlLoopOperationManager implements Serializable {
}
+ private void initAppc(ControlLoopEvent onset, Policy policy) throws AaiException {
+ if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) {
+ /*
+ * The target vnf-id may not be the same as the source vnf-id specified in the yaml, the target
+ * vnf-id is retrieved by a named query to A&AI.
+ */
+ if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
+ GenericVnf genvnf = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset)
+ .getGenericVnfByModelInvariantId(policy.getTarget().getResourceID());
+ if (genvnf == null) {
+ logger.info("Target entity could not be found");
+ throw new AaiException("Target vnf-id could not be found");
+ }
+ this.targetEntity = genvnf.getVnfId();
+
+ } else {
+ this.targetEntity =
+ AppcLcmActorServiceProvider.vnfNamedQuery(policy.getTarget().getResourceID(),
+ this.targetEntity, PolicyEngine.manager.getEnvironmentProperty("aai.url"),
+ PolicyEngine.manager.getEnvironmentProperty("aai.username"),
+ PolicyEngine.manager.getEnvironmentProperty("aai.password"));
+ }
+ }
+ }
+
+
public ControlLoopEventManager getEventManager() {
return eventManager;
}
@@ -218,72 +226,48 @@ public class ControlLoopOperationManager implements Serializable {
throw new ControlLoopException("PNF target is not supported");
case VM:
case VNF:
- VirtualControlLoopEvent virtualOnset = (VirtualControlLoopEvent) this.onset;
- if (this.onset.getTarget().equalsIgnoreCase(VSERVER_VSERVER_NAME)) {
- return virtualOnset.getAai().get(VSERVER_VSERVER_NAME);
- } else if (this.onset.getTarget().equalsIgnoreCase(GENERIC_VNF_VNF_ID)) {
- return virtualOnset.getAai().get(GENERIC_VNF_VNF_ID);
- } else if (this.onset.getTarget().equalsIgnoreCase(GENERIC_VNF_VNF_NAME)) {
- /*
- * If the onset is enriched with the vnf-id, we don't need an A&AI response
- */
- if (virtualOnset.getAai().containsKey(GENERIC_VNF_VNF_ID)) {
- return virtualOnset.getAai().get(GENERIC_VNF_VNF_ID);
- }
-
- /*
- * If the vnf-name was retrieved from the onset then the vnf-id must be obtained from the event
- * manager's A&AI GET query
- */
- String vnfId;
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) {
- vnfId = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset).getDefaultGenericVnf()
- .getVnfId();
- } else {
- vnfId = this.eventManager.getVnfResponse().getVnfId();
- }
- if (vnfId == null) {
- throw new AaiException("No vnf-id found");
- }
- return vnfId;
- }
- throw new ControlLoopException("Target does not match target type");
+ return getVfModuleTarget();
case VFMODULE:
- VirtualControlLoopEvent virtualOnsetEvent = (VirtualControlLoopEvent) this.onset;
- if (this.onset.getTarget().equalsIgnoreCase(VSERVER_VSERVER_NAME)) {
- return virtualOnsetEvent.getAai().get(VSERVER_VSERVER_NAME);
- } else if (this.onset.getTarget().equalsIgnoreCase(GENERIC_VNF_VNF_ID)) {
- return virtualOnsetEvent.getAai().get(GENERIC_VNF_VNF_ID);
- } else if (this.onset.getTarget().equalsIgnoreCase(GENERIC_VNF_VNF_NAME)) {
- /*
- * If the onset is enriched with the vnf-id, we don't need an A&AI response
- */
- if (virtualOnsetEvent.getAai().containsKey(GENERIC_VNF_VNF_ID)) {
- return virtualOnsetEvent.getAai().get(GENERIC_VNF_VNF_ID);
- }
-
- /*
- * If the vnf-name was retrieved from the onset then the vnf-id must be obtained from the event
- * manager's A&AI GET query
- */
- String vnfId;
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) {
- vnfId = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset).getDefaultGenericVnf()
- .getVnfId();
- } else {
- vnfId = this.eventManager.getVnfResponse().getVnfId();
- }
- if (vnfId == null) {
- throw new AaiException("No vnf-id found");
- }
- return vnfId;
- }
- throw new ControlLoopException("Target does not match target type");
+ return getVfModuleTarget();
default:
throw new ControlLoopException("The target type is not supported");
}
}
+
+ private String getVfModuleTarget() throws AaiException, ControlLoopException {
+ VirtualControlLoopEvent virtualOnsetEvent = (VirtualControlLoopEvent) this.onset;
+ if (this.onset.getTarget().equalsIgnoreCase(VSERVER_VSERVER_NAME)) {
+ return virtualOnsetEvent.getAai().get(VSERVER_VSERVER_NAME);
+ } else if (this.onset.getTarget().equalsIgnoreCase(GENERIC_VNF_VNF_ID)) {
+ return virtualOnsetEvent.getAai().get(GENERIC_VNF_VNF_ID);
+ } else if (this.onset.getTarget().equalsIgnoreCase(GENERIC_VNF_VNF_NAME)) {
+ /*
+ * If the onset is enriched with the vnf-id, we don't need an A&AI response
+ */
+ if (virtualOnsetEvent.getAai().containsKey(GENERIC_VNF_VNF_ID)) {
+ return virtualOnsetEvent.getAai().get(GENERIC_VNF_VNF_ID);
+ }
+
+ /*
+ * If the vnf-name was retrieved from the onset then the vnf-id must be obtained from the event
+ * manager's A&AI GET query
+ */
+ String vnfId;
+ if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
+ vnfId = this.eventManager.getCqResponse((VirtualControlLoopEvent) onset).getDefaultGenericVnf()
+ .getVnfId();
+ } else {
+ vnfId = this.eventManager.getVnfResponse().getVnfId();
+ }
+ if (vnfId == null) {
+ throw new AaiException("No vnf-id found");
+ }
+ return vnfId;
+ }
+ throw new ControlLoopException("Target does not match target type");
+ }
+
/**
* Start an operation.
*
@@ -311,88 +295,113 @@ public class ControlLoopOperationManager implements Serializable {
//
switch (policy.getActor()) {
case "APPC":
- /*
- * If the recipe is ModifyConfig, a legacy APPC request is constructed. Otherwise an LCMRequest is
- * constructed.
- */
- this.currentOperation = operation;
- if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) {
- this.operationRequest = AppcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
- operation.clOperation, this.policy, this.targetEntity);
- } else {
- this.operationRequest = AppcLcmActorServiceProvider.constructRequest(
- (VirtualControlLoopEvent) onset, operation.clOperation, this.policy, this.targetEntity);
- }
- //
- // Save the operation
- //
-
- return operationRequest;
+ return startAppcOperation(onset, operation);
case "SO":
- SoActorServiceProvider soActorSp = new SoActorServiceProvider();
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) {
- this.operationRequest =
- soActorSp.constructRequestCq((VirtualControlLoopEvent) onset, operation.clOperation,
- this.policy, eventManager.getCqResponse((VirtualControlLoopEvent) onset));
- } else {
- this.operationRequest = soActorSp.constructRequest((VirtualControlLoopEvent) onset,
- operation.clOperation, this.policy, eventManager.getNqVserverFromAai());
- }
-
- // Save the operation
- this.currentOperation = operation;
-
- if (this.operationRequest == null) {
- this.policyResult = PolicyResult.FAILURE;
- }
-
- return operationRequest;
+ return startSoOperation(onset, operation);
case "VFC":
- if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty("aai.customQuery"))) {
- this.operationRequest = VfcActorServiceProvider.constructRequestCq((VirtualControlLoopEvent) onset,
- operation.clOperation, this.policy,
- eventManager.getCqResponse((VirtualControlLoopEvent) onset));
- } else {
- this.operationRequest = VfcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
- operation.clOperation, this.policy, this.eventManager.getVnfResponse(),
- PolicyEngine.manager.getEnvironmentProperty("vfc.url"),
- PolicyEngine.manager.getEnvironmentProperty("vfc.username"),
- PolicyEngine.manager.getEnvironmentProperty("vfc.password"));
- }
- this.currentOperation = operation;
- if (this.operationRequest == null) {
- this.policyResult = PolicyResult.FAILURE;
- }
- return operationRequest;
+ return startVfcOperation(onset, operation);
case "SDNR":
- /*
- * If the recipe is ModifyConfig or ModifyConfigANR, a SDNR request is constructed.
- */
- this.currentOperation = operation;
- this.operationRequest = SdnrActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
- operation.clOperation, this.policy);
- //
- // Save the operation
- //
- if (this.operationRequest == null) {
- this.policyResult = PolicyResult.FAILURE;
- }
-
- return operationRequest;
+ return startSdnrOperation(onset, operation);
case "SDNC":
- SdncActorServiceProvider provider = new SdncActorServiceProvider();
- this.operationRequest =
- provider.constructRequest((VirtualControlLoopEvent) onset, operation.clOperation, this.policy);
- this.currentOperation = operation;
- if (this.operationRequest == null) {
- this.policyResult = PolicyResult.FAILURE;
- }
- return operationRequest;
+ return startSdncOperation(onset, operation);
default:
throw new ControlLoopException("invalid actor " + policy.getActor() + " on policy");
}
}
+
+ private Object startAppcOperation(ControlLoopEvent onset, Operation operation) {
+ /*
+ * If the recipe is ModifyConfig, a legacy APPC request is constructed. Otherwise an LCMRequest is
+ * constructed.
+ */
+ this.currentOperation = operation;
+ if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) {
+ this.operationRequest = AppcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
+ operation.clOperation, this.policy, this.targetEntity);
+ } else {
+ this.operationRequest = AppcLcmActorServiceProvider.constructRequest(
+ (VirtualControlLoopEvent) onset, operation.clOperation, this.policy, this.targetEntity);
+ }
+ //
+ // Save the operation
+ //
+
+ return operationRequest;
+ }
+
+
+ private Object startSoOperation(ControlLoopEvent onset, Operation operation) throws AaiException {
+ SoActorServiceProvider soActorSp = new SoActorServiceProvider();
+ if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
+ this.operationRequest =
+ soActorSp.constructRequestCq((VirtualControlLoopEvent) onset, operation.clOperation,
+ this.policy, eventManager.getCqResponse((VirtualControlLoopEvent) onset));
+ } else {
+ this.operationRequest = soActorSp.constructRequest((VirtualControlLoopEvent) onset,
+ operation.clOperation, this.policy, eventManager.getNqVserverFromAai());
+ }
+
+ // Save the operation
+ this.currentOperation = operation;
+
+ if (this.operationRequest == null) {
+ this.policyResult = PolicyResult.FAILURE;
+ }
+
+ return operationRequest;
+ }
+
+
+ private Object startVfcOperation(ControlLoopEvent onset, Operation operation) throws AaiException {
+ if (Boolean.valueOf(PolicyEngine.manager.getEnvironmentProperty(AAI_CUSTOM_QUERY))) {
+ this.operationRequest = VfcActorServiceProvider.constructRequestCq((VirtualControlLoopEvent) onset,
+ operation.clOperation, this.policy,
+ eventManager.getCqResponse((VirtualControlLoopEvent) onset));
+ } else {
+ this.operationRequest = VfcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
+ operation.clOperation, this.policy, this.eventManager.getVnfResponse(),
+ PolicyEngine.manager.getEnvironmentProperty("vfc.url"),
+ PolicyEngine.manager.getEnvironmentProperty("vfc.username"),
+ PolicyEngine.manager.getEnvironmentProperty("vfc.password"));
+ }
+ this.currentOperation = operation;
+ if (this.operationRequest == null) {
+ this.policyResult = PolicyResult.FAILURE;
+ }
+ return operationRequest;
+ }
+
+
+ private Object startSdnrOperation(ControlLoopEvent onset, Operation operation) {
+ /*
+ * If the recipe is ModifyConfig or ModifyConfigANR, a SDNR request is constructed.
+ */
+ this.currentOperation = operation;
+ this.operationRequest = SdnrActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
+ operation.clOperation, this.policy);
+ //
+ // Save the operation
+ //
+ if (this.operationRequest == null) {
+ this.policyResult = PolicyResult.FAILURE;
+ }
+
+ return operationRequest;
+ }
+
+
+ private Object startSdncOperation(ControlLoopEvent onset, Operation operation) {
+ SdncActorServiceProvider provider = new SdncActorServiceProvider();
+ this.operationRequest =
+ provider.constructRequest((VirtualControlLoopEvent) onset, operation.clOperation, this.policy);
+ this.currentOperation = operation;
+ if (this.operationRequest == null) {
+ this.policyResult = PolicyResult.FAILURE;
+ }
+ return operationRequest;
+ }
+
/**
* Handle a response.
*
@@ -448,15 +457,10 @@ public class ControlLoopOperationManager implements Serializable {
//
// Determine which subrequestID (ie. attempt)
//
- Integer operationAttempt = null;
- try {
- operationAttempt = Integer.parseInt(appcResponse.getCommonHeader().getSubRequestId());
- } catch (NumberFormatException e) {
- //
- // We cannot tell what happened if this doesn't exist
- //
+ Integer operationAttempt = getSubRequestId(appcResponse);
+ if (operationAttempt == null) {
this.completeOperation(operationAttempt, "Policy was unable to parse APP-C SubRequestID (it was null).",
- PolicyResult.FAILURE_EXCEPTION);
+ PolicyResult.FAILURE_EXCEPTION);
return PolicyResult.FAILURE_EXCEPTION;
}
//
@@ -483,6 +487,12 @@ public class ControlLoopOperationManager implements Serializable {
PolicyResult.FAILURE_EXCEPTION);
return PolicyResult.FAILURE_EXCEPTION;
}
+
+ return onResponse(appcResponse, operationAttempt, code);
+ }
+
+
+ private PolicyResult onResponse(Response appcResponse, Integer operationAttempt, ResponseCode code) {
//
// Ok, let's figure out what APP-C's response is
//
@@ -502,30 +512,21 @@ public class ControlLoopOperationManager implements Serializable {
//
this.completeOperation(operationAttempt, appcResponse.getStatus().getDescription(),
PolicyResult.FAILURE_EXCEPTION);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.FAILURE_EXCEPTION;
+ return getTimeoutResult(PolicyResult.FAILURE_EXCEPTION);
case SUCCESS:
//
//
//
this.completeOperation(operationAttempt, appcResponse.getStatus().getDescription(),
PolicyResult.SUCCESS);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.SUCCESS;
+ return getTimeoutResult(PolicyResult.SUCCESS);
case FAILURE:
//
//
//
this.completeOperation(operationAttempt, appcResponse.getStatus().getDescription(),
PolicyResult.FAILURE);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.FAILURE;
+ return getTimeoutResult(PolicyResult.FAILURE);
default:
return null;
}
@@ -546,6 +547,7 @@ public class ControlLoopOperationManager implements Serializable {
if (operationAttempt == null) {
this.completeOperation(operationAttempt, "Policy was unable to parse APP-C SubRequestID (it was null).",
PolicyResult.FAILURE_EXCEPTION);
+ return PolicyResult.FAILURE_EXCEPTION;
}
/*
@@ -579,6 +581,7 @@ public class ControlLoopOperationManager implements Serializable {
if (operationAttempt == null) {
this.completeOperation(operationAttempt, "Policy was unable to parse SDNR SubRequestID.",
PolicyResult.FAILURE_EXCEPTION);
+ return PolicyResult.FAILURE_EXCEPTION;
}
/*
@@ -610,22 +613,16 @@ public class ControlLoopOperationManager implements Serializable {
//
// Consider it as success
//
- this.completeOperation(this.attempts, msoResponse.getSoResponse().getHttpResponseCode() + " Success",
+ this.completeOperation(this.attempts, msoResponse.getSoResponse().getHttpResponseCode() + SUCCESS_MSG,
PolicyResult.SUCCESS);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.SUCCESS;
+ return getTimeoutResult(PolicyResult.SUCCESS);
default:
//
// Consider it as failure
//
- this.completeOperation(this.attempts, msoResponse.getSoResponse().getHttpResponseCode() + " Failed",
+ this.completeOperation(this.attempts, msoResponse.getSoResponse().getHttpResponseCode() + FAILED_MSG,
PolicyResult.FAILURE);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.FAILURE;
+ return getTimeoutResult(PolicyResult.FAILURE);
}
}
@@ -640,17 +637,14 @@ public class ControlLoopOperationManager implements Serializable {
//
// Consider it as success
//
- this.completeOperation(this.attempts, " Success", PolicyResult.SUCCESS);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.SUCCESS;
+ this.completeOperation(this.attempts, SUCCESS_MSG, PolicyResult.SUCCESS);
+ return getTimeoutResult(PolicyResult.SUCCESS);
} else {
//
// Consider it as failure
//
- this.completeOperation(this.attempts, " Failed", PolicyResult.FAILURE);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
+ this.completeOperation(this.attempts, FAILED_MSG, PolicyResult.FAILURE);
+ if (PolicyResult.FAILURE_TIMEOUT.equals(this.policyResult)) {
return null;
}
// increment operation attempts for retries
@@ -670,17 +664,14 @@ public class ControlLoopOperationManager implements Serializable {
//
// Consider it as success
//
- this.completeOperation(this.attempts, " Success", PolicyResult.SUCCESS);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
- return null;
- }
- return PolicyResult.SUCCESS;
+ this.completeOperation(this.attempts, SUCCESS_MSG, PolicyResult.SUCCESS);
+ return getTimeoutResult(PolicyResult.SUCCESS);
} else {
//
// Consider it as failure
//
- this.completeOperation(this.attempts, " Failed", PolicyResult.FAILURE);
- if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
+ this.completeOperation(this.attempts, FAILED_MSG, PolicyResult.FAILURE);
+ if (PolicyResult.FAILURE_TIMEOUT.equals(this.policyResult)) {
return null;
}
// increment operation attempts for retries
@@ -689,6 +680,22 @@ public class ControlLoopOperationManager implements Serializable {
}
}
+ private PolicyResult getTimeoutResult(PolicyResult result) {
+ return (PolicyResult.FAILURE_TIMEOUT.equals(this.policyResult) ? null : result);
+ }
+
+
+ private Integer getSubRequestId(Response appcResponse) {
+ try {
+ return Integer.valueOf(appcResponse.getCommonHeader().getSubRequestId());
+ } catch (NumberFormatException e) {
+ //
+ // We cannot tell what happened if this doesn't exist
+ //
+ return null;
+ }
+ }
+
/**
* Get the operation timeout.
*