summaryrefslogtreecommitdiffstats
path: root/models-interactions
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2019-10-15 16:19:40 +0000
committerGerrit Code Review <gerrit@onap.org>2019-10-15 16:19:40 +0000
commit9c2c12756735b0354de68903bbba7bfb55d56863 (patch)
treeb508b165865e6db5906a6de345817337b6e64101 /models-interactions
parentada98e3bfe5906f238a058c4ef056603dd0dbe63 (diff)
parentbd1e928680cbd46365d7a863c85f5274882a2a51 (diff)
Merge "Remove actor and recipe checks from ControlLoopCompiler.java"
Diffstat (limited to 'models-interactions')
-rw-r--r--models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java74
-rw-r--r--models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java4
-rw-r--r--models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java4
3 files changed, 20 insertions, 62 deletions
diff --git a/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java b/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java
index c1543d05b..e680969b2 100644
--- a/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java
+++ b/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java
@@ -395,55 +395,23 @@ public class ControlLoopCompiler implements Serializable {
}
private static boolean isActorOk(Policy operPolicy, ControlLoopCompilerCallback callback) {
- boolean isOk = true;
- if (operPolicy.getActor() == null) {
+ if (StringUtils.isBlank(operPolicy.getActor())) {
if (callback != null) {
callback.onError("Policy actor is null");
}
- isOk = false;
- }
- //
- // Construct a list for all valid actors
- //
- ImmutableList<String> actors = ImmutableList.of("APPC", "SDNC", "SDNR", "SO", "VFC");
- //
- if (operPolicy.getActor() != null && (!actors.contains(operPolicy.getActor())) ) {
- if (callback != null) {
- callback.onError("Policy actor is invalid");
- }
- isOk = false;
+ return false;
}
- return isOk;
+ return true;
}
private static boolean isRecipeOk(Policy operPolicy, ControlLoopCompilerCallback callback) {
- boolean isOk = true;
- if (operPolicy.getRecipe() == null) {
+ if (StringUtils.isBlank(operPolicy.getRecipe())) {
if (callback != null) {
callback.onError("Policy recipe is null");
}
- isOk = false;
- }
- //
- // NOTE: We need a way to find the acceptable recipe values (either Enum or a database that has these)
- //
- ImmutableMap<String, List<String>> recipes = new ImmutableMap.Builder<String, List<String>>()
- .put("APPC", ImmutableList.of("Restart", "Rebuild", "Migrate", "ModifyConfig"))
- .put("SDNC", ImmutableList.of("Reroute"))
- .put("SDNR", ImmutableList.of("ModifyConfig"))
- .put("SO", ImmutableList.of("VF Module Create", "VF Module Delete"))
- .put("VFC", ImmutableList.of("Restart"))
- .build();
- //
- if (operPolicy.getRecipe() != null
- && (!recipes.getOrDefault(operPolicy.getActor(),
- Collections.emptyList()).contains(operPolicy.getRecipe()))) {
- if (callback != null) {
- callback.onError("Policy recipe is invalid");
- }
- isOk = false;
+ return false;
}
- return isOk;
+ return true;
}
private static boolean isTargetOk(Policy operPolicy, ControlLoopCompilerCallback callback) {
@@ -490,75 +458,69 @@ public class ControlLoopCompiler implements Serializable {
}
private static boolean isSuccessPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback) {
- boolean isOk = true;
if (FinalResult.toResult(operPolicy.getSuccess()) != null
&& !operPolicy.getSuccess().equals(FinalResult.FINAL_SUCCESS.toString())) {
if (callback != null) {
callback.onError("Policy success is neither another policy nor FINAL_SUCCESS");
}
- isOk = false;
+ return false;
}
- return isOk;
+ return true;
}
private static boolean isFailurePolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback) {
- boolean isOk = true;
if (FinalResult.toResult(operPolicy.getFailure()) != null
&& !operPolicy.getFailure().equals(FinalResult.FINAL_FAILURE.toString())) {
if (callback != null) {
callback.onError("Policy failure is neither another policy nor FINAL_FAILURE");
}
- isOk = false;
+ return false;
}
- return isOk;
+ return true;
}
private static boolean isFailureRetriesPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback) {
- boolean isOk = true;
if (FinalResult.toResult(operPolicy.getFailure_retries()) != null
&& !operPolicy.getFailure_retries().equals(FinalResult.FINAL_FAILURE_RETRIES.toString())) {
if (callback != null) {
callback.onError("Policy failure retries is neither another policy nor FINAL_FAILURE_RETRIES");
}
- isOk = false;
+ return false;
}
- return isOk;
+ return true;
}
private static boolean isFailureTimeoutPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback) {
- boolean isOk = true;
if (FinalResult.toResult(operPolicy.getFailure_timeout()) != null
&& !operPolicy.getFailure_timeout().equals(FinalResult.FINAL_FAILURE_TIMEOUT.toString())) {
if (callback != null) {
callback.onError("Policy failure timeout is neither another policy nor FINAL_FAILURE_TIMEOUT");
}
- isOk = false;
+ return false;
}
- return isOk;
+ return true;
}
private static boolean isFailureExceptionPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback) {
- boolean isOk = true;
if (FinalResult.toResult(operPolicy.getFailure_exception()) != null
&& !operPolicy.getFailure_exception().equals(FinalResult.FINAL_FAILURE_EXCEPTION.toString())) {
if (callback != null) {
callback.onError("Policy failure exception is neither another policy nor FINAL_FAILURE_EXCEPTION");
}
- isOk = false;
+ return false;
}
- return isOk;
+ return true;
}
private static boolean isFailureGuardPolicyResultOk(Policy operPolicy, ControlLoopCompilerCallback callback) {
- boolean isOk = true;
if (FinalResult.toResult(operPolicy.getFailure_guard()) != null
&& !operPolicy.getFailure_guard().equals(FinalResult.FINAL_FAILURE_GUARD.toString())) {
if (callback != null) {
callback.onError("Policy failure guard is neither another policy nor FINAL_FAILURE_GUARD");
}
- isOk = false;
+ return false;
}
- return isOk;
+ return true;
}
private static PolicyNodeWrapper findPolicyNode(Map<Policy, PolicyNodeWrapper> mapNodes, String id) {
diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java
index 6603dcb82..f68b9d39e 100644
--- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java
+++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java
@@ -51,11 +51,7 @@ public class ControlLoopCompilerTest {
expectedOnErrorMessages.add("Policy id is set to a PolicyResult SUCCESS");
expectedOnErrorMessages.add("Policy id is set to a FinalResult FINAL_SUCCESS");
expectedOnErrorMessages.add("Policy actor is null");
- expectedOnErrorMessages.add("Policy actor is invalid");
expectedOnErrorMessages.add("Policy recipe is null");
- expectedOnErrorMessages.add(POLICY_RECIPE_IS_INVALID);
- expectedOnErrorMessages.add(POLICY_RECIPE_IS_INVALID);
- expectedOnErrorMessages.add(POLICY_RECIPE_IS_INVALID);
expectedOnErrorMessages.add("Policy target is null");
expectedOnErrorMessages.add("Policy target is invalid");
expectedOnErrorMessages.add("Policy success is neither another policy nor FINAL_SUCCESS");
diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java
index 602e12d6e..5182da560 100644
--- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java
+++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java
@@ -697,7 +697,7 @@ public class ControlLoopPolicyBuilderTest {
.description(TRIGGER_RESTART)
.actor(null)
.target(null)
- .recipe("Instantiate")
+ .recipe(null)
.payload(null)
.retries(2)
.timeout(300).build());
@@ -712,7 +712,7 @@ public class ControlLoopPolicyBuilderTest {
if ("Policy actor is null".equals(m.getMessage()) && m.getLevel() == MessageLevel.ERROR) {
invalidActor = true;
}
- if ("Policy recipe is invalid".equals(m.getMessage()) && m.getLevel() == MessageLevel.ERROR) {
+ if ("Policy recipe is null".equals(m.getMessage()) && m.getLevel() == MessageLevel.ERROR) {
invalidRecipe = true;
}
if ("Policy target is null".equals(m.getMessage()) && m.getLevel() == MessageLevel.ERROR) {