aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-03-12 15:16:44 -0400
committerJim Hahn <jrh3@att.com>2020-03-13 09:27:55 -0400
commit7f6929e5ea6da4015090b3adac73b35f9b3afb18 (patch)
treee1321bf17bfc7cd6f2231088b8a1d8b3d7b790e3
parentaa8225b5211485b3c1150c21e51fd3e93b7f31d3 (diff)
Fix sonar issues in drools-applications
Fixed various sonar issues, including moving some code to policy-common. Fixed some eclipse warnings, including deprecated junit APIs. Issue-ID: POLICY-2426 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I10b40c1e5af62308f2e4c315e4d399aafff2998f
-rw-r--r--controlloop/common/coordination/src/main/java/org/onap/policy/coordination/Util.java10
-rw-r--r--controlloop/common/database/src/main/java/org/onap/policy/database/std/StdOnapPip.java10
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/drl/legacy/ControlLoopParams.java4
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java2
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/EventManagerServices.java8
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java3
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/utils/ControlLoopUtils.java211
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java12
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java28
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java187
-rw-r--r--controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java4
-rw-r--r--controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java1
-rw-r--r--controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java4
-rw-r--r--controlloop/common/feature-controlloop-usecases/src/main/feature/config/usecases-controller.properties9
14 files changed, 42 insertions, 451 deletions
diff --git a/controlloop/common/coordination/src/main/java/org/onap/policy/coordination/Util.java b/controlloop/common/coordination/src/main/java/org/onap/policy/coordination/Util.java
index 12b361f9f..a47854736 100644
--- a/controlloop/common/coordination/src/main/java/org/onap/policy/coordination/Util.java
+++ b/controlloop/common/coordination/src/main/java/org/onap/policy/coordination/Util.java
@@ -1,8 +1,8 @@
/*-
* ============LICENSE_START=======================================================
- * controlloop
+ * ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -95,9 +95,9 @@ public final class Util {
*/
String xacmlPolicy = null;
try (Stream<String> stream = Files.lines(Paths.get(xacmlProtoFilename))) {
- xacmlPolicy = stream.map(s -> s.replaceAll("UNIQUE_ID", uniqueId))
- .map(s -> s.replaceAll("CONTROL_LOOP_ONE", cLOne))
- .map(s -> s.replaceAll("CONTROL_LOOP_TWO", cLTwo))
+ xacmlPolicy = stream.map(s -> s.replace("UNIQUE_ID", uniqueId))
+ .map(s -> s.replace("CONTROL_LOOP_ONE", cLOne))
+ .map(s -> s.replace("CONTROL_LOOP_TWO", cLTwo))
.collect(Collectors.joining(System.lineSeparator()));
} catch (IOException e) {
logger.error("Error while generating XACML policy for coordination directive", e);
diff --git a/controlloop/common/database/src/main/java/org/onap/policy/database/std/StdOnapPip.java b/controlloop/common/database/src/main/java/org/onap/policy/database/std/StdOnapPip.java
index 1416b3ef9..ab5fc4ec7 100644
--- a/controlloop/common/database/src/main/java/org/onap/policy/database/std/StdOnapPip.java
+++ b/controlloop/common/database/src/main/java/org/onap/policy/database/std/StdOnapPip.java
@@ -1,6 +1,8 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2019-2020 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.
@@ -105,7 +107,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine {
properties.getProperty(issuerName + ".persistenceunit"),
emProperties).createEntityManager();
} catch (Exception e) {
- logger.error("Persistence failed {} operations history db {}", e.getLocalizedMessage(), e);
+ logger.error("Persistence failed operations history db", e);
}
}
@@ -200,7 +202,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine {
pipResponse = null;
}
} catch (PIPException ex) {
- logger.error("PIPException getting subject-id attribute: " + ex.getMessage(), ex);
+ logger.error("PIPException getting subject-id attribute", ex);
}
return pipResponse;
}
@@ -229,7 +231,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine {
stdPipResponse.addAttribute(new StdMutableAttribute(category, attributeId, attributeValue,
pipRequest.getIssuer(), false));
} catch (Exception e) {
- logger.error("Failed to convert {} to integer {}", value, e);
+ logger.error("Failed to convert {} to integer", value, e);
}
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/drl/legacy/ControlLoopParams.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/drl/legacy/ControlLoopParams.java
index 769a6d971..3eac66112 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/drl/legacy/ControlLoopParams.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/drl/legacy/ControlLoopParams.java
@@ -35,5 +35,7 @@ public class ControlLoopParams implements Serializable {
private String policyName;
private String policyScope;
private String policyVersion;
- private ToscaPolicy toscaPolicy;
+
+ // not serializable, thus must be transient
+ private transient ToscaPolicy toscaPolicy;
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java
index f2e99a9ad..69cbe7839 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java
@@ -100,8 +100,6 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
FIRST_ONSET, SUBSEQUENT_ONSET, FIRST_ABATEMENT, SUBSEQUENT_ABATEMENT, SYNTAX_ERROR
}
- // TODO limit the number of policies that may be executed for a single event?
-
/**
* {@code True} if this object was created by this JVM instance, {@code false}
* otherwise. This will be {@code false} if this object is reconstituted from a
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/EventManagerServices.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/EventManagerServices.java
index d8668e47d..3fbedcb1f 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/EventManagerServices.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/EventManagerServices.java
@@ -27,6 +27,7 @@ import java.util.Map;
import java.util.Properties;
import lombok.Getter;
import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.common.utils.properties.PropertyObjectUtils;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.actor.guard.GuardActorServiceProvider;
import org.onap.policy.controlloop.actor.guard.GuardConfig;
@@ -38,7 +39,6 @@ import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerImpl;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerParams;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerStub;
-import org.onap.policy.controlloop.utils.ControlLoopUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -86,8 +86,8 @@ public class EventManagerServices {
Properties props = new Properties();
props.load(inpstr);
- Map<String, Object> parameters = ControlLoopUtils.toObject(props, ACTOR_SERVICE_PROPERTIES);
- ControlLoopUtils.compressLists(parameters);
+ Map<String, Object> parameters = PropertyObjectUtils.toObject(props, ACTOR_SERVICE_PROPERTIES);
+ PropertyObjectUtils.compressLists(parameters);
actorService.configure(parameters);
actorService.start();
@@ -157,7 +157,7 @@ public class EventManagerServices {
*/
public OperationHistoryDataManagerImpl makeDataManager(Properties props) {
try {
- Map<String, Object> parameters = ControlLoopUtils.toObject(props, DATA_MANAGER_PROPERTIES);
+ Map<String, Object> parameters = PropertyObjectUtils.toObject(props, DATA_MANAGER_PROPERTIES);
OperationHistoryDataManagerParams params = Util.translate(DATA_MANAGER_PROPERTIES, parameters,
OperationHistoryDataManagerParams.class);
ValidationResult result = params.validate(DATA_MANAGER_PROPERTIES);
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java
index b6c7c8b7a..104e28cd0 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/processor/ControlLoopProcessor.java
@@ -61,8 +61,9 @@ public class ControlLoopProcessor implements Serializable {
@Getter
private transient ToscaPolicy toscaOpPolicy;
+ // not serializable, thus must be transient
@Getter
- private DroolsPolicy domainOpPolicy;
+ private transient DroolsPolicy domainOpPolicy;
/**
* Construct an instance from yaml.
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/utils/ControlLoopUtils.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/utils/ControlLoopUtils.java
index d311b07fc..3e990efc4 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/utils/ControlLoopUtils.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/utils/ControlLoopUtils.java
@@ -18,14 +18,6 @@
package org.onap.policy.controlloop.utils;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.controlloop.processor.ControlLoopProcessor;
@@ -39,7 +31,6 @@ import org.slf4j.LoggerFactory;
public class ControlLoopUtils {
public static final Logger logger = LoggerFactory.getLogger(ControlLoopUtils.class);
- private static final Pattern NAME_PAT = Pattern.compile("(.*)\\[(\\d{1,3})\\]");
private ControlLoopUtils() {
super();
@@ -59,206 +50,4 @@ public class ControlLoopUtils {
return null;
}
}
-
- // TODO move the following to policy-common/utils
-
- /**
- * Converts a set of properties to a Map. Supports json-path style property names with
- * "." separating components, where components may have an optional subscript.
- *
- * @param properties properties to be converted
- * @param prefix properties whose names begin with this prefix are included. The
- * prefix is stripped from the name before adding the value to the map
- * @return a hierarchical map representing the properties
- */
- public static Map<String, Object> toObject(Properties properties, String prefix) {
- String dottedPrefix = prefix + (prefix.isEmpty() || prefix.endsWith(".") ? "" : ".");
- int pfxlen = dottedPrefix.length();
-
- Map<String, Object> map = new LinkedHashMap<>();
-
- for (String name : properties.stringPropertyNames()) {
- if (name.startsWith(dottedPrefix)) {
- String[] components = name.substring(pfxlen).split("[.]");
- setProperty(map, components, properties.getProperty(name));
- }
- }
-
- return map;
- }
-
- /**
- * Sets a property within a hierarchical map.
- *
- * @param map map into which the value should be placed
- * @param names property name components
- * @param value value to be placed into the map
- */
- private static void setProperty(Map<String, Object> map, String[] names, String value) {
- Map<String, Object> node = map;
-
- final int lastComp = names.length - 1;
-
- // process all but the final component
- for (int comp = 0; comp < lastComp; ++comp) {
- node = getNode(node, names[comp]);
- }
-
- // process the final component
- String name = names[lastComp];
- Matcher matcher = NAME_PAT.matcher(name);
-
- if (!matcher.matches()) {
- // no subscript
- node.put(name, value);
- return;
- }
-
- // subscripted
- List<Object> array = getArray(node, matcher.group(1));
- int index = Integer.parseInt(matcher.group(2));
- expand(array, index);
- array.set(index, value);
- }
-
- /**
- * Gets a node.
- *
- * @param map map from which to get the object
- * @param name name of the element to get from the map, with an optional subscript
- * @return a Map
- */
- @SuppressWarnings("unchecked")
- private static Map<String, Object> getNode(Map<String, Object> map, String name) {
- Matcher matcher = NAME_PAT.matcher(name);
-
- if (!matcher.matches()) {
- // no subscript
- return getObject(map, name);
- }
-
- // subscripted
- List<Object> array = getArray(map, matcher.group(1));
- int index = Integer.parseInt(matcher.group(2));
- expand(array, index);
-
- Object item = array.get(index);
- if (item instanceof Map) {
- return (Map<String, Object>) item;
-
- } else {
- LinkedHashMap<String, Object> result = new LinkedHashMap<>();
- array.set(index, result);
- return result;
- }
- }
-
- /**
- * Ensures that an array's size is large enough to hold the specified element.
- *
- * @param array array to be expanded
- * @param index index of the desired element
- */
- private static void expand(List<Object> array, int index) {
- while (array.size() <= index) {
- array.add(null);
- }
- }
-
- /**
- * Gets an object (i.e., Map) from a map. If the particular element is not a Map, then
- * it is replaced with an empty Map.
- *
- * @param map map from which to get the object
- * @param name name of the element to get from the map, without any subscript
- * @return a Map
- */
- private static Map<String, Object> getObject(Map<String, Object> map, String name) {
- @SuppressWarnings("unchecked")
- Map<String, Object> result = (Map<String, Object>) map.compute(name, (key, value) -> {
- if (value instanceof Map) {
- return value;
- } else {
- return new LinkedHashMap<>();
- }
- });
-
- return result;
- }
-
- /**
- * Gets an array from a map. If the particular element is not an array, then it is
- * replaced with an empty array.
- *
- * @param map map from which to get the array
- * @param name name of the element to get from the map, without any subscript
- * @return an array
- */
- private static List<Object> getArray(Map<String, Object> map, String name) {
- @SuppressWarnings("unchecked")
- List<Object> result = (List<Object>) map.compute(name, (key, value) -> {
- if (value instanceof List) {
- return value;
- } else {
- return new ArrayList<>();
- }
- });
-
- return result;
- }
-
- /**
- * Compresses lists contained within a generic object, removing all {@code null}
- * items.
- *
- * @param object object to be compressed
- * @return the original object, modified in place
- */
- public static Object compressLists(Object object) {
- if (object instanceof Map) {
- @SuppressWarnings("unchecked")
- Map<String, Object> asMap = (Map<String, Object>) object;
- compressMapValues(asMap);
-
- } else if (object instanceof List) {
- @SuppressWarnings("unchecked")
- List<Object> asList = (List<Object>) object;
- compressListItems(asList);
- }
-
- // else: ignore anything else
-
- return object;
- }
-
- /**
- * Walks a hierarchical map and removes {@code null} items found in any Lists.
- *
- * @param map map whose lists are to be compressed
- */
- private static void compressMapValues(Map<String, Object> map) {
- for (Object value : map.values()) {
- compressLists(value);
- }
- }
-
- /**
- * Removes {@code null} items from the list. In addition, it walks the items within
- * the list, compressing them, as well.
- *
- * @param list the list to be compressed
- */
- private static void compressListItems(List<Object> list) {
- Iterator<Object> iter = list.iterator();
- while (iter.hasNext()) {
- Object item = iter.next();
- if (item == null) {
- // null item - remove it
- iter.remove();
-
- } else {
- compressLists(item);
- }
- }
- }
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
index 266ad1ac9..db16c4528 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -50,9 +50,7 @@ import org.jetbrains.annotations.NotNull;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -85,10 +83,6 @@ public class ControlLoopEventManagerTest {
private static final String TWO_ONSET_TEST = "TwoOnsetTest";
private static final String VNF_UUID = "83f674e8-7555-44d7-9a39-bdc3770b0491";
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
private VirtualControlLoopEvent onset;
private LockCallback callback;
@@ -405,7 +399,7 @@ public class ControlLoopEventManagerTest {
VirtualControlLoopNotification notification = manager.activate(yamlString, event);
assertNotNull(notification);
assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
-
+
event.getAai().put(VSERVER_NAME, "testVserverName");
// serialize and de-serialize manager
@@ -452,7 +446,7 @@ public class ControlLoopEventManagerTest {
.hasMessage("Do not have a current operation.");
assertNull(manager.unlockCurrentOperation());
-
+
event.getAai().put(VSERVER_NAME, "testVserverName");
ControlLoopOperationManager clom = manager.processControlLoop();
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
index ae6af6c07..47e7d5344 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
@@ -159,29 +159,15 @@ public class ControlLoopProcessorTest {
InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
- ControlLoopProcessor clProcessor = new ControlLoopProcessor(yamlString);
- clProcessor.getCurrentPolicy();
- clProcessor.nextPolicyForResult(PolicyResult.SUCCESS);
-
- clProcessor = new ControlLoopProcessor(yamlString);
- clProcessor.getCurrentPolicy();
- clProcessor.nextPolicyForResult(PolicyResult.FAILURE);
-
- clProcessor = new ControlLoopProcessor(yamlString);
- clProcessor.getCurrentPolicy();
- clProcessor.nextPolicyForResult(PolicyResult.FAILURE_EXCEPTION);
-
- clProcessor = new ControlLoopProcessor(yamlString);
- clProcessor.getCurrentPolicy();
- clProcessor.nextPolicyForResult(PolicyResult.FAILURE_GUARD);
-
- clProcessor = new ControlLoopProcessor(yamlString);
- clProcessor.getCurrentPolicy();
- clProcessor.nextPolicyForResult(PolicyResult.FAILURE_RETRIES);
+ for (PolicyResult result : PolicyResult.values()) {
+ checkResult(yamlString, result);
+ }
+ }
- clProcessor = new ControlLoopProcessor(yamlString);
+ private void checkResult(String yamlString, PolicyResult result) throws ControlLoopException {
+ ControlLoopProcessor clProcessor = new ControlLoopProcessor(yamlString);
clProcessor.getCurrentPolicy();
- clProcessor.nextPolicyForResult(PolicyResult.FAILURE_TIMEOUT);
+ clProcessor.nextPolicyForResult(result);
}
/**
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
index 2f14954ca..7238ba05b 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
@@ -1,5 +1,7 @@
/*-
* ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,19 +24,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
-import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
-import java.util.AbstractSet;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
import org.junit.Test;
-import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -55,179 +47,4 @@ public class ControlLoopUtilsTest {
assertNull(ControlLoopUtils.toControlLoopParams(null));
}
-
- @Test
- public void testToObject() {
- Map<String, String> map = Map.of("abc", "def", "ghi", "jkl");
- Properties props = new Properties();
- props.putAll(map);
-
- // with empty prefix
- Map<String, Object> result = ControlLoopUtils.toObject(props, "");
- assertEquals(map, result);
-
- // with dotted prefix - other items skipped
- map = Map.of("pfx.abc", "def", "ghi", "jkl", "pfx.mno", "pqr", "differentpfx.stu", "vwx");
- props.clear();
- props.putAll(Map.of("pfx.abc", "def", "ghi", "jkl", "pfx.mno", "pqr", "differentpfx.stu", "vwx"));
- result = ControlLoopUtils.toObject(props, "pfx.");
- map = Map.of("abc", "def", "mno", "pqr");
- assertEquals(map, result);
-
- // undotted prefix - still skips other items
- result = ControlLoopUtils.toObject(props, "pfx");
- assertEquals(map, result);
- }
-
- @Test
- public void testSetProperty() {
- // one, two, and three components in the name, the last two with subscripts
- Map<String, Object> map = Map.of("one", "one.abc", "two.def", "two.ghi", "three.jkl.mno[0]", "three.pqr",
- "three.jkl.mno[1]", "three.stu");
- Properties props = new Properties();
- props.putAll(map);
-
- Map<String, Object> result = ControlLoopUtils.toObject(props, "");
- // @formatter:off
- map = Map.of(
- "one", "one.abc",
- "two", Map.of("def", "two.ghi"),
- "three", Map.of("jkl",
- Map.of("mno",
- List.of("three.pqr", "three.stu"))));
- // @formatter:on
- assertEquals(map, result);
- }
-
- @Test
- public void testGetNode() {
- Map<String, Object> map = Map.of("abc[0].def", "node.ghi", "abc[0].jkl", "node.mno", "abc[1].def", "node.pqr");
- Properties props = new Properties();
- props.putAll(map);
-
- Map<String, Object> result = ControlLoopUtils.toObject(props, "");
- // @formatter:off
- map = Map.of(
- "abc",
- List.of(
- Map.of("def", "node.ghi", "jkl", "node.mno"),
- Map.of("def", "node.pqr")
- ));
- // @formatter:on
- assertEquals(map, result);
-
- }
-
- @Test
- public void testExpand() {
- // add subscripts out of order
- Properties props = makeProperties("abc[2]", "expand.def", "abc[1]", "expand.ghi");
-
- Map<String, Object> result = ControlLoopUtils.toObject(props, "");
- // @formatter:off
- Map<String,Object> map =
- Map.of("abc",
- Arrays.asList(null, "expand.ghi", "expand.def"));
- // @formatter:on
- assertEquals(map, result);
-
- }
-
- @Test
- public void testGetObject() {
- // first value is primitive, while second is a map
- Properties props = makeProperties("object.abc", "object.def", "object.abc.ghi", "object.jkl");
-
- Map<String, Object> result = ControlLoopUtils.toObject(props, "");
- // @formatter:off
- Map<String,Object> map =
- Map.of("object",
- Map.of("abc",
- Map.of("ghi", "object.jkl")));
- // @formatter:on
- assertEquals(map, result);
- }
-
- @Test
- public void testGetArray() {
- // first value is primitive, while second is an array
- Properties props = makeProperties("array.abc", "array.def", "array.abc[0].ghi", "array.jkl");
-
- Map<String, Object> result = ControlLoopUtils.toObject(props, "");
- // @formatter:off
- Map<String,Object> map =
- Map.of("array",
- Map.of("abc",
- List.of(
- Map.of("ghi", "array.jkl"))));
- // @formatter:on
- assertEquals(map, result);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testCompressLists() throws IOException, CoderException {
- assertEquals("plain-string", ControlLoopUtils.compressLists("plain-string").toString());
-
- // @formatter:off
- Map<String, Object> map =
- Map.of(
- "cmp.abc", "cmp.def",
- "cmp.ghi",
- Arrays.asList(null, "cmp.list1", null, "cmp.list2",
- Map.of("cmp.map", Arrays.asList("cmp.map.list1", "cmp.map1.list2", null))));
- // @formatter:on
-
- // the data structure needs to be modifiable, so we'll encode/decode it
- StandardCoder coder = new StandardCoder();
- map = coder.decode(coder.encode(map), LinkedHashMap.class);
-
- ControlLoopUtils.compressLists(map);
-
- // @formatter:off
- Map<String, Object> expected =
- Map.of(
- "cmp.abc", "cmp.def",
- "cmp.ghi",
- Arrays.asList("cmp.list1", "cmp.list2",
- Map.of("cmp.map", Arrays.asList("cmp.map.list1", "cmp.map1.list2"))));
- // @formatter:on
- assertEquals(expected, map);
- }
-
- /**
- * Makes properties containing the specified key/value pairs. The property set returns
- * names in the order listed.
- *
- * @return a new properties containing the specified key/value pairs
- */
- private Properties makeProperties(String key1, String value1, String key2, String value2) {
- // control the order in which the names are returned
- List<String> keyList = List.of(key1, key2);
-
- Set<String> keySet = new AbstractSet<>() {
- @Override
- public Iterator<String> iterator() {
- return keyList.iterator();
- }
-
- @Override
- public int size() {
- return 2;
- }
- };
-
- Properties props = new Properties() {
- private static final long serialVersionUID = 1L;
-
- @Override
- public Set<String> stringPropertyNames() {
- return keySet;
- }
- };
-
- props.putAll(Map.of(key1, value1, key2, value2));
-
- return props;
- }
}
diff --git a/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java b/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java
index 35aabe424..0f35b733b 100644
--- a/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java
+++ b/controlloop/common/feature-controlloop-management/src/main/java/org/onap/policy/drools/server/restful/RestControlLoopManager.java
@@ -79,7 +79,7 @@ public class RestControlLoopManager {
return Response.status(Response.Status.OK).entity(controlLoopNames).build();
} catch (IllegalArgumentException e) {
- logger.error("{}", e);
+ logger.error("'GET' controlloops threw an exception", e);
return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
}
}
@@ -109,7 +109,7 @@ public class RestControlLoopManager {
return Response.status(Response.Status.OK).entity(controlLoopParams).build();
} catch (IllegalArgumentException e) {
- logger.error("{}", e);
+ logger.error("'GET' controlloop threw an exception", e);
return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
}
}
diff --git a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java
index 7fad4468d..2a5bffc7f 100644
--- a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java
+++ b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java
@@ -82,7 +82,6 @@ public class RestControlLoopManagerTest {
private static final String URL_CONTEXT_PATH_TOOLS_AAI = URL_CONTEXT_PATH_TOOLS + "aai/";
private static final String URL_CONTEXT_PATH_TOOLS_AAI_CQ =
URL_CONTEXT_PATH_TOOLS_AAI + "customQuery/";
- private static final String POLICY = "src/test/resources/vCPE.yaml";
private static final String CONTROLLER_FILE = "op-controller.properties";
private static final String CONTROLLER_FILE_BAK = "op-controller.properties.bak";
diff --git a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java
index 9dc4c5ad3..f0d8eb0ad 100644
--- a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java
+++ b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/CacheBasedControlLoopMetricsManager.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -100,7 +100,7 @@ class CacheBasedControlLoopMetricsManager implements ControlLoopMetrics {
RemovalListener<UUID, VirtualControlLoopNotification> listener = notification -> {
if (notification.wasEvicted()) {
evicted(notification.getValue());
- } else {
+ } else if (logger.isInfoEnabled()) {
logger.info("REMOVAL: {} because of {}", notification.getValue().getRequestId(),
notification.getCause().name());
}
diff --git a/controlloop/common/feature-controlloop-usecases/src/main/feature/config/usecases-controller.properties b/controlloop/common/feature-controlloop-usecases/src/main/feature/config/usecases-controller.properties
index fd31ece5b..048130d87 100644
--- a/controlloop/common/feature-controlloop-usecases/src/main/feature/config/usecases-controller.properties
+++ b/controlloop/common/feature-controlloop-usecases/src/main/feature/config/usecases-controller.properties
@@ -23,9 +23,12 @@ controller.name=usecases
dmaap.source.topics=DCAE_TOPIC,APPC-CL,APPC-LCM-WRITE,SDNR-CL-RSP
dmaap.sink.topics=APPC-CL,APPC-LCM-READ,POLICY-CL-MGT,SDNR-CL,DCAE_CL_RSP
-dmaap.source.topics.DCAE_TOPIC.events=org.onap.policy.controlloop.CanonicalOnset,org.onap.policy.controlloop.CanonicalAbated
-dmaap.source.topics.DCAE_TOPIC.events.org.onap.policy.controlloop.CanonicalOnset.filter=[?($.closedLoopEventStatus == 'ONSET')]
-dmaap.source.topics.DCAE_TOPIC.events.org.onap.policy.controlloop.CanonicalAbated.filter=[?($.closedLoopEventStatus == 'ABATED')]
+dmaap.source.topics.DCAE_TOPIC.events=\
+ org.onap.policy.controlloop.CanonicalOnset,org.onap.policy.controlloop.CanonicalAbated
+dmaap.source.topics.DCAE_TOPIC.events.org.onap.policy.controlloop.CanonicalOnset.\
+ filter=[?($.closedLoopEventStatus == 'ONSET')]
+dmaap.source.topics.DCAE_TOPIC.events.org.onap.policy.controlloop.CanonicalAbated.\
+ filter=[?($.closedLoopEventStatus == 'ABATED')]
dmaap.source.topics.DCAE_TOPIC.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gson
dmaap.source.topics.APPC-CL.events=org.onap.policy.appc.Response