From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:19:06 -0800 Subject: Third part of onap rename This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../AbstractRankedAttributesResolverFactory.java | 38 ++++ .../appc/rankingframework/ConfigurationEntry.java | 30 +++ .../appc/rankingframework/ConfigurationSet.java | 33 +++ .../rankingframework/RankedAttributesContext.java | 29 +++ .../rankingframework/RankedAttributesResolver.java | 29 +++ .../RankedAttributesResolverFactory.java | 29 +++ .../rankingframework/impl/BacktraceStrategy.java | 122 +++++++++++ .../appc/rankingframework/impl/CompositeNode.java | 41 ++++ .../onap/appc/rankingframework/impl/Constants.java | 33 +++ .../impl/DefaultRankedAttributesTreeFactory.java | 52 +++++ .../onap/appc/rankingframework/impl/LeafNode.java | 48 +++++ .../org/onap/appc/rankingframework/impl/Node.java | 43 ++++ .../onap/appc/rankingframework/impl/NodeBase.java | 90 ++++++++ .../impl/RankedAttributesTree.java | 48 +++++ .../impl/RankedAttributesTreeBuilder.java | 103 ++++++++++ .../onap/appc/rankingframework/impl/Strategy.java | 33 +++ .../org/onap/appc/rankingframework/impl/Utils.java | 43 ++++ .../AbstractRankedAttributesResolverFactory.java | 38 ---- .../appc/rankingframework/ConfigurationEntry.java | 30 --- .../appc/rankingframework/ConfigurationSet.java | 33 --- .../rankingframework/RankedAttributesContext.java | 29 --- .../rankingframework/RankedAttributesResolver.java | 29 --- .../RankedAttributesResolverFactory.java | 29 --- .../rankingframework/impl/BacktraceStrategy.java | 122 ----------- .../appc/rankingframework/impl/CompositeNode.java | 41 ---- .../appc/rankingframework/impl/Constants.java | 33 --- .../impl/DefaultRankedAttributesTreeFactory.java | 52 ----- .../appc/rankingframework/impl/LeafNode.java | 48 ----- .../openecomp/appc/rankingframework/impl/Node.java | 43 ---- .../appc/rankingframework/impl/NodeBase.java | 90 -------- .../impl/RankedAttributesTree.java | 48 ----- .../impl/RankedAttributesTreeBuilder.java | 103 ---------- .../appc/rankingframework/impl/Strategy.java | 33 --- .../appc/rankingframework/impl/Utils.java | 43 ---- .../rankingframework/TestRankingFramework.java | 228 +++++++++++++++++++++ .../rankingframework/TestRankingFramework.java | 228 --------------------- 36 files changed, 1072 insertions(+), 1072 deletions(-) create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/AbstractRankedAttributesResolverFactory.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/ConfigurationEntry.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/ConfigurationSet.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/RankedAttributesContext.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/RankedAttributesResolver.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/RankedAttributesResolverFactory.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/BacktraceStrategy.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/CompositeNode.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Constants.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/DefaultRankedAttributesTreeFactory.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/LeafNode.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Node.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/NodeBase.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/RankedAttributesTree.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/RankedAttributesTreeBuilder.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Strategy.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Utils.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/AbstractRankedAttributesResolverFactory.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/ConfigurationEntry.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/ConfigurationSet.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesContext.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesResolver.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesResolverFactory.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/BacktraceStrategy.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/CompositeNode.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Constants.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/DefaultRankedAttributesTreeFactory.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/LeafNode.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Node.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/NodeBase.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/RankedAttributesTree.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/RankedAttributesTreeBuilder.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Strategy.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Utils.java create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/onap/appc/rankingframework/TestRankingFramework.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/openecomp/appc/rankingframework/TestRankingFramework.java (limited to 'appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src') diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/AbstractRankedAttributesResolverFactory.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/AbstractRankedAttributesResolverFactory.java new file mode 100644 index 000000000..99ac8a74e --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/AbstractRankedAttributesResolverFactory.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework; + +import org.onap.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/onap/appc/rankingframework/ConfigurationEntry.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/ConfigurationEntry.java new file mode 100644 index 000000000..66c4ce7da --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/ConfigurationEntry.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework; + +public interface ConfigurationEntry { + Object getAttributeValue(String name); + R getResult(); +} diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/ConfigurationSet.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/ConfigurationSet.java new file mode 100644 index 000000000..461d197e7 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/ConfigurationSet.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework; + +import java.util.Collection; + +public interface ConfigurationSet { + Collection getRankedAttributeNames(); + + Iterable> getEntries(); +} diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/RankedAttributesContext.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/RankedAttributesContext.java new file mode 100644 index 000000000..09e749852 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/RankedAttributesContext.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework; + +public interface RankedAttributesContext { + Object getAttributeValue(String name); +} diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/RankedAttributesResolver.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/RankedAttributesResolver.java new file mode 100644 index 000000000..bd9da0911 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/RankedAttributesResolver.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework; + +public interface RankedAttributesResolver { + R resolve(RankedAttributesContext context); +} diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/RankedAttributesResolverFactory.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/RankedAttributesResolverFactory.java new file mode 100644 index 000000000..4f5a85299 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/RankedAttributesResolverFactory.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework; + +public interface RankedAttributesResolverFactory { + RankedAttributesResolver create(ConfigurationSet config); +} diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/BacktraceStrategy.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/BacktraceStrategy.java new file mode 100644 index 000000000..6523fef65 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/BacktraceStrategy.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework.impl; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.onap.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 resolve(CompositeNode rootNode, List 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 visited = new HashSet<>(); + + CompositeNode 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 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) childNode; + break; + case LEAF: + if (logger.isDebugEnabled()) { + logger.debug( String.format("Result node has been resolved succesfully - '%s'", childNode)); + } + result = ((LeafNode) 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/onap/appc/rankingframework/impl/CompositeNode.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/CompositeNode.java new file mode 100644 index 000000000..8d15c5632 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/CompositeNode.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework.impl; + +import java.util.Map; + +class CompositeNode extends NodeBase { + + private final Map> children; + + CompositeNode(String name, Object value, CompositeNode parent, Map> children) { + super(name, value, parent, Type.COMPOSITE); + this.children = children; + } + + Map> children() { + return children; + } +} diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Constants.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Constants.java new file mode 100644 index 000000000..2e4ffd8e1 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Constants.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.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/onap/appc/rankingframework/impl/DefaultRankedAttributesTreeFactory.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/DefaultRankedAttributesTreeFactory.java new file mode 100644 index 000000000..4d59735b5 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/DefaultRankedAttributesTreeFactory.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework.impl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.onap.appc.rankingframework.ConfigurationSet; +import org.onap.appc.rankingframework.RankedAttributesResolver; +import org.onap.appc.rankingframework.RankedAttributesResolverFactory; + +public final class DefaultRankedAttributesTreeFactory implements RankedAttributesResolverFactory { + + private final Strategy DEFAULT_STRATEGY = new BacktraceStrategy(); + + @Override + public RankedAttributesResolver create(ConfigurationSet config) { + + CompositeNode root = RankedAttributesTreeBuilder.build(config); + RankedAttributesResolver tree = new RankedAttributesTree(root, toList(config.getRankedAttributeNames()), + DEFAULT_STRATEGY); + return tree; + } + + private static List toList(Collection col) { + return Collections.unmodifiableList(new ArrayList<>(col)); + } +} diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/LeafNode.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/LeafNode.java new file mode 100644 index 000000000..c6bb97378 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/LeafNode.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework.impl; + +class LeafNode extends NodeBase { + + private final R result; + + LeafNode(String name, Object value, CompositeNode 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/onap/appc/rankingframework/impl/Node.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Node.java new file mode 100644 index 000000000..940e50972 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Node.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework.impl; + +interface Node { + enum Type { + LEAF, COMPOSITE + } + + String id(); + + String name(); + + Object value(); + + CompositeNode parent(); + + Type type(); + + boolean isDefaultMatch(); +} diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/NodeBase.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/NodeBase.java new file mode 100644 index 000000000..1075cca50 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/NodeBase.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework.impl; + +import java.util.UUID; + +abstract class NodeBase implements Node { + + private final String name; + private final Object value; + private final Type type; + private final CompositeNode parent; + private final String id = UUID.randomUUID().toString(); + + NodeBase(String name, Object value, CompositeNode 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 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/onap/appc/rankingframework/impl/RankedAttributesTree.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/RankedAttributesTree.java new file mode 100644 index 000000000..f3e3191ec --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/RankedAttributesTree.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework.impl; + +import java.util.List; + +import org.onap.appc.rankingframework.RankedAttributesContext; +import org.onap.appc.rankingframework.RankedAttributesResolver; + +class RankedAttributesTree implements RankedAttributesResolver { + + private final CompositeNode root; + private final Strategy strategy; + private final List rankedNames; + + RankedAttributesTree(CompositeNode root, List 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/onap/appc/rankingframework/impl/RankedAttributesTreeBuilder.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/RankedAttributesTreeBuilder.java new file mode 100644 index 000000000..2a7cfbfe0 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/RankedAttributesTreeBuilder.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework.impl; + +import java.util.HashMap; + +import org.onap.appc.rankingframework.ConfigurationEntry; +import org.onap.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 CompositeNode build(ConfigurationSet config) { + + Object[] names = config.getRankedAttributeNames().toArray(); + + CompositeNode root = new CompositeNode<>("ROOT", Constants.DEFAULT_MATCH, null, + new HashMap>()); + + if (logger.isDebugEnabled()) { + logger.debug(String.format("Building decision tree for ranked attributes: %s", config.getRankedAttributeNames())); + } + + for (ConfigurationEntry entry : config.getEntries()) { + process(entry, names, root); + } + + return root; + } + + private static void process(ConfigurationEntry entry, Object[] names, CompositeNode root) { + CompositeNode 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 currentNode = (CompositeNode) parentNode.children().get(value); + if (currentNode == null) { + currentNode = new CompositeNode<>(name, value, parentNode, new HashMap>()); + parentNode.children().put(value, currentNode); + } + parentNode = currentNode; + } else { + LeafNode currentNode = (LeafNode) parentNode.children().get(value); + if (currentNode == null) { + currentNode = new LeafNode(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 Object value(ConfigurationEntry 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/onap/appc/rankingframework/impl/Strategy.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Strategy.java new file mode 100644 index 000000000..36f898163 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Strategy.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework.impl; + +import java.util.List; + +import org.onap.appc.rankingframework.RankedAttributesContext; + +interface Strategy { + R resolve(CompositeNode root, List rankedNames, RankedAttributesContext context); +} diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Utils.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Utils.java new file mode 100644 index 000000000..fb18377f9 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/onap/appc/rankingframework/impl/Utils.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.rankingframework.impl; + +class Utils { + + private Utils() { + } + + static 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/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 deleted file mode 100644 index 99ac8a74e..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/AbstractRankedAttributesResolverFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework; - -import org.onap.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 deleted file mode 100644 index 66c4ce7da..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/ConfigurationEntry.java +++ /dev/null @@ -1,30 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework; - -public interface ConfigurationEntry { - 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 deleted file mode 100644 index 461d197e7..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/ConfigurationSet.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework; - -import java.util.Collection; - -public interface ConfigurationSet { - Collection getRankedAttributeNames(); - - Iterable> 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 deleted file mode 100644 index 09e749852..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesContext.java +++ /dev/null @@ -1,29 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.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 deleted file mode 100644 index bd9da0911..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesResolver.java +++ /dev/null @@ -1,29 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework; - -public interface RankedAttributesResolver { - 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 deleted file mode 100644 index 4f5a85299..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/RankedAttributesResolverFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework; - -public interface RankedAttributesResolverFactory { - RankedAttributesResolver create(ConfigurationSet 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 deleted file mode 100644 index 6523fef65..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/BacktraceStrategy.java +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework.impl; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.onap.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 resolve(CompositeNode rootNode, List 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 visited = new HashSet<>(); - - CompositeNode 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 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) childNode; - break; - case LEAF: - if (logger.isDebugEnabled()) { - logger.debug( String.format("Result node has been resolved succesfully - '%s'", childNode)); - } - result = ((LeafNode) 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 deleted file mode 100644 index 8d15c5632..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/CompositeNode.java +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework.impl; - -import java.util.Map; - -class CompositeNode extends NodeBase { - - private final Map> children; - - CompositeNode(String name, Object value, CompositeNode parent, Map> children) { - super(name, value, parent, Type.COMPOSITE); - this.children = children; - } - - Map> 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 deleted file mode 100644 index 2e4ffd8e1..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Constants.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.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 deleted file mode 100644 index 4d59735b5..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/DefaultRankedAttributesTreeFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework.impl; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.onap.appc.rankingframework.ConfigurationSet; -import org.onap.appc.rankingframework.RankedAttributesResolver; -import org.onap.appc.rankingframework.RankedAttributesResolverFactory; - -public final class DefaultRankedAttributesTreeFactory implements RankedAttributesResolverFactory { - - private final Strategy DEFAULT_STRATEGY = new BacktraceStrategy(); - - @Override - public RankedAttributesResolver create(ConfigurationSet config) { - - CompositeNode root = RankedAttributesTreeBuilder.build(config); - RankedAttributesResolver tree = new RankedAttributesTree(root, toList(config.getRankedAttributeNames()), - DEFAULT_STRATEGY); - return tree; - } - - private static List toList(Collection 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 deleted file mode 100644 index c6bb97378..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/LeafNode.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework.impl; - -class LeafNode extends NodeBase { - - private final R result; - - LeafNode(String name, Object value, CompositeNode 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 deleted file mode 100644 index 940e50972..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Node.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework.impl; - -interface Node { - enum Type { - LEAF, COMPOSITE - } - - String id(); - - String name(); - - Object value(); - - CompositeNode 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 deleted file mode 100644 index 1075cca50..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/NodeBase.java +++ /dev/null @@ -1,90 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework.impl; - -import java.util.UUID; - -abstract class NodeBase implements Node { - - private final String name; - private final Object value; - private final Type type; - private final CompositeNode parent; - private final String id = UUID.randomUUID().toString(); - - NodeBase(String name, Object value, CompositeNode 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 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 deleted file mode 100644 index f3e3191ec..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/RankedAttributesTree.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework.impl; - -import java.util.List; - -import org.onap.appc.rankingframework.RankedAttributesContext; -import org.onap.appc.rankingframework.RankedAttributesResolver; - -class RankedAttributesTree implements RankedAttributesResolver { - - private final CompositeNode root; - private final Strategy strategy; - private final List rankedNames; - - RankedAttributesTree(CompositeNode root, List 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 deleted file mode 100644 index 2a7cfbfe0..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/RankedAttributesTreeBuilder.java +++ /dev/null @@ -1,103 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework.impl; - -import java.util.HashMap; - -import org.onap.appc.rankingframework.ConfigurationEntry; -import org.onap.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 CompositeNode build(ConfigurationSet config) { - - Object[] names = config.getRankedAttributeNames().toArray(); - - CompositeNode root = new CompositeNode<>("ROOT", Constants.DEFAULT_MATCH, null, - new HashMap>()); - - if (logger.isDebugEnabled()) { - logger.debug(String.format("Building decision tree for ranked attributes: %s", config.getRankedAttributeNames())); - } - - for (ConfigurationEntry entry : config.getEntries()) { - process(entry, names, root); - } - - return root; - } - - private static void process(ConfigurationEntry entry, Object[] names, CompositeNode root) { - CompositeNode 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 currentNode = (CompositeNode) parentNode.children().get(value); - if (currentNode == null) { - currentNode = new CompositeNode<>(name, value, parentNode, new HashMap>()); - parentNode.children().put(value, currentNode); - } - parentNode = currentNode; - } else { - LeafNode currentNode = (LeafNode) parentNode.children().get(value); - if (currentNode == null) { - currentNode = new LeafNode(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 Object value(ConfigurationEntry 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 deleted file mode 100644 index 36f898163..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Strategy.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework.impl; - -import java.util.List; - -import org.onap.appc.rankingframework.RankedAttributesContext; - -interface Strategy { - R resolve(CompositeNode root, List 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 deleted file mode 100644 index fb18377f9..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/main/java/org/openecomp/appc/rankingframework/impl/Utils.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.rankingframework.impl; - -class Utils { - - private Utils() { - } - - static 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/onap/appc/rankingframework/TestRankingFramework.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/onap/appc/rankingframework/TestRankingFramework.java new file mode 100644 index 000000000..99376923f --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/onap/appc/rankingframework/TestRankingFramework.java @@ -0,0 +1,228 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.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.onap.appc.rankingframework.AbstractRankedAttributesResolverFactory; +import org.onap.appc.rankingframework.ConfigurationEntry; +import org.onap.appc.rankingframework.ConfigurationSet; +import org.onap.appc.rankingframework.RankedAttributesContext; +import org.onap.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 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 entry(String [] attributes, String result) { + if (attributes == null || attributes.length != NAMES.size()) { + throw new IllegalArgumentException(); + } + + Map 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 config(ConfigurationEntry ... 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 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 { + + private final Collection> entries; + private final Collection names; + + ConfigurationSetImpl(Collection> entries, Collection names) { + this.entries = entries; + this.names = names; + } + + @Override + public Iterable> getEntries() { + return entries; + } + + @Override + public Collection getRankedAttributeNames() { + return names; + } + } + + private static class ConfigurationEntryImpl implements ConfigurationEntry { + + private final Map attributes; + private final String result; + + ConfigurationEntryImpl(Map 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 map; + + Context(Map map) { + this.map = map; + } + + @Override + public Object getAttributeValue(String name) { + return map.get(name); + } + } + + private static ConfigurationSet testData() { + @SuppressWarnings("unchecked") + ConfigurationSet 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 resolver(ConfigurationSet config) { + return AbstractRankedAttributesResolverFactory.getInstance().create(config); + } + + @Test + public void testExactMatch() { + + ConfigurationSet config = testData(); + + RankedAttributesResolver resolver = resolver(config) ; + + RankedAttributesContext context = context("US", "CA", "SFO"); + + String result = resolver.resolve(context); + + Assert.assertEquals(PACIFIC, result); + } + + @Test + public void testDefaultMatchPartial() { + + ConfigurationSet config = testData(); + + RankedAttributesResolver resolver = resolver(config) ; + + RankedAttributesContext context = context("US", "AK", "Anchorage"); + + String result = resolver.resolve(context); + + Assert.assertEquals(PACIFIC, result); + } + + @Test + public void testDefaultMatchFull() { + + ConfigurationSet config = testData(); + + RankedAttributesResolver resolver = resolver(config) ; + + RankedAttributesContext context = context("US", "IL", "Chicago"); + + String result = resolver.resolve(context); + + Assert.assertEquals(NA, result); + } + + @Test + public void testDefaultMatchInTheMiddle() { + + ConfigurationSet config = testData(); + + RankedAttributesResolver resolver = resolver(config) ; + + RankedAttributesContext context = context("US", "TX", "Houston"); + + String result = resolver.resolve(context); + + Assert.assertEquals(ATLANTIC, result); + } + + @Test + public void testBacktrace() { + + ConfigurationSet config = testData(); + + RankedAttributesResolver 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/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 deleted file mode 100644 index 99376923f..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/openecomp/appc/rankingframework/TestRankingFramework.java +++ /dev/null @@ -1,228 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.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.onap.appc.rankingframework.AbstractRankedAttributesResolverFactory; -import org.onap.appc.rankingframework.ConfigurationEntry; -import org.onap.appc.rankingframework.ConfigurationSet; -import org.onap.appc.rankingframework.RankedAttributesContext; -import org.onap.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 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 entry(String [] attributes, String result) { - if (attributes == null || attributes.length != NAMES.size()) { - throw new IllegalArgumentException(); - } - - Map 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 config(ConfigurationEntry ... 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 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 { - - private final Collection> entries; - private final Collection names; - - ConfigurationSetImpl(Collection> entries, Collection names) { - this.entries = entries; - this.names = names; - } - - @Override - public Iterable> getEntries() { - return entries; - } - - @Override - public Collection getRankedAttributeNames() { - return names; - } - } - - private static class ConfigurationEntryImpl implements ConfigurationEntry { - - private final Map attributes; - private final String result; - - ConfigurationEntryImpl(Map 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 map; - - Context(Map map) { - this.map = map; - } - - @Override - public Object getAttributeValue(String name) { - return map.get(name); - } - } - - private static ConfigurationSet testData() { - @SuppressWarnings("unchecked") - ConfigurationSet 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 resolver(ConfigurationSet config) { - return AbstractRankedAttributesResolverFactory.getInstance().create(config); - } - - @Test - public void testExactMatch() { - - ConfigurationSet config = testData(); - - RankedAttributesResolver resolver = resolver(config) ; - - RankedAttributesContext context = context("US", "CA", "SFO"); - - String result = resolver.resolve(context); - - Assert.assertEquals(PACIFIC, result); - } - - @Test - public void testDefaultMatchPartial() { - - ConfigurationSet config = testData(); - - RankedAttributesResolver resolver = resolver(config) ; - - RankedAttributesContext context = context("US", "AK", "Anchorage"); - - String result = resolver.resolve(context); - - Assert.assertEquals(PACIFIC, result); - } - - @Test - public void testDefaultMatchFull() { - - ConfigurationSet config = testData(); - - RankedAttributesResolver resolver = resolver(config) ; - - RankedAttributesContext context = context("US", "IL", "Chicago"); - - String result = resolver.resolve(context); - - Assert.assertEquals(NA, result); - } - - @Test - public void testDefaultMatchInTheMiddle() { - - ConfigurationSet config = testData(); - - RankedAttributesResolver resolver = resolver(config) ; - - RankedAttributesContext context = context("US", "TX", "Houston"); - - String result = resolver.resolve(context); - - Assert.assertEquals(ATLANTIC, result); - } - - @Test - public void testBacktrace() { - - ConfigurationSet config = testData(); - - RankedAttributesResolver resolver = resolver(config) ; - - RankedAttributesContext context = context("US", "CA", "SJC"); - - String result = resolver.resolve(context); - - Assert.assertEquals(NA, result); - } -} -- cgit 1.2.3-korg