summaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'feature-lifecycle/src/main/java/org')
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java4
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeDroolsController.java24
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactController.java2
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java19
4 files changed, 26 insertions, 23 deletions
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java
index 12828e02..003740c1 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFeature.java
@@ -71,7 +71,7 @@ public class LifecycleFeature
@Override
public boolean beforeShutdown(PolicyEngine engine) {
- return fsmShutdown(engine);
+ return fsmShutdown();
}
@Override
@@ -114,7 +114,7 @@ public class LifecycleFeature
return false;
}
- private boolean fsmShutdown(PolicyEngine engine) {
+ private boolean fsmShutdown() {
fsm.shutdown();
return false;
}
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeDroolsController.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeDroolsController.java
index 8dfbf2f3..71e40726 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeDroolsController.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeDroolsController.java
@@ -24,7 +24,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Function;
+import java.util.function.Predicate;
import lombok.Getter;
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;
@@ -50,7 +50,7 @@ public class PolicyTypeDroolsController implements PolicyTypeController {
protected static final ToscaPolicyTypeIdentifier compliantType =
new ToscaPolicyTypeIdentifier("onap.policies.controlloop.operational.common.Drools", "1.0.0");
- private static final Logger logger = LoggerFactory.getLogger(PolicyTypeController.class);
+ private static final Logger logger = LoggerFactory.getLogger(PolicyTypeDroolsController.class);
@Getter
protected final Map<String, PolicyController> controllers = new ConcurrentHashMap<>();
@@ -60,7 +60,7 @@ public class PolicyTypeDroolsController implements PolicyTypeController {
@GsonJsonIgnore
@JsonIgnore
- protected final transient LifecycleFsm fsm;
+ protected final LifecycleFsm fsm;
/**
* Creates a Policy Type Drools Controller.
@@ -120,17 +120,12 @@ public class PolicyTypeDroolsController implements PolicyTypeController {
return List.of(this.controllers.get(controllerName));
}
- private boolean perform(ToscaPolicy policy, Function<PolicyController, Boolean> operation) {
+ private boolean perform(ToscaPolicy policy, Predicate<PolicyController> operation) {
try {
List<PolicyController> selected = selectControllers(policy);
boolean success = true;
for (PolicyController controller : selected) {
- try {
- success = operation.apply(controller) && success;
- } catch (RuntimeException r) {
- logger.warn("invalid offer to controller: {}", controller);
- success = false;
- }
+ success = modifyController(operation, controller) && success;
}
return success && !selected.isEmpty();
} catch (CoderException e) {
@@ -139,6 +134,15 @@ public class PolicyTypeDroolsController implements PolicyTypeController {
}
}
+ private boolean modifyController(Predicate<PolicyController> operation, PolicyController controller) {
+ try {
+ return operation.test(controller);
+ } catch (RuntimeException r) {
+ logger.warn("invalid offer to controller: {}", controller);
+ return false;
+ }
+ }
+
private List<PolicyController> selectControllers(ToscaPolicy policy) throws CoderException {
List<PolicyController> selected;
if (legacyType.equals(policyType)) {
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactController.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactController.java
index 113bb885..810c2ecf 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactController.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactController.java
@@ -44,7 +44,7 @@ public class PolicyTypeNativeArtifactController implements PolicyTypeController
@GsonJsonIgnore
@JsonIgnore
- protected final transient LifecycleFsm fsm;
+ protected final LifecycleFsm fsm;
public PolicyTypeNativeArtifactController(LifecycleFsm fsm, ToscaPolicyTypeIdentifier policyType) {
this.policyType = policyType;
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java
index e74b2895..9a11955a 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsController.java
@@ -55,7 +55,7 @@ public class PolicyTypeNativeDroolsController implements PolicyTypeController {
@GsonJsonIgnore
@JsonIgnore
- protected final transient LifecycleFsm fsm;
+ protected final LifecycleFsm fsm;
public PolicyTypeNativeDroolsController(LifecycleFsm fsm, ToscaPolicyTypeIdentifier policyType) {
this.policyType = policyType;
@@ -72,9 +72,10 @@ public class PolicyTypeNativeDroolsController implements PolicyTypeController {
ControllerProperties controllerConfig = controllerPolicy.getProperties();
+ configControllerName(controllerConfig, controllerProps);
+
boolean success =
- configControllerName(controllerConfig, controllerProps)
- && configControllerSources(controllerConfig, controllerProps)
+ configControllerSources(controllerConfig, controllerProps)
&& configControllerSinks(controllerConfig, controllerProps)
&& configControllerCustom(controllerConfig, controllerProps);
@@ -145,10 +146,9 @@ public class PolicyTypeNativeDroolsController implements PolicyTypeController {
return nativePolicy;
}
- private boolean configControllerName(ControllerProperties controllerConfig, Properties controllerProps) {
+ private void configControllerName(ControllerProperties controllerConfig, Properties controllerProps) {
controllerProps
.setProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME, controllerConfig.getControllerName());
- return true;
}
private boolean configControllerSources(ControllerProperties controllerConfig, Properties controllerProps) {
@@ -241,11 +241,10 @@ public class PolicyTypeNativeDroolsController implements PolicyTypeController {
private boolean configControllerCustom(ControllerProperties controllerConfig, Properties controllerProps) {
Map<String, String> configCustom = controllerConfig.getCustomConfig();
- if (configCustom == null || configCustom.isEmpty()) {
- return true;
+ if (configCustom != null && !configCustom.isEmpty()) {
+ controllerProps.putAll(configCustom);
}
- controllerProps.putAll(configCustom);
return true;
}
@@ -255,7 +254,7 @@ public class PolicyTypeNativeDroolsController implements PolicyTypeController {
private List<String> sourceTopics(List<ControllerSourceTopic> sourceTopics) {
if (sourceTopics == null) {
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
return sourceTopics.stream()
@@ -265,7 +264,7 @@ public class PolicyTypeNativeDroolsController implements PolicyTypeController {
private List<String> sinkTopics(List<ControllerSinkTopic> sinkTopics) {
if (sinkTopics == null) {
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
return sinkTopics.stream()