summaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib
diff options
context:
space:
mode:
authorPatrick Brady <pb071s@att.com>2017-02-15 23:11:26 -0800
committerPatrick Brady <pb071s@att.com>2017-02-15 23:13:06 -0800
commit1c192d2dd68724e292b6a30f463085a262e1e813 (patch)
treed0e2b3a396e169863cd0efaa835c8675e9d5aaac /appc-dispatcher/appc-dispatcher-common/ranking-framework-lib
parentc69ba05c7508aa7d7f675189a45c8c87569369ef (diff)
Moving all files to root directory
Change-Id: Ica5535fd6ec85f350fe1640b42137b49f83f10f0 Signed-off-by: Patrick Brady <pb071s@att.com>
Diffstat (limited to 'appc-dispatcher/appc-dispatcher-common/ranking-framework-lib')
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/.gitignore1
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/.settings/org.eclipse.wst.common.project.facet.core.xml4
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/pom.xml37
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/AbstractRankedAttributesResolverFactory.java35
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/ConfigurationEntry.java27
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/ConfigurationSet.java30
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesContext.java26
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesResolver.java26
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesResolverFactory.java26
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/BacktraceStrategy.java119
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/CompositeNode.java38
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Constants.java30
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/DefaultRankedAttributesTreeFactory.java49
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/LeafNode.java45
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Node.java40
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/NodeBase.java87
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/RankedAttributesTree.java45
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/RankedAttributesTreeBuilder.java100
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Strategy.java30
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Utils.java40
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/openecomp/appc/rankingframework/TestRankingFramework.java225
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/resources/com/att/eelf/logback.xml27
-rw-r--r--appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/resources/logback.xml46
23 files changed, 1133 insertions, 0 deletions
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/.gitignore b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/.gitignore
new file mode 100644
index 000000000..b83d22266
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/.settings/org.eclipse.wst.common.project.facet.core.xml b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/.settings/org.eclipse.wst.common.project.facet.core.xml
new file mode 100644
index 000000000..f4ef8aa0a
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <installed facet="java" version="1.8"/>
+</faceted-project>
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/pom.xml b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/pom.xml
new file mode 100644
index 000000000..03562065d
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/pom.xml
@@ -0,0 +1,37 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.openecomp.appc</groupId>
+ <artifactId>appc-dispatcher-common</artifactId>
+ <version>1.0.0</version>
+ </parent>
+ <artifactId>appc-ranking-framework-lib</artifactId>
+ <packaging>bundle</packaging>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>com.att.eelf</groupId>
+ <artifactId>eelf-core</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Version>${project.version}</Bundle-Version>
+ <Export-Package>org.openecomp.appc.rankingframework</Export-Package>
+ <Private-Package>org.openecomp.appc.rankingframework.impl</Private-Package>
+ <Embed-Dependency>eelf-core,logback-core,logback-classic;scope=compile|runtime;inline=false</Embed-Dependency>
+ <Embed-Transitive>true</Embed-Transitive>
+ <Import-Package>!groovy.lang,!javax.jms,!org.codehaus.commons.compiler,!org.codehaus.groovy.*,!org.codehaus.janino,!com.ibm.icu.*,!com.sun.faces.*,!org.apache.log,*</Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/AbstractRankedAttributesResolverFactory.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/AbstractRankedAttributesResolverFactory.java
new file mode 100644
index 000000000..75480b300
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/AbstractRankedAttributesResolverFactory.java
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework;
+
+import org.openecomp.appc.rankingframework.impl.DefaultRankedAttributesTreeFactory;
+
+public abstract class AbstractRankedAttributesResolverFactory implements RankedAttributesResolverFactory {
+
+ private static class ReferenceHolder {
+ private static final RankedAttributesResolverFactory INSTANCE = new DefaultRankedAttributesTreeFactory();
+ }
+
+ public static RankedAttributesResolverFactory getInstance() {
+ return ReferenceHolder.INSTANCE;
+ }
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/ConfigurationEntry.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/ConfigurationEntry.java
new file mode 100644
index 000000000..77fa8930d
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/ConfigurationEntry.java
@@ -0,0 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework;
+
+public interface ConfigurationEntry<R> {
+ Object getAttributeValue(String name);
+ R getResult();
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/ConfigurationSet.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/ConfigurationSet.java
new file mode 100644
index 000000000..2e862d9fc
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/ConfigurationSet.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework;
+
+import java.util.Collection;
+
+public interface ConfigurationSet<R> {
+ Collection<String> getRankedAttributeNames();
+
+ Iterable<ConfigurationEntry<R>> getEntries();
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesContext.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesContext.java
new file mode 100644
index 000000000..a8d9b71ec
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesContext.java
@@ -0,0 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework;
+
+public interface RankedAttributesContext {
+ Object getAttributeValue(String name);
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesResolver.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesResolver.java
new file mode 100644
index 000000000..1948ccc1f
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesResolver.java
@@ -0,0 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework;
+
+public interface RankedAttributesResolver<R> {
+ R resolve(RankedAttributesContext context);
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesResolverFactory.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesResolverFactory.java
new file mode 100644
index 000000000..7267c046c
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesResolverFactory.java
@@ -0,0 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework;
+
+public interface RankedAttributesResolverFactory {
+ <R> RankedAttributesResolver<R> create(ConfigurationSet<R> config);
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/BacktraceStrategy.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/BacktraceStrategy.java
new file mode 100644
index 000000000..1365ae834
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/BacktraceStrategy.java
@@ -0,0 +1,119 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework.impl;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.openecomp.appc.rankingframework.RankedAttributesContext;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+class BacktraceStrategy implements Strategy {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(BacktraceStrategy.class);
+
+ @Override
+ public <R> R resolve(CompositeNode<R> rootNode, List<String> rankedNames, RankedAttributesContext context) {
+
+ if (logger.isDebugEnabled()) {
+ StringBuilder buff = new StringBuilder(128);
+ for (String name : rankedNames) {
+ buff.append("/{").append(name).append(" = ").append(Utils.value(context.getAttributeValue(name))).append('}');
+ }
+ logger.debug(String.format("Trying to resolve path: %s", buff));
+ }
+
+ Set<String> visited = new HashSet<>();
+
+ CompositeNode<R> parentNode = rootNode;
+ int depth = 0;
+ boolean stop = false;
+ R result = null;
+
+ String attribute = null;
+ Object value = null;
+
+ do {
+ if (value == null) {
+ attribute = rankedNames.get(depth);
+ value = Utils.value(context.getAttributeValue(attribute));
+ }
+
+ Node<R> childNode = parentNode.children().get(value);
+
+ if (childNode != null) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(String.format("Found matching node '%s' - checking it out", childNode));
+ }
+
+ if (!visited.add(childNode.id())) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(String.format("The matching node '%s' was checked before - ignoring it", childNode));
+ }
+ childNode = null;
+ }
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug(String.format("Node '%s/{%s = %s}' not found - falling back", parentNode, attribute, value != null ? value : "NULL"));
+ }
+ }
+
+ if (childNode != null) {
+ switch (childNode.type()) {
+ case COMPOSITE:
+ depth++;
+ value = null;
+ parentNode = (CompositeNode<R>) childNode;
+ break;
+ case LEAF:
+ if (logger.isDebugEnabled()) {
+ logger.debug( String.format("Result node has been resolved succesfully - '%s'", childNode));
+ }
+ result = ((LeafNode<R>) childNode).result();
+ stop = true;
+ break;
+ default:
+ throw new IllegalStateException(childNode.type().name());
+ }
+ } else {
+ if (!value.equals(Constants.DEFAULT_MATCH)) {
+ logger.debug("Exact match didn't work, trying the default option, if any");
+ value = Constants.DEFAULT_MATCH;
+ } else if (depth > 0) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(String.format("Exact match didn't work and no default option available beneath '%s' - moving out", parentNode));
+ }
+ depth--;
+ value = null;
+ parentNode = parentNode.parent();
+ } else {
+ logger.debug("Didn't success to resolve the path - stopping without result");
+ stop = true;
+ }
+ }
+ } while (!stop);
+
+ return result;
+ }
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/CompositeNode.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/CompositeNode.java
new file mode 100644
index 000000000..0b5e633f3
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/CompositeNode.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework.impl;
+
+import java.util.Map;
+
+class CompositeNode<R> extends NodeBase<R> {
+
+ private final Map<Object, Node<R>> children;
+
+ CompositeNode(String name, Object value, CompositeNode<R> parent, Map<Object, Node<R>> children) {
+ super(name, value, parent, Type.COMPOSITE);
+ this.children = children;
+ }
+
+ Map<Object, Node<R>> children() {
+ return children;
+ }
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Constants.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Constants.java
new file mode 100644
index 000000000..4111131e2
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Constants.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework.impl;
+
+class Constants {
+
+ private Constants() {
+ }
+
+ static final String DEFAULT_MATCH = "*";
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/DefaultRankedAttributesTreeFactory.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/DefaultRankedAttributesTreeFactory.java
new file mode 100644
index 000000000..d7c48dae6
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/DefaultRankedAttributesTreeFactory.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.openecomp.appc.rankingframework.ConfigurationSet;
+import org.openecomp.appc.rankingframework.RankedAttributesResolver;
+import org.openecomp.appc.rankingframework.RankedAttributesResolverFactory;
+
+public final class DefaultRankedAttributesTreeFactory implements RankedAttributesResolverFactory {
+
+ private final Strategy DEFAULT_STRATEGY = new BacktraceStrategy();
+
+ @Override
+ public <R> RankedAttributesResolver<R> create(ConfigurationSet<R> config) {
+
+ CompositeNode<R> root = RankedAttributesTreeBuilder.build(config);
+ RankedAttributesResolver<R> tree = new RankedAttributesTree<R>(root, toList(config.getRankedAttributeNames()),
+ DEFAULT_STRATEGY);
+ return tree;
+ }
+
+ private static List<String> toList(Collection<String> col) {
+ return Collections.unmodifiableList(new ArrayList<>(col));
+ }
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/LeafNode.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/LeafNode.java
new file mode 100644
index 000000000..1b1dffdc8
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/LeafNode.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework.impl;
+
+class LeafNode<R> extends NodeBase<R> {
+
+ private final R result;
+
+ LeafNode(String name, Object value, CompositeNode<R> parent, R result) {
+ super(name, value, parent, Type.LEAF);
+ this.result = result;
+ }
+
+ R result() {
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer buff = new StringBuffer(128);
+ buff.append(super.toString());
+ buff.append(" --> ");
+ buff.append(result.toString());
+ return buff.toString();
+ }
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Node.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Node.java
new file mode 100644
index 000000000..c33e4d875
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Node.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework.impl;
+
+interface Node<R> {
+ enum Type {
+ LEAF, COMPOSITE
+ }
+
+ String id();
+
+ String name();
+
+ Object value();
+
+ CompositeNode<R> parent();
+
+ Type type();
+
+ boolean isDefaultMatch();
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/NodeBase.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/NodeBase.java
new file mode 100644
index 000000000..747d9cfd2
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/NodeBase.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework.impl;
+
+import java.util.UUID;
+
+abstract class NodeBase<R> implements Node<R> {
+
+ private final String name;
+ private final Object value;
+ private final Type type;
+ private final CompositeNode<R> parent;
+ private final String id = UUID.randomUUID().toString();
+
+ NodeBase(String name, Object value, CompositeNode<R> parent, Type type) {
+ this.name = name;
+ this.value = value;
+ this.parent = parent;
+ this.type = type;
+ }
+
+ @Override
+ public String id() {
+ return id;
+ }
+
+ @Override
+ public Type type() {
+ return type;
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public Object value() {
+ return value;
+ }
+
+ @Override
+ public CompositeNode<R> parent() {
+ return parent;
+ }
+
+ @Override
+ public boolean isDefaultMatch() {
+ return value.equals(Constants.DEFAULT_MATCH);
+ }
+
+ @Override
+ public String toString() {
+ if (!name.equals("ROOT")) {
+ StringBuffer buff = new StringBuffer(128);
+ if (parent != null) {
+ buff.append(parent.toString());
+ }
+ buff.append("/{");
+ buff.append(name).append(" = ").append(value);
+ buff.append("}");
+
+ return buff.toString();
+ } else {
+ return "";
+ }
+ }
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/RankedAttributesTree.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/RankedAttributesTree.java
new file mode 100644
index 000000000..305af85a6
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/RankedAttributesTree.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework.impl;
+
+import java.util.List;
+
+import org.openecomp.appc.rankingframework.RankedAttributesContext;
+import org.openecomp.appc.rankingframework.RankedAttributesResolver;
+
+class RankedAttributesTree<R> implements RankedAttributesResolver<R> {
+
+ private final CompositeNode<R> root;
+ private final Strategy strategy;
+ private final List<String> rankedNames;
+
+ RankedAttributesTree(CompositeNode<R> root, List<String> rankedNames, Strategy strategy) {
+ this.root = root;
+ this.rankedNames = rankedNames;
+ this.strategy = strategy;
+ }
+
+ @Override
+ public R resolve(RankedAttributesContext context) {
+ return strategy.resolve(root, rankedNames, context);
+ }
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/RankedAttributesTreeBuilder.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/RankedAttributesTreeBuilder.java
new file mode 100644
index 000000000..16aee5607
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/RankedAttributesTreeBuilder.java
@@ -0,0 +1,100 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework.impl;
+
+import java.util.HashMap;
+
+import org.openecomp.appc.rankingframework.ConfigurationEntry;
+import org.openecomp.appc.rankingframework.ConfigurationSet;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+class RankedAttributesTreeBuilder {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(RankedAttributesTreeBuilder.class);
+
+ private RankedAttributesTreeBuilder() {
+ }
+
+ static <R> CompositeNode<R> build(ConfigurationSet<R> config) {
+
+ Object[] names = config.getRankedAttributeNames().toArray();
+
+ CompositeNode<R> root = new CompositeNode<>("ROOT", Constants.DEFAULT_MATCH, null,
+ new HashMap<Object, Node<R>>());
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(String.format("Building decision tree for ranked attributes: %s", config.getRankedAttributeNames()));
+ }
+
+ for (ConfigurationEntry<R> entry : config.getEntries()) {
+ process(entry, names, root);
+ }
+
+ return root;
+ }
+
+ private static <R> void process(ConfigurationEntry<R> entry, Object[] names, CompositeNode<R> root) {
+ CompositeNode<R> parentNode = null;
+ for (int i = 0; i < names.length; i++) {
+
+ if (i == 0) {
+ parentNode = root;
+ }
+
+ final String name = (String) names[i];
+
+ final Object value = value(entry, name);
+
+ if (i < names.length - 1) {
+ CompositeNode<R> currentNode = (CompositeNode<R>) parentNode.children().get(value);
+ if (currentNode == null) {
+ currentNode = new CompositeNode<>(name, value, parentNode, new HashMap<Object, Node<R>>());
+ parentNode.children().put(value, currentNode);
+ }
+ parentNode = currentNode;
+ } else {
+ LeafNode<R> currentNode = (LeafNode<R>) parentNode.children().get(value);
+ if (currentNode == null) {
+ currentNode = new LeafNode<R>(name, value, parentNode, entry.getResult());
+ parentNode.children().put(value, currentNode);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(String.format("Branch has been created: %s", currentNode));
+ }
+ } else {
+ logger.error(
+ String.format("Duplicated configuration entry has been detected for attribute '%s' with value '%s' - the node '%s'exists already",
+ name,
+ value,
+ currentNode));
+ throw new IllegalArgumentException("Duplicated configuration entry: " + currentNode);
+ }
+ }
+ }
+ }
+
+ private static <R> Object value(ConfigurationEntry<R> entry, String name) {
+ Object value = entry.getAttributeValue(name);
+ return Utils.value(value);
+ }
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Strategy.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Strategy.java
new file mode 100644
index 000000000..121f1fb2d
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Strategy.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework.impl;
+
+import java.util.List;
+
+import org.openecomp.appc.rankingframework.RankedAttributesContext;
+
+interface Strategy {
+ <R> R resolve(CompositeNode<R> root, List<String> rankedNames, RankedAttributesContext context);
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Utils.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Utils.java
new file mode 100644
index 000000000..88ca6d5f5
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Utils.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework.impl;
+
+class Utils {
+
+ private Utils() {
+ }
+
+ static <R> Object value(Object value) {
+ if (value == null || (value instanceof String && isEmpty((String) value))) {
+ value = Constants.DEFAULT_MATCH;
+ }
+
+ return value;
+ }
+
+ private static boolean isEmpty(String str) {
+ return str == null || str.length() == 0;
+ }
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/openecomp/appc/rankingframework/TestRankingFramework.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/openecomp/appc/rankingframework/TestRankingFramework.java
new file mode 100644
index 000000000..75301dc37
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/openecomp/appc/rankingframework/TestRankingFramework.java
@@ -0,0 +1,225 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.appc.rankingframework;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.appc.rankingframework.AbstractRankedAttributesResolverFactory;
+import org.openecomp.appc.rankingframework.ConfigurationEntry;
+import org.openecomp.appc.rankingframework.ConfigurationSet;
+import org.openecomp.appc.rankingframework.RankedAttributesContext;
+import org.openecomp.appc.rankingframework.RankedAttributesResolver;
+
+public class TestRankingFramework {
+
+ private static final String COUNTRY = "COUNTRY";
+ private static final String STATE = "STATE";
+ private static final String CITY = "CITY";
+
+ private static final List<String> NAMES = Arrays.asList(COUNTRY, STATE, CITY);
+
+ private static final String PACIFIC = "Pacific";
+ private static final String ATLANTIC = "Atlantic";
+ private static final String ARCTIC = "Arctic";
+ private static final String NA = "N/A";
+
+ private static ConfigurationEntry<String> entry(String [] attributes, String result) {
+ if (attributes == null || attributes.length != NAMES.size()) {
+ throw new IllegalArgumentException();
+ }
+
+ Map<String, String> map = new HashMap<>(attributes.length);
+ for (int i = 0; i < attributes.length; i++) {
+ map.put(NAMES.get(i), attributes[i]);
+ }
+
+ return new ConfigurationEntryImpl(map, result);
+ }
+
+ private static ConfigurationSet<String> config(ConfigurationEntry<String> ... entries) {
+ return new ConfigurationSetImpl(Arrays.asList(entries), NAMES);
+ }
+
+ private static RankedAttributesContext context(String ... attributes) {
+ if (attributes == null || attributes.length != NAMES.size()) {
+ throw new IllegalArgumentException();
+ }
+
+ Map<String, String> map = new HashMap<>(attributes.length);
+ for (int i = 0; i < attributes.length; i++) {
+ map.put(NAMES.get(i), attributes[i]);
+ }
+
+ return new Context(map);
+ }
+
+ private static class ConfigurationSetImpl implements ConfigurationSet<String> {
+
+ private final Collection<ConfigurationEntry<String>> entries;
+ private final Collection<String> names;
+
+ ConfigurationSetImpl(Collection<ConfigurationEntry<String>> entries, Collection<String> names) {
+ this.entries = entries;
+ this.names = names;
+ }
+
+ @Override
+ public Iterable<ConfigurationEntry<String>> getEntries() {
+ return entries;
+ }
+
+ @Override
+ public Collection<String> getRankedAttributeNames() {
+ return names;
+ }
+ }
+
+ private static class ConfigurationEntryImpl implements ConfigurationEntry<String> {
+
+ private final Map<String, String> attributes;
+ private final String result;
+
+ ConfigurationEntryImpl(Map<String, String> attributes, String result) {
+ this.attributes = attributes;
+ this.result = result;
+ }
+
+ @Override
+ public Object getAttributeValue(String name) {
+ return attributes.get(name);
+ }
+
+ @Override
+ public String getResult() {
+ return result;
+ }
+ }
+
+ private static class Context implements RankedAttributesContext {
+
+ private final Map<String, String> map;
+
+ Context(Map<String, String> map) {
+ this.map = map;
+ }
+
+ @Override
+ public Object getAttributeValue(String name) {
+ return map.get(name);
+ }
+ }
+
+ private static ConfigurationSet<String> testData() {
+ @SuppressWarnings("unchecked")
+ ConfigurationSet<String> config = config(
+ entry(new String [] {"US", "CA", "SFO"}, PACIFIC),
+ entry(new String [] {"US", "CA", "LA"}, PACIFIC),
+ entry(new String [] {"US", "FL", "MIAMI"}, ATLANTIC),
+ entry(new String [] {"US", "AK", "Barrow"}, ARCTIC),
+ entry(new String [] {"US", "AK", "*"}, PACIFIC),
+ entry(new String [] {"US", "*", "Houston"}, ATLANTIC),
+ entry(new String [] {"US", "*", "*"}, NA)
+ );
+
+ return config;
+ }
+
+ private static RankedAttributesResolver<String> resolver(ConfigurationSet<String> config) {
+ return AbstractRankedAttributesResolverFactory.getInstance().create(config);
+ }
+
+ @Test
+ public void testExactMatch() {
+
+ ConfigurationSet<String> config = testData();
+
+ RankedAttributesResolver<String> resolver = resolver(config) ;
+
+ RankedAttributesContext context = context("US", "CA", "SFO");
+
+ String result = resolver.resolve(context);
+
+ Assert.assertEquals(PACIFIC, result);
+ }
+
+ @Test
+ public void testDefaultMatchPartial() {
+
+ ConfigurationSet<String> config = testData();
+
+ RankedAttributesResolver<String> resolver = resolver(config) ;
+
+ RankedAttributesContext context = context("US", "AK", "Anchorage");
+
+ String result = resolver.resolve(context);
+
+ Assert.assertEquals(PACIFIC, result);
+ }
+
+ @Test
+ public void testDefaultMatchFull() {
+
+ ConfigurationSet<String> config = testData();
+
+ RankedAttributesResolver<String> resolver = resolver(config) ;
+
+ RankedAttributesContext context = context("US", "IL", "Chicago");
+
+ String result = resolver.resolve(context);
+
+ Assert.assertEquals(NA, result);
+ }
+
+ @Test
+ public void testDefaultMatchInTheMiddle() {
+
+ ConfigurationSet<String> config = testData();
+
+ RankedAttributesResolver<String> resolver = resolver(config) ;
+
+ RankedAttributesContext context = context("US", "TX", "Houston");
+
+ String result = resolver.resolve(context);
+
+ Assert.assertEquals(ATLANTIC, result);
+ }
+
+ @Test
+ public void testBacktrace() {
+
+ ConfigurationSet<String> config = testData();
+
+ RankedAttributesResolver<String> resolver = resolver(config) ;
+
+ RankedAttributesContext context = context("US", "CA", "SJC");
+
+ String result = resolver.resolve(context);
+
+ Assert.assertEquals(NA, result);
+ }
+}
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/resources/com/att/eelf/logback.xml b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/resources/com/att/eelf/logback.xml
new file mode 100644
index 000000000..2ac88adbc
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/resources/com/att/eelf/logback.xml
@@ -0,0 +1,27 @@
+<!--
+ ============LICENSE_START=======================================================
+ openECOMP : APP-C
+ ================================================================================
+ Copyright (C) 2017 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=========================================================
+ -->
+
+<configuration scan="true" scanPeriod="3 seconds" debug="false">
+
+<!--
+ Dummy file to suppress default EELF configuration
+ -->
+</configuration>
diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/resources/logback.xml b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/resources/logback.xml
new file mode 100644
index 000000000..c93e4e4a9
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/resources/logback.xml
@@ -0,0 +1,46 @@
+<!--
+ ============LICENSE_START=======================================================
+ openECOMP : APP-C
+ ================================================================================
+ Copyright (C) 2017 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=========================================================
+ -->
+
+<configuration scan="true" scanPeriod="3 seconds" debug="false">
+
+ <property name="logDirectory" value="target" />
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern> %.-5level %-36.36logger - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>${logDirectory}/debug.log</file>
+ <encoder>
+ <pattern> %.-5level %-36.36logger - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="org.openecomp.appc" level="DEBUG" additivity="false">
+ <appender-ref ref="FILE" />
+ </logger>
+
+ <root level="WARN">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>