Merge "Add provider for Tosca Policies"
authorJorge Hernandez <jorge.hernandez-herrero@att.com>
Tue, 26 Mar 2019 00:32:17 +0000 (00:32 +0000)
committerGerrit Code Review <gerrit@onap.org>
Tue, 26 Mar 2019 00:32:17 +0000 (00:32 +0000)
38 files changed:
models-base/src/main/java/org/onap/policy/models/base/Validated.java [new file with mode: 0644]
models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java [new file with mode: 0644]
models-base/src/test/java/org/onap/policy/models/base/keys/TestModels.java [deleted file]
models-decisions/src/main/java/org/onap/policy/models/decisions/concepts/DecisionRequest.java
models-decisions/src/main/java/org/onap/policy/models/decisions/concepts/DecisionResponse.java
models-examples/src/main/resources/policies/vCPE.policies.optimization.input.tosca.yaml [new file with mode: 0644]
models-examples/src/main/resources/policies/vDNS.policy.guard.frequency.output.tosca.yaml [new file with mode: 0644]
models-examples/src/main/resources/policies/vDNS.policy.guard.minmax.input.json
models-examples/src/main/resources/policies/vDNS.policy.guard.minmax.input.tosca.yaml [new file with mode: 0644]
models-examples/src/main/resources/policies/vDNS.policy.guard.minmax.output.tosca.yaml [new file with mode: 0644]
models-examples/src/main/resources/policytypes/onap.policies.optimization.AffinityPolicy.yaml [new file with mode: 0644]
models-examples/src/main/resources/policytypes/onap.policies.optimization.DistancePolicy.yaml [new file with mode: 0644]
models-examples/src/main/resources/policytypes/onap.policies.optimization.HpaPolicy.yaml [new file with mode: 0644]
models-examples/src/main/resources/policytypes/onap.policies.optimization.OptimizationPolicy.yaml [new file with mode: 0644]
models-examples/src/main/resources/policytypes/onap.policies.optimization.PciPolicy.yaml [new file with mode: 0644]
models-examples/src/main/resources/policytypes/onap.policies.optimization.QueryPolicy.yaml [new file with mode: 0644]
models-examples/src/main/resources/policytypes/onap.policies.optimization.SubscriberPolicy.yaml [new file with mode: 0644]
models-examples/src/main/resources/policytypes/onap.policies.optimization.Vim_fit.yaml [new file with mode: 0644]
models-examples/src/main/resources/policytypes/onap.policies.optimization.VnfPolicy.yaml [new file with mode: 0644]
models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java [moved from models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPolicy.java with 56% similarity]
models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpGroup.java
models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpInstanceDetails.java
models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpPolicies.java
models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpSubGroup.java
models-pap/src/main/java/org/onap/policy/models/pap/concepts/Policy.java
models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyIdent.java [new file with mode: 0644]
models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyIdentOptVersion.java [moved from models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpInstanceDetails.java with 51% similarity]
models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyTypeIdent.java [new file with mode: 0644]
models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpGroup.java [deleted file]
models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpSubGroup.java [deleted file]
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdent.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdentOptVersion.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyTypeIdent.java [moved from models-base/src/main/java/org/onap/policy/models/base/keys/PolicyTypeIdent.java with 80% similarity]
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/IdentTestBase.java [new file with mode: 0644]
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdent.java [new file with mode: 0644]
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdentOptVersion.java [new file with mode: 0644]
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyTypeIdent.java [moved from models-base/src/test/java/org/onap/policy/models/base/keys/TestPolicyTypeIdent.java with 62% similarity]

diff --git a/models-base/src/main/java/org/onap/policy/models/base/Validated.java b/models-base/src/main/java/org/onap/policy/models/base/Validated.java
new file mode 100644 (file)
index 0000000..7a0a837
--- /dev/null
@@ -0,0 +1,253 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.base;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Map.Entry;
+import lombok.NonNull;
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * Classes that can be validated. This can be used as a super class or as a stand-alone
+ * utility class.
+ */
+public class Validated {
+
+    /**
+     * Validates the fields of the object. The default method simply returns the result.
+     *
+     * @param result where to place the result
+     * @return the result
+     */
+    public PfValidationResult validate(@NonNull PfValidationResult result) {
+        return result;
+    }
+
+    /**
+     * Validates that a field value is not null.
+     *
+     * @param container the object that contains the field
+     * @param fieldName name of the field to be validated
+     * @param value value to be validated
+     * @param result where to place the result
+     * @return the result
+     */
+    public PfValidationResult validateNotNull(@NonNull Object container, @NonNull String fieldName, Object value,
+                    @NonNull PfValidationResult result) {
+
+        if (value == null) {
+            addError(container, fieldName, result, "null");
+        }
+
+        return result;
+    }
+
+    /**
+     * Validates that the name and version of a concept key do not have the null default
+     * values.
+     *
+     * @param value value to be validated
+     * @param result where to place the result
+     * @return the result
+     */
+    public PfValidationResult validateNotNull(@NonNull PfConceptKey value, @NonNull PfValidationResult result) {
+
+        if (PfConceptKey.NULL_KEY_NAME.equals(value.getName())) {
+            addError(value, "name", result, "null");
+        }
+
+        if (PfConceptKey.NULL_KEY_VERSION.equals(value.getVersion())) {
+            addError(value, "version", result, "null");
+        }
+
+        return result;
+    }
+
+    /**
+     * Validates the contents of a field, verifying that it matches a pattern, if it is
+     * non-null.
+     *
+     * @param container the object that contains the field
+     * @param fieldName name of the field to be validated
+     * @param value value to be validated
+     * @param pattern pattern used to validate the value
+     * @param result where to place the result
+     * @return the result
+     */
+    public PfValidationResult validateText(@NonNull Object container, @NonNull String fieldName, String value,
+                    @NonNull String pattern, @NonNull PfValidationResult result) {
+
+        if (value != null) {
+            addError(container, fieldName, result,
+                            Assertions.getStringParameterValidationMessage(fieldName, value, pattern));
+        }
+
+        return result;
+    }
+
+    /**
+     * Validates the contents of a property field, verifying that the keys ands values are
+     * non-null.
+     *
+     * @param container the object that contains the field
+     * @param fieldName name of the field to be validated
+     * @param properties properties to be validated
+     * @param resultIn where to place the result
+     * @return the result
+     */
+    public <T> PfValidationResult validatePropertiesNotNull(@NonNull Object container, @NonNull String fieldName,
+                    Map<String, T> properties, @NonNull PfValidationResult resultIn) {
+
+        PfValidationResult result = resultIn;
+
+        if (properties == null) {
+            return result;
+        }
+
+        for (Entry<String, T> ent : properties.entrySet()) {
+            String key = ent.getKey();
+            String keyName = fieldName + "." + key;
+            result = validateNotNull(container, keyName, key, result);
+
+            result = validateNotNull(container, keyName, ent.getValue(), result);
+        }
+
+        return result;
+    }
+
+    /**
+     * Validates the items in a collection field are non-null.
+     *
+     * @param container the object that contains the field
+     * @param fieldName name of the field to be validated
+     * @param collection collection whose items are to be validated
+     * @param resultIn where to place the result
+     * @return the result
+     */
+    public <T> PfValidationResult validateCollectionNotNull(@NonNull Object container, @NonNull String fieldName,
+                    Collection<T> collection, @NonNull PfValidationResult resultIn) {
+
+        PfValidationResult result = resultIn;
+
+        if (collection == null) {
+            return result;
+        }
+
+        String prefix = fieldName + ".";
+        int count = 0;
+
+        for (T item : collection) {
+            result = validateNotNull(container, prefix + count, item, result);
+            ++count;
+        }
+
+        return result;
+    }
+
+    /**
+     * Invokes the "validate()" method on each item in a collection field, if the item is
+     * non-null.
+     *
+     * @param container the object that contains the field
+     * @param fieldName name of the field to be validated
+     * @param collection collection whose items are to be validated
+     * @param result where to place the result
+     * @return the result
+     */
+    public <T extends Validated> PfValidationResult validateCollection(@NonNull Object container,
+                    @NonNull String fieldName, Collection<T> collection, @NonNull PfValidationResult result) {
+
+        if (collection == null) {
+            return result;
+        }
+
+        for (T item : collection) {
+            if (item != null) {
+                result = item.validate(result);
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * Invokes the "validate()" method on each item in a concept collection field, if the
+     * item is non-null.
+     *
+     * @param container the object that contains the field
+     * @param fieldName name of the field to be validated
+     * @param collection collection whose items are to be validated
+     * @param result where to place the result
+     * @return the result
+     */
+    public <T extends PfConcept> PfValidationResult validateConceptCollection(@NonNull Object container,
+                    @NonNull String fieldName, Collection<T> collection, @NonNull PfValidationResult result) {
+
+        if (collection == null) {
+            return result;
+        }
+
+        for (T item : collection) {
+            if (item != null) {
+                result = item.validate(result);
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * Adds an error message to the validation result.
+     *
+     * @param container the object that contains the field
+     * @param fieldName name of the field to be validated
+     * @param result where to place the result
+     * @param errmsg the error message to be added, or {@code null} if nothing to add
+     */
+    public void addError(@NonNull Object container, @NonNull String fieldName, @NonNull PfValidationResult result,
+                    String errmsg) {
+        if (errmsg != null) {
+            result.addValidationMessage(new PfValidationMessage(makeKey(container), container.getClass(),
+                            ValidationResult.INVALID, fieldName + " invalid-" + errmsg));
+        }
+    }
+
+    /**
+     * Makes a PfKey suitable for insertion into a validation message. Note: the
+     * "toString()" method of the key simply invokes container.toString();
+     *
+     * @param container the container object for which the key should be made
+     * @return a key for the container
+     */
+    public PfKey makeKey(@NonNull Object container) {
+
+        return new PfConceptKey() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public String toString() {
+                return container.toString();
+            }
+        };
+    }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java b/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java
new file mode 100644 (file)
index 0000000..391e733
--- /dev/null
@@ -0,0 +1,441 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.base;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ValidatedTest {
+    private static final String ERROR_MESSAGE = "error message";
+    private static final String COLLECTION_FIELD = "coll";
+    private static final String VALID_VALUE = "abc123";
+    private static final String PROPS_FIELD = "props";
+    private static final String MY_NAME = "my.name";
+    private static final String VALID_FIELD = "validField";
+    private static final String INVALID_FIELD = "invalidField";
+    private static final String NULL_FIELD = "nullField";
+    private static final String WORD_PAT = "\\w*";
+    private static final String MY_TO_STRING = "[some text]";
+    private static final String VERSION = "1.2.3";
+
+    private Validated validated;
+
+    @Before
+    public void setUp() {
+        validated = new Validated();
+    }
+
+    @Test
+    public void testValidate() {
+        assertThatThrownBy(() -> validated.validate(null)).isInstanceOf(NullPointerException.class);
+
+        PfValidationResult result = new PfValidationResult();
+        assertSame(result, validated.validate(result));
+        assertTrue(result.isValid());
+        assertEquals(0, result.getMessageList().size());
+    }
+
+    @Test
+    public void testValidateNotNull() {
+        PfValidationResult result = new PfValidationResult();
+
+        final PfValidationResult result2 = result;
+        assertThatThrownBy(() -> validated.validateNotNull(null, VALID_FIELD, VALID_VALUE, result2))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validateNotNull(this, null, VALID_VALUE, result2))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validateNotNull(this, VALID_FIELD, VALID_VALUE, null))
+                        .isInstanceOf(NullPointerException.class);
+
+        // null text
+        result = validated.validateNotNull(this, NULL_FIELD, null, result);
+
+        // invalid text
+        result = validated.validateNotNull(this, INVALID_FIELD, "!!!", result);
+
+        // valid text
+        result = validated.validateNotNull(this, VALID_FIELD, VALID_VALUE, result);
+
+        // different value
+        result = validated.validateNotNull(this, VALID_FIELD, Integer.valueOf(10), result);
+
+        assertFalse(result.isValid());
+        assertEquals(1, result.getMessageList().size());
+
+        // check result for null text
+        PfValidationMessage msg = result.getMessageList().get(0);
+        assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
+        assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
+        assertTrue(msg.getMessage().contains("nullField invalid-null"));
+    }
+
+    @Test
+    public void testValidateNotNullConceptKey() {
+        PfValidationResult result = new PfValidationResult();
+
+        // null key
+        PfConceptKey key = new PfConceptKey();
+        key.setVersion(VERSION);
+        result = validated.validateNotNull(key, result);
+
+        // null value
+        key = new PfConceptKey();
+        key.setName(MY_NAME);
+        result = validated.validateNotNull(key, result);
+
+        // both null
+        key = new PfConceptKey();
+        result = validated.validateNotNull(key, result);
+
+        assertFalse(result.isValid());
+        assertEquals(4, result.getMessageList().size());
+
+        // valid key & value
+        key = new PfConceptKey();
+        key.setName(MY_NAME);
+        key.setVersion(VERSION);
+        result = validated.validateNotNull(key, result);
+
+        // no change
+        assertFalse(result.isValid());
+        assertEquals(4, result.getMessageList().size());
+
+        Iterator<PfValidationMessage> it = result.getMessageList().iterator();
+
+        // check null key
+        PfValidationMessage msg = it.next();
+        assertEquals(PfConceptKey.class.getName(), msg.getObservedClass());
+        assertTrue(msg.getMessage().contains("name invalid-null"));
+
+        // check null value
+        msg = it.next();
+        assertEquals(PfConceptKey.class.getName(), msg.getObservedClass());
+        assertTrue(msg.getMessage().contains("version invalid-null"));
+
+        // check both null
+        msg = it.next();
+        assertEquals(PfConceptKey.class.getName(), msg.getObservedClass());
+        assertTrue(msg.getMessage().contains("name invalid-null"));
+        assertTrue(it.next().getMessage().contains("version invalid-null"));
+
+        final PfConceptKey key2 = key;
+        assertThatThrownBy(() -> validated.validateNotNull(key2, null)).isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validateNotNull(null, new PfValidationResult()))
+                        .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void testValidateText() {
+        PfValidationResult result = new PfValidationResult();
+
+        final PfValidationResult result2 = result;
+        assertThatThrownBy(() -> validated.validateText(null, VALID_FIELD, VALID_VALUE, WORD_PAT, result2))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validateText(this, null, VALID_VALUE, WORD_PAT, result2))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validateText(this, VALID_FIELD, VALID_VALUE, null, result2))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validateText(this, VALID_FIELD, VALID_VALUE, WORD_PAT, null))
+                        .isInstanceOf(NullPointerException.class);
+
+        // null text
+        result = validated.validateText(this, NULL_FIELD, null, WORD_PAT, result);
+
+        // invalid text
+        result = validated.validateText(this, INVALID_FIELD, "!!!", WORD_PAT, result);
+
+        // valid text
+        result = validated.validateText(this, VALID_FIELD, VALID_VALUE, WORD_PAT, result);
+
+        assertFalse(result.isValid());
+        assertEquals(1, result.getMessageList().size());
+
+        // check result for invalid text
+        PfValidationMessage msg = result.getMessageList().get(0);
+        assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
+        assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
+        assertTrue(msg.getMessage().contains("invalidField invalid-parameter invalidField"));
+    }
+
+    @Test
+    public void testValidatePropertiesNotNull() {
+        PfValidationResult result = new PfValidationResult();
+        result = validated.validatePropertiesNotNull(this, "properties", null, result);
+        assertTrue(result.isValid());
+        assertEquals(0, result.getMessageList().size());
+
+        Map<String, Integer> map = new LinkedHashMap<>();
+
+        // null key
+        map.put(null, 10);
+
+        // null value
+        map.put("abc", null);
+
+        // valid key & value
+        map.put("def", 11);
+
+
+        result = validated.validatePropertiesNotNull(this, PROPS_FIELD, map, result);
+
+        assertFalse(result.isValid());
+        assertEquals(2, result.getMessageList().size());
+
+        Iterator<PfValidationMessage> it = result.getMessageList().iterator();
+
+        // check null key
+        PfValidationMessage msg = it.next();
+        assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
+        assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
+        assertTrue(msg.getMessage().contains("props.null invalid-null"));
+
+        // check null value
+        msg = it.next();
+        assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
+        assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
+        assertTrue(msg.getMessage().contains("props.abc invalid-null"));
+
+        final PfValidationResult result2 = result;
+        assertThatThrownBy(() -> validated.validatePropertiesNotNull(null, PROPS_FIELD, map, result2))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validatePropertiesNotNull(this, null, map, result2))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validatePropertiesNotNull(this, PROPS_FIELD, map, null))
+                        .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void testValidateCollectionNotNull() {
+        PfValidationResult result = new PfValidationResult();
+        result = validated.validateCollectionNotNull(this, "collection", null, result);
+        assertTrue(result.isValid());
+        assertEquals(0, result.getMessageList().size());
+
+        final List<String> lst = Arrays.asList("abc", null, "def", null);
+
+        result = validated.validateCollectionNotNull(this, COLLECTION_FIELD, lst, result);
+
+        assertFalse(result.isValid());
+        assertEquals(2, result.getMessageList().size());
+
+        Iterator<PfValidationMessage> it = result.getMessageList().iterator();
+
+        // check first item
+        PfValidationMessage msg = it.next();
+        assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
+        assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
+        assertTrue(msg.getMessage().contains("coll.1 invalid-null"));
+
+        // check null value
+        msg = it.next();
+        assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
+        assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
+        assertTrue(msg.getMessage().contains("coll.3 invalid-null"));
+
+        final PfValidationResult result2 = result;
+        assertThatThrownBy(() -> validated.validateCollectionNotNull(null, COLLECTION_FIELD, lst, result2))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validateCollectionNotNull(this, null, lst, result2))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validateCollectionNotNull(this, COLLECTION_FIELD, lst, null))
+                        .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void testValidateCollection() {
+        PfValidationResult result = new PfValidationResult();
+        result = validated.validateCollection(this, "collection", null, result);
+        assertTrue(result.isValid());
+        assertEquals(0, result.getMessageList().size());
+
+        List<MyValid> lst = Arrays.asList(new MyValid(0, false), new MyValid(1, true), null, new MyValid(2, false),
+                        new MyValid(3, true));
+        result = validated.validateCollection(this, COLLECTION_FIELD, lst, result);
+
+        assertFalse(result.isValid());
+        assertEquals(2, result.getMessageList().size());
+
+        Iterator<PfValidationMessage> it = result.getMessageList().iterator();
+
+        // check first item
+        PfValidationMessage msg = it.next();
+        assertEquals(MyValid.class.getName().replace('$', '.'), msg.getObservedClass());
+        assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
+        assertTrue(msg.getMessage().contains("index.0 invalid-wrong value"));
+
+        // check null value
+        msg = it.next();
+        assertEquals(MyValid.class.getName().replace('$', '.'), msg.getObservedClass());
+        assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
+        assertTrue(msg.getMessage().contains("index.2 invalid-wrong value"));
+
+        final PfValidationResult result2 = result;
+        assertThatThrownBy(() -> validated.validateCollection(null, COLLECTION_FIELD, lst, result2))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validateCollection(this, null, lst, result2))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validateCollection(this, COLLECTION_FIELD, lst, null))
+                        .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void testValidateConceptCollection() {
+        PfValidationResult result = new PfValidationResult();
+        result = validated.validateConceptCollection(this, "collection", null, result);
+        assertTrue(result.isValid());
+        assertEquals(0, result.getMessageList().size());
+
+        List<MyConcept> lst = Arrays.asList(new MyConcept(0, false), new MyConcept(1, true), null,
+                        new MyConcept(2, false), new MyConcept(3, true));
+        result = validated.validateConceptCollection(this, COLLECTION_FIELD, lst, result);
+
+        assertFalse(result.isValid());
+        assertEquals(2, result.getMessageList().size());
+
+        Iterator<PfValidationMessage> it = result.getMessageList().iterator();
+
+        // check first item
+        PfValidationMessage msg = it.next();
+        assertEquals(MyConcept.class.getName().replace('$', '.'), msg.getObservedClass());
+        assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
+        assertTrue(msg.getMessage().contains("index.0 invalid-wrong value"));
+
+        // check null value
+        msg = it.next();
+        assertEquals(MyConcept.class.getName().replace('$', '.'), msg.getObservedClass());
+        assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
+        assertTrue(msg.getMessage().contains("index.2 invalid-wrong value"));
+
+        final PfValidationResult result2 = result;
+        assertThatThrownBy(() -> validated.validateConceptCollection(null, COLLECTION_FIELD, lst, result2))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validateConceptCollection(this, null, lst, result2))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.validateConceptCollection(this, COLLECTION_FIELD, lst, null))
+                        .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void testAddError() {
+        final PfValidationResult result = new PfValidationResult();
+        final PfValidationResult result2 = result;
+
+        assertThatThrownBy(() -> validated.addError(null, VALID_FIELD, result2, ERROR_MESSAGE))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.addError(this, null, result2, ERROR_MESSAGE))
+                        .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> validated.addError(this, VALID_FIELD, null, ERROR_MESSAGE))
+                        .isInstanceOf(NullPointerException.class);
+
+        validated.addError(this, VALID_FIELD, result, "error-A");
+        validated.addError(this, VALID_FIELD, result, null);
+        validated.addError(this, VALID_FIELD, result, "error-B");
+
+        assertFalse(result.isValid());
+        assertEquals(2, result.getMessageList().size());
+
+        Iterator<PfValidationMessage> it = result.getMessageList().iterator();
+
+        PfValidationMessage msg = it.next();
+        assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
+        assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
+        assertTrue(msg.getMessage().contains("validField invalid-error-A"));
+
+        msg = it.next();
+        assertEquals(ValidatedTest.class.getName(), msg.getObservedClass());
+        assertEquals(MY_TO_STRING, msg.getObservedKey().toString());
+        assertTrue(msg.getMessage().contains("validField invalid-error-B"));
+    }
+
+    @Test
+    public void testMakeKey() {
+        assertThatThrownBy(() -> validated.makeKey(null)).isInstanceOf(NullPointerException.class);
+
+        PfKey key = validated.makeKey(this);
+        assertEquals(MY_TO_STRING, key.toString());
+    }
+
+    @Override
+    public String toString() {
+        return MY_TO_STRING;
+    }
+
+    private static class MyValid extends Validated {
+        private boolean valid;
+        private int index;
+
+        public MyValid(int index, boolean valid) {
+            this.index = index;
+            this.valid = valid;
+        }
+
+        @Override
+        public PfValidationResult validate(PfValidationResult result) {
+            if (!valid) {
+                this.addError(this, "index." + index, result, "wrong value");
+            }
+
+            return result;
+        }
+
+        @Override
+        public String toString() {
+            return MY_TO_STRING;
+        }
+    }
+
+    private static class MyConcept extends PfConceptKey {
+        private static final long serialVersionUID = 1L;
+
+        private boolean valid;
+        private int index;
+
+        public MyConcept(int index, boolean valid) {
+            this.index = index;
+            this.valid = valid;
+        }
+
+        @Override
+        public PfValidationResult validate(PfValidationResult result) {
+            if (!valid) {
+                new Validated().addError(this, "index." + index, result, "wrong value");
+            }
+
+            return result;
+        }
+
+        @Override
+        public String toString() {
+            return MY_TO_STRING;
+        }
+    }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/keys/TestModels.java b/models-base/src/test/java/org/onap/policy/models/base/keys/TestModels.java
deleted file mode 100644 (file)
index a1bf3be..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.base.keys;
-
-import com.openpojo.reflection.filters.FilterPackageInfo;
-import com.openpojo.validation.Validator;
-import com.openpojo.validation.ValidatorBuilder;
-import com.openpojo.validation.test.impl.GetterTester;
-import com.openpojo.validation.test.impl.SetterTester;
-
-import org.junit.Test;
-import org.onap.policy.common.utils.validation.ToStringTester;
-
-/**
- * Class to perform unit testing of models.
- *
- * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
- */
-public class TestModels {
-
-    @Test
-    public void testModels() {
-        final Validator validator = ValidatorBuilder.create().with(new ToStringTester()).with(new SetterTester())
-                .with(new GetterTester()).build();
-        validator.validate(TestModels.class.getPackage().getName(), new FilterPackageInfo());
-    }
-}
index 94c9c95..1ba7f43 100644 (file)
@@ -43,6 +43,9 @@ public class DecisionRequest {
     @SerializedName("ONAPInstance")
     private String  onapInstance;
 
+    @SerializedName("requestId")
+    private String  requestId;
+
     @SerializedName("action")
     private String  action;
 
index b265fe4..b4f2886 100644 (file)
@@ -33,7 +33,8 @@ import lombok.Data;
  */
 @Data
 public class DecisionResponse {
-
-    private String  errorMessage;
+    private String status;
+    private Map<String, Object> advice;
+    private Map<String, Object> obligations;
     private List<Map<String, Object>> policies;
 }
diff --git a/models-examples/src/main/resources/policies/vCPE.policies.optimization.input.tosca.yaml b/models-examples/src/main/resources/policies/vCPE.policies.optimization.input.tosca.yaml
new file mode 100644 (file)
index 0000000..378e815
--- /dev/null
@@ -0,0 +1,130 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+topology_template:
+policies:
+    - 
+        OSDF_CASABLANCA.Affinity_vCPE_1:
+            type: onap.policies.optimization.AffinityPolicy
+            version: 1.0.0
+            metadata:
+                policy-id: OSDF_CASABLANCA.Affinity_vCPE_1
+            properties:
+                identity: affinity_vCPE
+                policyScope: [vCPE, US, INTERNATIONAL, ip, vGMuxInfra, vG]
+                affinityProperties: 
+                    qualifier: same
+                    category: complex
+                policyType: zone
+                resources: [vGMuxInfra, vG]
+    -
+        OSDF_CASABLANCA.Capacity_vG_1:
+            type: onap.policies.optimization.Vim_fit
+            version: 1.0.0
+            metadata:
+                policy-id: OSDF_CASABLANCA.Capacity_vG_1
+            properties:
+                identity: capacity_vG
+                policyScope: [VCPE, US, INTERNATIONAL, ip, vG]
+                resources: [vG]
+                capacityProperty: 
+                   controller: multicloud
+                   request: "{\"vCPU\": 10, \"Memory\": {\"quantity\": {\"get_param\": \"REQUIRED_MEM\"}, \"unit\": \"GB\"}, \"Storage\": {\"quantity\": {\"get_param\": \"REQUIRED_DISK\"}, \"unit\": \"GB\"}}"
+                policyType: vim_fit
+                applicableResources: any
+    -
+        OSDF_CASABLANCA.Distance_vG_1:
+            type: onap.policies.optimization.DistancePolicy
+            version: 1.0.0
+            metadata:
+                policy-id: OSDF_CASABLANCA.Distance_vG_1
+            properties:
+                distanceProperties: 
+                    locationInfo: customer_loc
+                    distance: 
+                        value: 1500
+                        operator: "<"
+                        unit: km
+                identity: "distance-vG"
+                resources: [vG]
+                policyScope: [vCPE, US, INTERNATIONAL, ip, vG]
+                policyType: distance_to_location
+                applicableResources: any
+    -
+        OSDF_CASABLANCA.hpa_policy_vG_1:
+            type: onap.policies.optimization.HpaPolicy
+            version: 1.0.0
+            metadata:
+                policy-id: OSDF_CASABLANCA.hpa_policy_vG_1
+            properties:
+                resources: [vG]
+                identity: "hpa-vG"
+                policyScope: [vCPE, US, INTERNATIONAL, ip, vG]
+                policyType: hpa            
+                # NONE OF THE FLAVORFEATURES CAME OUT RIGHT
+    -
+        OSDF_CASABLANCA.queryPolicy_vCPE:
+            type: onap.policies.optimization.QueryPolicy
+            version: 1.0.0
+            metadata:
+                policy-id: OSDF_CASABLANCA.queryPolicy_vCPE
+            properties:
+                queryProperties: 
+                    - 
+                        attribute: locationId
+                        attribute_location: customerLocation
+                        value: ""
+                    - 
+                        attribute: id
+                        attribute_location: "vpnInfo.vpnId"
+                        value: ""
+                    - 
+                        attribute: upstreamBW
+                        attribute_location: "vpnInfo.upstreamBW"
+                        value: ""
+                    - 
+                        attribute: customerLatitude
+                        attribute_location: customerLatitude
+                        value: 1.1
+                    - 
+                        attribute: customerLongitude
+                        attribute_location: customerLongitude
+                        value: 2.2
+                serviceName: vCPE
+                policyScope: [vCPE, US, INTERNATIONAL, ip, vGMuxInfra, vG]
+                policyType: request_param_query
+                identity: vCPE_Query_Policy            
+            
+    -
+        OSDF_CASABLANCA.SubscriberPolicy_v1:
+            type: onap.policies.optimization.SubscriberPolicy
+            version: 1.0.0
+            metadata:
+                policy-id: OSDF_CASABLANCA.SubscriberPolicy_v1
+            properties:
+                identity: subscriber_vCPE
+                policyScope: [vCPE, subscriber_x, subscriber_y, subscriberPolicy]
+                properties: 
+                    subscriberName: [subscriber_x, subscriber_y]
+                    subscriberRole: ["PVT Homing"]
+                    provStatus: [CAPPED]
+                policyType: subscriberPolicy
+                serviceName: vCPE
+    -
+        OSDF_CASABLANCA.vnfPolicy_vG:
+            type: onap.policies.optimization.VnfPolicy
+            version: 1.0.0
+            metadata:
+                policy-id: OSDF_CASABLANCA.vnfPolicy_vG
+            properties:
+                identity: vnf_vG
+                policyScope: [vCPE, US, INTERNATIONAL, ip, vG]
+                policyType: vnfPolicy
+                resources: [vG]
+                applicableResources: any
+                vnfProperties: 
+                    - 
+                        inventoryProvider: aai
+                        serviceType: ""
+                        inventoryType: cloud
+                        customerId: ""
+                        orchestrationStatus: ""
+                        equipmentRole: ""
\ No newline at end of file
diff --git a/models-examples/src/main/resources/policies/vDNS.policy.guard.frequency.output.tosca.yaml b/models-examples/src/main/resources/policies/vDNS.policy.guard.frequency.output.tosca.yaml
new file mode 100644 (file)
index 0000000..9cd275e
--- /dev/null
@@ -0,0 +1,20 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+topology_template:
+  policies:
+    -
+      guard.frequency.scaleout:
+        type: onap.policies.controlloop.guard.FrequencyLimiter
+        version: 1.0.0
+        metadata:
+          policy-id : guard.frequency.scaleout
+          policy-version: 1
+        properties:
+          actor: SO
+          recipe: scaleOut
+          targets: .*
+          clname: ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3
+          limit: 1
+          timeWindow: 10
+          timeUnits: minute
+          guardActiveStart: 00:00:01-05:00
+          guardActiveEnd: 23:59:59-05:00
diff --git a/models-examples/src/main/resources/policies/vDNS.policy.guard.minmax.input.tosca.yaml b/models-examples/src/main/resources/policies/vDNS.policy.guard.minmax.input.tosca.yaml
new file mode 100644 (file)
index 0000000..6e0e9f2
--- /dev/null
@@ -0,0 +1,18 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+topology_template:
+  policies:
+    -
+      guard.minmax.scaleout:
+        type: onap.policies.controlloop.guard.MinMax
+        version: 1.0.0
+        metadata:
+          policy-id : guard.minmax.scaleout
+        properties:
+          actor: SO
+          recipe: scaleOut
+          targets: .*
+          clname: ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3
+          min: 1
+          max: 5
+          guardActiveStart: 00:00:01-05:00
+          guardActiveEnd: 23:59:59-05:00
diff --git a/models-examples/src/main/resources/policies/vDNS.policy.guard.minmax.output.tosca.yaml b/models-examples/src/main/resources/policies/vDNS.policy.guard.minmax.output.tosca.yaml
new file mode 100644 (file)
index 0000000..5ac7601
--- /dev/null
@@ -0,0 +1,19 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+topology_template:
+  policies:
+    -
+      guard.minmax.scaleout:
+        type: onap.policies.controlloop.guard.MinMax
+        version: 1.0.0
+        metadata:
+          policy-id : guard.minmax.scaleout
+          policy-version: 1
+        properties:
+          actor: SO
+          recipe: scaleOut
+          targets: .*
+          clname: ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3
+          min: 1
+          max: 5
+          guardActiveStart: 00:00:01-05:00
+          guardActiveEnd: 23:59:59-05:00
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.optimization.AffinityPolicy.yaml b/models-examples/src/main/resources/policytypes/onap.policies.optimization.AffinityPolicy.yaml
new file mode 100644 (file)
index 0000000..c2fd504
--- /dev/null
@@ -0,0 +1,62 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+    - onap.policies.Optimization:
+        derived_from: tosca.policies.Root
+        version: 1.0.0
+        description: a base policy type for all policies that govern optimization
+    - onap.policies.optimization.AffinityPolicy:
+        derived_from: onap.policies.Optimization
+        properties:
+            policyScope:
+                type: list
+                description: scope where the policy is applicable
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+            policyType:
+                type: list
+                description: type of a policy
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+                    consraints:
+                    -   valid_values:
+                        - zone
+            identity:
+                type: string
+                required: true
+            applicableResources:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+                    constraints:
+                    -   valid_values:
+                        - any
+                        - all
+            affinityProperties:
+                type: policy.data.affinityProperties_properties
+                required: true
+            resources:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+data_types:
+    policy.data.affinityProperties_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            qualifier:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+                    constraints:
+                    -   valid_values:
+                        - same
+                        - different
+            category:
+                type: string
+                required: true
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.optimization.DistancePolicy.yaml b/models-examples/src/main/resources/policytypes/onap.policies.optimization.DistancePolicy.yaml
new file mode 100644 (file)
index 0000000..93ddd63
--- /dev/null
@@ -0,0 +1,82 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+    - onap.policies.Optimization:
+        derived_from: tosca.policies.Root
+        version: 1.0.0
+        description: a base policy type for all policies that govern optimization
+    - onap.policies.optimization.DistancePolicy:
+        derived_from: onap.policies.Optimization
+        properties:
+            policyScope:
+                type: list
+                description: scope where the policy is applicable
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+            policyType:
+                type: list
+                description: type of a policy
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+                    consraints:
+                    -   valid_values:
+                        - distance_to_location
+            identity:
+                type: string
+                required: true
+            resources:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+            applicableResources:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+                    constraints:
+                    -   valid_values:
+                        - any
+                        - all
+            distanceProperties:
+                type: policy.data.distanceProperties_properties
+                required: true
+data_types:
+    policy.data.distanceProperties_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            locationInfo:
+                type: string
+                required: true
+            distance:
+                type: policy.data.distance_properties
+                required: true
+    policy.data.distance_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            value:
+                type: string
+                required: true
+            operator:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+                    constraints:
+                    -   valid_values:
+                        - <
+                        - <=
+                        - '>'
+                        - '>='
+                        - '='
+            unit:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+                    constraints:
+                    -   valid_values:
+                        - km
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.optimization.HpaPolicy.yaml b/models-examples/src/main/resources/policytypes/onap.policies.optimization.HpaPolicy.yaml
new file mode 100644 (file)
index 0000000..63f0d8a
--- /dev/null
@@ -0,0 +1,131 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+    - onap.policies.Optimization:
+        derived_from: tosca.policies.Root
+        version: 1.0.0
+        description: a base policy type for all policies that govern optimization
+    - onap.policies.optimization.HpaPolicy:
+        derived_from: onap.policies.Optimization
+        properties:
+            policyScope:
+                type: list
+                description: scope where the policy is applicable
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+            policyType:
+                type: list
+                description: type of a policy
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+                    consraints:
+                    -   valid_values:
+                        - hpa
+            resources:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+            identity:
+                type: string
+                required: true
+            flavorFeatures:
+                type: list
+                required: true
+                entry_schema:
+                    type:policy.data.flavorFeatures_properties
+data_types:
+    policy.data.flavorFeatures_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            id:
+                type: string
+                required: true
+            type:
+                type: string
+                required: true
+            directives:
+                type: list
+                required: true
+                entry_schema:
+                    type: policy.data.directives_properties
+            flavorProperties:
+                type: list
+                required: true
+                entry_schema:
+                    type: policy.data.flavorProperties_properties
+    policy.data.directives_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            type:
+                type: string
+            attributes:
+                type: list
+                entry_schema:
+                    type: policy.data.directives_attributes_properties
+    policy.data.directives_attributes_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            attribute_name:
+                type: string
+            attribute_value:
+                type: string
+    policy.data.flavorProperties_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            hpa-feature:
+                type: string
+                required: true
+            mandatory:
+                type: string
+                required: true
+            score:
+                type: string
+                required: false
+            architecture:
+                type: string
+                required: true
+            hpa-version:
+                type: string
+                required: true
+            directives:
+                type: list
+                required: true
+                entry_schema:
+                    type: policy.data.directives_properties
+            hpa-feature-attributes:
+                type: list
+                required: true
+                entry_schema:
+                    type: policy.data.hpa-feature-attributes_properties
+    policy.data.hpa-feature-attributes_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            hpa-attribute-key:
+                type: string
+                required: true
+            hpa-attribute-value:
+                type: string
+                required: true
+            operator:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+                    constraints:
+                    -   valid_values:
+                        - <
+                        - <=
+                        - '>'
+                        - '>='
+                        - '='
+                        - '!='
+                        - any
+                        - all
+                        - subset
+            unit:
+                type: string
+                required: false
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.optimization.OptimizationPolicy.yaml b/models-examples/src/main/resources/policytypes/onap.policies.optimization.OptimizationPolicy.yaml
new file mode 100644 (file)
index 0000000..edfac14
--- /dev/null
@@ -0,0 +1,89 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+    - onap.policies.Optimization:
+        derived_from: tosca.policies.Root
+        version: 1.0.0
+        description: a base policy type for all policies that govern optimization
+    - onap.policies.optimization.OptimizationPolicy:
+        derived_from: onap.policies.Optimization
+        properties:
+            policyScope:
+                type: list
+                description: scope where the policy is applicable
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+            policyType:
+                type: list
+                description: type of a policy
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+                    consraints:
+                    -   valid_values:
+                        - placement_optimization
+            identity:
+                type: string
+                required: true
+            objective:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+                    constraints:
+                    -   valid_values:
+                        - minimize
+                        - maximize
+            objectiveParameter:
+                type: policy.data.objectiveParameter_properties
+                required: true
+data_types:
+    policy.data.objectiveParameter_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            parameterAttributes:
+                type: list
+                required: true
+                entry_schema:
+                    type: policy.data.parameterAttributes_properties
+            operator:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+                    constraints:
+                    -   valid_values:
+                        - '*'
+                        - +
+                        - '-'
+                        - /
+                        - '%'
+    policy.data.parameterAttributes_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            resources:
+                type: string
+                required: true
+            customerLocationInfo:
+                type: string
+                required: true
+            parameter:
+                type: string
+                required: true
+            weight:
+                type: string
+                required: true
+            operator:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+                    constraints:
+                    -   valid_values:
+                        - '*'
+                        - +
+                        - '-'
+                        - /
+                        - '%'
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.optimization.PciPolicy.yaml b/models-examples/src/main/resources/policytypes/onap.policies.optimization.PciPolicy.yaml
new file mode 100644 (file)
index 0000000..1355eb0
--- /dev/null
@@ -0,0 +1,58 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+    - onap.policies.Optimization:
+        derived_from: tosca.policies.Root
+        version: 1.0.0
+        description: a base policy type for all policies that govern optimization
+    - onap.policies.optimization.PciPolicy:
+        derived_from: onap.policies.Optimization
+        properties:
+            policyScope:
+                type: list
+                description: scope where the policy is applicable
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+            policyType:
+                type: list
+                description: type of a policy
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+                    consraints:
+                    -   valid_values:
+                        - pciPolicy
+            identity:
+                type: string
+                required: true
+            resources:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+            pciProperties:
+                type: list
+                required: false
+                entry_schema:
+                -   type:policy.data.pciProperties_properties
+data_types:
+    policy.data.pciProperties_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            algoCategory:
+                type: string
+                required: false
+            pciOptmizationAlgoName:
+                type: string
+                required: false
+            pciOptimizationNwConstraint:
+                type: string
+                required: false
+            pciOptimizationPriority:
+                type: string
+                required: false
+            pciOptimizationTimeConstraint:
+                type: string
+                required: false
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.optimization.QueryPolicy.yaml b/models-examples/src/main/resources/policytypes/onap.policies.optimization.QueryPolicy.yaml
new file mode 100644 (file)
index 0000000..f7036dc
--- /dev/null
@@ -0,0 +1,47 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+    - onap.policies.Optimization:
+        derived_from: tosca.policies.Root
+        version: 1.0.0
+        description: a base policy type for all policies that govern optimization
+    - onap.policies.optimization.QueryPolicy:
+        derived_from: onap.policies.Optimization
+        properties:
+            policyScope:
+                type: list
+                description: scope where the policy is applicable
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+            policyType:
+                type: list
+                description: type of a policy
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+                    consraints:
+                    -   valid_values:
+                        - request_param_query
+            identity:
+                type: string
+                required: true
+            queryProperties:
+                type: list
+                required: true
+                entry_schema:
+                    type:policy.data.queryProperties_properties
+data_types:
+    policy.data.queryProperties_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            attribute:
+                type: string
+                required: true
+            value:
+                type: string
+                required: true
+            attribute_location:
+                type: string
+                required: true
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.optimization.SubscriberPolicy.yaml b/models-examples/src/main/resources/policytypes/onap.policies.optimization.SubscriberPolicy.yaml
new file mode 100644 (file)
index 0000000..3c2c2b2
--- /dev/null
@@ -0,0 +1,51 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+    - onap.policies.Optimization:
+        derived_from: tosca.policies.Root
+        version: 1.0.0
+        description: a base policy type for all policies that govern optimization
+    - onap.policies.optimization.SubscriberPolicy:
+        derived_from: onap.policies.Optimization
+        properties:
+            policyScope:
+                type: list
+                description: scope where the policy is applicable
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+            policyType:
+                type: list
+                description: type of a policy
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+                    consraints:
+                    -   valid_values:
+                        - subscriberPolicy
+            identity:
+                type: string
+                required: true
+            properties:
+                type: policy.data.properties_properties
+                required: true
+data_types:
+    policy.data.properties_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            subscriberName:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+            subscriberRole:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+            provStatus:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.optimization.Vim_fit.yaml b/models-examples/src/main/resources/policytypes/onap.policies.optimization.Vim_fit.yaml
new file mode 100644 (file)
index 0000000..860c37f
--- /dev/null
@@ -0,0 +1,56 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+    - onap.policies.Optimization:
+        derived_from: tosca.policies.Root
+        version: 1.0.0
+        description: a base policy type for all policies that govern optimization
+    - onap.policies.optimization.Vim_fit:
+        derived_from: onap.policies.Optimization
+        properties:
+            policyScope:
+                type: list
+                description: scope where the policy is applicable
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+            policyType:
+                type: list
+                description: type of a policy
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+                    consraints:
+                    -   valid_values:
+                        - vim_fit
+            identity:
+                type: string
+                required: true
+            applicableResources:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+                    constraints:
+                    -   valid_values:
+                        - any
+                        - all
+            resources:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+            capacityProperties:
+                type: policy.data.capacityProperties_properties
+                required: true
+data_types:
+    policy.data.capacityProperties_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            controller:
+                type: string
+                required: true
+            request:
+                type: string
+                required: true
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.optimization.VnfPolicy.yaml b/models-examples/src/main/resources/policytypes/onap.policies.optimization.VnfPolicy.yaml
new file mode 100644 (file)
index 0000000..13d4f13
--- /dev/null
@@ -0,0 +1,73 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+    - onap.policies.Optimization:
+        derived_from: tosca.policies.Root
+        version: 1.0.0
+        description: a base policy type for all policies that govern optimization
+    - onap.policies.optimization.VnfPolicy:
+        derived_from: onap.policies.Optimization
+        properties:
+            policyScope:
+                type: list
+                description: scope where the policy is applicable
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+            policyType:
+                type: list
+                description: type of a policy
+                required: true
+                matchable: true
+                entry_schema:
+                    type: string
+                    consraints:
+                    -   valid_values:
+                        - vnfPolicy
+            identity:
+                type: string
+                required: true
+            resources:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+            applicableResources:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+                    constraints:
+                    -   valid_values:
+                        - any
+                        - all
+            vnfProperties:
+                type: list
+                required: true
+                entry_schema:
+                    type:policy.data.vnfProperties_properties
+data_types:
+    policy.data.vnfProperties_properties:
+        derived_from: tosca.nodes.Root
+        properties:
+            inventoryProvider:
+                type: string
+                required: true
+            serviceType:
+                type: string
+                required: true
+            inventoryType:
+                type: list
+                required: true
+                entry_schema:
+                    type: string
+                    constraints:
+                    -   valid_values:
+                        - serviceInstanceId
+                        - vnfName
+                        - cloudRegionId
+                        - vimId
+            customerId:
+                type: string
+                required: true
+
 
 package org.onap.policy.models.pap.concepts;
 
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import java.util.List;
 
-import org.junit.Test;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
 
 /**
- * Test the copy constructor, as {@link TestModels} tests the other methods.
+ * Request deploy or update a set of policies using the <i>simple</i> PDP Group deployment
+ * REST API. Only the "name" and "policyVersion" fields of a Policy are used, and only the
+ * "name" field is actually required.
  */
-public class TestPolicy {
-
-    @Test
-    public void testCopyConstructor() {
-        assertThatThrownBy(() -> new Policy(null)).isInstanceOf(NullPointerException.class);
-
-        Policy orig = new Policy();
-
-        // verify with null values
-        assertEquals(orig.toString(), new Policy(orig).toString());
-
-        // verify with all values
-        orig.setName("my-name");
-        orig.setPolicyType("my-type");
-        orig.setPolicyTypeImpl("my-impl");
-        orig.setPolicyTypeVersion("my-type-vers");
-        assertEquals(orig.toString(), new Policy(orig).toString());
-    }
+@Getter
+@Setter
+@ToString
+public class PdpDeployPolicies {
+    private List<PolicyIdentOptVersion> policies;
 }
index d5e4191..29c4713 100644 (file)
 
 package org.onap.policy.models.pap.concepts;
 
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import lombok.Getter;
-import lombok.NonNull;
 import lombok.Setter;
 import lombok.ToString;
-import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.models.pdp.enums.PdpState;
 
 /**
@@ -47,25 +44,4 @@ public class PdpGroup {
     private String description;
     private Map<String, String> properties;
     private List<PdpSubGroup> pdpSubgroups;
-
-    /**
-     * Constructs the object.
-     */
-    public PdpGroup() {
-        super();
-    }
-
-    /**
-     * Constructs the object, making a deep copy from the source.
-     *
-     * @param source source from which to copy fields
-     */
-    public PdpGroup(@NonNull PdpGroup source) {
-        this.name = source.name;
-        this.version = source.version;
-        this.pdpGroupState = source.pdpGroupState;
-        this.description = source.description;
-        this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties));
-        this.pdpSubgroups = PfUtils.mapList(source.pdpSubgroups, PdpSubGroup::new);
-    }
 }
index c214c74..d584616 100644 (file)
@@ -22,7 +22,6 @@
 package org.onap.policy.models.pap.concepts;
 
 import lombok.Getter;
-import lombok.NonNull;
 import lombok.Setter;
 import lombok.ToString;
 import org.onap.policy.models.pdp.enums.PdpHealthStatus;
@@ -42,23 +41,4 @@ public class PdpInstanceDetails {
     private PdpState pdpState;
     private PdpHealthStatus healthy;
     private String message;
-
-    /**
-     * Constructs the object.
-     */
-    public PdpInstanceDetails() {
-        super();
-    }
-
-    /**
-     * Constructs the object, making a deep copy from the source.
-     *
-     * @param source source from which to copy fields
-     */
-    public PdpInstanceDetails(@NonNull PdpInstanceDetails source) {
-        this.instanceId = source.instanceId;
-        this.pdpState = source.pdpState;
-        this.healthy = source.healthy;
-        this.message = source.message;
-    }
 }
index e5ae24d..3111bec 100644 (file)
@@ -26,6 +26,7 @@ import lombok.Getter;
 import lombok.Setter;
 import lombok.ToString;
 
+// TODO delete this once PAP has been modified to use PdpDeployPolicies
 /**
  * Request deploy or update a set of policies using the <i>simple</i> PDP Group deployment
  * REST API. Only the "name" and "policyVersion" fields of a Policy are used, and only the
index 4335698..9989d25 100644 (file)
 
 package org.onap.policy.models.pap.concepts;
 
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import lombok.Getter;
-import lombok.NonNull;
 import lombok.Setter;
 import lombok.ToString;
-import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.keys.PolicyTypeIdent;
 
 /**
  * Class to represent a group of all PDP's of the same pdp type running for a particular
@@ -49,26 +45,4 @@ public class PdpSubGroup {
     private int desiredInstanceCount;
     private Map<String, String> properties;
     private List<PdpInstanceDetails> pdpInstances;
-
-    /**
-     * Constructs the object.
-     */
-    public PdpSubGroup() {
-        super();
-    }
-
-    /**
-     * Constructs the object, making a deep copy from the source.
-     *
-     * @param source source from which to copy fields
-     */
-    public PdpSubGroup(@NonNull PdpSubGroup source) {
-        this.pdpType = source.pdpType;
-        this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, PolicyTypeIdent::new);
-        this.policies = PfUtils.mapList(source.policies, Policy::new);
-        this.currentInstanceCount = source.currentInstanceCount;
-        this.desiredInstanceCount = source.desiredInstanceCount;
-        this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties));
-        this.pdpInstances = PfUtils.mapList(source.pdpInstances, PdpInstanceDetails::new);
-    }
 }
index b83510e..541eb24 100644 (file)
@@ -22,7 +22,6 @@
 package org.onap.policy.models.pap.concepts;
 
 import lombok.Getter;
-import lombok.NonNull;
 import lombok.Setter;
 import lombok.ToString;
 
@@ -41,24 +40,4 @@ public class Policy {
     private String policyType;
     private String policyTypeVersion;
     private String policyTypeImpl;
-
-    /**
-     * Constructs the object.
-     */
-    public Policy() {
-        super();
-    }
-
-    /**
-     * Constructs the object, making a deep copy from the source.
-     *
-     * @param source source from which to copy fields
-     */
-    public Policy(@NonNull Policy source) {
-        this.name = source.name;
-        this.policyVersion = source.policyVersion;
-        this.policyType = source.policyType;
-        this.policyTypeVersion = source.policyTypeVersion;
-        this.policyTypeImpl = source.policyTypeImpl;
-    }
 }
diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyIdent.java b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyIdent.java
new file mode 100644 (file)
index 0000000..2eb9df1
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pap.concepts;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+/**
+ * Identifies a policy. Both the name and version must be non-null.
+ */
+@Getter
+@Setter
+@ToString
+public class PolicyIdent {
+    private String name;
+    private String version;
+}
 
 package org.onap.policy.models.pap.concepts;
 
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.onap.policy.models.pdp.enums.PdpHealthStatus;
-import org.onap.policy.models.pdp.enums.PdpState;
+import lombok.Getter;
+import lombok.NonNull;
+import lombok.Setter;
+import lombok.ToString;
 
 /**
- * Test the copy constructor, as {@link TestModels} tests the other methods.
+ * Policy identifier with an optional version; only the "name" is required.
  */
-public class TestPdpInstanceDetails {
-
-    @Test
-    public void testCopyConstructor() {
-        assertThatThrownBy(() -> new PdpInstanceDetails(null)).isInstanceOf(NullPointerException.class);
-
-        PdpInstanceDetails orig = new PdpInstanceDetails();
-
-        // verify with null values
-        assertEquals(orig.toString(), new PdpInstanceDetails(orig).toString());
-
-        // verify with all values
-        orig.setHealthy(PdpHealthStatus.TEST_IN_PROGRESS);
-        orig.setInstanceId("my-id");
-        orig.setMessage("my-message");
-        orig.setPdpState(PdpState.SAFE);
-        assertEquals(orig.toString(), new PdpInstanceDetails(orig).toString());
-    }
+@Getter
+@Setter
+@ToString
+public class PolicyIdentOptVersion {
+    @NonNull
+    private String name;
+
+    private String version;
 }
diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyTypeIdent.java b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyTypeIdent.java
new file mode 100644 (file)
index 0000000..3d466b7
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pap.concepts;
+
+import lombok.Getter;
+import lombok.NonNull;
+import lombok.Setter;
+import lombok.ToString;
+
+/**
+ * Identifies a policy type. Both the name and version must be non-null.
+ */
+@Getter
+@Setter
+@ToString
+@NonNull
+public class PolicyTypeIdent {
+    private String name;
+    private String version;
+}
diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpGroup.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpGroup.java
deleted file mode 100644 (file)
index ee52d82..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP Policy Models
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.pap.concepts;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-
-import java.util.Arrays;
-import java.util.Map;
-import java.util.TreeMap;
-import org.junit.Test;
-import org.onap.policy.models.pdp.enums.PdpState;
-
-/**
- * Test the copy constructor, as {@link TestModels} tests the other methods.
- */
-public class TestPdpGroup {
-
-    @Test
-    public void testCopyConstructor() {
-        assertThatThrownBy(() -> new PdpGroup(null)).isInstanceOf(NullPointerException.class);
-
-        PdpGroup orig = new PdpGroup();
-
-        // verify with null values
-        assertEquals(orig.toString(), new PdpGroup(orig).toString());
-
-        // verify with all values
-        orig.setDescription("my-descript");
-        orig.setName("my-name");
-        orig.setPdpGroupState(PdpState.SAFE);
-
-        PdpSubGroup sub1 = new PdpSubGroup();
-        sub1.setCurrentInstanceCount(10);
-        PdpSubGroup sub2 = new PdpSubGroup();
-        sub2.setCurrentInstanceCount(11);
-        orig.setPdpSubgroups(Arrays.asList(sub1, sub2));
-
-        Map<String, String> props = new TreeMap<>();
-        props.put("key-A", "value-A");
-        props.put("key-B", "value-B");
-        orig.setProperties(props);
-
-        System.out.println("orig=" + orig);
-
-        assertEquals(orig.toString(), new PdpGroup(orig).toString());
-    }
-}
diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpSubGroup.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestPdpSubGroup.java
deleted file mode 100644 (file)
index 9af2f4e..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP Policy Models
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.pap.concepts;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-
-import java.util.Arrays;
-import java.util.Map;
-import java.util.TreeMap;
-import org.junit.Test;
-import org.onap.policy.models.base.keys.PolicyTypeIdent;
-
-/**
- * Test the copy constructor, as {@link TestModels} tests the other methods.
- */
-public class TestPdpSubGroup {
-
-    @Test
-    public void testCopyConstructor() {
-        assertThatThrownBy(() -> new PdpSubGroup(null)).isInstanceOf(NullPointerException.class);
-
-        PdpSubGroup orig = new PdpSubGroup();
-
-        // verify with null values
-        assertEquals(orig.toString(), new PdpSubGroup(orig).toString());
-
-        // verify with all values
-        orig.setCurrentInstanceCount(10);
-        orig.setDesiredInstanceCount(11);
-
-        PdpInstanceDetails inst1 = new PdpInstanceDetails();
-        inst1.setInstanceId("my-id-A");
-        PdpInstanceDetails inst2 = new PdpInstanceDetails();
-        inst2.setInstanceId("my-id-B");
-        orig.setPdpInstances(Arrays.asList(inst1, inst2));
-
-        orig.setPdpType("my-type");
-
-        Policy pol1 = new Policy();
-        pol1.setName("policy-A");
-        Policy pol2 = new Policy();
-        pol2.setName("policy-B");
-        orig.setPolicies(Arrays.asList(pol1, pol2));
-
-        Map<String, String> props = new TreeMap<>();
-        props.put("key-A", "value-A");
-        props.put("key-B", "value-B");
-        orig.setProperties(props);
-
-        PolicyTypeIdent supp1 = new PolicyTypeIdent("supp-A", "1.2");
-        PolicyTypeIdent supp2 = new PolicyTypeIdent("supp-B", "3.4");
-        orig.setSupportedPolicyTypes(Arrays.asList(supp1, supp2));
-
-        assertEquals(orig.toString(), new PdpSubGroup(orig).toString());
-    }
-}
index f7b911f..814d357 100644 (file)
@@ -25,7 +25,6 @@ import java.util.List;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.ToString;
-import org.onap.policy.models.base.keys.PolicyTypeIdent;
 import org.onap.policy.models.pdp.enums.PdpHealthStatus;
 import org.onap.policy.models.pdp.enums.PdpMessageType;
 import org.onap.policy.models.pdp.enums.PdpState;
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdent.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdent.java
new file mode 100644 (file)
index 0000000..6d6b6fe
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import lombok.NoArgsConstructor;
+import lombok.NonNull;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.Validated;
+
+/**
+ * Identifies a policy. Both the name and version must be non-null.
+ */
+@NonNull
+@NoArgsConstructor
+public class PolicyIdent extends PfConceptKey {
+    private static final long serialVersionUID = 1L;
+    private static final Validated validator = new Validated();
+
+    public PolicyIdent(String name, String version) {
+        super(name, version);
+    }
+
+    public PolicyIdent(PolicyIdent source) {
+        super(source);
+    }
+
+    @Override
+    public PfValidationResult validate(PfValidationResult result) {
+        return super.validate(validator.validateNotNull(this, result));
+    }
+}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdentOptVersion.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdentOptVersion.java
new file mode 100644 (file)
index 0000000..a68a271
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import lombok.NoArgsConstructor;
+import lombok.NonNull;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.Validated;
+
+/**
+ * Policy identifier with an optional version; only the "name" is required.
+ */
+@NonNull
+@NoArgsConstructor
+public class PolicyIdentOptVersion extends PfConceptKey {
+    private static final long serialVersionUID = 1L;
+    private static final Validated validator = new Validated();
+
+
+    public PolicyIdentOptVersion(PolicyIdentOptVersion source) {
+        super(source);
+    }
+
+    /**
+     * Validates the object.
+     *
+     * @param resultIn where to place any errors
+     * @return a validation result
+     */
+    public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+        PfValidationResult result = resultIn;
+
+        String name = getName();
+        if (PfConceptKey.NULL_KEY_NAME.equals(name)) {
+            validator.addError(this, "name", result, "null");
+        }
+        result = validator.validateText(this, "name", name, PfKey.NAME_REGEXP, result);
+
+        return validator.validateText(this, "version", getVersion(), PfKey.VERSION_REGEXP, result);
+    }
+}
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.policy.models.base.keys;
+package org.onap.policy.models.pdp.concepts;
 
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.Validated;
 
 /**
  * Identifies a policy type. Both the name and version must be non-null.
@@ -31,6 +33,7 @@ import org.onap.policy.models.base.PfConceptKey;
 @NoArgsConstructor
 public class PolicyTypeIdent extends PfConceptKey {
     private static final long serialVersionUID = 1L;
+    private static final Validated validator = new Validated();
 
     public PolicyTypeIdent(String name, String version) {
         super(name, version);
@@ -39,4 +42,9 @@ public class PolicyTypeIdent extends PfConceptKey {
     public PolicyTypeIdent(PolicyTypeIdent source) {
         super(source);
     }
+
+    @Override
+    public PfValidationResult validate(PfValidationResult result) {
+        return super.validate(validator.validateNotNull(this, result));
+    }
 }
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/IdentTestBase.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/IdentTestBase.java
new file mode 100644 (file)
index 0000000..10bc9a9
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+
+/**
+ * Super class to test identity keys.
+ *
+ * @param <T> type of key being tested
+ */
+public class IdentTestBase<T> {
+
+    private static final Coder coder = new StandardCoder();
+
+    private final Class<T> clazz;
+
+
+    /**
+     * Constructs the object.
+     * @param clazz the type of class being tested
+     */
+    public IdentTestBase(Class<T> clazz) {
+        this.clazz = clazz;
+    }
+
+    /**
+     * Makes an identifier. Uses JSON which does no error checking.
+     *
+     * @param name name to put into the identifier
+     * @param version version to put into the identifier
+     * @return a new identifier
+     * @throws CoderException if the JSON cannot be decoded
+     */
+    public T makeIdent(String name, String version) throws CoderException {
+        StringBuilder bldr = new StringBuilder();
+        bldr.append("{");
+
+        if (name != null) {
+            bldr.append("'name':'");
+            bldr.append(name);
+            bldr.append("'");
+        }
+
+        if (version != null) {
+            if (name != null) {
+                bldr.append(',');
+            }
+
+            bldr.append("'version':'");
+            bldr.append(version);
+            bldr.append("'");
+        }
+
+        bldr.append("}");
+
+        String json = bldr.toString().replace('\'', '"');
+
+        return coder.decode(json, clazz);
+    }
+}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdent.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdent.java
new file mode 100644 (file)
index 0000000..4cd5570
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfValidationResult;
+
+/**
+ * Test the other constructors, as {@link TestModels} tests the other methods.
+ */
+public class TestPolicyIdent extends IdentTestBase<PolicyIdent> {
+    private static final String NAME = "my-name";
+    private static final String VERSION = "1.2.3";
+
+    public TestPolicyIdent() {
+        super(PolicyIdent.class);
+    }
+
+    @Test
+    public void testAllArgsConstructor() {
+        assertThatThrownBy(() -> new PolicyIdent(null, VERSION)).isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> new PolicyIdent(NAME, null)).isInstanceOf(NullPointerException.class);
+
+        PolicyIdent orig = new PolicyIdent(NAME, VERSION);
+        assertEquals(NAME, orig.getName());
+        assertEquals(VERSION, orig.getVersion());
+    }
+
+    @Test
+    public void testCopyConstructor() {
+        assertThatThrownBy(() -> new PolicyIdent(null)).isInstanceOf(NullPointerException.class);
+
+        PolicyIdent orig = new PolicyIdent();
+
+        // verify with null values
+        assertEquals(orig.toString(), new PolicyIdent(orig).toString());
+
+        // verify with all values
+        orig = new PolicyIdent(NAME, VERSION);
+        assertEquals(orig.toString(), new PolicyIdent(orig).toString());
+    }
+
+    @Test
+    public void testValidate() throws Exception {
+        assertTrue(makeIdent(NAME, VERSION).validate(new PfValidationResult()).isValid());
+
+        // everything is null
+        PfValidationResult result = makeIdent(null, null).validate(new PfValidationResult());
+        assertFalse(result.isValid());
+        assertEquals(2, result.getMessageList().size());
+
+        // name is null
+        result = makeIdent(null, VERSION).validate(new PfValidationResult());
+        assertFalse(result.isValid());
+        assertEquals(1, result.getMessageList().size());
+
+        // version is null
+        result = makeIdent(NAME, null).validate(new PfValidationResult());
+        assertFalse(result.isValid());
+        assertEquals(1, result.getMessageList().size());
+
+        // version is invalid
+        result = makeIdent(NAME, "!!!" + VERSION).validate(new PfValidationResult());
+        assertFalse(result.isValid());
+        assertEquals(1, result.getMessageList().size());
+    }
+}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdentOptVersion.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdentOptVersion.java
new file mode 100644 (file)
index 0000000..3428ac1
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfValidationResult;
+
+/**
+ * Test the other constructors, as {@link TestModels} tests the other methods.
+ */
+public class TestPolicyIdentOptVersion extends IdentTestBase<PolicyIdentOptVersion> {
+    private static final String NAME = "my-name";
+    private static final String VERSION = "1.2.3";
+
+    public TestPolicyIdentOptVersion() {
+        super(PolicyIdentOptVersion.class);
+    }
+
+    @Test
+    public void testCopyConstructor() throws Exception {
+        assertThatThrownBy(() -> new PolicyIdentOptVersion(null)).isInstanceOf(NullPointerException.class);
+
+        PolicyIdentOptVersion orig = new PolicyIdentOptVersion();
+
+        // verify with null values
+        assertEquals(orig.toString(), new PolicyIdentOptVersion(orig).toString());
+
+        // verify with all values
+        orig = makeIdent(NAME, VERSION);
+        assertEquals(orig.toString(), new PolicyIdentOptVersion(orig).toString());
+    }
+
+    @Test
+    public void testValidate() throws Exception {
+        assertThatThrownBy(() -> makeIdent(NAME, VERSION).validate(null)).isInstanceOf(NullPointerException.class);
+        assertTrue(makeIdent(NAME, VERSION).validate(new PfValidationResult()).isValid());
+        assertTrue(makeIdent(NAME, null).validate(new PfValidationResult()).isValid());
+
+        // everything is null
+        PfValidationResult result = makeIdent(null, null).validate(new PfValidationResult());
+        assertFalse(result.isValid());
+        assertEquals(1, result.getMessageList().size());
+
+        // name is null
+        result = makeIdent(null, VERSION).validate(new PfValidationResult());
+        assertFalse(result.isValid());
+        assertEquals(1, result.getMessageList().size());
+
+        // name is null, version is invalid
+        result = makeIdent(null, "$$$" + VERSION).validate(new PfValidationResult());
+        assertFalse(result.isValid());
+        assertEquals(2, result.getMessageList().size());
+
+        // name is invalid
+        result = makeIdent("!!!invalid name$$$", VERSION).validate(new PfValidationResult());
+        assertFalse(result.isValid());
+        assertEquals(1, result.getMessageList().size());
+
+        // version is invalid
+        result = makeIdent(NAME, "!!!" + VERSION).validate(new PfValidationResult());
+        assertFalse(result.isValid());
+        assertEquals(1, result.getMessageList().size());
+    }
+}
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.policy.models.base.keys;
+package org.onap.policy.models.pdp.concepts;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
-import org.onap.policy.models.base.keys.PolicyTypeIdent;
-import org.onap.policy.models.base.keys.TestModels;
+import org.onap.policy.models.base.PfValidationResult;
 
 /**
  * Test the other constructors, as {@link TestModels} tests the other methods.
  */
-public class TestPolicyTypeIdent {
+public class TestPolicyTypeIdent extends IdentTestBase<PolicyTypeIdent> {
     private static final String NAME = "my-name";
     private static final String VERSION = "1.2.3";
 
+    public TestPolicyTypeIdent() {
+        super(PolicyTypeIdent.class);
+    }
+
     @Test
     public void testAllArgsConstructor() {
         assertThatThrownBy(() -> new PolicyTypeIdent(null, VERSION)).isInstanceOf(NullPointerException.class);
@@ -57,4 +62,30 @@ public class TestPolicyTypeIdent {
         orig = new PolicyTypeIdent(NAME, VERSION);
         assertEquals(orig.toString(), new PolicyTypeIdent(orig).toString());
     }
+
+    @Test
+    public void testValidate() throws Exception {
+        assertTrue(makeIdent(NAME, VERSION).validate(new PfValidationResult()).isValid());
+
+        // everything is null
+        PfValidationResult result = makeIdent(null, null).validate(new PfValidationResult());
+        assertFalse(result.isValid());
+        assertEquals(2, result.getMessageList().size());
+
+        // name is null
+        result = makeIdent(null, VERSION).validate(new PfValidationResult());
+        assertFalse(result.isValid());
+        assertEquals(1, result.getMessageList().size());
+
+        // version is null
+        result = makeIdent(NAME, null).validate(new PfValidationResult());
+        assertFalse(result.isValid());
+        assertEquals(1, result.getMessageList().size());
+
+        // version is invalid
+        result = makeIdent(NAME, "!!!" + VERSION).validate(new PfValidationResult());
+        assertFalse(result.isValid());
+        assertEquals(1, result.getMessageList().size());
+    }
+
 }