summaryrefslogtreecommitdiffstats
path: root/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/FeatureEnabledChecker.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-03-26 16:48:31 -0400
committerJim Hahn <jrh3@att.com>2018-03-28 23:47:53 -0400
commita3fa1c69a955af57f4e9023488bac3ef67a4fc3e (patch)
tree0f5173ea23c5d40cdef0f64dffc3fc18e695cf64 /feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/FeatureEnabledChecker.java
parent1d2c8346e0ac02320ca933b66c1943c7f72343c6 (diff)
Add pooling capability
Add an optional feature that that supports session pooling, wherein more than one host can be active at a time. Use beforeInsert() instead of beforeOffer(), where possible. Move request-id-extraction from policy-managment to feature-pooling. Combined AdditionalProperties into PoolingProperties. Finished junit tests for DmaapManager. Adjusted filters for all XxxState classes, and added testGetFilter to all XxxStateTest classes. Always publish Offline message when the internal topic fails. Remove DelayedExtractor, as it isn't needed. Renamed ExtractorMap to ClassExtractors, and added property name prefix to the constructor to give more control over property naming to invokers. Remove State copy constructor. Use class name instead of class in ClassExtractors map. Remove BucketAssignments from ProcessingState. Remove some TODO items. Add META-INF for implemented feature APIs. Fix ClassExtractor bug where it can't find a field in a superclass, and add a test for classes defined in another file. Add assembly and rename project directory. Add more junit coverage. Change-Id: I7f132f84a7b284a58ab09c9069db19b853acd7e9 Issue-ID: POLICY-577 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/FeatureEnabledChecker.java')
-rw-r--r--feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/FeatureEnabledChecker.java144
1 files changed, 144 insertions, 0 deletions
diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/FeatureEnabledChecker.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/FeatureEnabledChecker.java
new file mode 100644
index 00000000..d2f32043
--- /dev/null
+++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/FeatureEnabledChecker.java
@@ -0,0 +1,144 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.policy.drools.pooling;
+
+// TODO move to policy-utils
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.Properties;
+import org.onap.policy.common.utils.properties.SpecPropertyConfiguration;
+import org.onap.policy.common.utils.properties.exception.PropertyException;
+
+/**
+ * Checks whether or not a feature is enabled. The name of the "enable" property
+ * is assumed to be of the form accepted by a {@link SpecPropertyConfiguration},
+ * which contains a substitution place-holder into which a "specializer" (e.g.,
+ * controller or session name) is substituted.
+ */
+public class FeatureEnabledChecker {
+
+ /**
+ *
+ */
+ private FeatureEnabledChecker() {
+ super();
+ }
+
+ /**
+ * Determines if a feature is enabled for a particular specializer.
+ *
+ * @param props properties from which to extract the "enabled" flag
+ * @param specializer specializer to be substituted into the property name
+ * when extracting
+ * @param propName the name of the "enabled" property
+ * @return {@code true} if the feature is enabled, or {@code false} if it is
+ * not enabled (or if the property doesn't exist)
+ * @throws IllegalArgumentException if the "enabled" property is not a
+ * boolean value
+ */
+ public static boolean isFeatureEnabled(Properties props, String specializer, String propName) {
+
+ try {
+ return new Config(specializer, props, propName).isEnabled();
+
+ } catch (PropertyException e) {
+ throw new IllegalArgumentException("cannot check property " + propName, e);
+ }
+ }
+
+
+ /**
+ * Configuration used to extract the value.
+ */
+ private static class Config extends SpecPropertyConfiguration {
+
+ /**
+ * There is a bit of trickery here. This annotation is just a
+ * place-holder to get the superclass to invoke the
+ * {@link #setValue(java.lang.reflect.Field, Properties, Property)
+ * setValue()} method. When that's invoked, we'll substitute
+ * {@link #propOverride} instead of this annotation.
+ */
+ @Property(name = "feature-enabled-property-place-holder")
+ private boolean enabled;
+
+ /**
+ * Annotation that will actually be used to set the field.
+ */
+ private Property propOverride;
+
+ /**
+ *
+ * @param specializer specializer to be substituted into the property
+ * name when extracting
+ * @param props properties from which to extract the "enabled" flag
+ * @param propName the name of the "enabled" property
+ * @throws PropertyException if an error occurs
+ */
+ public Config(String specializer, Properties props, String propName) throws PropertyException {
+ super(specializer);
+
+ propOverride = new Property() {
+
+ @Override
+ public String name() {
+ return propName;
+ }
+
+ @Override
+ public String defaultValue() {
+ // feature is disabled by default
+ return "false";
+ }
+
+ @Override
+ public String accept() {
+ return "";
+ }
+
+ @Override
+ public Class<? extends Annotation> annotationType() {
+ return Property.class;
+ }
+ };
+
+ setAllFields(props);
+ }
+
+ /**
+ * Substitutes {@link #propOverride} for "prop".
+ */
+ @Override
+ protected boolean setValue(Field field, Properties props, Property prop) throws PropertyException {
+ return super.setValue(field, props, propOverride);
+ }
+
+ /**
+ *
+ * @return {@code true} if the feature is enabled, {@code false}
+ * otherwise
+ */
+ public boolean isEnabled() {
+ return enabled;
+ }
+ };
+}