diff options
39 files changed, 4421 insertions, 1156 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java index 949cb96dc..d259fa260 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java @@ -30,6 +30,8 @@ import java.util.Map.Entry; import java.util.NavigableMap; import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; +import java.util.function.Function; import javax.persistence.CascadeType; import javax.persistence.EmbeddedId; @@ -45,6 +47,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; +import org.apache.commons.lang3.StringUtils; import org.onap.policy.models.base.PfValidationResult.ValidationResult; // @formatter:off @@ -67,7 +70,7 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult; @EqualsAndHashCode(callSuper = false) public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> extends PfConcept - implements PfConceptGetter<C>, PfAuthorative<List<Map<String, A>>> { + implements PfConceptGetter<C>, PfAuthorative<List<Map<String, A>>> { private static final long serialVersionUID = -324211738823208318L; @EmbeddedId @@ -151,7 +154,7 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex public List<Map<String, A>> toAuthorative() { // The returned list is a list of map singletons with one map for each map // entry in the concept container - List<Map<String, A>> toscaPolicyMapList = new ArrayList<>(); + List<Map<String, A>> toscaConceptMapList = new ArrayList<>(); for (Entry<PfConceptKey, C> conceptEntry : getConceptMap().entrySet()) { // Create a map to hold this entry @@ -163,10 +166,10 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex toscaPolicyMap.put(conceptEntry.getKey().getName(), authoritiveImpl.toAuthorative()); // Add the map to the returned list - toscaPolicyMapList.add(toscaPolicyMap); + toscaConceptMapList.add(toscaPolicyMap); } - return toscaPolicyMapList; + return toscaConceptMapList; } @Override @@ -178,31 +181,32 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex for (Map<String, A> incomingConceptMap : authorativeList) { // Add the map entries one by one for (Entry<String, A> incomingConceptEntry : incomingConceptMap.entrySet()) { - C jpaConcept = getConceptNewInstance(); + PfConceptKey conceptKey = new PfConceptKey(); + if (incomingConceptEntry.getKey().matches(PfKey.KEY_ID_REGEXP)) { + conceptKey = new PfConceptKey(incomingConceptEntry.getKey()); + } else { + conceptKey.setName(incomingConceptEntry.getKey()); + if (incomingConceptEntry.getValue().getVersion() != null) { + conceptKey.setVersion(incomingConceptEntry.getValue().getVersion()); + } else { + conceptKey.setVersion(PfKey.NULL_KEY_VERSION); + } + } + + incomingConceptEntry.getValue().setName(findConceptField(conceptKey, conceptKey.getName(), + incomingConceptEntry.getValue(), PfNameVersion::getName)); + incomingConceptEntry.getValue().setVersion(findConceptField(conceptKey, conceptKey.getVersion(), + incomingConceptEntry.getValue(), PfNameVersion::getVersion)); + + C jpaConcept = getConceptNewInstance(); // This cast allows us to call the fromAuthorative method @SuppressWarnings("unchecked") PfAuthorative<A> authoritiveImpl = (PfAuthorative<A>) jpaConcept; - if (incomingConceptEntry.getValue().getName() == null) { - incomingConceptEntry.getValue().setName(incomingConceptEntry.getKey()); - } - // Set the key name and the rest of the values on the concept authoritiveImpl.fromAuthorative(incomingConceptEntry.getValue()); - // This cast gets the key of the concept - PfConceptKey conceptKey = (PfConceptKey) jpaConcept.getKey(); - - // Set the concept key of the concept - conceptKey.setName(incomingConceptEntry.getValue().getName()); - - if (incomingConceptEntry.getValue().getVersion() != null) { - conceptKey.setVersion(incomingConceptEntry.getValue().getVersion()); - } else { - conceptKey.setVersion(PfKey.NULL_KEY_VERSION); - } - // After all that, save the map entry conceptMap.put(conceptKey, jpaConcept); } @@ -210,8 +214,23 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex if (conceptMap.isEmpty()) { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, - "An incoming list of concepts must have at least one entry"); + "An incoming list of concepts must have at least one entry"); + } + } + + /** + * Get an authorative list of the concepts in this container. + * + * @return the authorative list of concepts + */ + public List<A> toAuthorativeList() { + List<A> toscaConceptList = new ArrayList<>(); + + for (Map<String, A> toscaConceptMap : toAuthorative()) { + toscaConceptList.addAll(toscaConceptMap.values()); } + + return toscaConceptList; } @Override @@ -229,7 +248,7 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex if (key.equals(PfConceptKey.getNullKey())) { result.addValidationMessage( - new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); + new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); } result = key.validate(result); @@ -253,14 +272,14 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex for (final Entry<PfConceptKey, C> conceptEntry : conceptMap.entrySet()) { if (conceptEntry.getKey().equals(PfConceptKey.getNullKey())) { result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on concept entry " + conceptEntry.getKey() + " may not be the null key")); + "key on concept entry " + conceptEntry.getKey() + " may not be the null key")); } else if (conceptEntry.getValue() == null) { result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "value on concept entry " + conceptEntry.getKey() + " may not be null")); + "value on concept entry " + conceptEntry.getKey() + " may not be null")); } else if (!conceptEntry.getKey().equals(conceptEntry.getValue().getKey())) { result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on concept entry key " + conceptEntry.getKey() + " does not equal concept value key " - + conceptEntry.getValue().getKey())); + "key on concept entry key " + conceptEntry.getKey() + " does not equal concept value key " + + conceptEntry.getValue().getKey())); result = conceptEntry.getValue().validate(result); } else { result = conceptEntry.getValue().validate(result); @@ -295,9 +314,33 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex return 0; } + /** + * Get all the concepts that match the given name and version. + * + * @param conceptKeyName the name of the concept, if null, return all names + * @param conceptKeyVersion the version of the concept, if null, return all versions + * @return conceptKeyVersion + */ + public Set<C> getAllNamesAndVersions(final String conceptKeyName, final String conceptKeyVersion) { + if (conceptKeyName == null || conceptKeyVersion == null) { + return getAll(conceptKeyName, conceptKeyVersion); + } else { + final Set<C> returnSet = new TreeSet<>(); + C foundConcept = get(conceptKeyName, conceptKeyVersion); + if (foundConcept != null) { + returnSet.add(foundConcept); + } + return returnSet; + } + } + @Override public C get(final PfConceptKey conceptKey) { - return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).get(conceptKey); + if (conceptKey.isNullVersion()) { + return get(conceptKey.getName()); + } else { + return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).get(conceptKey); + } } @Override @@ -308,7 +351,7 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex @Override public C get(final String conceptKeyName, final String conceptKeyVersion) { return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).get(conceptKeyName, - conceptKeyVersion); + conceptKeyVersion); } @Override @@ -319,7 +362,7 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex @Override public Set<C> getAll(final String conceptKeyName, final String conceptKeyVersion) { return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).getAll(conceptKeyName, - conceptKeyVersion); + conceptKeyVersion); } /** @@ -331,11 +374,24 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex private C getConceptNewInstance() { try { String conceptClassName = - ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0].getTypeName(); + ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0].getTypeName(); return (C) Class.forName(conceptClassName).getDeclaredConstructor().newInstance(); } catch (Exception ex) { throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, - "failed to instantiate instance of container concept class", ex); + "failed to instantiate instance of container concept class", ex); + } + } + + private String findConceptField(final PfConceptKey conceptKey, final String keyFieldValue, + final PfNameVersion concept, final Function<PfNameVersion, String> fieldGetterFunction) { + + String conceptField = fieldGetterFunction.apply(concept); + + if (StringUtils.isBlank(conceptField) || keyFieldValue.equals(conceptField)) { + return keyFieldValue; + } else { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, "Key " + conceptKey.getId() + " field " + + keyFieldValue + " does not match the value " + conceptField + " in the concept field"); } } } diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptGetterImpl.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptGetterImpl.java index c641a8035..033a7ddb2 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptGetterImpl.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptGetterImpl.java @@ -55,7 +55,7 @@ public class PfConceptGetterImpl<C> implements PfConceptGetter<C> { Assertions.argumentNotNull(conceptKeyName, "conceptKeyName may not be null"); // The very fist key that could have this name - final PfConceptKey lowestArtifactKey = new PfConceptKey(conceptKeyName, "0.0.1"); + final PfConceptKey lowestArtifactKey = new PfConceptKey(conceptKeyName, PfKey.NULL_KEY_VERSION); // Check if we found a key for our name PfConceptKey foundKey = conceptMap.ceilingKey(lowestArtifactKey); diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java b/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java index 461fd2495..61028f927 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfKeyImpl.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,9 +23,11 @@ package org.onap.policy.models.base; import java.util.ArrayList; import java.util.List; + import lombok.Getter; import lombok.NonNull; import lombok.ToString; + import org.onap.policy.common.utils.validation.Assertions; import org.onap.policy.models.base.PfValidationResult.ValidationResult; @@ -116,6 +118,15 @@ public abstract class PfKeyImpl extends PfKey { } /** + * Determines if the name is "null". + * + * @return {@code true} if the name is null, {@code false} otherwise + */ + public boolean isNullName() { + return PfKey.NULL_KEY_NAME.equals(getName()); + } + + /** * Determines if the version is "null". * * @return {@code true} if the version is null, {@code false} otherwise @@ -147,7 +158,7 @@ public abstract class PfKeyImpl extends PfKey { } if (thisVersionArray.length >= 2 && otherVersionArray.length >= 2 - && !thisVersionArray[1].equals(otherVersionArray[1])) { + && !thisVersionArray[1].equals(otherVersionArray[1])) { return Compatibility.MINOR; } @@ -189,12 +200,12 @@ public abstract class PfKeyImpl extends PfKey { } if (thisVersionArray.length >= 2 && otherVersionArray.length >= 2 - && !thisVersionArray[1].equals(otherVersionArray[1])) { + && !thisVersionArray[1].equals(otherVersionArray[1])) { return Integer.valueOf(thisVersionArray[1]) > Integer.valueOf(otherVersionArray[1]); } if (thisVersionArray.length >= 3 && otherVersionArray.length >= 3 - && !thisVersionArray[2].equals(otherVersionArray[2])) { + && !thisVersionArray[2].equals(otherVersionArray[2])) { return Integer.valueOf(thisVersionArray[2]) > Integer.valueOf(otherVersionArray[2]); } @@ -215,8 +226,7 @@ public abstract class PfKeyImpl extends PfKey { if (versionArray.length >= 2) { return Integer.parseInt(versionArray[1]); - } - else { + } else { return 0; } } @@ -227,26 +237,25 @@ public abstract class PfKeyImpl extends PfKey { if (versionArray.length >= 3) { return Integer.parseInt(versionArray[2]); - } - else { + } else { return 0; } } @Override public PfValidationResult validate(final PfValidationResult result) { - final String nameValidationErrorMessage = Assertions.getStringParameterValidationMessage(NAME_TOKEN, getName(), - getNameRegEx()); + final String nameValidationErrorMessage = + Assertions.getStringParameterValidationMessage(NAME_TOKEN, getName(), getNameRegEx()); if (nameValidationErrorMessage != null) { result.addValidationMessage(new PfValidationMessage(this, this.getClass(), ValidationResult.INVALID, - "name invalid-" + nameValidationErrorMessage)); + "name invalid-" + nameValidationErrorMessage)); } - final String versionValidationErrorMessage = Assertions.getStringParameterValidationMessage(VERSION_TOKEN, - getVersion(), getVersionRegEx()); + final String versionValidationErrorMessage = + Assertions.getStringParameterValidationMessage(VERSION_TOKEN, getVersion(), getVersionRegEx()); if (versionValidationErrorMessage != null) { result.addValidationMessage(new PfValidationMessage(this, this.getClass(), ValidationResult.INVALID, - "version invalid-" + versionValidationErrorMessage)); + "version invalid-" + versionValidationErrorMessage)); } return result; diff --git a/models-base/src/test/java/org/onap/policy/models/base/ModelServiceTest.java b/models-base/src/test/java/org/onap/policy/models/base/ModelServiceTest.java index 1b7a996ed..60ae85dd8 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/ModelServiceTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/ModelServiceTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,7 +31,7 @@ import org.onap.policy.models.base.testconcepts.DummyPfModel; public class ModelServiceTest { - private static final String MODEL_KEY_IS_NULL = "modelKey is marked @NonNull but is null"; + private static final String MODEL_KEY_IS_NULL = "modelKey is marked .*on.*ull but is null$"; private static final String MODEL_NAME = "ModelName"; @Test @@ -40,7 +40,7 @@ public class ModelServiceTest { assertFalse(PfModelService.existsModel("NonExistantName")); assertThatThrownBy(() -> PfModelService.getModel("NonExistantName")) - .hasMessage("Model for name NonExistantName not found in model service"); + .hasMessage("Model for name NonExistantName not found in model service"); PfModelService.registerModel(MODEL_NAME, new DummyPfModel()); assertTrue(PfModelService.existsModel(MODEL_NAME)); @@ -50,7 +50,7 @@ public class ModelServiceTest { assertFalse(PfModelService.existsModel(MODEL_NAME)); assertThatThrownBy(() -> PfModelService.getModel(MODEL_NAME)) - .hasMessage("Model for name ModelName not found in model service"); + .hasMessage("Model for name ModelName not found in model service"); PfModelService.registerModel(MODEL_NAME, new DummyPfModel()); assertTrue(PfModelService.existsModel(MODEL_NAME)); @@ -59,20 +59,18 @@ public class ModelServiceTest { PfModelService.clear(); assertFalse(PfModelService.existsModel(MODEL_NAME)); assertThatThrownBy(() -> PfModelService.getModel(MODEL_NAME)) - .hasMessage("Model for name ModelName not found in model service"); + .hasMessage("Model for name ModelName not found in model service"); - assertThatThrownBy(() -> PfModelService.registerModel(null, null)) - .hasMessage(MODEL_KEY_IS_NULL); + assertThatThrownBy(() -> PfModelService.registerModel(null, null)).hasMessageMatching(MODEL_KEY_IS_NULL); assertThatThrownBy(() -> PfModelService.registerModel("nullModelName", null)) - .hasMessage("model is marked @NonNull but is null"); + .hasMessageMatching("^model is marked .*on.*ull but is null$"); assertThatThrownBy(() -> PfModelService.registerModel(null, new DummyPfModel())) - .hasMessage(MODEL_KEY_IS_NULL); + .hasMessageMatching(MODEL_KEY_IS_NULL); - assertThatThrownBy(() -> PfModelService.deregisterModel(null)) - .hasMessage(MODEL_KEY_IS_NULL); + assertThatThrownBy(() -> PfModelService.deregisterModel(null)).hasMessageMatching(MODEL_KEY_IS_NULL); - assertThatThrownBy(() -> PfModelService.getModel(null)).hasMessage(MODEL_KEY_IS_NULL); + assertThatThrownBy(() -> PfModelService.getModel(null)).hasMessageMatching(MODEL_KEY_IS_NULL); } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java index b760e17c0..600605ae1 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java @@ -48,12 +48,14 @@ import org.onap.policy.models.base.testconcepts.DummyPfConceptSub; */ public class PfConceptContainerTest { - private static final String NAME2 = "name2"; - private static final String NAME1 = "name1"; private static final String NAME0 = "name0"; - private static final String KEY_IS_NULL = "key is marked @NonNull but is null"; + private static final String NAME1 = "name1"; + private static final String NAME2 = "name2"; + private static final String NAME3 = "name3"; + private static final String ID3 = "name3:0.0.1"; + private static final String VERSION0_0_1 = "0.0.1"; + private static final String KEY_IS_NULL = "^key is marked .*on.*ull but is null$"; private static final String DUMMY_VALUE = "Dummy"; - private static final String VERSION0 = "0.0.1"; @SuppressWarnings({"unchecked", "rawtypes"}) @Test @@ -70,15 +72,16 @@ public class PfConceptContainerTest { container = new DummyPfConceptContainer(new PfConceptKey(), new TreeMap<PfConceptKey, DummyPfConcept>()); assertNotNull(container); - assertThatThrownBy(() -> new PfConceptContainer((PfConceptKey) null, null)).hasMessage(KEY_IS_NULL); + assertThatThrownBy(() -> new PfConceptContainer((PfConceptKey) null, null)).hasMessageMatching(KEY_IS_NULL); - assertThatThrownBy(() -> new DummyPfConceptContainer((PfConceptKey) null, null)).hasMessage(KEY_IS_NULL); + assertThatThrownBy(() -> new DummyPfConceptContainer((PfConceptKey) null, null)) + .hasMessageMatching(KEY_IS_NULL); assertThatThrownBy(() -> new DummyPfConceptContainer(new PfConceptKey(), null)) - .hasMessage("conceptMap is marked @NonNull but is null"); + .hasMessageMatching("^conceptMap is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new DummyPfConceptContainer(null, new TreeMap<PfConceptKey, DummyPfConcept>())) - .hasMessage(KEY_IS_NULL); + .hasMessageMatching(KEY_IS_NULL); container.getKey().setName(DUMMY_VALUE); DummyPfConceptContainer clonedContainer = new DummyPfConceptContainer(container); @@ -86,12 +89,12 @@ public class PfConceptContainerTest { assertEquals(DUMMY_VALUE, clonedContainer.getKey().getName()); assertThatThrownBy(() -> new DummyPfConceptContainer((DummyPfConceptContainer) null)) - .hasMessage("copyConcept is marked @NonNull but is null"); + .hasMessageMatching("^copyConcept is marked .*on.*ull but is null$"); List<PfKey> keyList = container.getKeys(); assertEquals(1, keyList.size()); - PfConceptKey conceptKey = new PfConceptKey("Key", VERSION0); + PfConceptKey conceptKey = new PfConceptKey("Key", VERSION0_0_1); Map<PfConceptKey, DummyPfConcept> conceptMap = new TreeMap<>(); conceptMap.put(conceptKey, new DummyPfConcept(conceptKey)); @@ -115,7 +118,7 @@ public class PfConceptContainerTest { assertEquals(0, container.compareTo(clonedContainer)); assertThatThrownBy(() -> new DummyPfConceptContainer((DummyPfConceptContainer) null)) - .isInstanceOf(NullPointerException.class); + .isInstanceOf(NullPointerException.class); assertFalse(container.compareTo(null) == 0); assertEquals(0, container.compareTo(container)); @@ -127,16 +130,17 @@ public class PfConceptContainerTest { testContainer.getKey().setVersion(container.getKey().getVersion()); assertEquals(0, container.compareTo(testContainer)); - PfConceptKey testConceptKey = new PfConceptKey("TestKey", VERSION0); + PfConceptKey testConceptKey = new PfConceptKey("TestKey", VERSION0_0_1); testContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey)); assertFalse(container.compareTo(testContainer) == 0); final DummyPfConceptContainer container3 = container; - assertThatThrownBy(() -> container3.validate(null)).hasMessage("resultIn is marked @NonNull but is null"); + assertThatThrownBy(() -> container3.validate(null)) + .hasMessageMatching("^resultIn is marked .*on.*ull but is null$"); DummyPfConceptContainer validateContainer = new DummyPfConceptContainer(); assertFalse(validateContainer.validate(new PfValidationResult()).isOk()); - validateContainer.setKey(new PfConceptKey("VCKey", VERSION0)); + validateContainer.setKey(new PfConceptKey("VCKey", VERSION0_0_1)); assertTrue(validateContainer.validate(new PfValidationResult()).isOk()); validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey)); @@ -167,39 +171,83 @@ public class PfConceptContainerTest { returnSet = container.getAll(conceptKey.getName(), conceptKey.getVersion()); assertEquals(conceptKey, returnSet.iterator().next().getKey()); + returnSet = container.getAllNamesAndVersions(conceptKey.getName(), conceptKey.getVersion()); + assertEquals(conceptKey, returnSet.iterator().next().getKey()); + returnSet = container.getAllNamesAndVersions(null, conceptKey.getVersion()); + assertEquals(conceptKey, returnSet.iterator().next().getKey()); + returnSet = container.getAllNamesAndVersions(null, null); + assertEquals(conceptKey, returnSet.iterator().next().getKey()); + returnSet = container.getAllNamesAndVersions(conceptKey.getName(), null); + assertEquals(conceptKey, returnSet.iterator().next().getKey()); + returnSet = container.getAllNamesAndVersions("IDontExist", "1.0.0"); + assertTrue(returnSet.isEmpty()); + container.getConceptMap().put(conceptKey, new DummyPfConceptSub(conceptKey)); + + PfConceptKey anotherKey = new PfConceptKey(conceptKey); + assertEquals(conceptKey, container.get(anotherKey).getKey()); + anotherKey.setVersion(PfKey.NULL_KEY_VERSION); + assertEquals(conceptKey, container.get(anotherKey).getKey()); } @Test public void testAuthorative() { Map<String, DummyAuthorativeConcept> dacMap = new LinkedHashMap<>(); dacMap.put(NAME0, new DummyAuthorativeConcept(NAME0, "1.2.3", "Hello")); - dacMap.put(NAME1, new DummyAuthorativeConcept(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, "Hi")); + dacMap.put(NAME1, new DummyAuthorativeConcept("IncorrectName", PfKey.NULL_KEY_VERSION, "Hi")); dacMap.put(NAME2, new DummyAuthorativeConcept(NAME2, "1.2.3", "Howdy")); + dacMap.put(ID3, new DummyAuthorativeConcept(NAME3, "9.9.9", "Ciao")); + dacMap.put("name4:1.2.3", new DummyAuthorativeConcept(null, null, "Slan")); + dacMap.put("name5", new DummyAuthorativeConcept(null, null, "Bye")); List<Map<String, DummyAuthorativeConcept>> authorativeList = new ArrayList<>(); authorativeList.add(dacMap); DummyPfConceptContainer container = new DummyPfConceptContainer(); + + assertThatThrownBy(() -> container.fromAuthorative(authorativeList)) + .hasMessage("Key name1:0.0.0 field name1 does not match the value IncorrectName in the concept field"); + + dacMap.put(NAME1, new DummyAuthorativeConcept(NAME1, PfKey.NULL_KEY_VERSION, "Hi")); + + assertThatThrownBy(() -> container.fromAuthorative(authorativeList)) + .hasMessage("Key name3:0.0.1 field 0.0.1 does not match the value 9.9.9 in the concept field"); + + dacMap.put(ID3, new DummyAuthorativeConcept(NAME3, "0.0.1", "Ciao")); + container.fromAuthorative(authorativeList); assertEquals("Hello", container.getConceptMap().get(new PfConceptKey("name0:1.2.3")).getDescription()); - assertEquals("Hi", container.getConceptMap().get(new PfConceptKey("NULL:0.0.0")).getDescription()); + assertEquals("Hi", container.getConceptMap().get(new PfConceptKey("name1:0.0.0")).getDescription()); assertEquals("Howdy", container.getConceptMap().get(new PfConceptKey("name2:1.2.3")).getDescription()); + assertEquals("Ciao", container.getConceptMap().get(new PfConceptKey("name3:0.0.1")).getDescription()); + assertEquals("name4", container.getConceptMap().get(new PfConceptKey("name4:1.2.3")).getName()); + assertEquals("1.2.3", container.getConceptMap().get(new PfConceptKey("name4:1.2.3")).getVersion()); + assertEquals("0.0.0", container.getConceptMap().get(new PfConceptKey("name5:0.0.0")).getVersion()); List<Map<String, DummyAuthorativeConcept>> outMapList = container.toAuthorative(); - assertEquals(dacMap.get(NAME1), outMapList.get(0).get("NULL")); - assertEquals(dacMap.get(NAME0).getDescription(), outMapList.get(1).get(NAME0).getDescription()); + assertEquals(dacMap.get(NAME0), outMapList.get(0).get(NAME0)); + assertEquals(dacMap.get(NAME1).getDescription(), outMapList.get(1).get(NAME1).getDescription()); assertEquals(dacMap.get(NAME2), outMapList.get(2).get(NAME2)); + assertEquals(dacMap.get(NAME3), outMapList.get(2).get(NAME3)); + + List<DummyAuthorativeConcept> outConceptList = container.toAuthorativeList(); + assertEquals("Hello", outConceptList.get(0).getDescription()); + assertEquals("Hi", outConceptList.get(1).getDescription()); + assertEquals("Howdy", outConceptList.get(2).getDescription()); + assertEquals("Ciao", outConceptList.get(3).getDescription()); + assertEquals("name4", outConceptList.get(4).getName()); + assertEquals("1.2.3", outConceptList.get(4).getVersion()); + assertEquals("0.0.0", outConceptList.get(5).getVersion()); DummyBadPfConceptContainer badContainer = new DummyBadPfConceptContainer(); assertThatThrownBy(() -> badContainer.fromAuthorative(authorativeList)) - .hasMessage("failed to instantiate instance of container concept class"); + .hasMessage("failed to instantiate instance of container concept class"); authorativeList.clear(); assertThatThrownBy(() -> container.fromAuthorative(authorativeList)) - .hasMessage("An incoming list of concepts must have at least one entry"); + .hasMessage("An incoming list of concepts must have at least one entry"); } @Test(expected = NullPointerException.class) diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptFilterTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptFilterTest.java new file mode 100644 index 000000000..e82ab41eb --- /dev/null +++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptFilterTest.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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 static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +/** + * Test the {@link PfObjectFilter} interface. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class PfConceptFilterTest { + + @Test + public void testPfConceptFilter() { + List<PfConcept> listToBeFiltered = new ArrayList<>(); + + PfConceptFilter conceptFilter = new PfConceptFilter(null, null, null); + List<PfConcept> filteredList = conceptFilter.filter(listToBeFiltered); + assertTrue(filteredList.isEmpty()); + + conceptFilter = new PfConceptFilter(null, PfConceptFilter.LATEST_VERSION, null); + filteredList = conceptFilter.filter(listToBeFiltered); + assertTrue(filteredList.isEmpty()); + + assertThatThrownBy(() -> { + final PfConceptFilter conceptFilterNull = new PfConceptFilter(null, null, null); + conceptFilterNull.filter(null); + }).hasMessageMatching("^originalList is marked .*on.*ull but is null$"); + } +} diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptKeyTest.java index a29858393..62d8d2bb3 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptKeyTest.java @@ -1,5 +1,6 @@ /*- * ============LICENSE_START======================================================= + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,7 +33,7 @@ import org.onap.policy.models.base.testconcepts.DummyPfConcept; public class PfConceptKeyTest { private static final String VERSION001 = "0.0.1"; - private static final String ID_IS_NULL = "id is marked @NonNull but is null"; + private static final String ID_IS_NULL = "id is marked .*on.*ull but is null$"; @Test public void testConceptKey() { @@ -47,6 +48,7 @@ public class PfConceptKeyTest { assertEquals(someKey1, someKey2); assertEquals(someKey1, someKey3); assertFalse(someKey1.isNullVersion()); + assertFalse(someKey1.isNullName()); assertEquals("PfConceptKey(name=my-name, version=0.0.1)", someKey1.toString()); assertEquals("my-name", someKey1.getName()); @@ -55,7 +57,6 @@ public class PfConceptKeyTest { assertEquals(someKey2, someKey1.getKey()); assertEquals(1, someKey1.getKeys().size()); - PfConcept pfc = new DummyPfConcept(); assertEquals(PfConceptKey.getNullKey().getId(), pfc.getId()); @@ -63,16 +64,16 @@ public class PfConceptKeyTest { assertTrue(PfConceptKey.getNullKey().isNullKey()); - assertThatThrownBy(() -> PfConceptKey.getNullKey().matchesId(null)).hasMessage(ID_IS_NULL); + assertThatThrownBy(() -> PfConceptKey.getNullKey().matchesId(null)).hasMessageMatching(ID_IS_NULL); assertThatThrownBy(() -> someKey0.setName(null)).isInstanceOf(NullPointerException.class) - .hasMessage("name is marked @NonNull but is null"); + .hasMessageMatching("^name is marked .*on.*ull but is null$"); assertThatThrownBy(() -> someKey0.setVersion(null)).isInstanceOf(NullPointerException.class) - .hasMessage("version is marked @NonNull but is null"); + .hasMessageMatching("^version is marked .*on.*ull but is null$"); assertThatIllegalArgumentException().isThrownBy(() -> new PfConceptKey("my-name.*", VERSION001)).withMessage( - "parameter 'name': value 'my-name.*', does not match regular expression '^[A-Za-z0-9\\-_\\.]+$'" - .replace('\'', '"')); + "parameter 'name': value 'my-name.*', does not match regular expression '^[A-Za-z0-9\\-_\\.]+$'" + .replace('\'', '"')); } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java index f467ec35a..4210bc607 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,18 +29,20 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.lang.reflect.Field; + import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; + import org.junit.Test; import org.onap.policy.models.base.PfKey.Compatibility; import org.onap.policy.models.base.testconcepts.DummyPfKey; public class PfKeyImplTest { - private static final String OTHER_IS_NULL = "otherKey is marked @NonNull but is null"; - private static final String ID_IS_NULL = "id is marked @NonNull but is null"; + private static final String OTHER_IS_NULL = "^otherKey is marked .*on.*ull but is null$"; + private static final String ID_IS_NULL = "^id is marked .*on.*ull but is null$"; private static final String VERSION123 = "1.2.3"; private static final String VERSION100 = "1.0.0"; private static final String VERSION001 = "0.0.1"; @@ -48,11 +50,11 @@ public class PfKeyImplTest { @Test public void testConceptKey() { assertThatIllegalArgumentException().isThrownBy(() -> new MyKey("some bad key id")) - .withMessage("parameter \"id\": value \"some bad key id\", " - + "does not match regular expression \"" + PfKey.KEY_ID_REGEXP + "\""); + .withMessage("parameter \"id\": value \"some bad key id\", " + "does not match regular expression \"" + + PfKey.KEY_ID_REGEXP + "\""); assertThatThrownBy(() -> new MyKey((MyKey) null)) - .hasMessage("copyConcept is marked @NonNull but is null"); + .hasMessageMatching("^copyConcept is marked .*on.*ull but is null$"); MyKey someKey0 = new MyKey(); assertTrue(someKey0.isNullKey()); @@ -89,7 +91,7 @@ public class PfKeyImplTest { assertEquals("name:0.1.2", someKey4.getId()); assertThatThrownBy(() -> someKey0.getCompatibility(null)).isInstanceOf(NullPointerException.class) - .hasMessage("otherKey is marked @NonNull but is null"); + .hasMessageMatching("^otherKey is marked .*on.*ull but is null$"); assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(new DummyPfKey())); assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(someKey1)); @@ -109,19 +111,19 @@ public class PfKeyImplTest { assertFalse(someKey1.isCompatible(new DummyPfKey())); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey0.validate(new PfValidationResult()).getValidationResult()); + someKey0.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey1.validate(new PfValidationResult()).getValidationResult()); + someKey1.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey2.validate(new PfValidationResult()).getValidationResult()); + someKey2.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey3.validate(new PfValidationResult()).getValidationResult()); + someKey3.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey4.validate(new PfValidationResult()).getValidationResult()); + someKey4.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey5.validate(new PfValidationResult()).getValidationResult()); + someKey5.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey6.validate(new PfValidationResult()).getValidationResult()); + someKey6.validate(new PfValidationResult()).getValidationResult()); someKey0.clean(); assertNotNull(someKey0.toString()); @@ -132,7 +134,7 @@ public class PfKeyImplTest { assertEquals(-12, someKey7.compareTo(someKey0)); assertThatThrownBy(() -> someKey0.compareTo(null)).isInstanceOf(NullPointerException.class) - .hasMessage("otherObj is marked @NonNull but is null"); + .hasMessageMatching("^otherObj is marked .*on.*ull but is null$"); assertEquals(0, someKey0.compareTo(someKey0)); assertEquals(-36, someKey0.compareTo(new DummyPfKey())); @@ -148,18 +150,20 @@ public class PfKeyImplTest { @Test public void testNullArguments() { - assertThatThrownBy(() -> new MyKey((String) null)).hasMessage(ID_IS_NULL); + assertThatThrownBy(() -> new MyKey((String) null)).hasMessageMatching(ID_IS_NULL); assertThatThrownBy(() -> new MyKey((MyKey) null)) - .hasMessage("copyConcept is marked @NonNull but is null"); + .hasMessageMatching("^copyConcept is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> new MyKey(null, null)).hasMessage("name is marked @NonNull but is null"); + assertThatThrownBy(() -> new MyKey(null, null)).hasMessageMatching("name is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> new MyKey("name", null)).hasMessage("version is marked @NonNull but is null"); + assertThatThrownBy(() -> new MyKey("name", null)) + .hasMessageMatching("^version is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> new MyKey(null, VERSION001)).hasMessage("name is marked @NonNull but is null"); + assertThatThrownBy(() -> new MyKey(null, VERSION001)) + .hasMessageMatching("^name is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> new MyKey("AKey", VERSION001).isCompatible(null)).hasMessage(OTHER_IS_NULL); + assertThatThrownBy(() -> new MyKey("AKey", VERSION001).isCompatible(null)).hasMessageMatching(OTHER_IS_NULL); } @Test @@ -174,10 +178,8 @@ public class PfKeyImplTest { testKey.validate(validationResult); nameField.set(testKey, "TheKey"); nameField.setAccessible(false); - assertEquals( - "name invalid-parameter name with value Key Name " - + "does not match regular expression " + PfKey.NAME_REGEXP, - validationResult.getMessageList().get(0).getMessage()); + assertEquals("name invalid-parameter name with value Key Name " + "does not match regular expression " + + PfKey.NAME_REGEXP, validationResult.getMessageList().get(0).getMessage()); Field versionField = testKey.getClass().getDeclaredField("version"); versionField.setAccessible(true); @@ -186,21 +188,18 @@ public class PfKeyImplTest { testKey.validate(validationResult2); versionField.set(testKey, VERSION001); versionField.setAccessible(false); - assertEquals( - "version invalid-parameter version with value Key Version " - + "does not match regular expression " + PfKey.VERSION_REGEXP, - validationResult2.getMessageList().get(0).getMessage()); + assertEquals("version invalid-parameter version with value Key Version " + "does not match regular expression " + + PfKey.VERSION_REGEXP, validationResult2.getMessageList().get(0).getMessage()); } @Test public void testkeynewerThan() { MyKey key1 = new MyKey("Key1", VERSION123); - assertThatThrownBy(() -> key1.isNewerThan(null)).hasMessage(OTHER_IS_NULL); + assertThatThrownBy(() -> key1.isNewerThan(null)).hasMessageMatching(OTHER_IS_NULL); - assertThatThrownBy(() -> key1.isNewerThan(new PfReferenceKey())) - .hasMessage("org.onap.policy.models.base.PfReferenceKey is not " - + "an instance of " + PfKeyImpl.class.getName()); + assertThatThrownBy(() -> key1.isNewerThan(new PfReferenceKey())).hasMessage( + "org.onap.policy.models.base.PfReferenceKey is not " + "an instance of " + PfKeyImpl.class.getName()); assertFalse(key1.isNewerThan(key1)); @@ -241,10 +240,10 @@ public class PfKeyImplTest { PfReferenceKey refKey = new PfReferenceKey(); - assertThatThrownBy(() -> refKey.isNewerThan(null)).hasMessage(OTHER_IS_NULL); + assertThatThrownBy(() -> refKey.isNewerThan(null)).hasMessageMatching(OTHER_IS_NULL); assertThatThrownBy(() -> refKey.isNewerThan(new MyKey())) - .hasMessage(MyKey.class.getName() + " is not an instance of " + PfReferenceKey.class.getName()); + .hasMessage(MyKey.class.getName() + " is not an instance of " + PfReferenceKey.class.getName()); assertFalse(refKey.isNewerThan(refKey)); } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java index 3e5d738bd..46a00664f 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,7 +34,7 @@ import org.onap.policy.models.base.testconcepts.DummyPfConceptKeySub; public class PfKeyUseTest { - private static final String OTHER_KEY_IS_NULL = "otherKey is marked @NonNull but is null"; + private static final String OTHER_KEY_IS_NULL = "^otherKey is marked .*on.*ull but is null$"; @Test public void testKeyUse() { @@ -43,7 +43,7 @@ public class PfKeyUseTest { assertNotNull(new PfKeyUse(new PfReferenceKey())); assertThatThrownBy(() -> new PfKeyUse((PfKeyUse) null)) - .hasMessage("copyConcept is marked @NonNull but is null"); + .hasMessageMatching("^copyConcept is marked .*on.*ull but is null$"); PfConceptKey key = new PfConceptKey("Key", "0.0.1"); PfKeyUse keyUse = new PfKeyUse(); @@ -55,7 +55,7 @@ public class PfKeyUseTest { assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key)); - assertThatThrownBy(() -> key.getCompatibility(null)).hasMessage(OTHER_KEY_IS_NULL); + assertThatThrownBy(() -> key.getCompatibility(null)).hasMessageMatching(OTHER_KEY_IS_NULL); assertTrue(keyUse.isCompatible(key)); @@ -87,20 +87,20 @@ public class PfKeyUseTest { PfValidationResult resultNull = new PfValidationResult(); assertEquals(false, keyUseNull.validate(resultNull).isValid()); - assertThatThrownBy(() -> keyUse.setKey(null)).hasMessage("key is marked @NonNull but is null"); + assertThatThrownBy(() -> keyUse.setKey(null)).hasMessageMatching("^key is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> keyUse.getCompatibility(null)).hasMessage(OTHER_KEY_IS_NULL); + assertThatThrownBy(() -> keyUse.getCompatibility(null)).hasMessageMatching(OTHER_KEY_IS_NULL); - assertThatThrownBy(() -> keyUse.isCompatible(null)).hasMessage(OTHER_KEY_IS_NULL); + assertThatThrownBy(() -> keyUse.isCompatible(null)).hasMessageMatching(OTHER_KEY_IS_NULL); - assertThatThrownBy(() -> keyUse.validate(null)).hasMessage("result is marked @NonNull but is null"); + assertThatThrownBy(() -> keyUse.validate(null)).hasMessageMatching("^result is marked .*on.*ull but is null$"); PfKeyUse testKeyUse = new PfKeyUse(new DummyPfConceptKeySub(new PfConceptKey())); assertEquals(testKeyUse, new PfKeyUse(testKeyUse)); assertThatThrownBy(() -> new PfKeyUse((PfKeyUse) null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> keyUse.isNewerThan(null)).hasMessage(OTHER_KEY_IS_NULL); + assertThatThrownBy(() -> keyUse.isNewerThan(null)).hasMessageMatching(OTHER_KEY_IS_NULL); assertEquals(false, testKeyUse.isNewerThan(keyUse)); assertEquals(false, testKeyUse.isNewerThan(testKeyUse)); diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java index 9b1a778ac..c124393fe 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -46,10 +46,10 @@ public class PfModelTest { assertNotNull(new DummyPfModel(new DummyPfModel())); assertThatThrownBy(() -> new DummyPfModel((PfConceptKey) null)) - .hasMessage("key is marked @NonNull but is null"); + .hasMessageMatching("^key is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new DummyPfModel((DummyPfModel) null)) - .hasMessage("copyConcept is marked @NonNull but is null"); + .hasMessageMatching("^copyConcept is marked .*on.*ull but is null$"); DummyPfModel dpm = new DummyPfModel(new PfConceptKey("modelKey", VERSION001)); DummyPfModel dpmClone = new DummyPfModel(dpm); @@ -74,7 +74,7 @@ public class PfModelTest { DummyPfModel dpm = new DummyPfModel(dpmKey); assertTrue(dpm.validate(new PfValidationResult()).isValid()); - assertThatThrownBy(() -> dpm.validate(null)).hasMessage("resultIn is marked @NonNull but is null"); + assertThatThrownBy(() -> dpm.validate(null)).hasMessageMatching("^resultIn is marked .*on.*ull but is null$"); dpm.setKey(PfConceptKey.getNullKey()); assertFalse(dpm.validate(new PfValidationResult()).isValid()); diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java index b12ce4de0..ba36b9e8f 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +29,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.lang.reflect.Field; + import org.junit.Test; public class PfReferenceKeyTest { @@ -54,7 +55,7 @@ public class PfReferenceKeyTest { assertEquals("NULL:0.0.0:NULL:NULL", PfReferenceKey.getNullKey().getId()); assertThatThrownBy(() -> new PfReferenceKey(new PfConceptKey(), null)) - .hasMessage("parameter \"localName\" is null"); + .hasMessage("parameter \"localName\" is null"); PfReferenceKey testReferenceKey = new PfReferenceKey(); testReferenceKey.setParentConceptKey(new PfConceptKey("PN", VERSION001)); @@ -83,7 +84,7 @@ public class PfReferenceKeyTest { assertEquals("NLN", testReferenceKey.getLocalName()); assertThatThrownBy(() -> testReferenceKey.isCompatible(null)) - .hasMessage("otherKey is marked @NonNull but is null"); + .hasMessageMatching("^otherKey is marked .*on.*ull but is null$"); assertFalse(testReferenceKey.isCompatible(PfConceptKey.getNullKey())); assertFalse(testReferenceKey.isCompatible(PfReferenceKey.getNullKey())); @@ -101,7 +102,7 @@ public class PfReferenceKeyTest { PfReferenceKey clonedReferenceKey = new PfReferenceKey(testReferenceKey); assertEquals("PfReferenceKey(parentKeyName=NPKN, parentKeyVersion=0.0.1, parentLocalName=NPKLN, localName=NLN)", - clonedReferenceKey.toString()); + clonedReferenceKey.toString()); assertFalse(testReferenceKey.hashCode() == 0); @@ -144,9 +145,9 @@ public class PfReferenceKeyTest { parentNameField.set(testReferenceKey, "ParentName"); parentNameField.setAccessible(false); assertEquals( - "parentKeyName invalid-parameter parentKeyName with value Parent Name " - + "does not match regular expression " + PfKey.NAME_REGEXP, - validationResult.getMessageList().get(0).getMessage()); + "parentKeyName invalid-parameter parentKeyName with value Parent Name " + + "does not match regular expression " + PfKey.NAME_REGEXP, + validationResult.getMessageList().get(0).getMessage()); Field parentVersionField = testReferenceKey.getClass().getDeclaredField("parentKeyVersion"); parentVersionField.setAccessible(true); @@ -156,9 +157,9 @@ public class PfReferenceKeyTest { parentVersionField.set(testReferenceKey, VERSION001); parentVersionField.setAccessible(false); assertEquals( - "parentKeyVersion invalid-parameter parentKeyVersion with value Parent Version " - + "does not match regular expression " + PfKey.VERSION_REGEXP, - validationResult2.getMessageList().get(0).getMessage()); + "parentKeyVersion invalid-parameter parentKeyVersion with value Parent Version " + + "does not match regular expression " + PfKey.VERSION_REGEXP, + validationResult2.getMessageList().get(0).getMessage()); Field parentLocalNameField = testReferenceKey.getClass().getDeclaredField("parentLocalName"); parentLocalNameField.setAccessible(true); @@ -168,9 +169,9 @@ public class PfReferenceKeyTest { parentLocalNameField.set(testReferenceKey, PARENT_LOCAL_NAME); parentLocalNameField.setAccessible(false); assertEquals( - "parentLocalName invalid-parameter parentLocalName with value " - + "Parent Local Name does not match regular expression [A-Za-z0-9\\-_\\.]+|^$", - validationResult3.getMessageList().get(0).getMessage()); + "parentLocalName invalid-parameter parentLocalName with value " + + "Parent Local Name does not match regular expression [A-Za-z0-9\\-_\\.]+|^$", + validationResult3.getMessageList().get(0).getMessage()); Field localNameField = testReferenceKey.getClass().getDeclaredField("localName"); localNameField.setAccessible(true); @@ -180,8 +181,8 @@ public class PfReferenceKeyTest { localNameField.set(testReferenceKey, LOCAL_NAME); localNameField.setAccessible(false); assertEquals( - "localName invalid-parameter localName with value Local Name " - + "does not match regular expression [A-Za-z0-9\\-_\\.]+|^$", - validationResult4.getMessageList().get(0).getMessage()); + "localName invalid-parameter localName with value Local Name " + + "does not match regular expression [A-Za-z0-9\\-_\\.]+|^$", + validationResult4.getMessageList().get(0).getMessage()); } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfSearchableKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfSearchableKeyTest.java index 942f47c1d..e3a0e3338 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfSearchableKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfSearchableKeyTest.java @@ -1,5 +1,6 @@ /*- * ============LICENSE_START======================================================= + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,7 +32,7 @@ import org.onap.policy.models.base.testconcepts.DummyPfConcept; public class PfSearchableKeyTest { private static final String VERSION001 = "0.0.1"; - private static final String ID_IS_NULL = "id is marked @NonNull but is null"; + private static final String ID_IS_NULL = "^id is marked .*on.*ull but is null$"; @Test public void testSearchableKey() { @@ -54,7 +55,6 @@ public class PfSearchableKeyTest { assertEquals(someKey2, someKey1.getKey()); assertEquals(1, someKey1.getKeys().size()); - PfConcept pfc = new DummyPfConcept(); assertEquals(PfSearchableKey.getNullKey().getId(), pfc.getId()); @@ -62,13 +62,13 @@ public class PfSearchableKeyTest { assertTrue(PfSearchableKey.getNullKey().isNullKey()); - assertThatThrownBy(() -> PfSearchableKey.getNullKey().matchesId(null)).hasMessage(ID_IS_NULL); + assertThatThrownBy(() -> PfSearchableKey.getNullKey().matchesId(null)).hasMessageMatching(ID_IS_NULL); assertThatThrownBy(() -> someKey0.setName(null)).isInstanceOf(NullPointerException.class) - .hasMessage("name is marked @NonNull but is null"); + .hasMessageMatching("^name is marked .*on.*ull but is null$"); assertThatThrownBy(() -> someKey0.setVersion(null)).isInstanceOf(NullPointerException.class) - .hasMessage("version is marked @NonNull but is null"); + .hasMessageMatching("^version is marked .*on.*ull but is null$"); PfSearchableKey someKey4 = new PfSearchableKey("my-name.*", VERSION001); assertEquals("my-name.*", someKey4.getName()); diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java index 28b9fd922..1495fca7d 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java @@ -1,8 +1,6 @@ /*- * ============LICENSE_START======================================================= - * ONAP Policy Model - * ================================================================================ - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,14 +26,15 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.Date; + import org.junit.Test; public class PfTimestampKeyTest { private static final String VERSION001 = "0.0.1"; - private static final String CONCEPT_IS_NULL = "copyConcept is marked @NonNull but is null"; - private static final String NAME_IS_NULL = "name is marked @NonNull but is null"; - private static final String VERSION_IS_NULL = "version is marked @NonNull but is null"; - private static final String TIMESTAMP_IS_NULL = "timeStamp is marked @NonNull but is null"; + private static final String CONCEPT_IS_NULL = "^copyConcept is marked .*on.*ull but is null$"; + private static final String NAME_IS_NULL = "^name is marked .*on.*ull but is null$"; + private static final String VERSION_IS_NULL = "^version is marked .*on.*ull but is null$"; + private static final String TIMESTAMP_IS_NULL = "^timeStamp is marked .*on.*ull but is null$"; private static final long timeStamp = 1574832537641L; @Test @@ -60,24 +59,24 @@ public class PfTimestampKeyTest { assertEquals(1, someKey1.getKeys().size()); assertThatThrownBy(() -> new PfTimestampKey((PfTimestampKey) null)).isInstanceOf(NullPointerException.class) - .hasMessage(CONCEPT_IS_NULL); + .hasMessageMatching(CONCEPT_IS_NULL); assertThatThrownBy(() -> new PfTimestampKey(null, null, null)).isInstanceOf(NullPointerException.class) - .hasMessage(NAME_IS_NULL); + .hasMessageMatching(NAME_IS_NULL); assertThatThrownBy(() -> new PfTimestampKey("my-name", null, null)).isInstanceOf(NullPointerException.class) - .hasMessage(VERSION_IS_NULL); + .hasMessageMatching(VERSION_IS_NULL); assertThatThrownBy(() -> new PfTimestampKey("my-name", VERSION001, null)) - .isInstanceOf(NullPointerException.class).hasMessage(TIMESTAMP_IS_NULL); + .isInstanceOf(NullPointerException.class).hasMessageMatching(TIMESTAMP_IS_NULL); assertThatThrownBy(() -> someKey0.setName(null)).isInstanceOf(NullPointerException.class) - .hasMessage(NAME_IS_NULL); + .hasMessageMatching(NAME_IS_NULL); assertThatThrownBy(() -> someKey0.setVersion(null)).isInstanceOf(NullPointerException.class) - .hasMessage(VERSION_IS_NULL); + .hasMessageMatching(VERSION_IS_NULL); assertThatThrownBy(() -> someKey0.setTimeStamp(null)).isInstanceOf(NullPointerException.class) - .hasMessage(TIMESTAMP_IS_NULL); + .hasMessageMatching(TIMESTAMP_IS_NULL); assertFalse(someKey1.isNewerThan(someKey2)); assertThatThrownBy(() -> someKey1.isNewerThan((PfKey) null)).isInstanceOf(NullPointerException.class) - .hasMessage("otherKey is marked @NonNull but is null"); + .hasMessageMatching("^otherKey is marked .*on.*ull but is null$"); someKey2.setTimeStamp(new Date(timeStamp + 1)); assertTrue(someKey2.isNewerThan(someKey1)); someKey3.setName("my-name3"); @@ -86,7 +85,7 @@ public class PfTimestampKeyTest { assertEquals(-1, someKey1.compareTo(someKey2)); assertEquals(-1, someKey1.compareTo(someKey3)); assertThatThrownBy(() -> someKey1.compareTo((PfConcept) null)).isInstanceOf(NullPointerException.class) - .hasMessage("otherObj is marked @NonNull but is null"); + .hasMessageMatching("^otherObj is marked .*on.*ull but is null$"); PfTimestampKey someKey4 = new PfTimestampKey("NULL", "0.0.0", new Date(timeStamp)); assertFalse(someKey4.isNullKey()); diff --git a/models-examples/src/main/resources/policies/vCPE.apex.policy.operational.input.tosca.json b/models-examples/src/main/resources/policies/vCPE.apex.policy.operational.input.tosca.json new file mode 100644 index 000000000..52a17a050 --- /dev/null +++ b/models-examples/src/main/resources/policies/vCPE.apex.policy.operational.input.tosca.json @@ -0,0 +1,2896 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", + "topology_template": { + "policies": [ + { + "operational.apex.vCPE": { + "type": "onap.policies.controlloop.operational.common.Apex", + "type_version": "1.0.0", + "derived_from": "tosca.policies.Root", + "name": "operational.apex.vCPE", + "version": "1.0.0", + "properties": { + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12561, + "policy_type_impl": { + "apexPolicyModel": { + "key": { + "name": "ONAPvCPEPolicyModel", + "version": "0.0.1" + }, + "keyInformation": { + "key": { + "name": "ONAPvCPEPolicyModel_KeyInfo", + "version": "0.0.1" + }, + "keyInfoMap": { + "entry": [ + { + "key": { + "name": "AAILookupTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "AAILookupTask", + "version": "0.0.1" + }, + "UUID": "bc77813f-e2fa-33e0-aef0-c5b6a8832698", + "description": "Generated description for concept referred to by key \"AAILookupTask:0.0.1\"" + } + }, + { + "key": { + "name": "APPCLCMRequestType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "APPCLCMRequestType", + "version": "0.0.1" + }, + "UUID": "ab26e475-d09d-36cd-a65c-8a8b556f0fa2", + "description": "Generated description for concept referred to by key \"APPCLCMRequestType:0.0.1\"" + } + }, + { + "key": { + "name": "APPCLCMResponseType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "APPCLCMResponseType", + "version": "0.0.1" + }, + "UUID": "a60b42bb-c308-30ea-be59-5bc54864508b", + "description": "Generated description for concept referred to by key \"APPCLCMResponseType:0.0.1\"" + } + }, + { + "key": { + "name": "APPCRestartVNFRequestEvent", + "version": "2.0.0" + }, + "value": { + "key": { + "name": "APPCRestartVNFRequestEvent", + "version": "2.0.0" + }, + "UUID": "0b16f8d9-6ee9-30d7-bcd2-e4ded9fccf9b", + "description": "Generated description for concept referred to by key \"APPCRestartVNFRequestEvent:2.0.0\"" + } + }, + { + "key": { + "name": "APPCRestartVNFRequestTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "APPCRestartVNFRequestTask", + "version": "0.0.1" + }, + "UUID": "719ae90e-ab01-322e-ace3-8c379e7c1fbf", + "description": "Generated description for concept referred to by key \"APPCRestartVNFRequestTask:0.0.1\"" + } + }, + { + "key": { + "name": "APPCRestartVNFResponseEvent", + "version": "2.0.0" + }, + "value": { + "key": { + "name": "APPCRestartVNFResponseEvent", + "version": "2.0.0" + }, + "UUID": "7034c5a9-2ea7-3e9e-9ccf-3610c3bf80d9", + "description": "Generated description for concept referred to by key \"APPCRestartVNFResponseEvent:2.0.0\"" + } + }, + { + "key": { + "name": "APPCRestartVNFResponseTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "APPCRestartVNFResponseTask", + "version": "0.0.1" + }, + "UUID": "fe641fd9-6583-37c5-b317-2a33a3ca5ac7", + "description": "Generated description for concept referred to by key \"APPCRestartVNFResponseTask:0.0.1\"" + } + }, + { + "key": { + "name": "AbatedTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "AbatedTask", + "version": "0.0.1" + }, + "UUID": "0eb3974f-4fdc-3c90-b351-34e7e18ff1ab", + "description": "Generated description for concept referred to by key \"AbatedTask:0.0.1\"" + } + }, + { + "key": { + "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "version": "1.0.2" + }, + "value": { + "key": { + "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "version": "1.0.2" + }, + "UUID": "63ff5c25-f245-37e9-a580-6ac274ced3a7", + "description": "Generated description for concept referred to by key \"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e:1.0.2\"" + } + }, + { + "key": { + "name": "ControlLoopExecutionIDAlbum", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ControlLoopExecutionIDAlbum", + "version": "0.0.1" + }, + "UUID": "5b2bc0cf-0807-3ab1-9004-f21806d800f0", + "description": "Generated description for concept referred to by key \"ControlLoopExecutionIDAlbum:0.0.1\"" + } + }, + { + "key": { + "name": "ControlLoopLogEvent", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ControlLoopLogEvent", + "version": "0.0.1" + }, + "UUID": "ed8a82ad-52c2-3d58-8c08-601606894b86", + "description": "Generated description for concept referred to by key \"ControlLoopLogEvent:0.0.1\"" + } + }, + { + "key": { + "name": "ControlLoopLogTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ControlLoopLogTask", + "version": "0.0.1" + }, + "UUID": "1b175691-6b5d-31f6-bf2d-4be95a01f92e", + "description": "Generated description for concept referred to by key \"ControlLoopLogTask:0.0.1\"" + } + }, + { + "key": { + "name": "DeniedTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "DeniedTask", + "version": "0.0.1" + }, + "UUID": "00142e3c-ee3b-323f-9490-6e4b7f34b09f", + "description": "Generated description for concept referred to by key \"DeniedTask:0.0.1\"" + } + }, + { + "key": { + "name": "GetVCPEStateTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "GetVCPEStateTask", + "version": "0.0.1" + }, + "UUID": "644d2a3d-0f3a-3664-8000-280c400a5cc1", + "description": "Generated description for concept referred to by key \"GetVCPEStateTask:0.0.1\"" + } + }, + { + "key": { + "name": "GuardDecisionAttributesType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "GuardDecisionAttributesType", + "version": "0.0.1" + }, + "UUID": "5f6dff51-c183-322f-9aba-c6074aa0ece5", + "description": "Generated description for concept referred to by key \"GuardDecisionAttributesType:0.0.1\"" + } + }, + { + "key": { + "name": "GuardRequestEvent", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "GuardRequestEvent", + "version": "0.0.1" + }, + "UUID": "fb383a58-715b-3972-a3e6-38010a8de234", + "description": "Generated description for concept referred to by key \"GuardRequestEvent:0.0.1\"" + } + }, + { + "key": { + "name": "GuardRequestTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "GuardRequestTask", + "version": "0.0.1" + }, + "UUID": "0427d63c-da78-334c-a5bd-95fbbb162398", + "description": "Generated description for concept referred to by key \"GuardRequestTask:0.0.1\"" + } + }, + { + "key": { + "name": "GuardResponseEvent", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "GuardResponseEvent", + "version": "0.0.1" + }, + "UUID": "395f6d46-cf24-3d3e-b1fd-1a189a58993d", + "description": "Generated description for concept referred to by key \"GuardResponseEvent:0.0.1\"" + } + }, + { + "key": { + "name": "GuardResponseTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "GuardResponseTask", + "version": "0.0.1" + }, + "UUID": "1a8b3f30-a7aa-330b-8131-4aea06ad6934", + "description": "Generated description for concept referred to by key \"GuardResponseTask:0.0.1\"" + } + }, + { + "key": { + "name": "NoAAILookupTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "NoAAILookupTask", + "version": "0.0.1" + }, + "UUID": "648bc8f9-ad2b-3a1b-abe2-89401645f191", + "description": "Generated description for concept referred to by key \"NoAAILookupTask:0.0.1\"" + } + }, + { + "key": { + "name": "ONAPvCPEPolicyModel", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ONAPvCPEPolicyModel", + "version": "0.0.1" + }, + "UUID": "cf1aa7f4-6fe3-3cba-90b4-49dcf46f0d57", + "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel:0.0.1\"" + } + }, + { + "key": { + "name": "ONAPvCPEPolicyModel_Albums", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ONAPvCPEPolicyModel_Albums", + "version": "0.0.1" + }, + "UUID": "13f8471b-2b9c-32e0-940b-fe640ea442cf", + "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Albums:0.0.1\"" + } + }, + { + "key": { + "name": "ONAPvCPEPolicyModel_Events", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ONAPvCPEPolicyModel_Events", + "version": "0.0.1" + }, + "UUID": "4b8e6653-731d-38c5-a195-0cadf533a7a1", + "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Events:0.0.1\"" + } + }, + { + "key": { + "name": "ONAPvCPEPolicyModel_KeyInfo", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ONAPvCPEPolicyModel_KeyInfo", + "version": "0.0.1" + }, + "UUID": "87a9d6da-7d4b-3041-8a70-49442750d590", + "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_KeyInfo:0.0.1\"" + } + }, + { + "key": { + "name": "ONAPvCPEPolicyModel_Policies", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ONAPvCPEPolicyModel_Policies", + "version": "0.0.1" + }, + "UUID": "6220cca4-66f5-3d1b-9f19-688a9b4b70f5", + "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Policies:0.0.1\"" + } + }, + { + "key": { + "name": "ONAPvCPEPolicyModel_Schemas", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ONAPvCPEPolicyModel_Schemas", + "version": "0.0.1" + }, + "UUID": "3df4eef8-e764-3398-afe9-86730e20905a", + "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Schemas:0.0.1\"" + } + }, + { + "key": { + "name": "ONAPvCPEPolicyModel_Tasks", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ONAPvCPEPolicyModel_Tasks", + "version": "0.0.1" + }, + "UUID": "1781b875-a3e8-3407-98bd-ba9580cfc543", + "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Tasks:0.0.1\"" + } + }, + { + "key": { + "name": "ReceiveEventPolicy", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ReceiveEventPolicy", + "version": "0.0.1" + }, + "UUID": "568b7345-9de1-36d3-b6a3-9b857e6809a1", + "description": "Generated description for concept referred to by key \"ReceiveEventPolicy:0.0.1\"" + } + }, + { + "key": { + "name": "RequestIDVNFIDAlbum", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "RequestIDVNFIDAlbum", + "version": "0.0.1" + }, + "UUID": "5d8e8298-ded6-30a5-9825-48111dc17a58", + "description": "Generated description for concept referred to by key \"RequestIDVNFIDAlbum:0.0.1\"" + } + }, + { + "key": { + "name": "RestartAPPCRequestPolicy", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "RestartAPPCRequestPolicy", + "version": "0.0.1" + }, + "UUID": "33d02162-314b-352b-b8b9-2862e8883894", + "description": "Generated description for concept referred to by key \"RestartAPPCRequestPolicy:0.0.1\"" + } + }, + { + "key": { + "name": "RestartAPPCResponsePolicy", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "RestartAPPCResponsePolicy", + "version": "0.0.1" + }, + "UUID": "ef4fcbd2-1609-377c-9875-8d27f7a901df", + "description": "Generated description for concept referred to by key \"RestartAPPCResponsePolicy:0.0.1\"" + } + }, + { + "key": { + "name": "SimpleBooleanType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "SimpleBooleanType", + "version": "0.0.1" + }, + "UUID": "7218fb2f-59e3-321d-9ae1-bc97b19eb4ae", + "description": "Generated description for concept referred to by key \"SimpleBooleanType:0.0.1\"" + } + }, + { + "key": { + "name": "SimpleLongType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "SimpleLongType", + "version": "0.0.1" + }, + "UUID": "2dfcd9ec-a6f9-3f9f-958f-9b36cf4ac574", + "description": "Generated description for concept referred to by key \"SimpleLongType:0.0.1\"" + } + }, + { + "key": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "UUID": "8a4957cf-9493-3a76-8c22-a208e23259af", + "description": "Generated description for concept referred to by key \"SimpleStringType:0.0.1\"" + } + }, + { + "key": { + "name": "UUIDType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "UUIDType", + "version": "0.0.1" + }, + "UUID": "6a8cc68e-dfc8-3403-9c6d-071c886b319c", + "description": "Generated description for concept referred to by key \"UUIDType:0.0.1\"" + } + }, + { + "key": { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + }, + "UUID": "47a4403e-3074-3964-83ef-93eefaffd192", + "description": "Generated description for concept referred to by key \"VCPEClosedLoopStatusAlbum:0.0.1\"" + } + }, + { + "key": { + "name": "VCPEClosedLoopStatusType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "VCPEClosedLoopStatusType", + "version": "0.0.1" + }, + "UUID": "6e7dced1-53f1-39e2-b4e6-412b75d5b9e6", + "description": "Generated description for concept referred to by key \"VCPEClosedLoopStatusType:0.0.1\"" + } + }, + { + "key": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "UUID": "5e56a3fd-f82a-3ced-821b-b9fbaf65d367", + "description": "Generated description for concept referred to by key \"VCPEStateUpdatedEvent:0.0.1\"" + } + }, + { + "key": { + "name": "VirtualControlLoopEventType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "VirtualControlLoopEventType", + "version": "0.0.1" + }, + "UUID": "15aca887-8f6c-3713-8114-0f49f03adab7", + "description": "Generated description for concept referred to by key \"VirtualControlLoopEventType:0.0.1\"" + } + }, + { + "key": { + "name": "VirtualControlLoopNotificationType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "VirtualControlLoopNotificationType", + "version": "0.0.1" + }, + "UUID": "283f5b0d-d8cd-31b0-91fa-89b9de2e1fda", + "description": "Generated description for concept referred to by key \"VirtualControlLoopNotificationType:0.0.1\"" + } + } + ] + } + }, + "policies": { + "key": { + "name": "ONAPvCPEPolicyModel_Policies", + "version": "0.0.1" + }, + "policyMap": { + "entry": [ + { + "key": { + "name": "ReceiveEventPolicy", + "version": "0.0.1" + }, + "value": { + "policyKey": { + "name": "ReceiveEventPolicy", + "version": "0.0.1" + }, + "template": "Freestyle", + "state": { + "entry": [ + { + "key": "AbatedState", + "value": { + "stateKey": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "AbatedState" + }, + "trigger": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "stateOutputs": { + "entry": [ + { + "key": "AbatedOutput", + "value": { + "key": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "AbatedState", + "localName": "AbatedOutput" + }, + "outgoingEvent": { + "name": "ControlLoopLogEvent", + "version": "0.0.1" + }, + "nextState": { + "parentKeyName": "NULL", + "parentKeyVersion": "0.0.0", + "parentLocalName": "NULL", + "localName": "NULL" + } + } + } + ] + }, + "contextAlbumReference": [], + "taskSelectionLogic": { + "key": "NULL", + "logicFlavour": "UNDEFINED", + "logic": "" + }, + "stateFinalizerLogicMap": { + "entry": [] + }, + "defaultTask": { + "name": "ControlLoopLogTask", + "version": "0.0.1" + }, + "taskReferences": { + "entry": [ + { + "key": { + "name": "ControlLoopLogTask", + "version": "0.0.1" + }, + "value": { + "key": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "AbatedState", + "localName": "ReceiveEventPolicy" + }, + "outputType": "DIRECT", + "output": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "AbatedState", + "localName": "AbatedOutput" + } + } + } + ] + } + } + }, + { + "key": "GetVCPEState", + "value": { + "stateKey": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "GetVCPEState" + }, + "trigger": { + "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "version": "1.0.2" + }, + "stateOutputs": { + "entry": [ + { + "key": "GetVCPEStateOutput", + "value": { + "key": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "GetVCPEState", + "localName": "GetVCPEStateOutput" + }, + "outgoingEvent": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "nextState": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "RequestAAIState" + } + } + } + ] + }, + "contextAlbumReference": [], + "taskSelectionLogic": { + "key": "NULL", + "logicFlavour": "UNDEFINED", + "logic": "" + }, + "stateFinalizerLogicMap": { + "entry": [] + }, + "defaultTask": { + "name": "GetVCPEStateTask", + "version": "0.0.1" + }, + "taskReferences": { + "entry": [ + { + "key": { + "name": "GetVCPEStateTask", + "version": "0.0.1" + }, + "value": { + "key": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "GetVCPEState", + "localName": "ReceiveEventPolicy" + }, + "outputType": "DIRECT", + "output": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "GetVCPEState", + "localName": "GetVCPEStateOutput" + } + } + } + ] + } + } + }, + { + "key": "OnsetOrAbatedState", + "value": { + "stateKey": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "OnsetOrAbatedState" + }, + "trigger": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "stateOutputs": { + "entry": [ + { + "key": "AbatedOutput", + "value": { + "key": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "OnsetOrAbatedState", + "localName": "AbatedOutput" + }, + "outgoingEvent": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "nextState": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "AbatedState" + } + } + }, + { + "key": "OnsetOutput", + "value": { + "key": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "OnsetOrAbatedState", + "localName": "OnsetOutput" + }, + "outgoingEvent": { + "name": "GuardRequestEvent", + "version": "0.0.1" + }, + "nextState": { + "parentKeyName": "NULL", + "parentKeyVersion": "0.0.0", + "parentLocalName": "NULL", + "localName": "NULL" + } + } + } + ] + }, + "contextAlbumReference": [ + { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + } + ], + "taskSelectionLogic": { + "key": "TaskSelectionLogic", + "logicFlavour": "JAVASCRIPT", + "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar returnValue = true;\nvar status = null;\n\nif( executor.inFields.get(\"vnfID\") == null) {\n executor.logger.info(\"OnsetOrAbatedStateTSL: vnfID is null\");\n var vnfName = executor.inFields.get(\"vnfName\");\n var vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfName\"));\n status = vcpeClosedLoopStatus.get(\"closedLoopEventStatus\").toString();\n} else {\n var vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n status = vcpeClosedLoopStatus.get(\"closedLoopEventStatus\").toString();\n}\n\nif (status == \"ONSET\") {\n executor.subject.getTaskKey(\"GuardRequestTask\").copyTo(executor.selectedTask);\n} else if (status == \"ABATED\") {\n executor.subject.getTaskKey(\"AbatedTask\").copyTo(executor.selectedTask);\n onsetFlag = executor.isFalse;\n} else {\n executor.message = \"closedLoopEventStatus is \\\"\" + status + \"\\\", it must be either \\\"ONSET\\\" or \\\"ABATED\\\"\";\n returnValue = false;\n}\n\nexecutor.logger.info(\"ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:\" + executor.selectedTask);\n\nreturnValue;" + }, + "stateFinalizerLogicMap": { + "entry": [] + }, + "defaultTask": { + "name": "AbatedTask", + "version": "0.0.1" + }, + "taskReferences": { + "entry": [ + { + "key": { + "name": "AbatedTask", + "version": "0.0.1" + }, + "value": { + "key": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "OnsetOrAbatedState", + "localName": "ReceiveEventPolicy" + }, + "outputType": "DIRECT", + "output": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "OnsetOrAbatedState", + "localName": "AbatedOutput" + } + } + }, + { + "key": { + "name": "GuardRequestTask", + "version": "0.0.1" + }, + "value": { + "key": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "OnsetOrAbatedState", + "localName": "ReceiveEventPolicy" + }, + "outputType": "DIRECT", + "output": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "OnsetOrAbatedState", + "localName": "OnsetOutput" + } + } + } + ] + } + } + }, + { + "key": "RequestAAIState", + "value": { + "stateKey": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "RequestAAIState" + }, + "trigger": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "stateOutputs": { + "entry": [ + { + "key": "RequestAAIStateOutput", + "value": { + "key": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "RequestAAIState", + "localName": "RequestAAIStateOutput" + }, + "outgoingEvent": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "nextState": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "OnsetOrAbatedState" + } + } + } + ] + }, + "contextAlbumReference": [ + { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + } + ], + "taskSelectionLogic": { + "key": "NULL", + "logicFlavour": "UNDEFINED", + "logic": "" + }, + "stateFinalizerLogicMap": { + "entry": [] + }, + "defaultTask": { + "name": "AAILookupTask", + "version": "0.0.1" + }, + "taskReferences": { + "entry": [ + { + "key": { + "name": "AAILookupTask", + "version": "0.0.1" + }, + "value": { + "key": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "RequestAAIState", + "localName": "ReceiveEventPolicy" + }, + "outputType": "DIRECT", + "output": { + "parentKeyName": "ReceiveEventPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "RequestAAIState", + "localName": "RequestAAIStateOutput" + } + } + } + ] + } + } + } + ] + }, + "firstState": "GetVCPEState" + } + }, + { + "key": { + "name": "RestartAPPCRequestPolicy", + "version": "0.0.1" + }, + "value": { + "policyKey": { + "name": "RestartAPPCRequestPolicy", + "version": "0.0.1" + }, + "template": "Freestyle", + "state": { + "entry": [ + { + "key": "DeniedState", + "value": { + "stateKey": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "DeniedState" + }, + "trigger": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "stateOutputs": { + "entry": [ + { + "key": "DeniedOutput", + "value": { + "key": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "DeniedState", + "localName": "DeniedOutput" + }, + "outgoingEvent": { + "name": "ControlLoopLogEvent", + "version": "0.0.1" + }, + "nextState": { + "parentKeyName": "NULL", + "parentKeyVersion": "0.0.0", + "parentLocalName": "NULL", + "localName": "NULL" + } + } + } + ] + }, + "contextAlbumReference": [], + "taskSelectionLogic": { + "key": "NULL", + "logicFlavour": "UNDEFINED", + "logic": "" + }, + "stateFinalizerLogicMap": { + "entry": [] + }, + "defaultTask": { + "name": "ControlLoopLogTask", + "version": "0.0.1" + }, + "taskReferences": { + "entry": [ + { + "key": { + "name": "ControlLoopLogTask", + "version": "0.0.1" + }, + "value": { + "key": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "DeniedState", + "localName": "RestartAPPCRequestPolicy" + }, + "outputType": "DIRECT", + "output": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "DeniedState", + "localName": "DeniedOutput" + } + } + } + ] + } + } + }, + { + "key": "PermitOrDenyState", + "value": { + "stateKey": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "PermitOrDenyState" + }, + "trigger": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "stateOutputs": { + "entry": [ + { + "key": "DenyOutput", + "value": { + "key": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "PermitOrDenyState", + "localName": "DenyOutput" + }, + "outgoingEvent": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "nextState": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "DeniedState" + } + } + }, + { + "key": "PermitOutput", + "value": { + "key": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "PermitOrDenyState", + "localName": "PermitOutput" + }, + "outgoingEvent": { + "name": "APPCRestartVNFRequestEvent", + "version": "2.0.0" + }, + "nextState": { + "parentKeyName": "NULL", + "parentKeyVersion": "0.0.0", + "parentLocalName": "NULL", + "localName": "NULL" + } + } + } + ] + }, + "contextAlbumReference": [ + { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + } + ], + "taskSelectionLogic": { + "key": "TaskSelectionLogic", + "logicFlavour": "JAVASCRIPT", + "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nvar guardResult = vcpeClosedLoopStatus.get(\"notification\");\n\nif (guardResult == \"OPERATION: GUARD_PERMIT\") {\n executor.subject.getTaskKey(\"APPCRestartVNFRequestTask\").copyTo(executor.selectedTask);\n} else {\n executor.subject.getTaskKey(\"DeniedTask\").copyTo(executor.selectedTask);\n}\n\nexecutor.logger.info(\"RestartAPPCRequestPolicyPermitOrDenyTSL State Selected Task:\" + executor.selectedTask);\n\ntrue;" + }, + "stateFinalizerLogicMap": { + "entry": [] + }, + "defaultTask": { + "name": "DeniedTask", + "version": "0.0.1" + }, + "taskReferences": { + "entry": [ + { + "key": { + "name": "APPCRestartVNFRequestTask", + "version": "0.0.1" + }, + "value": { + "key": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "PermitOrDenyState", + "localName": "RestartAPPCRequestPolicy" + }, + "outputType": "DIRECT", + "output": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "PermitOrDenyState", + "localName": "PermitOutput" + } + } + }, + { + "key": { + "name": "DeniedTask", + "version": "0.0.1" + }, + "value": { + "key": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "PermitOrDenyState", + "localName": "RestartAPPCRequestPolicy" + }, + "outputType": "DIRECT", + "output": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "PermitOrDenyState", + "localName": "DenyOutput" + } + } + } + ] + } + } + }, + { + "key": "PolicyGuardResponseState", + "value": { + "stateKey": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "PolicyGuardResponseState" + }, + "trigger": { + "name": "GuardResponseEvent", + "version": "0.0.1" + }, + "stateOutputs": { + "entry": [ + { + "key": "GuardResponseOutput", + "value": { + "key": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "PolicyGuardResponseState", + "localName": "GuardResponseOutput" + }, + "outgoingEvent": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "nextState": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "PermitOrDenyState" + } + } + } + ] + }, + "contextAlbumReference": [], + "taskSelectionLogic": { + "key": "NULL", + "logicFlavour": "UNDEFINED", + "logic": "" + }, + "stateFinalizerLogicMap": { + "entry": [] + }, + "defaultTask": { + "name": "GuardResponseTask", + "version": "0.0.1" + }, + "taskReferences": { + "entry": [ + { + "key": { + "name": "GuardResponseTask", + "version": "0.0.1" + }, + "value": { + "key": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "PolicyGuardResponseState", + "localName": "RestartAPPCRequestPolicy" + }, + "outputType": "DIRECT", + "output": { + "parentKeyName": "RestartAPPCRequestPolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "PolicyGuardResponseState", + "localName": "GuardResponseOutput" + } + } + } + ] + } + } + } + ] + }, + "firstState": "PolicyGuardResponseState" + } + }, + { + "key": { + "name": "RestartAPPCResponsePolicy", + "version": "0.0.1" + }, + "value": { + "policyKey": { + "name": "RestartAPPCResponsePolicy", + "version": "0.0.1" + }, + "template": "Freestyle", + "state": { + "entry": [ + { + "key": "ResponseLogState", + "value": { + "stateKey": { + "parentKeyName": "RestartAPPCResponsePolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "ResponseLogState" + }, + "trigger": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "stateOutputs": { + "entry": [ + { + "key": "ResponseLogOutput", + "value": { + "key": { + "parentKeyName": "RestartAPPCResponsePolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "ResponseLogState", + "localName": "ResponseLogOutput" + }, + "outgoingEvent": { + "name": "ControlLoopLogEvent", + "version": "0.0.1" + }, + "nextState": { + "parentKeyName": "NULL", + "parentKeyVersion": "0.0.0", + "parentLocalName": "NULL", + "localName": "NULL" + } + } + } + ] + }, + "contextAlbumReference": [], + "taskSelectionLogic": { + "key": "NULL", + "logicFlavour": "UNDEFINED", + "logic": "" + }, + "stateFinalizerLogicMap": { + "entry": [] + }, + "defaultTask": { + "name": "ControlLoopLogTask", + "version": "0.0.1" + }, + "taskReferences": { + "entry": [ + { + "key": { + "name": "ControlLoopLogTask", + "version": "0.0.1" + }, + "value": { + "key": { + "parentKeyName": "RestartAPPCResponsePolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "ResponseLogState", + "localName": "RestartAPPCResponsePolicy" + }, + "outputType": "DIRECT", + "output": { + "parentKeyName": "RestartAPPCResponsePolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "ResponseLogState", + "localName": "ResponseLogOutput" + } + } + } + ] + } + } + }, + { + "key": "RestartAPPCResponseState", + "value": { + "stateKey": { + "parentKeyName": "RestartAPPCResponsePolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "RestartAPPCResponseState" + }, + "trigger": { + "name": "APPCRestartVNFResponseEvent", + "version": "2.0.0" + }, + "stateOutputs": { + "entry": [ + { + "key": "APPCRestartVNFResponseOutput", + "value": { + "key": { + "parentKeyName": "RestartAPPCResponsePolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "RestartAPPCResponseState", + "localName": "APPCRestartVNFResponseOutput" + }, + "outgoingEvent": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "nextState": { + "parentKeyName": "RestartAPPCResponsePolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "NULL", + "localName": "ResponseLogState" + } + } + } + ] + }, + "contextAlbumReference": [], + "taskSelectionLogic": { + "key": "NULL", + "logicFlavour": "UNDEFINED", + "logic": "" + }, + "stateFinalizerLogicMap": { + "entry": [] + }, + "defaultTask": { + "name": "APPCRestartVNFResponseTask", + "version": "0.0.1" + }, + "taskReferences": { + "entry": [ + { + "key": { + "name": "APPCRestartVNFResponseTask", + "version": "0.0.1" + }, + "value": { + "key": { + "parentKeyName": "RestartAPPCResponsePolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "RestartAPPCResponseState", + "localName": "RestartAPPCResponsePolicy" + }, + "outputType": "DIRECT", + "output": { + "parentKeyName": "RestartAPPCResponsePolicy", + "parentKeyVersion": "0.0.1", + "parentLocalName": "RestartAPPCResponseState", + "localName": "APPCRestartVNFResponseOutput" + } + } + } + ] + } + } + } + ] + }, + "firstState": "RestartAPPCResponseState" + } + } + ] + } + }, + "tasks": { + "key": { + "name": "ONAPvCPEPolicyModel_Tasks", + "version": "0.0.1" + }, + "taskMap": { + "entry": [ + { + "key": { + "name": "AAILookupTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "AAILookupTask", + "version": "0.0.1" + }, + "inputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "outputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "taskParameters": { + "entry": [] + }, + "contextAlbumReference": [ + { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + } + ], + "taskLogic": { + "key": "TaskLogic", + "logicFlavour": "JAVASCRIPT", + "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nexecutor.logger.info(\"Executing A&AI Lookup\");\nexecutor.logger.info(vcpeClosedLoopStatus);\n\nvar aaiInfo = vcpeClosedLoopStatus.get(\"AAI\");\nvar returnValue = true;\n\nif (aaiInfo.get(\"vserverName\") == null) {\n executor.message = \"the field vserver.vserver-name must exist in the onset control loop event\";\n executor.logger.warn(executor.message);\n returnValue = false;\n}\nelse if (aaiInfo.get(\"genericVnfVnfId\") == null && aaiInfo.get(\"genericVnfVnfName\") == null) {\n executor.message = \"either the field generic-vnf.vnf-id or generic-vnf.vnf-name must exist\"\n + \" in the onset control loop event\";\n executor.logger.warn(executor.message);\n returnValue = false;\n}\nelse {\n var restManager = new org.onap.policy.rest.RestManager;\n var aaiManager = new org.onap.policy.aai.AaiManager(restManager);\n\n // We need to instantiate the type in order to trigger the static JAXB handling\n // in the AaiCqResponse class\n var aaiCqResponseType = org.onap.policy.aai.AaiCqResponse;\n\n var aaiResponse = aaiManager.getCustomQueryResponse(\n \"http://localhost:54321/OnapVCpeSim/sim\",\n \"aai.username\",\n \"aai.password\",\n executor.inFields.get(\"requestID\"),\n vcpeClosedLoopStatus.get(\"AAI\").get(\"vserverName\")\n );\n\n var genericVnf;\n\n if (aaiInfo.get(\"genericVnfVnfId\") != null) {\n genericVnf = aaiResponse.getGenericVnfByModelInvariantId(aaiInfo.get(\"genericVnfVnfId\"));\n }\n else {\n genericVnf = aaiResponse.getGenericVnfByVnfName(aaiInfo.get(\"genericVnfVnfId\"));\n }\n\n aaiInfo.put(\"genericVnfResourceVersion\", genericVnf.getResourceVersion());\n aaiInfo.put(\"genericVnfVnfName\", genericVnf.getVnfName());\n aaiInfo.put(\"genericVnfProvStatus\", genericVnf.getProvStatus());\n aaiInfo.put(\"genericVnfIsClosedLoopDisabled\", genericVnf.isIsClosedLoopDisabled().toString());\n aaiInfo.put(\"genericVnfVnfType\", genericVnf.getVnfType());\n aaiInfo.put(\"genericVnfInMaint\", genericVnf.isInMaint().toString());\n aaiInfo.put(\"genericVnfServiceId\", genericVnf.getServiceId());\n aaiInfo.put(\"genericVnfVnfId\", genericVnf.getVnfId());\n aaiInfo.put(\"genericVnfOrchestrationStatus\",\n genericVnf.getVfModules().getVfModule().get(0).getOrchestrationStatus());\n\n executor.outFields.put(\"requestID\", executor.inFields.get(\"requestID\"));\n executor.outFields.put(\"vnfID\", executor.inFields.get(\"vnfID\"));\n\n executor.logger.info(executor.outFields);\n}\n\nreturnValue;" + } + } + }, + { + "key": { + "name": "APPCRestartVNFRequestTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "APPCRestartVNFRequestTask", + "version": "0.0.1" + }, + "inputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "outputFields": { + "entry": [ + { + "key": "APPCLCMRequestEvent", + "value": { + "key": "APPCLCMRequestEvent", + "fieldSchemaKey": { + "name": "APPCLCMRequestType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "taskParameters": { + "entry": [] + }, + "contextAlbumReference": [ + { + "name": "RequestIDVNFIDAlbum", + "version": "0.0.1" + }, + { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + } + ], + "taskLogic": { + "key": "TaskLogic", + "logicFlavour": "JAVASCRIPT", + "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar appcRequest = new org.onap.policy.appclcm.AppcLcmDmaapWrapper;\nappcRequest.setBody(new org.onap.policy.appclcm.AppcLcmBody);\nappcRequest.getBody().setInput(new org.onap.policy.appclcm.AppcLcmInput);\nappcRequest.getBody().getInput().setCommonHeader(\n new org.onap.policy.appclcm.AppcLcmCommonHeader);\n\nappcRequest.setVersion(\"2.0.0\");\nappcRequest.setRpcName(\"restart\");\nappcRequest.setCorrelationId(executor.inFields.get(\"requestID\"));\nappcRequest.setType(\"request\");\n\nvar vcpeClosedLoopStatus = executor\n .getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nappcRequest.getBody().getInput().getCommonHeader().setTimeStamp(java.time.Instant.now());\nappcRequest.getBody().getInput().getCommonHeader().setApiVer(\"2.00\");\nappcRequest.getBody().getInput().getCommonHeader().setOriginatorId(\n executor.inFields.get(\"requestID\").toString());\nappcRequest.getBody().getInput().getCommonHeader().setRequestId(\n executor.inFields.get(\"requestID\"));\nappcRequest.getBody().getInput().getCommonHeader().setSubRequestId(\"1\");\nappcRequest.getBody().getInput().getCommonHeader().getFlags().put(\"ttl\", \"10000\");\nappcRequest.getBody().getInput().getCommonHeader().getFlags().put(\"force\", \"TRUE\");\nappcRequest.getBody().getInput().getCommonHeader().getFlags().put(\"mode\", \"EXCLUSIVE\");\n\nappcRequest.getBody().getInput().setAction(\"Restart\");\nappcRequest.getBody().getInput().setActionIdentifiers(new java.util.HashMap());\nappcRequest.getBody().getInput().getActionIdentifiers().put(\"vnf-id\",\n executor.inFields.get(\"vnfID\").toString());\n\nexecutor.getContextAlbum(\"RequestIDVNFIDAlbum\").put(\n executor.inFields.get(\"requestID\").toString(),\n executor.inFields.get(\"vnfID\"));\n\nvcpeClosedLoopStatus.put(\"notification\", \"OPERATION\");\nvcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System\n .currentTimeMillis());\n\nexecutor.outFields.put(\"APPCLCMRequestEvent\", appcRequest);\n\nexecutor.logger.info(executor.outFields);\n\ntrue;" + } + } + }, + { + "key": { + "name": "APPCRestartVNFResponseTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "APPCRestartVNFResponseTask", + "version": "0.0.1" + }, + "inputFields": { + "entry": [ + { + "key": "APPCLCMResponseEvent", + "value": { + "key": "APPCLCMResponseEvent", + "fieldSchemaKey": { + "name": "APPCLCMResponseType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "outputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "taskParameters": { + "entry": [] + }, + "contextAlbumReference": [ + { + "name": "RequestIDVNFIDAlbum", + "version": "0.0.1" + }, + { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + } + ], + "taskLogic": { + "key": "TaskLogic", + "logicFlavour": "JAVASCRIPT", + "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * APPC LCM Response code: 100 ACCEPTED\n * 200 ERROR UNEXPECTED ERROR means failure\n * 312 REJECTED DUPLICATE REQUEST\n * 400 SUCCESS\n *\n * Note: Sometimes the corelationId has a -1 at the tail, need to get rid of it when present.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar appcResponse = executor.inFields.get(\"APPCLCMResponseEvent\");\n\nvar requestIDString = appcResponse.getCorrelationId().substr(0, 36);\nexecutor.logger.info(\"requestIDString = \" + requestIDString);\nvar vnfID = executor.getContextAlbum(\"RequestIDVNFIDAlbum\")\n .get(requestIDString);\nexecutor.logger.info(\"Size of RequestIDVNFIDAlbum = \"\n + executor.getContextAlbum(\"RequestIDVNFIDAlbum\").size());\nexecutor.logger.info(\"vnfID = \" + vnfID);\n\nvar returnValue = true;\n\nif (vnfID != null) {\n var vcpeClosedLoopStatus = executor.getContextAlbum(\n \"VCPEClosedLoopStatusAlbum\").get(vnfID.toString());\n var requestId = java.util.UUID.fromString(vcpeClosedLoopStatus\n .get(\"requestID\"));\n\n vcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System\n .currentTimeMillis());\n\n executor.logger.info(\"Got from APPC code: \"\n + org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody().getOutput()\n .getStatus().getCode()));\n\n if (org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody().getOutput().getStatus()\n .getCode()) == org.onap.policy.appclcm.AppcLcmResponseCode.SUCCESS) {\n vcpeClosedLoopStatus.put(\"notification\", \"OPERATION_SUCCESS\");\n vcpeClosedLoopStatus.put(\"message\", \"vCPE restarted\");\n executor.getContextAlbum(\"RequestIDVNFIDAlbum\").remove(requestIDString);\n } else if (org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody().getOutput().getStatus()\n .getCode()) == \"ACCEPTED\"\n || org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody().getOutput()\n .getStatus().getCode()) == \"REJECT\") {\n executor.logger\n .info(\"Got ACCEPTED 100 or REJECT 312, keep the context, wait for next response. Code is: \"\n + org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody()\n .getOutput().getStatus().getCode()));\n } else {\n executor.getContextAlbum(\"RequestIDVNFIDAlbum\").remove(requestIDString);\n vcpeClosedLoopStatus.put(\"notification\", \"OPERATION_FAILURE\");\n vcpeClosedLoopStatus.put(\"message\", \"vCPE restart failed\");\n }\n\n executor.outFields.put(\"requestID\", requestId);\n executor.outFields.put(\"vnfID\", vnfID);\n} else {\n executor.message = \"VNF ID not found in context album for request ID \"\n + requestIDString;\n returnValue = false\n}\n\nexecutor.logger.info(executor.outFields);\n\nreturnValue;" + } + } + }, + { + "key": { + "name": "AbatedTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "AbatedTask", + "version": "0.0.1" + }, + "inputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfName", + "value": { + "key": "vnfName", + "fieldSchemaKey": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "optional": true + } + } + ] + }, + "outputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfName", + "value": { + "key": "vnfName", + "fieldSchemaKey": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "optional": true + } + } + ] + }, + "taskParameters": { + "entry": [] + }, + "contextAlbumReference": [ + { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + } + ], + "taskLogic": { + "key": "TaskLogic", + "logicFlavour": "JAVASCRIPT", + "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = null;\nif( executor.inFields.get(\"vnfID\") == null) {\n executor.logger.info(\"AbatedTask: vnfID is null\");\n var vnfName = executor.inFields.get(\"vnfName\");\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfName\"));\n} else {\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n}\n\nvcpeClosedLoopStatus.put(\"notification\", \"FINAL_SUCCESS\");\nvcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System.currentTimeMillis());\nvcpeClosedLoopStatus.put(\"message\", \"situation has been abated\");\n\nexecutor.logger.info(executor.outFields);\n\ntrue;" + } + } + }, + { + "key": { + "name": "ControlLoopLogTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ControlLoopLogTask", + "version": "0.0.1" + }, + "inputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "outputFields": { + "entry": [ + { + "key": "VirtualControlLoopNotification", + "value": { + "key": "VirtualControlLoopNotification", + "fieldSchemaKey": { + "name": "VirtualControlLoopNotificationType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "taskParameters": { + "entry": [] + }, + "contextAlbumReference": [ + { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + } + ], + "taskLogic": { + "key": "TaskLogic", + "logicFlavour": "JAVASCRIPT", + "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vnfID = executor.inFields.get(\"vnfID\");\nif(vnfID == null) {\n vnfID = executor.inFields.get(\"vnfName\");\n}\nexecutor.logger.info(\"vnfID=\" + vnfID);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(vnfID.toString());\n\nexecutor.logger.info(\"Logging context information for VNF \\\"\" + vnfID + \"\\\"\");\n\nvar clNotification = new org.onap.policy.controlloop.VirtualControlLoopNotification();\n\nclNotification.setClosedLoopControlName(vcpeClosedLoopStatus.get(\"closedLoopControlName\"));\nclNotification.setClosedLoopAlarmStart(java.time.Instant.ofEpochMilli(vcpeClosedLoopStatus.get(\"closedLoopAlarmStart\")));\nclNotification.setClosedLoopAlarmEnd(java.time.Instant.ofEpochMilli(vcpeClosedLoopStatus.get(\"closedLoopAlarmEnd\")));\nclNotification.setClosedLoopEventClient(vcpeClosedLoopStatus.get(\"closedLoopEventClient\"));\nclNotification.setVersion(vcpeClosedLoopStatus.get(\"version\"));\nclNotification.setRequestId(java.util.UUID.fromString(vcpeClosedLoopStatus.get(\"requestID\")));\nclNotification.setTargetType(vcpeClosedLoopStatus.get(\"target_type\"));\nclNotification.setTarget(vcpeClosedLoopStatus.get(\"target\"));\nclNotification.setFrom(vcpeClosedLoopStatus.get(\"from\"));\nclNotification.setPolicyScope(vcpeClosedLoopStatus.get(\"policyScope\"));\nclNotification.setPolicyName(vcpeClosedLoopStatus.get(\"policyName\"));\nclNotification.setPolicyVersion(vcpeClosedLoopStatus.get(\"policyVersion\"));\nclNotification.setNotification(org.onap.policy.controlloop.ControlLoopNotificationType.toType(vcpeClosedLoopStatus.get(\"notification\")));\nclNotification.setMessage(vcpeClosedLoopStatus.get(\"message\"));\n\nvar notificationInstant = java.time.Instant.ofEpochSecond(vcpeClosedLoopStatus.get(\"notificationTime\"));\nvar notificationTime = java.time.ZonedDateTime.ofInstant(notificationInstant, java.time.ZoneOffset.UTC);\nclNotification.setNotificationTime(notificationTime);\n\nvar aaiInfo = vcpeClosedLoopStatus.get(\"AAI\");\n\nclNotification.getAai().put(\"generic-vnf.resource-version\", aaiInfo.get(\"genericVnfResourceVersion\"));\nclNotification.getAai().put(\"generic-vnf.vnf-name\", aaiInfo.get(\"genericVnfVnfName\"));\nclNotification.getAai().put(\"generic-vnf.prov-status\", aaiInfo.get(\"genericVnfProvStatus\"));\nclNotification.getAai().put(\"generic-vnf.is-closed-loop-disabled\", aaiInfo.get(\"genericVnfIsClosedLoopDisabled\"));\nclNotification.getAai().put(\"generic-vnf.orchestration-status\", aaiInfo.get(\"genericVnfOrchestrationStatus\"));\nclNotification.getAai().put(\"generic-vnf.vnf-type\", aaiInfo.get(\"genericVnfVnfType\"));\nclNotification.getAai().put(\"generic-vnf.in-maint\", aaiInfo.get(\"genericVnfInMaint\"));\nclNotification.getAai().put(\"generic-vnf.service-id\", aaiInfo.get(\"genericVnfServiceId\"));\n\nif(vnfID != null) {\n clNotification.getAai().put(\"generic-vnf.vnf-id\", aaiInfo.get(\"genericVnfVnfId\"));\n}\nexecutor.outFields.put(\"VirtualControlLoopNotification\", clNotification);\n\nexecutor.logger.info(executor.outFields);\n\ntrue;" + } + } + }, + { + "key": { + "name": "DeniedTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "DeniedTask", + "version": "0.0.1" + }, + "inputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "outputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "taskParameters": { + "entry": [] + }, + "contextAlbumReference": [ + { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + } + ], + "taskLogic": { + "key": "TaskLogic", + "logicFlavour": "JAVASCRIPT", + "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nvcpeClosedLoopStatus.put(\"notification\", \"REJECTED\");\nvcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System.currentTimeMillis());\n\nexecutor.logger.info(executor.outFields);\n\ntrue;" + } + } + }, + { + "key": { + "name": "GetVCPEStateTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "GetVCPEStateTask", + "version": "0.0.1" + }, + "inputFields": { + "entry": [ + { + "key": "VirtualControlLoopEvent", + "value": { + "key": "VirtualControlLoopEvent", + "fieldSchemaKey": { + "name": "VirtualControlLoopEventType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "outputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfName", + "value": { + "key": "vnfName", + "fieldSchemaKey": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "optional": true + } + } + ] + }, + "taskParameters": { + "entry": [] + }, + "contextAlbumReference": [ + { + "name": "RequestIDVNFIDAlbum", + "version": "0.0.1" + }, + { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + } + ], + "taskLogic": { + "key": "TaskLogic", + "logicFlavour": "JAVASCRIPT", + "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Note: The incoming closedloop message can be ONSET with both VNF-name and VNF-ID\n * or ABATED with only VNF-name. So need to handle differently. For ABATED case,\n * since we still keep the RequireIDVNFID context album, we can get it from there.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar clEventType = org.onap.policy.controlloop.VirtualControlLoopEvent;\nvar longType = java.lang.Long;\nvar uuidType = java.util.UUID;\n\nvar clEvent = executor.inFields.get(\"VirtualControlLoopEvent\");\n\nexecutor.logger.info(clEvent.toString());\nexecutor.logger.info(clEvent.getClosedLoopControlName());\n\nvar requestID = clEvent.getRequestId();\nexecutor.logger.info(\"requestID = \" + requestID);\nvar vnfID = null;\nvar vcpeClosedLoopStatus = null;\n\nif (clEvent.getAai().get(\"generic-vnf.vnf-id\") != null) {\n vnfID = uuidType.fromString(clEvent.getAai().get(\"generic-vnf.vnf-id\"));\n executor.logger.info(\"vnfID = \" + vnfID);\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(vnfID);\n\n if (vcpeClosedLoopStatus == null) {\n executor.logger.info(\"Creating context information for new vCPE VNF \\\"\" + vnfID.toString() + \"\\\"\");\n\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").getSchemaHelper().createNewInstance();\n\n vcpeClosedLoopStatus.put(\"closedLoopControlName\", clEvent.getClosedLoopControlName());\n vcpeClosedLoopStatus.put(\"closedLoopAlarmStart\", clEvent.getClosedLoopAlarmStart().toEpochMilli());\n vcpeClosedLoopStatus.put(\"closedLoopEventClient\", clEvent.getClosedLoopEventClient());\n vcpeClosedLoopStatus.put(\"closedLoopEventStatus\", clEvent.getClosedLoopEventStatus().toString());\n vcpeClosedLoopStatus.put(\"version\", clEvent.getVersion());\n vcpeClosedLoopStatus.put(\"requestID\", clEvent.getRequestId().toString());\n vcpeClosedLoopStatus.put(\"target_type\", clEvent.getTargetType().toString());\n vcpeClosedLoopStatus.put(\"target\", clEvent.getTarget());\n vcpeClosedLoopStatus.put(\"from\", clEvent.getFrom());\n vcpeClosedLoopStatus.put(\"policyScope\", \"vCPE\");\n vcpeClosedLoopStatus.put(\"policyName\", \"ONAPvCPEPolicyModel\");\n vcpeClosedLoopStatus.put(\"policyVersion\", \"0.0.1\");\n vcpeClosedLoopStatus.put(\"notification\", \"ACTIVE\");\n vcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System.currentTimeMillis());\n vcpeClosedLoopStatus.put(\"message\", \"\");\n\n var aaiInfo = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").getSchemaHelper().createNewSubInstance(\"VCPE_AAI_Type\");\n\n aaiInfo.put(\"genericVnfResourceVersion\", clEvent.getAai().get(\"generic-vnf.resource-version\"));\n aaiInfo.put(\"genericVnfVnfName\", clEvent.getAai().get(\"generic-vnf.vnf-name\"));\n aaiInfo.put(\"genericVnfProvStatus\", clEvent.getAai().get(\"generic-vnf.prov-status\"));\n aaiInfo.put(\"genericVnfIsClosedLoopDisabled\", clEvent.getAai().get(\"generic-vnf.is-closed-loop-disabled\"));\n aaiInfo.put(\"genericVnfOrchestrationStatus\", clEvent.getAai().get(\"generic-vnf.orchestration-status\"));\n aaiInfo.put(\"genericVnfVnfType\", clEvent.getAai().get(\"generic-vnf.vnf-type\"));\n aaiInfo.put(\"genericVnfInMaint\", clEvent.getAai().get(\"generic-vnf.in-maint\"));\n aaiInfo.put(\"genericVnfServiceId\", clEvent.getAai().get(\"generic-vnf.service-id\"));\n aaiInfo.put(\"genericVnfVnfId\", clEvent.getAai().get(\"generic-vnf.vnf-id\"));\n aaiInfo.put(\"vserverIsClosedLoopDisabled\", clEvent.getAai().get(\"vserver.is-closed-loop-disabled\"));\n aaiInfo.put(\"vserverProvStatus\", clEvent.getAai().get(\"vserver.prov-status\"));\n aaiInfo.put(\"vserverName\", clEvent.getAai().get(\"vserver.vserver-name\"));\n\n vcpeClosedLoopStatus.put(\"AAI\", aaiInfo);\n\n if (clEvent.getClosedLoopAlarmEnd() != null) {\n vcpeClosedLoopStatus.put(\"closedLoopAlarmEnd\", clEvent.getClosedLoopAlarmEnd().toEpochMilli());\n } else {\n vcpeClosedLoopStatus.put(\"closedLoopAlarmEnd\", java.lang.Long.valueOf(0));\n }\n\n executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").put(vnfID.toString(), vcpeClosedLoopStatus);\n\n executor.logger.info(\"Created context information for new vCPE VNF \\\"\" + vnfID.toString() + \"\\\"\");\n }\n\n executor.outFields.put(\"requestID\", requestID);\n executor.outFields.put(\"vnfID\", vnfID);\n\n executor.logger.info(executor.outFields);\n}\nelse {\n executor.logger.info(\"No vnf-id in VirtualControlLoopEvent, status:\" + clEvent.getClosedLoopEventStatus().toString());\n var vnfName = clEvent.getAai().get(\"generic-vnf.vnf-name\");\n executor.logger.info(\"No vnf-id in VirtualControlLoopEvent for \" + vnfName);\n\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(vnfName.toString());\n\n if (vcpeClosedLoopStatus == null) {\n executor.logger.info(\"Creating context information for new vCPE VNF \\\"\" + vnfName.toString() + \"\\\"\");\n\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").getSchemaHelper().createNewInstance();\n\n vcpeClosedLoopStatus.put(\"closedLoopControlName\", clEvent.getClosedLoopControlName());\n vcpeClosedLoopStatus.put(\"closedLoopAlarmStart\", clEvent.getClosedLoopAlarmStart().toEpochMilli());\n vcpeClosedLoopStatus.put(\"closedLoopEventClient\", clEvent.getClosedLoopEventClient());\n vcpeClosedLoopStatus.put(\"closedLoopEventStatus\", clEvent.getClosedLoopEventStatus().toString());\n vcpeClosedLoopStatus.put(\"version\", clEvent.getVersion());\n vcpeClosedLoopStatus.put(\"requestID\", clEvent.getRequestId().toString());\n vcpeClosedLoopStatus.put(\"target_type\", clEvent.getTargetType().toString());\n vcpeClosedLoopStatus.put(\"target\", clEvent.getTarget());\n vcpeClosedLoopStatus.put(\"from\", clEvent.getFrom());\n vcpeClosedLoopStatus.put(\"policyScope\", \"vCPE\");\n vcpeClosedLoopStatus.put(\"policyName\", \"ONAPvCPEPolicyModel\");\n vcpeClosedLoopStatus.put(\"policyVersion\", \"0.0.1\");\n vcpeClosedLoopStatus.put(\"notification\", \"ACTIVE\");\n vcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System.currentTimeMillis());\n vcpeClosedLoopStatus.put(\"message\", \"\");\n\n var aaiInfo = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").getSchemaHelper().createNewSubInstance(\"VCPE_AAI_Type\");\n\n aaiInfo.put(\"genericVnfVnfName\", clEvent.getAai().get(\"generic-vnf.vnf-name\"));\n vcpeClosedLoopStatus.put(\"AAI\", aaiInfo);\n\n if (clEvent.getClosedLoopAlarmEnd() != null) {\n vcpeClosedLoopStatus.put(\"closedLoopAlarmEnd\", clEvent.getClosedLoopAlarmEnd().toEpochMilli());\n } else {\n vcpeClosedLoopStatus.put(\"closedLoopAlarmEnd\", java.lang.Long.valueOf(0));\n }\n\n executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").put(vnfName.toString(), vcpeClosedLoopStatus);\n\n executor.logger.info(\"Created context information for new vCPE VNF \\\"\" + vnfName.toString() + \"\\\"\");\n }\n executor.outFields.put(\"requestID\", requestID);\n executor.outFields.put(\"vnfName\", vnfName);\n executor.logger.info(executor.outFields);\n}\n\ntrue;" + } + } + }, + { + "key": { + "name": "GuardRequestTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "GuardRequestTask", + "version": "0.0.1" + }, + "inputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "outputFields": { + "entry": [ + { + "key": "decisionAttributes", + "value": { + "key": "decisionAttributes", + "fieldSchemaKey": { + "name": "GuardDecisionAttributesType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "onapName", + "value": { + "key": "onapName", + "fieldSchemaKey": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "taskParameters": { + "entry": [] + }, + "contextAlbumReference": [ + { + "name": "ControlLoopExecutionIDAlbum", + "version": "0.0.1" + }, + { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + } + ], + "taskLogic": { + "key": "TaskLogic", + "logicFlavour": "JAVASCRIPT", + "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nvar guardDecisionAttributes = executor.subject.getOutFieldSchemaHelper(\"decisionAttributes\").createNewInstance();\n\nguardDecisionAttributes.put(\"actor\", \"APPC\");\nguardDecisionAttributes.put(\"recipe\", \"Restart\");\nguardDecisionAttributes.put(\"target\", executor.inFields.get(\"vnfID\").toString());\nguardDecisionAttributes.put(\"clname\", \"APEXvCPEImplementation\");\n\nexecutor.logger.info(guardDecisionAttributes);\n\nexecutor.outFields.put(\"decisionAttributes\", guardDecisionAttributes);\nexecutor.outFields.put(\"onapName\", \"PDPD\");\n\nexecutor.getContextAlbum(\"ControlLoopExecutionIDAlbum\").put(executor.executionId.toString(),\n executor.inFields.get(\"vnfID\"));\n\nexecutor.logger.info(executor.outFields);\n\ntrue;" + } + } + }, + { + "key": { + "name": "GuardResponseTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "GuardResponseTask", + "version": "0.0.1" + }, + "inputFields": { + "entry": [ + { + "key": "decision", + "value": { + "key": "decision", + "fieldSchemaKey": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "details", + "value": { + "key": "details", + "fieldSchemaKey": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "outputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "taskParameters": { + "entry": [] + }, + "contextAlbumReference": [ + { + "name": "ControlLoopExecutionIDAlbum", + "version": "0.0.1" + }, + { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + } + ], + "taskLogic": { + "key": "TaskLogic", + "logicFlavour": "JAVASCRIPT", + "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vnfID = executor.getContextAlbum(\"ControlLoopExecutionIDAlbum\").remove(executor.executionId.toString());\n\nexecutor.logger.info(\"Continuing execution with VNF ID: \" + vnfID);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(vnfID.toString());\nexecutor.logger.info(vcpeClosedLoopStatus);\n\nvar guardResult = executor.inFields.get(\"decision\");\nvar returnValue = true;\n\nif (guardResult == \"PERMIT\") {\n vcpeClosedLoopStatus.put(\"notification\", \"OPERATION: GUARD_PERMIT\");\n} else if (guardResult == \"DENY\") {\n vcpeClosedLoopStatus.put(\"notification\", \"OPERATION: GUARD_DENY\");\n} else {\n executor.message = \"guard result must be either \\\"PERMIT\\\" or \\\"DENY\\\"\";\n returnValue = false;\n}\n\nvar uuidType = java.util.UUID;\nvar requestID = uuidType.fromString(vcpeClosedLoopStatus.get(\"requestID\"));\n\nexecutor.outFields.put(\"requestID\", requestID);\nexecutor.outFields.put(\"vnfID\", vnfID);\n\nexecutor.logger.info(executor.outFields);\n\n\nreturnValue;" + } + } + }, + { + "key": { + "name": "NoAAILookupTask", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "NoAAILookupTask", + "version": "0.0.1" + }, + "inputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "outputFields": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + }, + "taskParameters": { + "entry": [] + }, + "contextAlbumReference": [], + "taskLogic": { + "key": "TaskLogic", + "logicFlavour": "JAVASCRIPT", + "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nexecutor.logger.info(executor.outFields);\n\ntrue;" + } + } + } + ] + } + }, + "events": { + "key": { + "name": "ONAPvCPEPolicyModel_Events", + "version": "0.0.1" + }, + "eventMap": { + "entry": [ + { + "key": { + "name": "APPCRestartVNFRequestEvent", + "version": "2.0.0" + }, + "value": { + "key": { + "name": "APPCRestartVNFRequestEvent", + "version": "2.0.0" + }, + "nameSpace": "org.onap.policy.apex.onap.vcpe", + "source": "APEX", + "target": "APPC", + "parameter": { + "entry": [ + { + "key": "APPCLCMRequestEvent", + "value": { + "key": "APPCLCMRequestEvent", + "fieldSchemaKey": { + "name": "APPCLCMRequestType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + } + } + }, + { + "key": { + "name": "APPCRestartVNFResponseEvent", + "version": "2.0.0" + }, + "value": { + "key": { + "name": "APPCRestartVNFResponseEvent", + "version": "2.0.0" + }, + "nameSpace": "org.onap.policy.apex.onap.vcpe", + "source": "APEX", + "target": "APPC", + "parameter": { + "entry": [ + { + "key": "APPCLCMResponseEvent", + "value": { + "key": "APPCLCMResponseEvent", + "fieldSchemaKey": { + "name": "APPCLCMResponseType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + } + } + }, + { + "key": { + "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "version": "1.0.2" + }, + "value": { + "key": { + "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "version": "1.0.2" + }, + "nameSpace": "org.onap.policy.apex.onap.vcpe", + "source": "DCAE", + "target": "APEX", + "parameter": { + "entry": [ + { + "key": "VirtualControlLoopEvent", + "value": { + "key": "VirtualControlLoopEvent", + "fieldSchemaKey": { + "name": "VirtualControlLoopEventType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + } + } + }, + { + "key": { + "name": "ControlLoopLogEvent", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ControlLoopLogEvent", + "version": "0.0.1" + }, + "nameSpace": "org.onap.policy.apex.onap.vcpe", + "source": "APEX", + "target": "APEX", + "parameter": { + "entry": [ + { + "key": "VirtualControlLoopNotification", + "value": { + "key": "VirtualControlLoopNotification", + "fieldSchemaKey": { + "name": "VirtualControlLoopNotificationType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + } + } + }, + { + "key": { + "name": "GuardRequestEvent", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "GuardRequestEvent", + "version": "0.0.1" + }, + "nameSpace": "org.onap.policy.apex.onap.vcpe", + "source": "APEX", + "target": "APEX", + "parameter": { + "entry": [ + { + "key": "decisionAttributes", + "value": { + "key": "decisionAttributes", + "fieldSchemaKey": { + "name": "GuardDecisionAttributesType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "onapName", + "value": { + "key": "onapName", + "fieldSchemaKey": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + } + } + }, + { + "key": { + "name": "GuardResponseEvent", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "GuardResponseEvent", + "version": "0.0.1" + }, + "nameSpace": "org.onap.policy.apex.onap.vcpe", + "source": "APEX", + "target": "APEX", + "parameter": { + "entry": [ + { + "key": "decision", + "value": { + "key": "decision", + "fieldSchemaKey": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "details", + "value": { + "key": "details", + "fieldSchemaKey": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "optional": false + } + } + ] + } + } + }, + { + "key": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "VCPEStateUpdatedEvent", + "version": "0.0.1" + }, + "nameSpace": "org.onap.policy.apex.onap.vcpe", + "source": "APEX", + "target": "APEX", + "parameter": { + "entry": [ + { + "key": "requestID", + "value": { + "key": "requestID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfID", + "value": { + "key": "vnfID", + "fieldSchemaKey": { + "name": "UUIDType", + "version": "0.0.1" + }, + "optional": false + } + }, + { + "key": "vnfName", + "value": { + "key": "vnfName", + "fieldSchemaKey": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "optional": true + } + } + ] + } + } + } + ] + } + }, + "albums": { + "key": { + "name": "ONAPvCPEPolicyModel_Albums", + "version": "0.0.1" + }, + "albums": { + "entry": [ + { + "key": { + "name": "ControlLoopExecutionIDAlbum", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "ControlLoopExecutionIDAlbum", + "version": "0.0.1" + }, + "scope": "policy", + "isWritable": true, + "itemSchema": { + "name": "UUIDType", + "version": "0.0.1" + } + } + }, + { + "key": { + "name": "RequestIDVNFIDAlbum", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "RequestIDVNFIDAlbum", + "version": "0.0.1" + }, + "scope": "policy", + "isWritable": true, + "itemSchema": { + "name": "UUIDType", + "version": "0.0.1" + } + } + }, + { + "key": { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "VCPEClosedLoopStatusAlbum", + "version": "0.0.1" + }, + "scope": "policy", + "isWritable": true, + "itemSchema": { + "name": "VCPEClosedLoopStatusType", + "version": "0.0.1" + } + } + } + ] + } + }, + "schemas": { + "key": { + "name": "ONAPvCPEPolicyModel_Schemas", + "version": "0.0.1" + }, + "schemas": { + "entry": [ + { + "key": { + "name": "APPCLCMRequestType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "APPCLCMRequestType", + "version": "0.0.1" + }, + "schemaFlavour": "Java", + "schemaDefinition": "org.onap.policy.appclcm.AppcLcmDmaapWrapper" + } + }, + { + "key": { + "name": "APPCLCMResponseType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "APPCLCMResponseType", + "version": "0.0.1" + }, + "schemaFlavour": "Java", + "schemaDefinition": "org.onap.policy.appclcm.AppcLcmDmaapWrapper" + } + }, + { + "key": { + "name": "GuardDecisionAttributesType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "GuardDecisionAttributesType", + "version": "0.0.1" + }, + "schemaFlavour": "Avro", + "schemaDefinition": "{\n \"type\": \"record\",\n \"name\": \"GuardDecisionAttributes_Type\",\n \"namespace\": \"org.onap.policy.apex.onap.vcpe\",\n \"fields\": [\n {\n \"name\": \"actor\",\n \"type\": \"string\"\n },\n {\n \"name\": \"recipe\",\n \"type\": \"string\"\n },\n {\n \"name\": \"target\",\n \"type\": \"string\"\n },\n {\n \"name\": \"clname\",\n \"type\": \"string\"\n }\n ]\n}" + } + }, + { + "key": { + "name": "SimpleBooleanType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "SimpleBooleanType", + "version": "0.0.1" + }, + "schemaFlavour": "Java", + "schemaDefinition": "java.lang.Boolean" + } + }, + { + "key": { + "name": "SimpleLongType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "SimpleLongType", + "version": "0.0.1" + }, + "schemaFlavour": "Java", + "schemaDefinition": "java.lang.Long" + } + }, + { + "key": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "SimpleStringType", + "version": "0.0.1" + }, + "schemaFlavour": "Java", + "schemaDefinition": "java.lang.String" + } + }, + { + "key": { + "name": "UUIDType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "UUIDType", + "version": "0.0.1" + }, + "schemaFlavour": "Java", + "schemaDefinition": "java.util.UUID" + } + }, + { + "key": { + "name": "VCPEClosedLoopStatusType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "VCPEClosedLoopStatusType", + "version": "0.0.1" + }, + "schemaFlavour": "Avro", + "schemaDefinition": "{\n \"type\": \"record\",\n \"name\": \"VCPEClosedLoopStatus\",\n \"fields\": [\n {\n \"name\": \"AAI\",\n \"type\": {\n \"type\": \"record\",\n \"name\": \"VCPE_AAI_Type\",\n \"namespace\": \"org.onap.policy.apex.onap.vcpe\",\n \"fields\": [\n {\n \"name\": \"genericVnfResourceVersion\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfVnfName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfProvStatus\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfIsClosedLoopDisabled\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfOrchestrationStatus\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfVnfType\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfInMaint\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfServiceId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfVnfId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"vserverIsClosedLoopDisabled\",\n \"type\": \"string\"\n },\n {\n \"name\": \"vserverName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"vserverProvStatus\",\n \"type\": \"string\"\n }\n ]\n }\n },\n {\n \"name\": \"closedLoopAlarmStart\",\n \"type\": \"long\"\n },\n {\n \"name\": \"closedLoopAlarmEnd\",\n \"type\": \"long\"\n },\n {\n \"name\": \"closedLoopControlName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"version\",\n \"type\": \"string\"\n },\n {\n \"name\": \"requestID\",\n \"type\": \"string\"\n },\n {\n \"name\": \"closedLoopEventClient\",\n \"type\": \"string\"\n },\n {\n \"name\": \"closedLoopEventStatus\",\n \"type\": \"string\"\n },\n {\n \"name\": \"target_type\",\n \"type\": \"string\"\n },\n {\n \"name\": \"target\",\n \"type\": \"string\"\n },\n {\n \"name\": \"from\",\n \"type\": \"string\"\n },\n {\n \"name\": \"policyScope\",\n \"type\": \"string\"\n },\n {\n \"name\": \"policyName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"policyVersion\",\n \"type\": \"string\"\n },\n {\n \"name\": \"notification\",\n \"type\": \"string\"\n },\n {\n \"name\": \"notificationTime\",\n \"type\": \"long\"\n },\n {\n \"name\": \"message\",\n \"type\": \"string\"\n }\n ]\n}" + } + }, + { + "key": { + "name": "VirtualControlLoopEventType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "VirtualControlLoopEventType", + "version": "0.0.1" + }, + "schemaFlavour": "Java", + "schemaDefinition": "org.onap.policy.controlloop.VirtualControlLoopEvent" + } + }, + { + "key": { + "name": "VirtualControlLoopNotificationType", + "version": "0.0.1" + }, + "value": { + "key": { + "name": "VirtualControlLoopNotificationType", + "version": "0.0.1" + }, + "schemaFlavour": "Java", + "schemaDefinition": "org.onap.policy.controlloop.VirtualControlLoopNotification" + } + } + ] + } + } + } + }, + "engineParameters": { + "executorParameters": { + "JAVASCRIPT": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters" + } + }, + "contextParameters": { + "parameterClassName": "org.onap.policy.apex.context.parameters.ContextParameters", + "schemaParameters": { + "Avro": { + "parameterClassName": "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters" + }, + "Java": { + "parameterClassName": "org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters", + "jsonAdapters": { + "Instant": { + "adaptedClass": "java.time.Instant", + "adaptorClass": "org.onap.policy.controlloop.util.Serialization$GsonInstantAdapter" + } + } + } + } + }, + "taskParameters": [ + { + "key": "ParameterKey1", + "value": "ParameterValue1" + }, + { + "taskId": "AAILookupTask:0.0.1", + "key": "SomeKeyForThisTask", + "value": "Value" + } + ] + } + }, + "eventInputParameters": { + "GuardRequestorConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters", + "parameters": { + "url": "http://111.222.333.444:5555/pdp/api/getDecision", + "httpMethod": "POST", + "restRequestTimeout": 2000, + "httpHeader": "Authorization:aaaaaaaaa== ClientAuth:bbbbbbbbb=" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventName": "GuardResponseEvent", + "eventNameFilter": "GuardResponseEvent", + "requestorMode": true, + "requestorPeer": "GuardRequestorProducer", + "requestorTimeout": 500 + }, + "DCAEConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://message-router:3904/events/unauthenticated.DCAE_CL_OUTPUT/APEX/1?timeout=60000" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON", + "parameters": { + "nameAlias": "closedLoopControlName", + "versionAlias": "version", + "sourceAlias": "from", + "pojoField": "VirtualControlLoopEvent" + } + }, + "eventName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e" + }, + "APPCConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://message-router:3904/events/APPC-LCM-WRITE/APEX/1?timeout=60000" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON", + "parameters": { + "versionAlias": "version", + "pojoField": "APPCLCMResponseEvent" + } + }, + "eventName": "APPCRestartVNFResponseEvent", + "eventNameFilter": "APPCRestartVNFResponseEvent" + } + }, + "eventOutputParameters": { + "logProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "/tmp/VCPEEventsOut.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + }, + "GuardRequestorProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTREQUESTOR", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters" + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "GuardRequestEvent", + "requestorMode": true, + "requestorPeer": "GuardRequestorConsumer", + "requestorTimeout": 500 + }, + "APPCProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://message-router:3904/events/APPC-LCM-READ" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON", + "parameters": { + "versionAlias": "version", + "sourceAlias": "from", + "pojoField": "APPCLCMRequestEvent" + } + }, + "eventNameFilter": "APPCRestartVNFRequestEvent" + }, + "PolicyLogProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "http://message-router:3904/events/POLICY-CL-MGT" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON", + "parameters": { + "versionAlias": "version", + "sourceAlias": "from", + "pojoField": "VirtualControlLoopNotification" + } + }, + "eventNameFilter": "ControlLoopLogEvent" + } + } + } + } + } + ] + } +} diff --git a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java index eb82ae231..f26034389 100644 --- a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java +++ b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,16 +32,16 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableMap; import com.google.protobuf.Struct; + import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.UUID; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; + import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; @@ -68,8 +69,6 @@ public class CdsActorServiceProviderTest { private static final String SUBREQUEST_ID = "123456"; private static final String CDS_RECIPE = "test-cds-recipe"; - @Rule - public ExpectedException exceptionRule = ExpectedException.none(); @Mock private CdsProcessorGrpcClient cdsClient; private CdsActorServiceProvider cdsActor; @@ -132,16 +131,14 @@ public class CdsActorServiceProviderTest { @Test public void testConstructRequestWhenMissingCdsParamsInPolicyPayload() { policy.setPayload(new HashMap<>()); - Optional<ExecutionServiceInput> cdsRequestOpt = cdsActor - .constructRequest(onset, operation, policy, aaiParams); + Optional<ExecutionServiceInput> cdsRequestOpt = cdsActor.constructRequest(onset, operation, policy, aaiParams); assertFalse(cdsRequestOpt.isPresent()); } @Test public void testConstructRequest() { - Optional<ExecutionServiceInput> cdsRequestOpt = cdsActor - .constructRequest(onset, operation, policy, aaiParams); + Optional<ExecutionServiceInput> cdsRequestOpt = cdsActor.constructRequest(onset, operation, policy, aaiParams); assertTrue(cdsRequestOpt.isPresent()); final ExecutionServiceInput cdsRequest = cdsRequestOpt.get(); @@ -187,13 +184,13 @@ public class CdsActorServiceProviderTest { public void testSendRequestToCdsLatchInterrupted() throws InterruptedException { // Reset cdsClient CountDownLatch countDownLatch = mock(CountDownLatch.class); - doThrow(new InterruptedException("Test latch interrupted failure")).when(countDownLatch) - .await(anyLong(), any(TimeUnit.class)); + doThrow(new InterruptedException("Test latch interrupted failure")).when(countDownLatch).await(anyLong(), + any(TimeUnit.class)); when(cdsClient.sendRequest(any(ExecutionServiceInput.class))).thenReturn(countDownLatch); CdsActorServiceProvider.CdsActorServiceManager cdsActorSvcMgr = cdsActor.new CdsActorServiceManager(); - CdsResponse response = cdsActorSvcMgr - .sendRequestToCds(cdsClient, cdsProps, ExecutionServiceInput.newBuilder().build()); + CdsResponse response = + cdsActorSvcMgr.sendRequestToCds(cdsClient, cdsProps, ExecutionServiceInput.newBuilder().build()); assertTrue(Thread.interrupted()); assertNotNull(response); assertEquals(CdsActorConstants.INTERRUPTED, response.getStatus()); @@ -202,8 +199,8 @@ public class CdsActorServiceProviderTest { @Test public void testSendRequestToCdsLatchTimedOut() { CdsActorServiceProvider.CdsActorServiceManager cdsActorSvcMgr = cdsActor.new CdsActorServiceManager(); - CdsResponse response = cdsActorSvcMgr - .sendRequestToCds(cdsClient, cdsProps, ExecutionServiceInput.newBuilder().build()); + CdsResponse response = + cdsActorSvcMgr.sendRequestToCds(cdsClient, cdsProps, ExecutionServiceInput.newBuilder().build()); assertNotNull(response); assertEquals(CdsActorConstants.TIMED_OUT, response.getStatus()); } diff --git a/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Resource.java b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Resource.java index 61b6e3afd..d5e8b6c2a 100644 --- a/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Resource.java +++ b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Resource.java @@ -3,7 +3,7 @@ * sdc * ================================================================================ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,23 +23,22 @@ package org.onap.policy.sdc; import java.io.Serializable; import java.util.UUID; -import lombok.Getter; -import lombok.Setter; -@Getter -@Setter +import lombok.Data; + +@Data public class Resource implements Serializable { private static final long serialVersionUID = -913729158733348027L; - private UUID resourceUuid; - private UUID resourceInvariantUuid; - private String resourceName; - private String resourceVersion; - private String resourceType; + private UUID resourceUuid; + private UUID resourceInvariantUuid; + private String resourceName; + private String resourceVersion; + private String resourceType; public Resource() { - //Empty Constructor + // Empty Constructor } /** @@ -80,74 +79,4 @@ public class Resource implements Serializable { this.resourceVersion = version; this.resourceType = type; } - - @Override - public String toString() { - return "Resource [resourceUuid=" + resourceUuid + ", resourceInvariantUuid=" + resourceInvariantUuid - + ", resourceName=" + resourceName + ", resourceVersion=" + resourceVersion + ", resourceType=" - + resourceType + "]"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((resourceInvariantUuid == null) ? 0 : resourceInvariantUuid.hashCode()); - result = prime * result + ((resourceName == null) ? 0 : resourceName.hashCode()); - result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode()); - result = prime * result + ((resourceUuid == null) ? 0 : resourceUuid.hashCode()); - result = prime * result + ((resourceVersion == null) ? 0 : resourceVersion.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Resource other = (Resource) obj; - if (resourceInvariantUuid == null) { - if (other.resourceInvariantUuid != null) { - return false; - } - } else if (!resourceInvariantUuid.equals(other.resourceInvariantUuid)) { - return false; - } - if (resourceName == null) { - if (other.resourceName != null) { - return false; - } - } else if (!resourceName.equals(other.resourceName)) { - return false; - } - if (resourceType == null) { - if (other.resourceType != null) { - return false; - } - } else if (!resourceType.equals(other.resourceType)) { - return false; - } - if (resourceUuid == null) { - if (other.resourceUuid != null) { - return false; - } - } else if (!resourceUuid.equals(other.resourceUuid)) { - return false; - } - if (resourceVersion == null) { - if (other.resourceVersion != null) { - return false; - } - } else if (!resourceVersion.equals(other.resourceVersion)) { - return false; - } - return true; - } - } diff --git a/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ResourceInstance.java b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ResourceInstance.java index 05842e24c..0b6068dce 100644 --- a/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ResourceInstance.java +++ b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ResourceInstance.java @@ -21,26 +21,31 @@ package org.onap.policy.sdc; +import com.google.gson.annotations.SerializedName; + import java.io.Serializable; import java.util.UUID; -import lombok.Getter; -import lombok.Setter; -@Getter -@Setter +import lombok.Data; + +@Data public class ResourceInstance implements Serializable { private static final long serialVersionUID = -5506162340393802424L; + @SerializedName("ResourceUUID") + private UUID resourceUuid; + private String resourceInstanceName; private String resourceName; - private UUID resourceInvariantUuid; private String resourceVersion; private String resourceType; - private UUID resourceUuid; + + @SerializedName("ResourceInvariantUUID") + private UUID resourceInvariantUuid; public ResourceInstance() { - //Empty Constructor + // Empty Constructor } /** @@ -59,86 +64,4 @@ public class ResourceInstance implements Serializable { this.resourceType = instance.resourceType; this.resourceUuid = instance.resourceUuid; } - - public UUID getResourceInvariantUUID() { - return resourceInvariantUuid; - } - - public void setResourceInvariantUUID(UUID resourceInvariantUuid) { - this.resourceInvariantUuid = resourceInvariantUuid; - } - - @Override - public String toString() { - return "ResourceInstance [resourceInstanceName=" + resourceInstanceName + ", resourceName=" + resourceName - + ", resourceInvariantUuid=" + resourceInvariantUuid + ", resourceVersion=" + resourceVersion - + ", resourceType=" + resourceType + ", resourceUuid=" + resourceUuid + "]"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((resourceInstanceName == null) ? 0 : resourceInstanceName.hashCode()); - result = prime * result + ((resourceInvariantUuid == null) ? 0 : resourceInvariantUuid.hashCode()); - result = prime * result + ((resourceName == null) ? 0 : resourceName.hashCode()); - result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode()); - result = prime * result + ((resourceUuid == null) ? 0 : resourceUuid.hashCode()); - result = prime * result + ((resourceVersion == null) ? 0 : resourceVersion.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ResourceInstance other = (ResourceInstance) obj; - if (resourceInstanceName == null) { - if (other.resourceInstanceName != null) { - return false; - } - } else if (!resourceInstanceName.equals(other.resourceInstanceName)) { - return false; - } - if (resourceInvariantUuid == null) { - if (other.resourceInvariantUuid != null) { - return false; - } - } else if (!resourceInvariantUuid.equals(other.resourceInvariantUuid)) { - return false; - } - if (resourceName == null) { - if (other.resourceName != null) { - return false; - } - } else if (!resourceName.equals(other.resourceName)) { - return false; - } - if (resourceType != other.resourceType) { - return false; - } - if (resourceUuid == null) { - if (other.resourceUuid != null) { - return false; - } - } else if (!resourceUuid.equals(other.resourceUuid)) { - return false; - } - if (resourceVersion == null) { - if (other.resourceVersion != null) { - return false; - } - } else if (!resourceVersion.equals(other.resourceVersion)) { - return false; - } - return true; - } - } diff --git a/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Service.java b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Service.java index 7ab2f9322..d372f1221 100644 --- a/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Service.java +++ b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Service.java @@ -3,7 +3,7 @@ * sdc * ================================================================================ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,11 +23,9 @@ package org.onap.policy.sdc; import java.io.Serializable; import java.util.UUID; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; -@Getter -@Setter +@Data public class Service implements Serializable { private static final long serialVersionUID = -1249276698549996806L; @@ -38,7 +36,7 @@ public class Service implements Serializable { private String serviceVersion; public Service() { - //Empty Constructor + // Empty Constructor } public Service(UUID uuid) { @@ -53,13 +51,13 @@ public class Service implements Serializable { * Constructor. * * @param uuid service id - * @param invariantUUID service invariant id + * @param invariantUuid service invariant id * @param name name * @param version version */ - public Service(UUID uuid, UUID invariantUUID, String name, String version) { + public Service(UUID uuid, UUID invariantUuid, String name, String version) { this.serviceUUID = uuid; - this.serviceInvariantUUID = invariantUUID; + this.serviceInvariantUUID = invariantUuid; this.serviceName = name; this.serviceVersion = version; } @@ -75,61 +73,4 @@ public class Service implements Serializable { this.serviceName = service.serviceName; this.serviceVersion = service.serviceVersion; } - - @Override - public String toString() { - return "Service [serviceUUID=" + serviceUUID + ", serviceInvariantUUID=" + serviceInvariantUUID - + ", serviceName=" + serviceName + ", serviceVersion=" + serviceVersion + "]"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((serviceInvariantUUID == null) ? 0 : serviceInvariantUUID.hashCode()); - result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode()); - result = prime * result + ((serviceUUID == null) ? 0 : serviceUUID.hashCode()); - result = prime * result + ((serviceVersion == null) ? 0 : serviceVersion.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Service other = (Service) obj; - if (serviceInvariantUUID == null) { - if (other.serviceInvariantUUID != null) { - return false; - } - } else if (!serviceInvariantUUID.equals(other.serviceInvariantUUID)) { - return false; - } - if (serviceName == null) { - if (other.serviceName != null) { - return false; - } - } else if (!serviceName.equals(other.serviceName)) { - return false; - } - if (serviceUUID == null) { - if (other.serviceUUID != null) { - return false; - } - } else if (!serviceUUID.equals(other.serviceUUID)) { - return false; - } - if (serviceVersion == null) { - return other.serviceVersion == null; - } else { - return serviceVersion.equals(other.serviceVersion); - } - } } diff --git a/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ServiceInstance.java b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ServiceInstance.java index e02952219..b476de20f 100644 --- a/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ServiceInstance.java +++ b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ServiceInstance.java @@ -3,7 +3,7 @@ * sdc * ================================================================================ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,11 +23,9 @@ package org.onap.policy.sdc; import java.io.Serializable; import java.util.UUID; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; -@Getter -@Setter +@Data public class ServiceInstance implements Serializable { private static final long serialVersionUID = 6285260780966679625L; @@ -36,12 +34,13 @@ public class ServiceInstance implements Serializable { private UUID serviceUUID; private UUID serviceInstanceUUID; private UUID widgetModelUUID; + private String widgetModelVersion; private String serviceName; private String serviceInstanceName; public ServiceInstance() { - //Empty Constructor + // Empty Constructor } /** @@ -61,87 +60,4 @@ public class ServiceInstance implements Serializable { this.serviceName = instance.serviceName; this.serviceInstanceName = instance.serviceInstanceName; } - - @Override - public String toString() { - return "ServiceInstance [personaModelUUID=" + personaModelUUID + ", serviceUUID=" + serviceUUID - + ", serviceInstanceUUID=" + serviceInstanceUUID + ", widgetModelUUID=" + widgetModelUUID - + ", widgetModelVersion=" + widgetModelVersion + ", serviceName=" + serviceName - + ", serviceInstanceName=" + serviceInstanceName + "]"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((personaModelUUID == null) ? 0 : personaModelUUID.hashCode()); - result = prime * result + ((serviceInstanceName == null) ? 0 : serviceInstanceName.hashCode()); - result = prime * result + ((serviceInstanceUUID == null) ? 0 : serviceInstanceUUID.hashCode()); - result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode()); - result = prime * result + ((serviceUUID == null) ? 0 : serviceUUID.hashCode()); - result = prime * result + ((widgetModelUUID == null) ? 0 : widgetModelUUID.hashCode()); - result = prime * result + ((widgetModelVersion == null) ? 0 : widgetModelVersion.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ServiceInstance other = (ServiceInstance) obj; - if (personaModelUUID == null) { - if (other.personaModelUUID != null) { - return false; - } - } else if (!personaModelUUID.equals(other.personaModelUUID)) { - return false; - } - if (serviceInstanceName == null) { - if (other.serviceInstanceName != null) { - return false; - } - } else if (!serviceInstanceName.equals(other.serviceInstanceName)) { - return false; - } - if (serviceInstanceUUID == null) { - if (other.serviceInstanceUUID != null) { - return false; - } - } else if (!serviceInstanceUUID.equals(other.serviceInstanceUUID)) { - return false; - } - if (serviceName == null) { - if (other.serviceName != null) { - return false; - } - } else if (!serviceName.equals(other.serviceName)) { - return false; - } - if (serviceUUID == null) { - if (other.serviceUUID != null) { - return false; - } - } else if (!serviceUUID.equals(other.serviceUUID)) { - return false; - } - if (widgetModelUUID == null) { - if (other.widgetModelUUID != null) { - return false; - } - } else if (!widgetModelUUID.equals(other.widgetModelUUID)) { - return false; - } - if (widgetModelVersion == null) { - return other.widgetModelVersion == null; - } else { - return widgetModelVersion.equals(other.widgetModelVersion); - } - } } diff --git a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceInstanceTest.java b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceInstanceTest.java index 8ae0084f6..e1068cb31 100644 --- a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceInstanceTest.java +++ b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceInstanceTest.java @@ -3,7 +3,7 @@ * sdc * ================================================================================ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ public class ResourceInstanceTest { ResourceInstance ri = new ResourceInstance(); assertEquals(null, ri.getResourceInstanceName()); assertEquals(null, ri.getResourceUuid()); - assertEquals(null, ri.getResourceInvariantUUID()); + assertEquals(null, ri.getResourceInvariantUuid()); assertEquals(null, ri.getResourceName()); assertEquals(null, ri.getResourceType()); assertEquals(null, ri.getResourceVersion()); @@ -47,7 +47,7 @@ public class ResourceInstanceTest { ResourceInstance ri2 = new ResourceInstance((ResourceInstance) null); assertEquals(null, ri2.getResourceInstanceName()); assertEquals(null, ri2.getResourceUuid()); - assertEquals(null, ri2.getResourceInvariantUUID()); + assertEquals(null, ri2.getResourceInvariantUuid()); assertEquals(null, ri2.getResourceName()); assertEquals(null, ri2.getResourceType()); assertEquals(null, ri2.getResourceVersion()); @@ -55,7 +55,7 @@ public class ResourceInstanceTest { ri2 = new ResourceInstance(ri); assertEquals(ri2.getResourceInstanceName(), ri.getResourceInstanceName()); assertEquals(ri2.getResourceUuid(), ri.getResourceUuid()); - assertEquals(ri2.getResourceInvariantUUID(), ri.getResourceInvariantUUID()); + assertEquals(ri2.getResourceInvariantUuid(), ri.getResourceInvariantUuid()); assertEquals(ri2.getResourceName(), ri.getResourceName()); assertEquals(ri2.getResourceType(), ri.getResourceType()); assertEquals(ri2.getResourceVersion(), ri.getResourceVersion()); @@ -65,7 +65,8 @@ public class ResourceInstanceTest { public void testInstanceName() { ResourceInstance ri = new ResourceInstance(); String name = "nameTestInstance"; - ri.setResourceInstanceName(name);; + ri.setResourceInstanceName(name); + ; assertEquals(name, ri.getResourceInstanceName()); } @@ -81,8 +82,8 @@ public class ResourceInstanceTest { public void testInvariantUuid() { ResourceInstance ri = new ResourceInstance(); UUID uuid = UUID.randomUUID(); - ri.setResourceInvariantUUID(uuid); - assertEquals(uuid, ri.getResourceInvariantUUID()); + ri.setResourceInvariantUuid(uuid); + assertEquals(uuid, ri.getResourceInvariantUuid()); } @Test @@ -117,8 +118,8 @@ public class ResourceInstanceTest { ri1.setResourceInstanceName(INSTANCE); ri1.setResourceName(RESOURCE); - ri1.setResourceInvariantUUID(UUID.randomUUID()); - ri1.setResourceInvariantUUID(UUID.randomUUID()); + ri1.setResourceInvariantUuid(UUID.randomUUID()); + ri1.setResourceInvariantUuid(UUID.randomUUID()); ri1.setResourceVersion(VERSION_000); ri1.setResourceType(ResourceType.VL); ri2 = new ResourceInstance(ri1); @@ -134,8 +135,8 @@ public class ResourceInstanceTest { ri1.setResourceInstanceName(INSTANCE); ri1.setResourceName(RESOURCE); - ri1.setResourceInvariantUUID(UUID.randomUUID()); - ri1.setResourceInvariantUUID(UUID.randomUUID()); + ri1.setResourceInvariantUuid(UUID.randomUUID()); + ri1.setResourceInvariantUuid(UUID.randomUUID()); ri1.setResourceVersion(VERSION_000); ri1.setResourceType(ResourceType.VL); ri2 = new ResourceInstance(ri1); @@ -150,8 +151,8 @@ public class ResourceInstanceTest { ri1.setResourceInstanceName(INSTANCE); ri1.setResourceName(RESOURCE); - ri1.setResourceInvariantUUID(UUID.randomUUID()); - ri1.setResourceInvariantUUID(UUID.randomUUID()); + ri1.setResourceInvariantUuid(UUID.randomUUID()); + ri1.setResourceInvariantUuid(UUID.randomUUID()); ri1.setResourceVersion(VERSION_000); ri1.setResourceType(ResourceType.VL); ri2 = new ResourceInstance(ri1); diff --git a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceInstanceTest.java b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceInstanceTest.java index c06974cd5..3e134d67b 100644 --- a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceInstanceTest.java +++ b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceInstanceTest.java @@ -3,7 +3,7 @@ * sdc * ================================================================================ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,7 +68,8 @@ public class ServiceInstanceTest { public void testInstanceName() { ServiceInstance si = new ServiceInstance(); String name = "nameTestInstance"; - si.setServiceInstanceName(name);; + si.setServiceInstanceName(name); + ; assertEquals(name, si.getServiceInstanceName()); } @@ -116,7 +117,8 @@ public class ServiceInstanceTest { public void testWidgetModelVersion() { ServiceInstance si = new ServiceInstance(); String version = "2.2.2"; - si.setWidgetModelVersion(version);; + si.setWidgetModelVersion(version); + ; assertEquals(version, si.getWidgetModelVersion()); } diff --git a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceTest.java b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceTest.java index 19238622d..73efbb014 100644 --- a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceTest.java +++ b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceTest.java @@ -3,7 +3,7 @@ * sdc * ================================================================================ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/models-interactions/model-yaml/pom.xml b/models-interactions/model-yaml/pom.xml index 7bd1fa497..2273abfc8 100644 --- a/models-interactions/model-yaml/pom.xml +++ b/models-interactions/model-yaml/pom.xml @@ -3,7 +3,7 @@ ONAP ================================================================================ Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. - Modifications Copyright (C) 2019 Nordix Foundation. + Modifications Copyright (C) 2019-2020 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -19,66 +19,75 @@ ============LICENSE_END========================================================= --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> +<project + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onap.policy.models</groupId> - <artifactId>policy-models-interactions</artifactId> - <version>2.2.1-SNAPSHOT</version> - </parent> + <parent> + <groupId>org.onap.policy.models</groupId> + <artifactId>policy-models-interactions</artifactId> + <version>2.2.1-SNAPSHOT</version> + </parent> - <groupId>org.onap.policy.models.policy-models-interactions</groupId> - <artifactId>model-yaml</artifactId> - - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-classic</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.yaml</groupId> - <artifactId>snakeyaml</artifactId> - </dependency> - <dependency> - <groupId>org.jgrapht</groupId> - <artifactId>jgrapht-core</artifactId> - <version>0.9.2</version> - </dependency> - <dependency> - <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> - <artifactId>sdc</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> - <artifactId>aai</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.onap.policy.common</groupId> - <artifactId>utils-test</artifactId> - <version>${policy.common.version}</version> - <scope>test</scope> - </dependency> - </dependencies> + <groupId>org.onap.policy.models.policy-models-interactions</groupId> + <artifactId>model-yaml</artifactId> + + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.yaml</groupId> + <artifactId>snakeyaml</artifactId> + </dependency> + <dependency> + <groupId>org.jgrapht</groupId> + <artifactId>jgrapht-core</artifactId> + <version>0.9.2</version> + </dependency> + <dependency> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>sdc</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>aai</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.common</groupId> + <artifactId>utils-test</artifactId> + <version>${policy.common.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> <!-- Without this defined here, the checkstyle plugin just simply fails outright. This needs to be investigated diff --git a/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ControlLoopPolicyBuilderImpl.java b/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ControlLoopPolicyBuilderImpl.java index 779e3096f..47f6f1494 100644 --- a/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ControlLoopPolicyBuilderImpl.java +++ b/models-interactions/model-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/impl/ControlLoopPolicyBuilderImpl.java @@ -3,14 +3,14 @@ * policy-yaml * ================================================================================ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * 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. @@ -22,6 +22,7 @@ package org.onap.policy.controlloop.policy.builder.impl; import com.google.common.base.Strings; + import java.util.LinkedList; import java.util.UUID; @@ -42,20 +43,17 @@ import org.onap.policy.controlloop.policy.builder.MessageLevel; import org.onap.policy.controlloop.policy.builder.Results; import org.onap.policy.sdc.Resource; import org.onap.policy.sdc.Service; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.DumperOptions.FlowStyle; import org.yaml.snakeyaml.Yaml; public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { private static final String UNKNOWN_POLICY = "Unknown policy "; - private static Logger logger = LoggerFactory.getLogger(ControlLoopPolicyBuilderImpl.class.getName()); private ControlLoopPolicy controlLoopPolicy; /** * Constructor. - * + * * @param controlLoopName control loop id * @param timeout timeout value */ @@ -69,15 +67,15 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { /** * Constructor. - * + * * @param controlLoopName control loop id * @param timeout timeout value * @param resource resource * @param services services * @throws BuilderException builder exception */ - public ControlLoopPolicyBuilderImpl(String controlLoopName, Integer timeout, Resource resource, Service... services) - throws BuilderException { + public ControlLoopPolicyBuilderImpl(String controlLoopName, Integer timeout, Resource resource, + Service... services) throws BuilderException { this(controlLoopName, timeout); this.addResource(resource); this.addService(services); @@ -90,15 +88,15 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { /** * Constructor. - * + * * @param controlLoopName control loop id * @param timeout timeout * @param service service * @param resources resources * @throws BuilderException builder exception */ - public ControlLoopPolicyBuilderImpl(String controlLoopName, Integer timeout, Service service, Resource[] resources) - throws BuilderException { + public ControlLoopPolicyBuilderImpl(String controlLoopName, Integer timeout, Service service, + Resource[] resources) throws BuilderException { this(controlLoopName, timeout); this.addService(service); this.addResource(resources); @@ -153,7 +151,6 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { return this; } - @Override public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException { for (Resource resource : resources) { @@ -199,8 +196,7 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { } @Override - public Policy setTriggerPolicy(PolicyParam policyParam) - throws BuilderException { + public Policy setTriggerPolicy(PolicyParam policyParam) throws BuilderException { Policy trigger = new Policy(policyParam); @@ -228,8 +224,7 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { } @Override - public Policy setPolicyForPolicyResult(PolicyParam policyParam, PolicyResult... results) - throws BuilderException { + public Policy setPolicyForPolicyResult(PolicyParam policyParam, PolicyResult... results) throws BuilderException { // // Find the existing policy // @@ -240,17 +235,19 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { // // Create the new Policy // - Policy newPolicy = new Policy( - PolicyParam.builder().id(UUID.randomUUID().toString()) - .name(policyParam.getName()) - .description(policyParam.getDescription()) - .actor(policyParam.getActor()) - .payload(policyParam.getPayload()) - .target(policyParam.getTarget()) - .recipe(policyParam.getRecipe()) - .retries(policyParam.getRetries()) - .timeout(policyParam.getTimeout()) - .build()); + // @formatter:off + Policy newPolicy = new Policy(PolicyParam.builder() + .id(UUID.randomUUID().toString()) + .name(policyParam.getName()) + .description(policyParam.getDescription()) + .actor(policyParam.getActor()) + .payload(policyParam.getPayload()) + .target(policyParam.getTarget()) + .recipe(policyParam.getRecipe()) + .retries(policyParam.getRetries()) + .timeout(policyParam.getTimeout()) + .build()); + // @formatter:on // // Connect the results // @@ -290,7 +287,7 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { @Override public Policy setPolicyForPolicyResult(String policyResultId, String policyId, PolicyResult... results) - throws BuilderException { + throws BuilderException { // // Find the existing policy // @@ -368,7 +365,6 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { try { ControlLoopCompiler.compile(controlLoopPolicy, callback); } catch (CompilerException e) { - logger.error(e.getMessage() + e); callback.results.addMessage(new MessageImpl(e.getMessage(), MessageLevel.EXCEPTION)); } // @@ -434,7 +430,7 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { @Override public boolean isOpenLoop() { return this.controlLoopPolicy.getControlLoop().getTrigger_policy() - .equals(FinalResult.FINAL_OPENLOOP.toString()); + .equals(FinalResult.FINAL_OPENLOOP.toString()); } @Override @@ -529,7 +525,7 @@ public class ControlLoopPolicyBuilderImpl implements ControlLoopPolicyBuilder { @Override public Policy addOperationsAccumulateParams(String policyId, OperationsAccumulateParams operationsAccumulateParams) - throws BuilderException { + throws BuilderException { Policy existingPolicy = this.findPolicy(policyId); if (existingPolicy == null) { throw new BuilderException(UNKNOWN_POLICY + policyId); diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java index 6fc3e1acb..98c00eb2f 100644 --- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java +++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/compiler/ControlLoopCompilerTest.java @@ -3,7 +3,7 @@ * policy-yaml unit test * ================================================================================ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ package org.onap.policy.controlloop.compiler; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -30,17 +31,14 @@ import java.io.FileInputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.List; -import org.junit.Rule; + import org.junit.Test; -import org.junit.rules.ExpectedException; import org.onap.policy.controlloop.policy.ControlLoopPolicy; import org.onap.policy.controlloop.policy.FinalResult; public class ControlLoopCompilerTest { private static final String RESTART_UNKNOWN_POLICY = - "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"; - @Rule - public ExpectedException expectedException = ExpectedException.none(); + "Operation Policy unique-policy-id-1-restart is connected to unknown policy unknown-policy"; @Test public void testTest() throws Exception { @@ -62,74 +60,68 @@ public class ControlLoopCompilerTest { expectedOnErrorMessages.add("controlLoop overall timeout is less than the sum of operational policy timeouts."); TestControlLoopCompilerCallback testControlLoopCompilerCallback = - new TestControlLoopCompilerCallback(expectedOnErrorMessages); - ControlLoopPolicy controlLoopPolicy = this.test("src/test/resources/v1.0.0/test.yaml", - testControlLoopCompilerCallback); + new TestControlLoopCompilerCallback(expectedOnErrorMessages); + ControlLoopPolicy controlLoopPolicy = + this.test("src/test/resources/v1.0.0/test.yaml", testControlLoopCompilerCallback); assertEquals(22, controlLoopPolicy.getPolicies().size()); assertTrue(testControlLoopCompilerCallback.areAllExpectedOnErrorsReceived()); } @Test public void testSuccessConnectedToUnknownPolicy() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage( - RESTART_UNKNOWN_POLICY); - this.test("src/test/resources/v1.0.0/bad_policy_success_connected_to_unknown_policy.yaml"); + assertThatThrownBy(() -> { + this.test("src/test/resources/v1.0.0/bad_policy_success_connected_to_unknown_policy.yaml"); + }).isInstanceOf(CompilerException.class).hasMessage(RESTART_UNKNOWN_POLICY); } @Test public void testFailureConnectedToUnknownPolicy() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage( - RESTART_UNKNOWN_POLICY); - this.test("src/test/resources/v1.0.0/bad_policy_failure_connected_to_unknown_policy.yaml"); + assertThatThrownBy(() -> { + this.test("src/test/resources/v1.0.0/bad_policy_failure_connected_to_unknown_policy.yaml"); + }).isInstanceOf(CompilerException.class).hasMessage(RESTART_UNKNOWN_POLICY); } @Test public void testFailureTimeoutToUnknownPolicy() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage( - RESTART_UNKNOWN_POLICY); - this.test("src/test/resources/v1.0.0/bad_policy_failure_timeout_connected_to_unknown_policy.yaml"); + assertThatThrownBy(() -> { + this.test("src/test/resources/v1.0.0/bad_policy_failure_timeout_connected_to_unknown_policy.yaml"); + }).isInstanceOf(CompilerException.class).hasMessage(RESTART_UNKNOWN_POLICY); } @Test public void testFailureRetriesToUnknownPolicy() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage( - RESTART_UNKNOWN_POLICY); - this.test("src/test/resources/v1.0.0/bad_policy_failure_retries_connected_to_unknown_policy.yaml"); + assertThatThrownBy(() -> { + this.test("src/test/resources/v1.0.0/bad_policy_failure_retries_connected_to_unknown_policy.yaml"); + }).isInstanceOf(CompilerException.class).hasMessage(RESTART_UNKNOWN_POLICY); } @Test public void testFailureExceptionToUnknownPolicy() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage( - RESTART_UNKNOWN_POLICY); - this.test("src/test/resources/v1.0.0/bad_policy_failure_exception_connected_to_unknown_policy.yaml"); + assertThatThrownBy(() -> { + this.test("src/test/resources/v1.0.0/bad_policy_failure_exception_connected_to_unknown_policy.yaml"); + }).isInstanceOf(CompilerException.class).hasMessage(RESTART_UNKNOWN_POLICY); } @Test public void testFailureGuardToUnknownPolicy() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage( - RESTART_UNKNOWN_POLICY); - this.test("src/test/resources/v1.0.0/bad_policy_failure_guard_connected_to_unknown_policy.yaml"); + assertThatThrownBy(() -> { + this.test("src/test/resources/v1.0.0/bad_policy_failure_guard_connected_to_unknown_policy.yaml"); + }).isInstanceOf(CompilerException.class).hasMessage(RESTART_UNKNOWN_POLICY); } @Test public void testInvalidTriggerPolicyId() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage( - "Unexpected value for trigger_policy, should only be " - + FinalResult.FINAL_OPENLOOP.toString() + " or a valid Policy ID"); - this.test("src/test/resources/v1.0.0/bad_trigger_1.yaml"); + assertThatThrownBy(() -> { + this.test("src/test/resources/v1.0.0/bad_trigger_1.yaml"); + }).isInstanceOf(CompilerException.class).hasMessage("Unexpected value for trigger_policy, should only be " + + FinalResult.FINAL_OPENLOOP.toString() + " or a valid Policy ID"); } @Test public void testNoTriggerPolicyId() throws Exception { - expectedException.expect(CompilerException.class); - this.test("src/test/resources/v1.0.0/bad_trigger_no_trigger_id.yaml"); + assertThatThrownBy(() -> { + this.test("src/test/resources/v1.0.0/bad_trigger_no_trigger_id.yaml"); + }).isInstanceOf(CompilerException.class); } @Test @@ -138,25 +130,25 @@ public class ControlLoopCompilerTest { expectedOnErrorMessages.add("Missing controlLoopName"); expectedOnErrorMessages.add("Unsupported version for this compiler"); TestControlLoopCompilerCallback testControlLoopCompilerCallback = - new TestControlLoopCompilerCallback(expectedOnErrorMessages); + new TestControlLoopCompilerCallback(expectedOnErrorMessages); this.test("src/test/resources/v1.0.0/bad_control_loop_no_control_loop_name.yaml", - testControlLoopCompilerCallback); + testControlLoopCompilerCallback); assertTrue(testControlLoopCompilerCallback.areAllExpectedOnErrorsReceived()); } @Test public void testInvalidFinalResult() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage( - "Unexpected Final Result for trigger_policy, should only be FINAL_OPENLOOP or a valid Policy ID"); - this.test("src/test/resources/v1.0.0/bad_trigger_2.yaml"); + assertThatThrownBy(() -> { + this.test("src/test/resources/v1.0.0/bad_trigger_2.yaml"); + }).isInstanceOf(CompilerException.class).hasMessage( + "Unexpected Final Result for trigger_policy, should only be FINAL_OPENLOOP or a valid Policy ID"); } @Test public void testCompileEmptyFile() throws Exception { - expectedException.expect(CompilerException.class); - expectedException.expectMessage("Could not parse yaml specification."); - this.test("src/test/resources/v1.0.0/empty.yaml"); + assertThatThrownBy(() -> { + this.test("src/test/resources/v1.0.0/empty.yaml"); + }).isInstanceOf(CompilerException.class).hasMessage("Could not parse yaml specification."); } public ControlLoopPolicy test(String testFile) throws Exception { @@ -171,8 +163,8 @@ public class ControlLoopCompilerTest { * @return the policy object * @throws Exception exception */ - public ControlLoopPolicy test(String testFile, - ControlLoopCompilerCallback controlLoopCompilerCallback) throws Exception { + public ControlLoopPolicy test(String testFile, ControlLoopCompilerCallback controlLoopCompilerCallback) + throws Exception { try (InputStream is = new FileInputStream(new File(testFile))) { return ControlLoopCompiler.compile(is, controlLoopCompilerCallback); } @@ -202,7 +194,5 @@ public class ControlLoopCompilerTest { public boolean areAllExpectedOnErrorsReceived() { return expectedOnErrorMessages.isEmpty(); } - } - } diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java index f646712fd..81520b578 100644 --- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java +++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyBuilderTest.java @@ -3,7 +3,7 @@ * policy-yaml unit test * ================================================================================ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,10 +32,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.UUID; + import org.junit.Ignore; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.onap.aai.domain.yang.Pnf; import org.onap.policy.controlloop.policy.builder.BuilderException; import org.onap.policy.controlloop.policy.builder.ControlLoopPolicyBuilder; @@ -49,7 +48,6 @@ import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.error.YAMLException; - public class ControlLoopPolicyBuilderTest { private static final String RESOURCE1 = "resource1"; @@ -60,8 +58,6 @@ public class ControlLoopPolicyBuilderTest { private static final String REBUILD = "Rebuild"; private static final String REBUILD_VM = "Rebuild VM"; private static final String REBUILD_RESTART = "If the restart fails, rebuild it."; - @Rule - public ExpectedException expectedException = ExpectedException.none(); @Test public void testControlLoop() throws BuilderException { @@ -69,7 +65,7 @@ public class ControlLoopPolicyBuilderTest { // Create a builder for our policy // ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); // // Test add services // @@ -105,25 +101,28 @@ public class ControlLoopPolicyBuilderTest { @Test public void testAddNullService() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); - expectedException.expect(BuilderException.class); - expectedException.expectMessage("Service must not be null"); - builder.addService((Service) null); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + + assertThatThrownBy(() -> { + builder.addService((Service) null); + }).isInstanceOf(BuilderException.class).hasMessage("Service must not be null"); } @Test public void testAddInvalidService() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); - expectedException.expect(BuilderException.class); - expectedException.expectMessage("Invalid service - need either a serviceUUID or serviceName"); - builder.addService(new Service()); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + + assertThatThrownBy(() -> { + builder.addService(new Service()); + }).isInstanceOf(BuilderException.class) + .hasMessage("Invalid service - need either a serviceUUID or serviceName"); } @Test public void testAddServiceWithUuid() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); UUID uuid = UUID.randomUUID(); Service serviceWithUuid = new Service(uuid); builder.addService(serviceWithUuid); @@ -133,26 +132,28 @@ public class ControlLoopPolicyBuilderTest { @Test public void testAddNullResource() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); - expectedException.expect(BuilderException.class); - expectedException.expectMessage("Resource must not be null"); - builder.addResource((Resource) null); - } + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + assertThatThrownBy(() -> { + builder.addResource((Resource) null); + }).isInstanceOf(BuilderException.class).hasMessage("Resource must not be null"); + } @Test public void testAddInvalidResource() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); - expectedException.expect(BuilderException.class); - expectedException.expectMessage("Invalid resource - need either resourceUUID or resourceName"); - builder.addResource(new Resource()); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + + assertThatThrownBy(() -> { + builder.addResource(new Resource()); + }).isInstanceOf(BuilderException.class) + .hasMessage("Invalid resource - need either resourceUUID or resourceName"); } @Test public void testAddAndRemoveResourceWithUuid() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); UUID uuid = UUID.randomUUID(); Resource resourceWithUuid = new Resource(uuid); builder.addResource(resourceWithUuid); @@ -165,44 +166,49 @@ public class ControlLoopPolicyBuilderTest { @Test public void testRemoveNullResource() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); Resource resource = new Resource(RESOURCE1, ResourceType.VF); builder.addResource(resource); - expectedException.expect(BuilderException.class); - expectedException.expectMessage("Resource must not be null"); - builder.removeResource((Resource) null); + + assertThatThrownBy(() -> { + builder.removeResource((Resource) null); + }).isInstanceOf(BuilderException.class).hasMessage("Resource must not be null"); } @Test public void testRemoveResourceNoExistingResources() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); - expectedException.expect(BuilderException.class); - expectedException.expectMessage("No existing resources to remove"); - builder.removeResource(new Resource(RESOURCE1, ResourceType.VF)); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + + assertThatThrownBy(() -> { + builder.removeResource(new Resource(RESOURCE1, ResourceType.VF)); + }).isInstanceOf(BuilderException.class).hasMessage("No existing resources to remove"); } @Test public void testRemoveInvalidResource() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); Resource resource = new Resource(RESOURCE1, ResourceType.VF); builder.addResource(resource); - expectedException.expect(BuilderException.class); - expectedException.expectMessage("Invalid resource - need either a resourceUUID or resourceName"); - builder.removeResource(new Resource()); + + assertThatThrownBy(() -> { + builder.removeResource(new Resource()); + }).isInstanceOf(BuilderException.class) + .hasMessage("Invalid resource - need either a resourceUUID or resourceName"); } @Test public void testRemoveUnknownResource() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); Resource resource = new Resource(RESOURCE1, ResourceType.VF); builder.addResource(resource); final String unknownResourceName = "reource2"; - expectedException.expect(BuilderException.class); - expectedException.expectMessage("Unknown resource " + unknownResourceName); - builder.removeResource(new Resource(unknownResourceName, ResourceType.VF)); + + assertThatThrownBy(() -> { + builder.removeResource(new Resource(unknownResourceName, ResourceType.VF)); + }).isInstanceOf(BuilderException.class).hasMessage("Unknown resource " + unknownResourceName); } @Test @@ -210,8 +216,8 @@ public class ControlLoopPolicyBuilderTest { Resource cts = new Resource("vCTS", ResourceType.VF); Service scp = new Service("vSCP"); Service usp = new Service("vUSP"); - ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory - .buildControlLoop(UUID.randomUUID().toString(), 2400, cts, scp, usp); + ControlLoopPolicyBuilder builder = + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400, cts, scp, usp); assertTrue(builder.getControlLoop().getResources().size() == 1); assertTrue(builder.getControlLoop().getServices().size() == 2); } @@ -221,8 +227,8 @@ public class ControlLoopPolicyBuilderTest { Resource cts = new Resource("vCTS", ResourceType.VF); Resource com = new Resource("vCTS", ResourceType.VF); Service scp = new Service("vSCP"); - ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory - .buildControlLoop(UUID.randomUUID().toString(), 2400, scp, cts, com); + ControlLoopPolicyBuilder builder = + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400, scp, cts, com); assertTrue(builder.getControlLoop().getServices().size() == 1); assertTrue(builder.getControlLoop().getResources().size() == 2); } @@ -238,9 +244,9 @@ public class ControlLoopPolicyBuilderTest { // PLEASE ADVISE IF THE BEHAVIOUR IS INCORRECT OR THE TEST CASE IS INVALID public void testControlLoopForPnf() throws BuilderException { Pnf pnf = new Pnf(); - //pnf.setPnfType(PnfType.ENODEB); + // pnf.setPnfType(PnfType.ENODEB); ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400, pnf); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400, pnf); assertEquals(pnf, builder.getControlLoop().getPnf()); builder.removePnf(); @@ -252,11 +258,11 @@ public class ControlLoopPolicyBuilderTest { // Fails for the same reason as the above test case public void testSetAndRemovePnf() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); assertNull(builder.getControlLoop().getPnf()); Pnf pnf = new Pnf(); - //pnf.setPnfType(PnfType.ENODEB); + // pnf.setPnfType(PnfType.ENODEB); builder.setPnf(pnf); assertEquals(pnf, builder.getControlLoop().getPnf()); @@ -267,25 +273,27 @@ public class ControlLoopPolicyBuilderTest { @Test public void testSetNullPnf() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); - expectedException.expect(BuilderException.class); - expectedException.expectMessage("PNF must not be null"); - builder.setPnf(null); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + + assertThatThrownBy(() -> { + builder.setPnf(null); + }).isInstanceOf(BuilderException.class).hasMessage("PNF must not be null"); } @Test public void testSetInvalidPnf() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); - expectedException.expect(BuilderException.class); - expectedException.expectMessage("Invalid PNF - need either pnfName or pnfType"); - builder.setPnf(new Pnf()); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + + assertThatThrownBy(() -> { + builder.setPnf(new Pnf()); + }).isInstanceOf(BuilderException.class).hasMessage("Invalid PNF - need either pnfName or pnfType"); } @Test public void testSetAbatement() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); assertFalse(builder.getControlLoop().getAbatement()); builder = builder.setAbatement(true); assertTrue(builder.getControlLoop().getAbatement()); @@ -293,11 +301,12 @@ public class ControlLoopPolicyBuilderTest { @Test public void testSetNullAbatement() throws BuilderException { - ControlLoopPolicyBuilder builder = + assertThatThrownBy(() -> { + ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); - expectedException.expect(BuilderException.class); - expectedException.expectMessage("abatement must not be null"); - builder = builder.setAbatement(null); + + builder = builder.setAbatement(null); + }).isInstanceOf(BuilderException.class).hasMessage("abatement must not be null"); } @Test @@ -306,7 +315,7 @@ public class ControlLoopPolicyBuilderTest { // Create a builder for our policy // ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); // // Test setTimeout // @@ -316,38 +325,38 @@ public class ControlLoopPolicyBuilderTest { // // Test calculateTimeout // - Policy trigger = - builder.setTriggerPolicy(PolicyParam.builder().id(UUID.randomUUID().toString()) - .name(RESTART_VM) - .description(TRIGGER_RESTART) - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(RESTART) - .payload(null) - .retries(2) - .timeout(300).build()); + // @formatter:off + Policy trigger = builder.setTriggerPolicy(PolicyParam.builder().id(UUID.randomUUID().toString()) + .name(RESTART_VM) + .description(TRIGGER_RESTART) + .actor("APPC").target(new Target(TargetType.VM)) + .recipe(RESTART) + .payload(null) + .retries(2) + .timeout(300) + .build()); + @SuppressWarnings("unused") Policy onRestartFailurePolicy = builder.setPolicyForPolicyResult( - PolicyParam.builder() - .name(REBUILD_VM) - .description("If the restart fails, rebuild it") - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(REBUILD) - .payload(null) - .retries(1) - .timeout(600) - .id(trigger.getId()).build(), - PolicyResult.FAILURE, - PolicyResult.FAILURE_RETRIES, - PolicyResult.FAILURE_TIMEOUT); + PolicyParam.builder() + .name(REBUILD_VM) + .description("If the restart fails, rebuild it").actor("APPC") + .target(new Target(TargetType.VM)) + .recipe(REBUILD) + .payload(null) + .retries(1) + .timeout(600) + .id(trigger.getId()) + .build(), + PolicyResult.FAILURE, PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT); assertEquals(Integer.valueOf(300 + 600), builder.calculateTimeout()); + // @formatter:on } @Test public void testTriggerPolicyMethods() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); // // Test isOpenLoop // @@ -355,35 +364,33 @@ public class ControlLoopPolicyBuilderTest { // // Test set initial trigger policy // - Policy triggerPolicy1 = - builder.setTriggerPolicy( - PolicyParam.builder().id(UUID.randomUUID().toString()) - .name(RESTART_VM) - .description(TRIGGER_RESTART) - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(RESTART) - .payload(null) - .retries(2) - .timeout(300).build()); + // @formatter:off + Policy triggerPolicy1 = builder.setTriggerPolicy(PolicyParam.builder().id(UUID.randomUUID().toString()) + .name(RESTART_VM) + .description(TRIGGER_RESTART) + .actor("APPC") + .target(new Target(TargetType.VM)) + .recipe(RESTART) + .payload(null) + .retries(2) + .timeout(300) + .build()); assertFalse(builder.isOpenLoop()); assertEquals(builder.getControlLoop().getTrigger_policy(), triggerPolicy1.getId()); // // Set trigger policy to a new policy // @SuppressWarnings("unused") - Policy triggerPolicy2 = - builder.setTriggerPolicy( - PolicyParam.builder() - .id(UUID.randomUUID().toString()) - .name("Rebuild the VM") - .description("Upon getting the trigger event, rebuild the VM") - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(REBUILD) - .payload(null) - .retries(2) - .timeout(300).build()); + Policy triggerPolicy2 = builder.setTriggerPolicy(PolicyParam.builder().id(UUID.randomUUID().toString()) + .name("Rebuild the VM") + .description("Upon getting the trigger event, rebuild the VM").actor("APPC") + .target(new Target(TargetType.VM)) + .recipe(REBUILD) + .payload(null) + .retries(2) + .timeout(300) + .build()); + // @formatter:on // // Test set trigger policy to another existing policy // @@ -399,78 +406,77 @@ public class ControlLoopPolicyBuilderTest { @Test public void testSetTriggerPolicyNullPolicyId() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); - expectedException.expect(BuilderException.class); - expectedException.expectMessage("Id must not be null"); - builder.setExistingTriggerPolicy(null); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + + assertThatThrownBy(() -> { + builder.setExistingTriggerPolicy(null); + }).isInstanceOf(BuilderException.class).hasMessage("Id must not be null"); } @Test public void testSetTriggerPolicyNoPoliciesExist() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); final String unknownPolicyId = "100"; - expectedException.expect(BuilderException.class); - expectedException.expectMessage(UNKNOWN_POLICY + unknownPolicyId); - builder.setExistingTriggerPolicy(unknownPolicyId); + + assertThatThrownBy(() -> { + builder.setExistingTriggerPolicy(unknownPolicyId); + }).isInstanceOf(BuilderException.class).hasMessage(UNKNOWN_POLICY + unknownPolicyId); } @Test public void testSetTriggerPolicyUnknownPolicy() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); - builder.setTriggerPolicy( - PolicyParam.builder() - .id(UUID.randomUUID().toString()) - .name(RESTART_VM) - .description(TRIGGER_RESTART) - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(RESTART) - .payload(null) - .retries(2) - .timeout(300).build()); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + // @formatter:off + builder.setTriggerPolicy(PolicyParam.builder().id(UUID.randomUUID().toString()) + .name(RESTART_VM) + .description(TRIGGER_RESTART) + .actor("APPC") + .target(new Target(TargetType.VM)) + .recipe(RESTART) + .payload(null) + .retries(2) + .timeout(300) + .build()); + // @formatter:on final String unknownPolicyId = "100"; - expectedException.expect(BuilderException.class); - expectedException.expectMessage(UNKNOWN_POLICY + unknownPolicyId); - builder.setExistingTriggerPolicy(unknownPolicyId); + + assertThatThrownBy(() -> { + builder.setExistingTriggerPolicy(unknownPolicyId); + }).isInstanceOf(BuilderException.class).hasMessage(UNKNOWN_POLICY + unknownPolicyId); } @Test public void testAddRemovePolicies() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); - Policy triggerPolicy = - builder.setTriggerPolicy( - PolicyParam.builder() - .id(UUID.randomUUID().toString()) - .name(RESTART_VM) - .description(TRIGGER_RESTART) - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(RESTART) - .payload(null) - .retries(2) - .timeout(300).build()); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + // @formatter:off + Policy triggerPolicy = builder.setTriggerPolicy(PolicyParam.builder().id(UUID.randomUUID().toString()) + .name(RESTART_VM) + .description(TRIGGER_RESTART) + .actor("APPC") + .target(new Target(TargetType.VM)) + .recipe(RESTART) + .payload(null) + .retries(2) + .timeout(300) + .build()); // // Test create a policy and chain it to the results of trigger policy // - Policy onRestartFailurePolicy1 = builder.setPolicyForPolicyResult( - PolicyParam.builder() - .name(REBUILD_VM) - .description(REBUILD_RESTART) - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(REBUILD) - .payload(null) - .retries(1) - .timeout(600) - .id(triggerPolicy.getId()).build(), - PolicyResult.FAILURE, - PolicyResult.FAILURE_EXCEPTION, - PolicyResult.FAILURE_RETRIES, - PolicyResult.FAILURE_TIMEOUT, - PolicyResult.FAILURE_GUARD); + Policy onRestartFailurePolicy1 = builder.setPolicyForPolicyResult(PolicyParam.builder() + .name(REBUILD_VM) + .description(REBUILD_RESTART) + .actor("APPC") + .target(new Target(TargetType.VM)) + .recipe(REBUILD).payload(null) + .retries(1) + .timeout(600) + .id(triggerPolicy.getId()) + .build(), + PolicyResult.FAILURE, PolicyResult.FAILURE_EXCEPTION, PolicyResult.FAILURE_RETRIES, + PolicyResult.FAILURE_TIMEOUT, PolicyResult.FAILURE_GUARD); // assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy1.getId())); assertTrue(builder.getTriggerPolicy().getFailure_exception().equals(onRestartFailurePolicy1.getId())); @@ -481,19 +487,20 @@ public class ControlLoopPolicyBuilderTest { // // Test create a policy and chain it to the results of trigger policy success // - Policy onSuccessPolicy1 = builder.setPolicyForPolicyResult( - PolicyParam.builder() - .name("Do something") - .description("If the restart succeeds, do something else.") - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe("SomethingElse") - .payload(null) - .retries(1) - .timeout(600) - .id(triggerPolicy.getId()).build(), - PolicyResult.SUCCESS); - // + Policy onSuccessPolicy1 = builder.setPolicyForPolicyResult(PolicyParam.builder() + .name("Do something") + .description("If the restart succeeds, do something else.") + .actor("APPC") + .target(new Target(TargetType.VM)) + .recipe("SomethingElse") + .payload(null) + .retries(1) + .timeout(600) + .id(triggerPolicy.getId()) + .build(), + PolicyResult.SUCCESS); + // + // @formatter:on assertTrue(builder.getTriggerPolicy().getSuccess().equals(onSuccessPolicy1.getId())); // @@ -502,55 +509,52 @@ public class ControlLoopPolicyBuilderTest { boolean removed = builder.removePolicy(onRestartFailurePolicy1.getId()); assertTrue(removed); assertTrue(builder.getTriggerPolicy().getFailure().equals(FinalResult.FINAL_FAILURE.toString())); - assertTrue(builder.getTriggerPolicy().getFailure_retries() - .equals(FinalResult.FINAL_FAILURE_RETRIES.toString())); - assertTrue(builder.getTriggerPolicy().getFailure_timeout() - .equals(FinalResult.FINAL_FAILURE_TIMEOUT.toString())); assertTrue( - builder.getTriggerPolicy().getFailure_guard().equals(FinalResult.FINAL_FAILURE_GUARD.toString())); + builder.getTriggerPolicy().getFailure_retries().equals(FinalResult.FINAL_FAILURE_RETRIES.toString())); + assertTrue( + builder.getTriggerPolicy().getFailure_timeout().equals(FinalResult.FINAL_FAILURE_TIMEOUT.toString())); + assertTrue(builder.getTriggerPolicy().getFailure_guard().equals(FinalResult.FINAL_FAILURE_GUARD.toString())); // // Create another policy and chain it to the results of trigger policy // - final Policy onRestartFailurePolicy2 = - builder.setPolicyForPolicyResult( - PolicyParam.builder() - .name(REBUILD_VM) - .description(REBUILD_RESTART) - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(REBUILD) - .payload(null) - .retries(2) - .timeout(600) - .id(triggerPolicy.getId()).build(), - PolicyResult.FAILURE, - PolicyResult.FAILURE_RETRIES, - PolicyResult.FAILURE_TIMEOUT); + // @formatter:off + final Policy onRestartFailurePolicy2 = builder.setPolicyForPolicyResult( + PolicyParam.builder() + .name(REBUILD_VM) + .description(REBUILD_RESTART) + .actor("APPC") + .target(new Target(TargetType.VM)) + .recipe(REBUILD) + .payload(null) + .retries(2) + .timeout(600) + .id(triggerPolicy.getId()) + .build(), + PolicyResult.FAILURE, PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT); + // @formatter:on // // Test reset policy results // triggerPolicy = builder.resetPolicyResults(triggerPolicy.getId()); assertTrue(builder.getTriggerPolicy().getFailure().equals(FinalResult.FINAL_FAILURE.toString())); - assertTrue(builder.getTriggerPolicy().getFailure_retries() - .equals(FinalResult.FINAL_FAILURE_RETRIES.toString())); - assertTrue(builder.getTriggerPolicy().getFailure_timeout() - .equals(FinalResult.FINAL_FAILURE_TIMEOUT.toString())); + assertTrue( + builder.getTriggerPolicy().getFailure_retries().equals(FinalResult.FINAL_FAILURE_RETRIES.toString())); + assertTrue( + builder.getTriggerPolicy().getFailure_timeout().equals(FinalResult.FINAL_FAILURE_TIMEOUT.toString())); // // Test set the policy results to an existing operational policy // - Policy onRestartFailurePolicy3 = - builder.setPolicyForPolicyResult(onRestartFailurePolicy2.getId(), triggerPolicy.getId(), - PolicyResult.FAILURE, PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT); + Policy onRestartFailurePolicy3 = builder.setPolicyForPolicyResult(onRestartFailurePolicy2.getId(), + triggerPolicy.getId(), PolicyResult.FAILURE, PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT); assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy3.getId())); assertTrue(builder.getTriggerPolicy().getFailure_retries().equals(onRestartFailurePolicy3.getId())); assertTrue(builder.getTriggerPolicy().getFailure_timeout().equals(onRestartFailurePolicy3.getId())); // // Test set the policy result for success to an existing operational policy // - Policy onRestartFailurePolicy4 = - builder.setPolicyForPolicyResult(onRestartFailurePolicy2.getId(), triggerPolicy.getId(), - PolicyResult.FAILURE, PolicyResult.FAILURE_EXCEPTION, PolicyResult.FAILURE_GUARD, - PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT, PolicyResult.SUCCESS); + Policy onRestartFailurePolicy4 = builder.setPolicyForPolicyResult(onRestartFailurePolicy2.getId(), + triggerPolicy.getId(), PolicyResult.FAILURE, PolicyResult.FAILURE_EXCEPTION, PolicyResult.FAILURE_GUARD, + PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT, PolicyResult.SUCCESS); assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy4.getId())); assertTrue(builder.getTriggerPolicy().getFailure_exception().equals(onRestartFailurePolicy4.getId())); assertTrue(builder.getTriggerPolicy().getFailure_guard().equals(onRestartFailurePolicy4.getId())); @@ -568,129 +572,136 @@ public class ControlLoopPolicyBuilderTest { @Test public void testAddToUnknownPolicy() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); final String policyId = "100"; - expectedException.expect(BuilderException.class); - expectedException.expectMessage(UNKNOWN_POLICY + policyId); - builder.setPolicyForPolicyResult( + assertThatThrownBy(() -> { + // @formatter:off + builder.setPolicyForPolicyResult( PolicyParam.builder() - .name(REBUILD_VM) - .description(REBUILD_RESTART) - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(REBUILD) - .payload(null) - .retries(1) - .timeout(600) - .id(policyId).build(), - PolicyResult.FAILURE, - PolicyResult.FAILURE_RETRIES, - PolicyResult.FAILURE_TIMEOUT, + .name(REBUILD_VM) + .description(REBUILD_RESTART) + .actor("APPC") + .target(new Target(TargetType.VM)) + .recipe(REBUILD) + .payload(null) + .retries(1) + .timeout(600) + .id(policyId) + .build(), + PolicyResult.FAILURE, PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT, PolicyResult.FAILURE_GUARD); + // @formatter:on + }).isInstanceOf(BuilderException.class).hasMessage(UNKNOWN_POLICY + policyId); + } @Test public void testAddExistingPolicyToUnknownPolicy() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); - Policy triggerPolicy = - builder.setTriggerPolicy( - PolicyParam.builder() - .id(UUID.randomUUID().toString()) - .name(RESTART_VM) - .description(TRIGGER_RESTART) - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(RESTART) - .payload(null) - .retries(2) - .timeout(300).build()); - - - Policy onRestartFailurePolicy = builder.setPolicyForPolicyResult( - PolicyParam.builder() - .name(REBUILD_VM) - .description(REBUILD_RESTART) - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(REBUILD) - .payload(null) - .retries(1) - .timeout(600) - .id(triggerPolicy.getId()).build(), - PolicyResult.FAILURE); - + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + // @formatter:off + Policy triggerPolicy = builder.setTriggerPolicy(PolicyParam.builder() + .id(UUID.randomUUID().toString()) + .name(RESTART_VM) + .description(TRIGGER_RESTART) + .actor("APPC") + .target(new Target(TargetType.VM)) + .recipe(RESTART) + .payload(null) + .retries(2) + .timeout(300) + .build()); + + Policy onRestartFailurePolicy = builder.setPolicyForPolicyResult(PolicyParam.builder() + .name(REBUILD_VM) + .description(REBUILD_RESTART) + .actor("APPC") + .target(new Target(TargetType.VM)) + .recipe(REBUILD) + .payload(null) + .retries(1) + .timeout(600) + .id(triggerPolicy.getId()) + .build(), + PolicyResult.FAILURE); + + // @formatter:on final String unknownPolicyId = "100"; - expectedException.expect(BuilderException.class); - expectedException.expectMessage(unknownPolicyId + " does not exist"); - builder.setPolicyForPolicyResult(onRestartFailurePolicy.getId(), unknownPolicyId, PolicyResult.FAILURE); + assertThatThrownBy(() -> { + builder.setPolicyForPolicyResult(onRestartFailurePolicy.getId(), unknownPolicyId, PolicyResult.FAILURE); + }).isInstanceOf(BuilderException.class).hasMessage(unknownPolicyId + " does not exist"); + } @Test public void testAddUnknownExistingPolicyToPolicy() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); - Policy triggerPolicy = - builder.setTriggerPolicy( - PolicyParam.builder() - .id(UUID.randomUUID().toString()) - .name(RESTART_VM) - .description(TRIGGER_RESTART) - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(RESTART) - .payload(null) - .retries(2) - .timeout(300).build()); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + // @formatter:off + Policy triggerPolicy = builder.setTriggerPolicy(PolicyParam.builder() + .id(UUID.randomUUID().toString()) + .name(RESTART_VM) + .description(TRIGGER_RESTART) + .actor("APPC") + .target(new Target(TargetType.VM)) + .recipe(RESTART) + .payload(null) + .retries(2) + .timeout(300) + .build()); + // @formatter:on final String unknownPolicyId = "100"; - expectedException.expect(BuilderException.class); - expectedException.expectMessage("Operational policy " + unknownPolicyId + " does not exist"); - builder.setPolicyForPolicyResult(unknownPolicyId, triggerPolicy.getId(), PolicyResult.FAILURE); + assertThatThrownBy(() -> { + builder.setPolicyForPolicyResult(unknownPolicyId, triggerPolicy.getId(), PolicyResult.FAILURE); + }).isInstanceOf(BuilderException.class).hasMessage("Operational policy " + unknownPolicyId + " does not exist"); + } @Test public void testAddOperationsAccumulateParams() throws BuilderException { ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400); + // @formatter:off Policy triggerPolicy = - builder.setTriggerPolicy( - PolicyParam.builder() - .id(UUID.randomUUID().toString()) - .name("Restart the eNodeB") - .description("Upon getting the trigger event, restart the eNodeB") - .actor("RANController") - .target(new Target(TargetType.PNF)) - .recipe(RESTART) - .payload(null) - .retries(2) - .timeout(300).build()); + builder.setTriggerPolicy(PolicyParam.builder() + .id(UUID.randomUUID().toString()) + .name("Restart the eNodeB") + .description("Upon getting the trigger event, restart the eNodeB") + .actor("RANController") + .target(new Target(TargetType.PNF)) + .recipe(RESTART) + .payload(null) + .retries(2) + .timeout(300) + .build()); + // @formatter:on // // Add the operationsAccumulateParams // - triggerPolicy = builder.addOperationsAccumulateParams(triggerPolicy.getId(), - new OperationsAccumulateParams("15m", 5)); + triggerPolicy = + builder.addOperationsAccumulateParams(triggerPolicy.getId(), new OperationsAccumulateParams("15m", 5)); assertNotNull(builder.getTriggerPolicy().getOperationsAccumulateParams()); assertEquals("15m", builder.getTriggerPolicy().getOperationsAccumulateParams().getPeriod()); assertTrue(builder.getTriggerPolicy().getOperationsAccumulateParams().getLimit() == 5); } - @Test public void testBuildSpecification() throws BuilderException { // // Create the builder // ControlLoopPolicyBuilder builder = - ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 800); + ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 800); // // Set the first invalid trigger policy // + // @formatter:off final Policy policy1 = builder.setTriggerPolicy( - PolicyParam.builder() + PolicyParam.builder() .id(UUID.randomUUID().toString()) .name(RESTART_VM) .description(TRIGGER_RESTART) @@ -699,8 +710,10 @@ public class ControlLoopPolicyBuilderTest { .recipe(null) .payload(null) .retries(2) - .timeout(300).build()); + .timeout(300) + .build()); Results results = builder.buildSpecification(); + // @formatter:on // // Check that ERRORs are in results for invalid policy arguments // @@ -732,32 +745,33 @@ public class ControlLoopPolicyBuilderTest { // // Set a valid trigger policy // - Policy policy1a = builder.setTriggerPolicy( - PolicyParam.builder() - .id(UUID.randomUUID().toString()) - .name(REBUILD_VM) - .description(REBUILD_RESTART) - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(REBUILD) - .payload(null) - .retries(1) - .timeout(600).build()); + // @formatter:off + Policy policy1a = builder.setTriggerPolicy(PolicyParam.builder() + .id(UUID.randomUUID().toString()) + .name(REBUILD_VM) + .description(REBUILD_RESTART) + .actor("APPC") + .target(new Target(TargetType.VM)) + .recipe(REBUILD) + .payload(null) + .retries(1) + .timeout(600) + .build()); // // Set a second valid trigger policy // - final Policy policy2 = - builder.setTriggerPolicy( - PolicyParam.builder() - .id(UUID.randomUUID().toString()) - .name(RESTART_VM) - .description(TRIGGER_RESTART) - .actor("APPC") - .target(new Target(TargetType.VM)) - .recipe(RESTART) - .payload(null) - .retries(2) - .timeout(300).build()); + final Policy policy2 = builder.setTriggerPolicy(PolicyParam.builder() + .id(UUID.randomUUID().toString()) + .name(RESTART_VM) + .description(TRIGGER_RESTART) + .actor("APPC") + .target(new Target(TargetType.VM)) + .recipe(RESTART) + .payload(null) + .retries(2) + .timeout(300) + .build()); + // @formatter:on // // Now, we have policy1 unreachable // @@ -765,7 +779,7 @@ public class ControlLoopPolicyBuilderTest { boolean unreachable = false; for (Message m : results.getMessages()) { if (m.getMessage().equals("Policy " + policy1a.getId() + " is not reachable.") - && m.getLevel() == MessageLevel.WARNING) { + && m.getLevel() == MessageLevel.WARNING) { unreachable = true; break; } @@ -775,12 +789,12 @@ public class ControlLoopPolicyBuilderTest { // Set policy1a for the failure results of policy2 // policy1a = builder.setPolicyForPolicyResult(policy1a.getId(), policy2.getId(), PolicyResult.FAILURE, - PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT); + PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT); results = builder.buildSpecification(); boolean invalidTimeout = false; for (Message m : results.getMessages()) { if ("controlLoop overall timeout is less than the sum of operational policy timeouts." - .equals(m.getMessage()) && m.getLevel() == MessageLevel.ERROR) { + .equals(m.getMessage()) && m.getLevel() == MessageLevel.ERROR) { invalidTimeout = true; break; } @@ -797,7 +811,7 @@ public class ControlLoopPolicyBuilderTest { unreachable = false; for (Message m : results.getMessages()) { if ("Open Loop policy contains policies. The policies will never be invoked.".equals(m.getMessage()) - && m.getLevel() == MessageLevel.WARNING) { + && m.getLevel() == MessageLevel.WARNING) { unreachable = true; break; } @@ -805,7 +819,6 @@ public class ControlLoopPolicyBuilderTest { assertTrue(unreachable); } - @Test public void test1() throws Exception { this.test("src/test/resources/v1.0.0/policy_Test.yaml"); @@ -842,20 +855,20 @@ public class ControlLoopPolicyBuilderTest { // Now we're going to try to use the builder to build this. // ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop( - policyTobuild.getControlLoop().getControlLoopName(), policyTobuild.getControlLoop().getTimeout()); + policyTobuild.getControlLoop().getControlLoopName(), policyTobuild.getControlLoop().getTimeout()); // // Add services // if (policyTobuild.getControlLoop().getServices() != null) { builder = builder.addService(policyTobuild.getControlLoop().getServices() - .toArray(new Service[policyTobuild.getControlLoop().getServices().size()])); + .toArray(new Service[policyTobuild.getControlLoop().getServices().size()])); } // // Add resources // if (policyTobuild.getControlLoop().getResources() != null) { builder = builder.addResource(policyTobuild.getControlLoop().getResources() - .toArray(new Resource[policyTobuild.getControlLoop().getResources().size()])); + .toArray(new Resource[policyTobuild.getControlLoop().getResources().size()])); } // // Set pnf @@ -879,12 +892,11 @@ public class ControlLoopPolicyBuilderTest { } private void setTriggerPolicies(ControlLoopPolicy policyTobuild, ControlLoopPolicyBuilder builder) - throws BuilderException { + throws BuilderException { for (Policy policy : policyTobuild.getPolicies()) { if (policy.getId() == policyTobuild.getControlLoop().getTrigger_policy()) { - builder.setTriggerPolicy( - PolicyParam.builder() - .id(UUID.randomUUID().toString()) + // @formatter:off + builder.setTriggerPolicy(PolicyParam.builder().id(UUID.randomUUID().toString()) .name(policy.getName()) .description(policy.getDescription()) .actor(policy.getActor()) @@ -892,9 +904,10 @@ public class ControlLoopPolicyBuilderTest { .recipe(policy.getRecipe()) .payload(null) .retries(policy.getRetry()) - .timeout(policy.getTimeout()).build()); + .timeout(policy.getTimeout()) + .build()); + // @formatter:on } } } - } diff --git a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java index 0b61991f1..43428c6f9 100644 --- a/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java +++ b/models-interactions/model-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java @@ -3,7 +3,7 @@ * policy-yaml unit test * ================================================================================ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,20 +23,14 @@ package org.onap.policy.controlloop.policy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import java.io.File; import java.io.FileInputStream; -import java.io.InputStream; +import java.io.InputStreamReader; + import org.junit.Test; -import org.onap.policy.common.utils.io.Serializer; +import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.DumperOptions.FlowStyle; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.Constructor; - public class ControlLoopPolicyTest { private static final Logger logger = LoggerFactory.getLogger(ControlLoopPolicyTest.class); @@ -62,9 +56,8 @@ public class ControlLoopPolicyTest { } @Test - public void testvFirewall() { - // Chenfei to fix this. - // this.test("src/test/resources/v2.0.0/policy_ONAP_demo_vFirewall.yaml"); + public void testvFirewall() throws Exception { + this.test("src/test/resources/v2.0.0/policy_ONAP_demo_vFirewall.yaml"); } @Test @@ -89,37 +82,30 @@ public class ControlLoopPolicyTest { * @throws Exception if an error occurs */ public void test(String testFile) throws Exception { - try (InputStream is = new FileInputStream(new File(testFile))) { + try (InputStreamReader fileInputStream = new InputStreamReader(new FileInputStream(testFile))) { // // Read the yaml into our Java Object // - Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class)); - Object obj = yaml.load(is); - assertNotNull(obj); - assertTrue(obj instanceof ControlLoopPolicy); - dump(obj); + ControlLoopPolicy controlLoopPolicy1 = + new YamlJsonTranslator().fromYaml(fileInputStream, ControlLoopPolicy.class); + assertNotNull(controlLoopPolicy1); + dump(controlLoopPolicy1); + // // Now dump it to a yaml string // - DumperOptions options = new DumperOptions(); - options.setDefaultFlowStyle(FlowStyle.BLOCK); - options.setPrettyFlow(true); - yaml = new Yaml(options); - String dumpedYaml = yaml.dump(obj); + String dumpedYaml = new YamlJsonTranslator().toYaml(controlLoopPolicy1); logger.debug(dumpedYaml); // // Read that string back into our java object // - Object newObject = yaml.load(dumpedYaml); - dump(newObject); - assertNotNull(newObject); - assertTrue(newObject instanceof ControlLoopPolicy); - assertEquals(obj, newObject); + ControlLoopPolicy controlLoopPolicy2 = + new YamlJsonTranslator().fromYaml(dumpedYaml, ControlLoopPolicy.class); + assertNotNull(controlLoopPolicy2); + dump(controlLoopPolicy2); // test serialization - ControlLoopPolicy policy = (ControlLoopPolicy) obj; - ControlLoopPolicy policy2 = Serializer.roundTrip(policy); - assertTrue(policy.equals(policy2)); + assertEquals(controlLoopPolicy1, controlLoopPolicy2); } } diff --git a/models-interactions/model-yaml/src/test/resources/v1.0.0/policy_Test.yaml b/models-interactions/model-yaml/src/test/resources/v1.0.0/policy_Test.yaml index 73486b08b..de2590c15 100644 --- a/models-interactions/model-yaml/src/test/resources/v1.0.0/policy_Test.yaml +++ b/models-interactions/model-yaml/src/test/resources/v1.0.0/policy_Test.yaml @@ -1,5 +1,5 @@ # Copyright 2018 AT&T Intellectual Property. All rights reserved -# Modifications Copyright (C) 2019 Nordix Foundation. +# Modifications Copyright (C) 2019-2020 Nordix Foundation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,9 +15,9 @@ controlLoop: controlLoopName: ControlLoop-TEST-5dfa8fce-bd7a-4424-b60d-ee2ad2f254a3 version: 1.0.0 - services: + services: - serviceName: Foo Service - resources: + resources: - resourceName: Bar VNF resourceType: VF trigger_policy: unique-policy-id-1-restart @@ -29,7 +29,8 @@ policies: description: actor: APPC recipe: Restart - target: VM + target: + type: VM retry: 2 timeout: 300 success: unique-policy-id-2-healthcheck-restart @@ -37,13 +38,14 @@ policies: failure_timeout: unique-policy-id-3-rebuild failure_retries: unique-policy-id-3-rebuild failure_exception: final_failure_exception - + - id: unique-policy-id-2-healthcheck-restart name: HealthCheck Policy description: actor: APPC recipe: HealthCheck - target: VM + target: + type: VM retry: 2 timeout: 300 success: final_success @@ -51,13 +53,14 @@ policies: failure_timeout: unique-policy-id-3-rebuild failure_retries: unique-policy-id-3-rebuild failure_exception: final_failure_exception - + - id: unique-policy-id-3-rebuild name: Rebuild Policy description: actor: APPC recipe: Rebuild - target: VM + target: + type: VM retry: 0 timeout: 600 success: unique-policy-id-4-healthcheck-rebuild @@ -65,13 +68,14 @@ policies: failure_timeout: unique-policy-id-5-migrate failure_retries: unique-policy-id-5-migrate failure_exception: final_failure_exception - + - id: unique-policy-id-4-healthcheck-rebuild name: HealthCheck the Rebuild Policy description: actor: APPC recipe: HealthCheck - target: VM + target: + type: VM retry: 2 timeout: 300 success: final_success @@ -79,13 +83,14 @@ policies: failure_timeout: unique-policy-id-5-migrate failure_retries: unique-policy-id-5-migrate failure_exception: final_failure_exception - + - id: unique-policy-id-5-migrate name: Migrate Policy description: actor: APPC recipe: Migrate - target: VM + target: + type: VM retry: 0 timeout: 600 success: unique-policy-id-6-healthcheck-migrate @@ -99,7 +104,8 @@ policies: description: actor: APPC recipe: HealthCheck - target: VM + target: + type: VM retry: 2 timeout: 300 success: final_success diff --git a/models-interactions/model-yaml/src/test/resources/v1.0.0/policy_vService.yaml b/models-interactions/model-yaml/src/test/resources/v1.0.0/policy_vService.yaml index 009a49c19..44c081cb7 100644 --- a/models-interactions/model-yaml/src/test/resources/v1.0.0/policy_vService.yaml +++ b/models-interactions/model-yaml/src/test/resources/v1.0.0/policy_vService.yaml @@ -1,5 +1,5 @@ # Copyright 2018 AT&T Intellectual Property. All rights reserved -# Modifications Copyright (C) 2019 Nordix Foundation. +# Modifications Copyright (C) 2019-2020 Nordix Foundation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,9 +15,9 @@ controlLoop: version: 1.0.0 controlLoopName: ControlLoop-vUSP-vCTS-cbed919f-2212-4ef7-8051-fe6308da1bda - services: + services: - serviceName: vUSP - resources: + resources: - resourceName: vCTS resourceType: VF - resourceName: vCOM @@ -37,7 +37,8 @@ policies: description: actor: APPC recipe: Restart - target: VM + target: + type: VM retry: 2 timeout: 300 success: final_success @@ -45,13 +46,14 @@ policies: failure_timeout: unique-policy-id-2-rebuild failure_retries: unique-policy-id-2-rebuild failure_exception: final_failure_exception - + - id: unique-policy-id-2-rebuild name: Rebuild Policy description: actor: APPC recipe: Rebuild - target: VM + target: + type: VM retry: 0 timeout: 600 success: final_success @@ -59,13 +61,14 @@ policies: failure_timeout: unique-policy-id-3-migrate failure_retries: unique-policy-id-3-migrate failure_exception: final_failure_exception - + - id: unique-policy-id-3-migrate name: Migrate Policy description: actor: APPC recipe: Migrate - target: VM + target: + type: VM retry: 0 timeout: 600 success: final_success diff --git a/models-interactions/model-yaml/src/test/resources/v2.0.0/policy_ONAP_demo_vFirewall.yaml b/models-interactions/model-yaml/src/test/resources/v2.0.0/policy_ONAP_demo_vFirewall.yaml index 00b9b4cb1..feaba64cf 100644 --- a/models-interactions/model-yaml/src/test/resources/v2.0.0/policy_ONAP_demo_vFirewall.yaml +++ b/models-interactions/model-yaml/src/test/resources/v2.0.0/policy_ONAP_demo_vFirewall.yaml @@ -1,5 +1,5 @@ # Copyright 2018-2019 AT&T Intellectual Property. All rights reserved -# Modifications Copyright (C) 2019 Nordix Foundation. +# Modifications Copyright (C) 2019-2020 Nordix Foundation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -60,7 +60,7 @@ policies: target: resourceID: Eace933104d443b496b8.nodes.heat.vpg payload: - generic-vnf.vnf-id: {generic-vnf.vnf-id} + generic-vnf.vnf-id: '{generic-vnf.vnf-id}' streams: '{"active-streams":5}' retry: 0 timeout: 300 diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java new file mode 100644 index 000000000..2f36f9a3c --- /dev/null +++ b/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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.provider.revisionhierarchy; + +import static org.assertj.core.api.Assertions.assertThatCode; + +import java.util.Base64; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.common.utils.coder.YamlJsonTranslator; +import org.onap.policy.common.utils.resources.TextFileUtils; +import org.onap.policy.models.provider.PolicyModelsProvider; +import org.onap.policy.models.provider.PolicyModelsProviderFactory; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; + +public class HierarchyFetchTest { + + private static PolicyModelsProviderParameters parameters; + + @BeforeClass + public static void beforeSetupParameters() { + parameters = new PolicyModelsProviderParameters(); + parameters.setDatabaseDriver("org.h2.Driver"); + parameters.setDatabaseUrl("jdbc:h2:mem:testdb"); + parameters.setDatabaseUser("policy"); + parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes())); + parameters.setPersistenceUnit("ToscaConceptTest"); + } + + @Test + public void testMultipleVersions() throws Exception { + PolicyModelsProvider databaseProvider = + new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); + + ToscaServiceTemplate serviceTemplate = new YamlJsonTranslator().fromYaml( + TextFileUtils + .getTextFileAsString("src/test/resources/servicetemplates/MultipleRevisionServiceTemplate.yaml"), + ToscaServiceTemplate.class); + + assertThatCode(() -> { + databaseProvider.createPolicies(serviceTemplate); + }).doesNotThrowAnyException(); + + databaseProvider.close(); + } +} diff --git a/models-provider/src/test/resources/servicetemplates/MultipleRevisionServiceTemplate.yaml b/models-provider/src/test/resources/servicetemplates/MultipleRevisionServiceTemplate.yaml new file mode 100644 index 000000000..5f250e022 --- /dev/null +++ b/models-provider/src/test/resources/servicetemplates/MultipleRevisionServiceTemplate.yaml @@ -0,0 +1,421 @@ +tosca_definitions_version: tosca_simple_yaml_1_1_0 +policy_types: + onap.policies.PolicyTypeLevel0:1.0.0: + derived_from: tosca.policies.Root + version: 1.0.0 + description: Level 0 policy type + properties: + policyLevel0Property0: + type: policy.data.DataType0 + policyLevel0Property1: + type: list + entry_schema: + type: policy.data.DataType1 + onap.policies.PolicyTypeLevel0:2.0.0: + derived_from: tosca.policies.Root + version: 2.0.0 + description: Level 0 policy type + properties: + policyLevel0Property0: + type: policy.data.DataType0 + policyLevel0Property1: + type: list + entry_schema: + type: policy.data.DataType1 + policyLevel0V2Property2: + type: policy.data.DataType5 + onap.policies.PolicyTypeLevel0: + derived_from: tosca.policies.Root + version: 3.0.0 + description: Level 0 policy type + properties: + policyLevel0Property0: + type: policy.data.DataType0 + policyLevel0Property1: + type: list + entry_schema: + type: policy.data.DataType1 + policyLevel0V2Property2: + type: policy.data.DataType5 + policyLevel0V3Property3: + type: policy.data.DataType6 + onap.policies.PolicyTypeLevel0.1:1.0.0: + derived_from: onap.policies.PolicyTypeLevel0 + version: 1.0.0 + description: Level 0.1 policy type + properties: + policyLevel0.1Property0: + type: policy.data.DataType5 + policyLevel0.1Property1: + type: policy.data.DataType6 + onap.policies.PolicyTypeLevel0.1:2.0.0: + derived_from: onap.policies.PolicyTypeLevel0 + version: 2.0.0 + description: Level 0.1 policy type + properties: + policyLevel0.1Property0: + type: policy.data.DataType5 + policyLevel0.1Property1: + type: policy.data.DataType6 + policyLevel0.1V2Property2: + type: policy.data.DataType5 + onap.policies.PolicyTypeLevel0.1: + derived_from: onap.policies.PolicyTypeLevel0 + version: 3.0.0 + description: Level 0.1 policy type + properties: + policyLevel0.1Property0: + type: policy.data.DataType5 + policyLevel0.1Property1: + type: policy.data.DataType6 + policyLevel0.1V2Property2: + type: policy.data.DataType5 + policyLevel0.1V3Property3: + type: policy.data.DataType6 + onap.policies.PolicyTypeLevel0.1.2:1.0.0: + derived_from: onap.policies.PolicyTypeLevel0.1 + version: 1.0.0 + description: Level 0.1.2 policy type + properties: + policyLevel0.1.2Property0: + type: policy.data.DataType5 + policyLevel0.1.2Property1: + type: policy.data.DataType6 + onap.policies.PolicyTypeLevel0.1.2:2.0.0: + derived_from: onap.policies.PolicyTypeLevel0.1 + version: 2.0.0 + description: Level 0.1.2 policy type + properties: + policyLevel0.1.2Property0: + type: policy.data.DataType5 + policyLevel0.1.2Property1: + type: policy.data.DataType6 + policyLevel0.1.2V2Property2: + type: policy.data.DataType5 + onap.policies.PolicyTypeLevel0.1.2: + derived_from: onap.policies.PolicyTypeLevel0.1 + version: 3.0.0 + description: Level 0.1.2 policy type + properties: + policyLevel0.1.2Property0: + type: policy.data.DataType5 + policyLevel0.1.2Property1: + type: policy.data.DataType6 + policyLevel0.1.2V2Property2: + type: policy.data.DataType5 + policyLevel0.1.2V3Property3: + type: policy.data.DataType6 + onap.policies.PolicyTypeLevel0.1.2.3:1.0.0: + derived_from: onap.policies.PolicyTypeLevel0.1.2 + version: 1.0.0 + description: Level 0.1.2.3 policy type + properties: + policyLevel0.1.2.3Property0: + type: policy.data.DataType5 + policyLevel0.1.2.3Property1: + type: policy.data.DataType6 + onap.policies.PolicyTypeLevel0.1.2.3:2.0.0: + derived_from: onap.policies.PolicyTypeLevel0.1.2 + version: 2.0.0 + description: Level 0.1.2.3 policy type + properties: + policyLevel0.1.2.3Property0: + type: policy.data.DataType5 + policyLevel0.1.2.3Property1: + type: policy.data.DataType6 + policyLevel0.1.2.3V2Property2: + type: policy.data.DataType5 + onap.policies.PolicyTypeLevel0.1.2.3: + derived_from: onap.policies.PolicyTypeLevel0.1.2 + version: 3.0.0 + description: Level 0.1.2.3 policy type + properties: + policyLevel0.1.2.3Property0: + type: policy.data.DataType5 + policyLevel0.1.2.3Property1: + type: policy.data.DataType6 + policyLevel0.1.2.3V2Property2: + type: policy.data.DataType5 + policyLevel0.1.2.3V3Property3: + type: policy.data.DataType6 +data_types: + policy.data.DataType0: + derived_from: tosca.datatypes.Root + version: 1.0.0 + properties: + dataType0Property0: + type: policy.data.DataType2 + required: false + dataType0Property1: + type: list + required: true + entry_schema: + type: policy.data.DataType3 + policy.data.DataType1: + derived_from: tosca.datatypes.Root + version: 1.0.0 + properties: + dataType1Property0: + type: policy.data.DataType4 + required: false + dataType1Property1: + type: list + required: true + entry_schema: + type: policy.data.DataType5 + policy.data.DataType2: + derived_from: tosca.datatypes.Root + version: 1.0.0 + properties: + dataType2Property0: + type: string + required: false + dataType2Property1: + type: list + required: true + entry_schema: + type: integer + policy.data.DataType3: + derived_from: tosca.datatypes.Root + version: 1.0.0 + properties: + dataType3Property0: + type: string + required: false + policy.data.DataType4: + derived_from: tosca.datatypes.Root + version: 1.0.0 + properties: + dataType4Property0: + type: string + required: false + dataType4Property1: + type: list + required: true + entry_schema: + type: integer + policy.data.DataType5:1.0.0: + derived_from: tosca.datatypes.Root + version: 1.0.0 + properties: + dataType5Property0: + type: string + required: false + policy.data.DataType5:2.0.0: + derived_from: tosca.datatypes.Root + version: 2.0.0 + properties: + dataType5Property0: + type: string + required: false + dataType5V2Property1: + type: string + required: false + policy.data.DataType5: + derived_from: tosca.datatypes.Root + version: 3.0.0 + properties: + dataType5Property0: + type: string + required: false + dataType5V2Property1: + type: string + required: false + dataType5V2Property2: + type: integer + required: false + policy.data.DataType6:1.0.0: + derived_from: tosca.datatypes.Root + version: 1.0.0 + properties: + dataType6Property0: + type: integer + required: false + policy.data.DataType6: + derived_from: tosca.datatypes.Root + version: 2.0.0 + properties: + dataType6Property0: + type: integer + required: false + dataType6V2Property1: + type: integer + required: false +topology_template: + policies: + - onap.policies.PolicyLevel0: + type: onap.policies.PolicyTypeLevel0 + version: 1.0.0 + type_version: 1.0.0 + description: Level 0 policy + properties: + policyLevel0Property0: + dataType0Property0: + dataType2Property0: dataType2Property0 value + dataType2Property1: + - 123 + - 456 + - 789 + dataType0Property1: + - dataType3Property0: dataType3Property0 value 0 + - dataType3Property0: dataType3Property0 value 1 + - dataType3Property0: dataType3Property0 value 2 + - dataType3Property0: dataType3Property0 value 3 + policyLevel0Property1: + - dataType1Property0: + dataType4Property0: dataType4Property0 value + dataType4Property1: + - 123 + - 456 + - 789 + dataType1Property1: + - dataType5Property0: dataType5Property0 value 0 + - dataType5Property0: dataType5Property0 value 1 + - dataType5Property0: dataType5Property0 value 2 + - dataType5Property0: dataType5Property0 value 3 + - dataType1Property0: + dataType4Property0: dataType4Property0 value + dataType4Property1: + - 123 + - 456 + - 789 + dataType1Property1: + - dataType5Property0: dataType5Property0 value 0 + - dataType5Property0: dataType5Property0 value 1 + - dataType5Property0: dataType5Property0 value 2 + - dataType5Property0: dataType5Property0 value 3 + - onap.policies.PolicyLevel0.1: + type: onap.policies.PolicyTypeLevel0 + version: 1.0.0 + type_version: 1.0.0 + description: Level 0 policy + properties: + policyLevel0Property0: + dataType0Property0: + dataType2Property0: dataType2Property0 value + dataType2Property1: + - 123 + - 456 + - 789 + dataType0Property1: + - dataType3Property0: dataType3Property0 value 0 + - dataType3Property0: dataType3Property0 value 1 + - dataType3Property0: dataType3Property0 value 2 + - dataType3Property0: dataType3Property0 value 3 + policyLevel0Property1: + - dataType1Property0: + dataType4Property0: dataType4Property0 value + dataType4Property1: + - 123 + - 456 + - 789 + dataType1Property1: + - dataType5Property0: dataType5Property0 value 0 + - dataType5Property0: dataType5Property0 value 1 + - dataType5Property0: dataType5Property0 value 2 + - dataType5Property0: dataType5Property0 value 3 + - dataType1Property0: + dataType4Property0: dataType4Property0 value + dataType4Property1: + - 123 + - 456 + - 789 + dataType1Property1: + - dataType5Property0: dataType5Property0 value 0 + - dataType5Property0: dataType5Property0 value 1 + - dataType5Property0: dataType5Property0 value 2 + - dataType5Property0: dataType5Property0 value 3 + policyLevel0.1Property0: policyLevel0.1Property0 value + policyLevel0.1Property1: 123 + - onap.policies.PolicyLevel0.1.2: + type: onap.policies.PolicyTypeLevel0 + version: 1.0.0 + type_version: 1.0.0 + description: Level 0 policy + properties: + policyLevel0Property0: + dataType0Property0: + dataType2Property0: dataType2Property0 value + dataType2Property1: + - 123 + - 456 + - 789 + dataType0Property1: + - dataType3Property0: dataType3Property0 value 0 + - dataType3Property0: dataType3Property0 value 1 + - dataType3Property0: dataType3Property0 value 2 + - dataType3Property0: dataType3Property0 value 3 + policyLevel0Property1: + - dataType1Property0: + dataType4Property0: dataType4Property0 value + dataType4Property1: + - 123 + - 456 + - 789 + dataType1Property1: + - dataType5Property0: dataType5Property0 value 0 + - dataType5Property0: dataType5Property0 value 1 + - dataType5Property0: dataType5Property0 value 2 + - dataType5Property0: dataType5Property0 value 3 + - dataType1Property0: + dataType4Property0: dataType4Property0 value + dataType4Property1: + - 123 + - 456 + - 789 + dataType1Property1: + - dataType5Property0: dataType5Property0 value 0 + - dataType5Property0: dataType5Property0 value 1 + - dataType5Property0: dataType5Property0 value 2 + - dataType5Property0: dataType5Property0 value 3 + policyLevel0.1Property0: policyLevel0.1Property0 value + policyLevel0.1Property1: 123 + policyLevel0.1.2Property0: policyLevel0.1.2Property0 value + policyLevel0.1.2Property1: 456 + - onap.policies.PolicyLevel0.1.2.3: + type: onap.policies.PolicyTypeLevel0 + version: 1.0.0 + type_version: 1.0.0 + description: Level 0 policy + properties: + policyLevel0Property0: + dataType0Property0: + dataType2Property0: dataType2Property0 value + dataType2Property1: + - 123 + - 456 + - 789 + dataType0Property1: + - dataType3Property0: dataType3Property0 value 0 + - dataType3Property0: dataType3Property0 value 1 + - dataType3Property0: dataType3Property0 value 2 + - dataType3Property0: dataType3Property0 value 3 + policyLevel0Property1: + - dataType1Property0: + dataType4Property0: dataType4Property0 value + dataType4Property1: + - 123 + - 456 + - 789 + dataType1Property1: + - dataType5Property0: dataType5Property0 value 0 + - dataType5Property0: dataType5Property0 value 1 + - dataType5Property0: dataType5Property0 value 2 + - dataType5Property0: dataType5Property0 value 3 + - dataType1Property0: + dataType4Property0: dataType4Property0 value + dataType4Property1: + - 123 + - 456 + - 789 + dataType1Property1: + - dataType5Property0: dataType5Property0 value 0 + - dataType5Property0: dataType5Property0 value 1 + - dataType5Property0: dataType5Property0 value 2 + - dataType5Property0: dataType5Property0 value 3 + policyLevel0.1Property0: policyLevel0.1Property0 value + policyLevel0.1Property1: 123 + policyLevel0.1.2Property0: policyLevel0.1.2Property0 value + policyLevel0.1.2Property1: 456 + policyLevel0.1.2.3Property0: policyLevel0.1.2.3Property0 value + policyLevel0.1.2.3Property1: 456 diff --git a/models-sim/models-sim-dmaap/src/main/resources/etc/ssl/policy-keystore b/models-sim/models-sim-dmaap/src/main/resources/etc/ssl/policy-keystore Binary files differindex 144caf252..389df5fe5 100644 --- a/models-sim/models-sim-dmaap/src/main/resources/etc/ssl/policy-keystore +++ b/models-sim/models-sim-dmaap/src/main/resources/etc/ssl/policy-keystore diff --git a/models-sim/policy-models-sim-pdp/src/main/resources/ssl/policy-keystore b/models-sim/policy-models-sim-pdp/src/main/resources/ssl/policy-keystore Binary files differindex 144caf252..389df5fe5 100644 --- a/models-sim/policy-models-sim-pdp/src/main/resources/ssl/policy-keystore +++ b/models-sim/policy-models-sim-pdp/src/main/resources/ssl/policy-keystore diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java index 65cce48db..a4a6e5942 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java @@ -66,7 +66,7 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting policy types */ public ToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, final String name, final String version) - throws PfModelException { + throws PfModelException { LOGGER.debug("->getPolicyTypes: name={}, version={}", name, version); @@ -88,15 +88,15 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting policy types */ public List<ToscaPolicyType> getPolicyTypeList(@NonNull final PfDao dao, final String name, final String version) - throws PfModelException { + throws PfModelException { LOGGER.debug("->getPolicyTypeList: name={}, version={}", name, version); List<ToscaPolicyType> policyTypeList; try { - policyTypeList = new ArrayList<>(new SimpleToscaProvider().getPolicyTypes(dao, name, version) - .toAuthorative().getPolicyTypes().values()); + policyTypeList = new ArrayList<>( + new SimpleToscaProvider().getPolicyTypes(dao, name, version).toAuthorative().getPolicyTypes().values()); } catch (PfModelRuntimeException pfme) { return handlePfModelRuntimeException(pfme); } @@ -114,36 +114,36 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting policy types */ public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final PfDao dao, - @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException { + @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException { LOGGER.debug("->getFilteredPolicyTypes: filter={}", filter); SimpleToscaProvider simpleToscaProvider = new SimpleToscaProvider(); final JpaToscaServiceTemplate dbServiceTemplate = simpleToscaProvider.getPolicyTypes(dao, null, null); - List<ToscaPolicyType> filteredPolicyTypes = - new ArrayList<>(dbServiceTemplate.toAuthorative().getPolicyTypes().values()); + List<ToscaPolicyType> filteredPolicyTypes = dbServiceTemplate.getPolicyTypes().toAuthorativeList(); filteredPolicyTypes = filter.filter(filteredPolicyTypes); if (CollectionUtils.isEmpty(filteredPolicyTypes)) { throw new PfModelRuntimeException(Response.Status.NOT_FOUND, - "policy types for filter " + filter.toString() + " do not exist"); + "policy types for filter " + filter.toString() + " do not exist"); } JpaToscaServiceTemplate filteredServiceTemplate = new JpaToscaServiceTemplate(); for (ToscaPolicyType policyType : filteredPolicyTypes) { JpaToscaServiceTemplate cascadedServiceTemplate = simpleToscaProvider - .getCascadedPolicyTypes(dbServiceTemplate, policyType.getName(), policyType.getVersion()); + .getCascadedPolicyTypes(dbServiceTemplate, policyType.getName(), policyType.getVersion()); filteredServiceTemplate = - ToscaServiceTemplateUtils.addFragment(filteredServiceTemplate, cascadedServiceTemplate); + ToscaServiceTemplateUtils.addFragment(filteredServiceTemplate, cascadedServiceTemplate); } ToscaServiceTemplate returnServiceTemplate = filteredServiceTemplate.toAuthorative(); LOGGER.debug("<-getFilteredPolicyTypes: filter={}, serviceTemplate={}", filter, returnServiceTemplate); return returnServiceTemplate; + } /** @@ -155,14 +155,14 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting policy types */ public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final PfDao dao, - @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException { + @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException { LOGGER.debug("->getFilteredPolicyTypeList: filter={}", filter); List<ToscaPolicyType> filteredPolicyTypeList = filter.filter(getPolicyTypeList(dao, null, null)); LOGGER.debug("<-getFilteredPolicyTypeList: filter={}, filteredPolicyTypeList={}", filter, - filteredPolicyTypeList); + filteredPolicyTypeList); return filteredPolicyTypeList; } @@ -176,12 +176,12 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors creating policy types */ public ToscaServiceTemplate createPolicyTypes(@NonNull final PfDao dao, - @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { + @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { LOGGER.debug("->createPolicyTypes: serviceTemplate={}", serviceTemplate); ToscaServiceTemplate createdServiceTempalate = new SimpleToscaProvider() - .createPolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); + .createPolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); LOGGER.debug("<-createPolicyTypes: createdServiceTempalate={}", createdServiceTempalate); return createdServiceTempalate; @@ -196,12 +196,12 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors updating policy types */ public ToscaServiceTemplate updatePolicyTypes(@NonNull final PfDao dao, - @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { + @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { LOGGER.debug("->updatePolicyTypes: serviceTempalate={}", serviceTemplate); ToscaServiceTemplate updatedServiceTempalate = new SimpleToscaProvider() - .updatePolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); + .updatePolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); LOGGER.debug("<-updatePolicyTypes: updatedServiceTempalate={}", updatedServiceTempalate); return updatedServiceTempalate; @@ -217,15 +217,15 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors deleting policy types */ public ToscaServiceTemplate deletePolicyType(@NonNull final PfDao dao, @NonNull final String name, - @NonNull final String version) throws PfModelException { + @NonNull final String version) throws PfModelException { LOGGER.debug("->deletePolicyType: name={}, version={}", name, version); ToscaServiceTemplate deletedServiceTempalate = - new SimpleToscaProvider().deletePolicyType(dao, new PfConceptKey(name, version)).toAuthorative(); + new SimpleToscaProvider().deletePolicyType(dao, new PfConceptKey(name, version)).toAuthorative(); LOGGER.debug("<-deletePolicyType: name={}, version={}, deletedServiceTempalate={}", name, version, - deletedServiceTempalate); + deletedServiceTempalate); return deletedServiceTempalate; } @@ -239,11 +239,11 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting policies */ public ToscaServiceTemplate getPolicies(@NonNull final PfDao dao, final String name, final String version) - throws PfModelException { + throws PfModelException { LOGGER.debug("->getPolicies: name={}, version={}", name, version); ToscaServiceTemplate gotServiceTempalate = - new SimpleToscaProvider().getPolicies(dao, name, version).toAuthorative(); + new SimpleToscaProvider().getPolicies(dao, name, version).toAuthorative(); LOGGER.debug("<-getPolicies: name={}, version={}, gotServiceTempalate={}", name, version, gotServiceTempalate); return gotServiceTempalate; @@ -259,14 +259,14 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting policies */ public List<ToscaPolicy> getPolicyList(@NonNull final PfDao dao, final String name, final String version) - throws PfModelException { + throws PfModelException { LOGGER.debug("->getPolicyList: name={}, version={}", name, version); List<ToscaPolicy> policyList; try { policyList = asConceptList(new SimpleToscaProvider().getPolicies(dao, name, version).toAuthorative() - .getToscaTopologyTemplate().getPolicies()); + .getToscaTopologyTemplate().getPolicies()); } catch (PfModelRuntimeException pfme) { return handlePfModelRuntimeException(pfme); } @@ -284,32 +284,31 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting policies */ public ToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter) - throws PfModelException { + throws PfModelException { LOGGER.debug("->getFilteredPolicies: filter={}", filter); String version = ToscaPolicyFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion(); SimpleToscaProvider simpleToscaProvider = new SimpleToscaProvider(); final JpaToscaServiceTemplate dbServiceTemplate = - simpleToscaProvider.getPolicies(dao, filter.getName(), version); + simpleToscaProvider.getPolicies(dao, filter.getName(), version); - List<ToscaPolicy> filteredPolicies = - asConceptList(dbServiceTemplate.toAuthorative().getToscaTopologyTemplate().getPolicies()); + List<ToscaPolicy> filteredPolicies = dbServiceTemplate.getTopologyTemplate().getPolicies().toAuthorativeList(); filteredPolicies = filter.filter(filteredPolicies); if (CollectionUtils.isEmpty(filteredPolicies)) { throw new PfModelRuntimeException(Response.Status.NOT_FOUND, - "policies for filter " + filter.toString() + " do not exist"); + "policies for filter " + filter.toString() + " do not exist"); } JpaToscaServiceTemplate filteredServiceTemplate = new JpaToscaServiceTemplate(); for (ToscaPolicy policy : filteredPolicies) { JpaToscaServiceTemplate cascadedServiceTemplate = - simpleToscaProvider.getCascadedPolicies(dbServiceTemplate, policy.getName(), policy.getVersion()); + simpleToscaProvider.getCascadedPolicies(dbServiceTemplate, policy.getName(), policy.getVersion()); filteredServiceTemplate = - ToscaServiceTemplateUtils.addFragment(filteredServiceTemplate, cascadedServiceTemplate); + ToscaServiceTemplateUtils.addFragment(filteredServiceTemplate, cascadedServiceTemplate); } ToscaServiceTemplate returnServiceTemplate = filteredServiceTemplate.toAuthorative(); @@ -327,7 +326,7 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting policies */ public List<ToscaPolicy> getFilteredPolicyList(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter) - throws PfModelException { + throws PfModelException { LOGGER.debug("->getFilteredPolicyList: filter={}", filter); String version = ToscaPolicyFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion(); @@ -347,12 +346,12 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors creating policies */ public ToscaServiceTemplate createPolicies(@NonNull final PfDao dao, - @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { + @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { LOGGER.debug("->createPolicies: serviceTempalate={}", serviceTemplate); - ToscaServiceTemplate createdServiceTempalate = new SimpleToscaProvider() - .createPolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); + ToscaServiceTemplate createdServiceTempalate = + new SimpleToscaProvider().createPolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); LOGGER.debug("<-createPolicies: createdServiceTempalate={}", createdServiceTempalate); return createdServiceTempalate; @@ -367,12 +366,12 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors updating policies */ public ToscaServiceTemplate updatePolicies(@NonNull final PfDao dao, - @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { + @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { LOGGER.debug("->updatePolicies: serviceTempalate={}", serviceTemplate); - ToscaServiceTemplate updatedServiceTempalate = new SimpleToscaProvider() - .updatePolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); + ToscaServiceTemplate updatedServiceTempalate = + new SimpleToscaProvider().updatePolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative(); LOGGER.debug("<-updatePolicies: updatedServiceTempalate={}", updatedServiceTempalate); return updatedServiceTempalate; @@ -388,15 +387,15 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors deleting policies */ public ToscaServiceTemplate deletePolicy(@NonNull final PfDao dao, @NonNull final String name, - @NonNull final String version) throws PfModelException { + @NonNull final String version) throws PfModelException { LOGGER.debug("->deletePolicy: name={}, version={}", name, version); ToscaServiceTemplate deletedServiceTempalate = - new SimpleToscaProvider().deletePolicy(dao, new PfConceptKey(name, version)).toAuthorative(); + new SimpleToscaProvider().deletePolicy(dao, new PfConceptKey(name, version)).toAuthorative(); LOGGER.debug("<-deletePolicy: name={}, version={}, deletedServiceTempalate={}", name, version, - deletedServiceTempalate); + deletedServiceTempalate); return deletedServiceTempalate; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogical.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogical.java index 41cd1c274..b98775167 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogical.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogical.java @@ -65,6 +65,7 @@ public class JpaToscaConstraintLogical extends JpaToscaConstraint { * * @param authorativeConcept the authorative concept to copy from */ + @SuppressWarnings("java:S2637") public JpaToscaConstraintLogical(final ToscaConstraint authorativeConcept) { super(authorativeConcept); } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintValidValues.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintValidValues.java index 664855e42..a96ae4623 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintValidValues.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintValidValues.java @@ -63,6 +63,7 @@ public class JpaToscaConstraintValidValues extends JpaToscaConstraint { * * @param authorativeConcept the authorative concept to copy from */ + @SuppressWarnings("java:S2637") public JpaToscaConstraintValidValues(final ToscaConstraint authorativeConcept) { super(authorativeConcept); } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java index 3f2ebe797..772fb9ee0 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java @@ -24,8 +24,11 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.function.Function; + import javax.ws.rs.core.Response; + import lombok.NonNull; + import org.apache.commons.collections4.CollectionUtils; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptContainer; @@ -142,7 +145,7 @@ public final class ToscaUtils { * @param serviceTemplate the service template containing policy types to be checked */ public static void assertExist(final JpaToscaServiceTemplate serviceTemplate, - final Function<JpaToscaServiceTemplate, String> checkerFunction) { + final Function<JpaToscaServiceTemplate, String> checkerFunction) { String message = checkerFunction.apply(serviceTemplate); if (message != null) { throw new PfModelRuntimeException(Response.Status.NOT_FOUND, message); @@ -155,7 +158,7 @@ public final class ToscaUtils { * @param serviceTemplate the service template containing policy types to be checked */ public static boolean doExist(final JpaToscaServiceTemplate serviceTemplate, - final Function<JpaToscaServiceTemplate, String> checkerFunction) { + final Function<JpaToscaServiceTemplate, String> checkerFunction) { return checkerFunction.apply(serviceTemplate) == null; } @@ -217,8 +220,8 @@ public final class ToscaUtils { * @return the entity set containing the ancestors of the incoming entity */ public static Collection<JpaToscaEntityType<ToscaEntity>> getEntityTypeAncestors( - @NonNull PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes, - @NonNull JpaToscaEntityType<?> entityType, @NonNull final PfValidationResult result) { + @NonNull PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes, + @NonNull JpaToscaEntityType<?> entityType, @NonNull final PfValidationResult result) { PfConceptKey parentEntityTypeKey = entityType.getDerivedFrom(); if (parentEntityTypeKey == null || parentEntityTypeKey.getName().endsWith(ROOT_KEY_NAME_SUFFIX)) { @@ -227,17 +230,17 @@ public final class ToscaUtils { if (entityType.getKey().equals(parentEntityTypeKey)) { result.addValidationMessage(new PfValidationMessage(entityType.getKey(), ToscaUtils.class, - ValidationResult.INVALID, "entity cannot be an ancestor of itself")); + ValidationResult.INVALID, "entity cannot be an ancestor of itself")); throw new PfModelRuntimeException(Response.Status.CONFLICT, result.toString()); } @SuppressWarnings("unchecked") Set<JpaToscaEntityType<ToscaEntity>> ancestorEntitySet = (Set<JpaToscaEntityType<ToscaEntity>>) entityTypes - .getAll(parentEntityTypeKey.getName(), parentEntityTypeKey.getVersion()); + .getAll(parentEntityTypeKey.getName(), parentEntityTypeKey.getVersion()); Set<JpaToscaEntityType<ToscaEntity>> ancestorEntitySetToReturn = new HashSet<>(ancestorEntitySet); if (ancestorEntitySet.isEmpty()) { result.addValidationMessage(new PfValidationMessage(entityType.getKey(), ToscaUtils.class, - ValidationResult.INVALID, "parent " + parentEntityTypeKey.getId() + " of entity not found")); + ValidationResult.INVALID, "parent " + parentEntityTypeKey.getId() + " of entity not found")); } else { for (JpaToscaEntityType<?> filteredEntityType : ancestorEntitySet) { ancestorEntitySetToReturn.addAll(getEntityTypeAncestors(entityTypes, filteredEntityType, result)); @@ -254,14 +257,14 @@ public final class ToscaUtils { * @param entityVersion the version of the entity */ public static void getEntityTree( - @NonNull final PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes, - final String entityName, final String entityVersion) { + @NonNull final PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes, + final String entityName, final String entityVersion) { PfValidationResult result = new PfValidationResult(); @SuppressWarnings("unchecked") Set<JpaToscaEntityType<?>> filteredEntitySet = - (Set<JpaToscaEntityType<?>>) entityTypes.getAll(entityName, entityVersion); + (Set<JpaToscaEntityType<?>>) entityTypes.getAllNamesAndVersions(entityName, entityVersion); Set<JpaToscaEntityType<?>> filteredEntitySetToReturn = new HashSet<>(filteredEntitySet); for (JpaToscaEntityType<?> filteredEntityType : filteredEntitySet) { filteredEntitySetToReturn @@ -273,6 +276,6 @@ public final class ToscaUtils { } entityTypes.getConceptMap().entrySet() - .removeIf(entityEntry -> !filteredEntitySetToReturn.contains(entityEntry.getValue())); + .removeIf(entityEntry -> !filteredEntitySetToReturn.contains(entityEntry.getValue())); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java index 4937c5cca..f2da23c02 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java @@ -118,7 +118,7 @@ public class SimpleToscaProviderTest { serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); assertEquals(1, createdServiceTemplate.getDataTypes().getConceptMap().size()); assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key)); @@ -127,19 +127,19 @@ public class SimpleToscaProviderTest { dataType0.setDescription("Updated Description"); JpaToscaServiceTemplate updatedServiceTemplate = - new SimpleToscaProvider().updateDataTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().updateDataTypes(pfDao, serviceTemplate); assertEquals(dataType0, updatedServiceTemplate.getDataTypes().get(dataType0Key)); assertEquals("Updated Description", updatedServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); JpaToscaServiceTemplate gotServiceTemplate = - new SimpleToscaProvider().getDataTypes(pfDao, dataType0Key.getName(), dataType0Key.getVersion()); + new SimpleToscaProvider().getDataTypes(pfDao, dataType0Key.getName(), dataType0Key.getVersion()); assertEquals(dataType0, gotServiceTemplate.getDataTypes().get(dataType0Key)); assertEquals("Updated Description", gotServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, new PfConceptKey("IDontExist:0.0.1"))) - .hasMessage("data type IDontExist:0.0.1 not found"); + .hasMessage("data type IDontExist:0.0.1 not found"); JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key); @@ -160,7 +160,7 @@ public class SimpleToscaProviderTest { assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key)) - .hasMessage("no data types found"); + .hasMessage("no data types found"); // Create the data type again new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); @@ -173,7 +173,7 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().createPolicyTypes(pfDao, updatedServiceTemplate); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key)) - .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2"); + .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2"); JpaToscaDataType dataType0v2 = new JpaToscaDataType(new PfConceptKey("DataType0:0.0.2")); updatedServiceTemplate.getDataTypes().getConceptMap().put(dataType0v2.getKey(), dataType0v2); @@ -185,7 +185,7 @@ public class SimpleToscaProviderTest { assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key)) - .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2"); + .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2"); JpaToscaDataType dataType1 = new JpaToscaDataType(new PfConceptKey("DataType1:0.0.3")); JpaToscaProperty prop1 = new JpaToscaProperty(new PfReferenceKey(dataType1.getKey(), "prop1")); @@ -195,7 +195,7 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().createDataTypes(pfDao, updatedServiceTemplate); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0v2.getKey())) - .hasMessage("data type DataType0:0.0.2 is in use, it is referenced in data type DataType1:0.0.3"); + .hasMessage("data type DataType0:0.0.2 is in use, it is referenced in data type DataType1:0.0.3"); } @Test @@ -215,7 +215,7 @@ public class SimpleToscaProviderTest { serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); assertEquals(1, createdServiceTemplate.getPolicyTypes().getConceptMap().size()); assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key)); @@ -224,14 +224,14 @@ public class SimpleToscaProviderTest { policyType0.setDescription("Updated Description"); JpaToscaServiceTemplate updatedServiceTemplate = - new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", - updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); JpaToscaServiceTemplate gotServiceTemplate = - new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion()); + new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion()); assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); @@ -246,7 +246,7 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key)) - .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2"); + .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2"); serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); @@ -261,10 +261,10 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key)) - .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2"); + .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2"); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, pt1.getKey())) - .hasMessage("policy type pt1:0.0.2 is in use, it is referenced in policy p1:0.0.1"); + .hasMessage("policy type pt1:0.0.2 is in use, it is referenced in policy p1:0.0.1"); new SimpleToscaProvider().deletePolicy(pfDao, p1.getKey()); @@ -273,14 +273,14 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().deletePolicy(pfDao, p0.getKey()); JpaToscaServiceTemplate deletedServiceTemplate = - new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key); + new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key); assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", - deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key)) - .hasMessage("no policy types found"); + .hasMessage("no policy types found"); } @Test @@ -294,7 +294,7 @@ public class SimpleToscaProviderTest { serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals(null, createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); @@ -302,33 +302,33 @@ public class SimpleToscaProviderTest { policyType0.setDescription("Updated Description"); JpaToscaServiceTemplate updatedServiceTemplate = - new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", - updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); JpaToscaServiceTemplate gotServiceTemplate = - new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion()); + new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion()); assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); JpaToscaServiceTemplate deletedServiceTemplate = - new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key); + new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key); assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", - deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key)) - .hasMessage("no policy types found"); + .hasMessage("no policy types found"); } @Test public void testPoliciesGet() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -337,18 +337,18 @@ public class SimpleToscaProviderTest { assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(), - createdServiceTemplate.getTopologyTemplate().getPolicies()); + createdServiceTemplate.getTopologyTemplate().getPolicies()); PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); JpaToscaServiceTemplate gotServiceTemplate = - new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); + new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey), - gotServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey)); + gotServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey)); JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, policyKey); assertEquals(1, deletedServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().size()); @@ -357,7 +357,7 @@ public class SimpleToscaProviderTest { @Test public void testPolicyCreate() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -366,16 +366,16 @@ public class SimpleToscaProviderTest { assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(), - createdServiceTemplate.getTopologyTemplate().getPolicies()); + createdServiceTemplate.getTopologyTemplate().getPolicies()); } @Test public void testPolicyUpdate() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -384,7 +384,7 @@ public class SimpleToscaProviderTest { assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate updatedServiceTemplate = - new SimpleToscaProvider().updatePolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().updatePolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate, updatedServiceTemplate); } @@ -392,7 +392,7 @@ public class SimpleToscaProviderTest { @Test public void testPoliciesDelete() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -401,26 +401,26 @@ public class SimpleToscaProviderTest { assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate.getTopologyTemplate(), createdServiceTemplate.getTopologyTemplate()); PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, new PfConceptKey("IDontExist:0.0.1"))) - .hasMessage("policy IDontExist:0.0.1 not found"); + .hasMessage("policy IDontExist:0.0.1 not found"); JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, policyKey); assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey), - deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey)); + deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey)); assertThatThrownBy(() -> { new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); }).hasMessage("policies for onap.restart.tca:1.0.0 do not exist"); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, policyKey)) - .hasMessage("no policies found"); + .hasMessage("no policies found"); } @Test @@ -428,21 +428,21 @@ public class SimpleToscaProviderTest { JpaToscaServiceTemplate testServiceTemplate = new JpaToscaServiceTemplate(); assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate)) - .hasMessage("topology template not specified on service template"); + .hasMessage("topology template not specified on service template"); testServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate)) - .hasMessage("no policies specified on topology template of service template"); + .hasMessage("no policies specified on topology template of service template"); testServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate)) - .hasMessage("list of policies specified on topology template of service template is empty"); + .hasMessage("list of policies specified on topology template of service template is empty"); } @Test public void testGetServiceTemplate() throws PfModelException { assertThatThrownBy(() -> new SimpleToscaProvider().getServiceTemplate(pfDao)) - .hasMessage("service template not found in database"); + .hasMessage("service template not found in database"); } @Test @@ -453,8 +453,8 @@ public class SimpleToscaProviderTest { serviceTemplateFragment.getPolicyTypes().getConceptMap().put(badPt.getKey(), badPt); assertThatThrownBy(() -> new SimpleToscaProvider().appendToServiceTemplate(pfDao, serviceTemplateFragment)) - .hasMessageContaining( - "key on concept entry PfConceptKey(name=NULL, version=0.0.0) may not be the null key"); + .hasMessageContaining( + "key on concept entry PfConceptKey(name=NULL, version=0.0.0) may not be the null key"); } @Test @@ -500,7 +500,7 @@ public class SimpleToscaProviderTest { serviceTemplate.getDataTypes().getConceptMap().put(p02.getKey(), p02); new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); - gotSt = new SimpleToscaProvider().getDataTypes(pfDao, p01.getName(), p01.getVersion()); + gotSt = new SimpleToscaProvider().getDataTypes(pfDao, p01.getName(), null); assertEquals(p01, gotSt.getDataTypes().get(p01.getKey())); assertEquals(p02, gotSt.getDataTypes().get(p01.getName())); @@ -542,7 +542,7 @@ public class SimpleToscaProviderTest { }).hasMessageMatching("policy types for hello:0.0.1 do not exist"); JpaToscaServiceTemplate gotSt = - new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion()); + new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion()); assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getKey())); assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getName())); @@ -557,7 +557,7 @@ public class SimpleToscaProviderTest { serviceTemplate.getPolicyTypes().getConceptMap().put(pt02.getKey(), pt02); new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); - gotSt = new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion()); + gotSt = new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), null); assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getKey())); assertEquals(pt02, gotSt.getPolicyTypes().get(pt01.getName())); @@ -621,7 +621,7 @@ public class SimpleToscaProviderTest { serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(p02.getKey(), p02); new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate); - gotSt = new SimpleToscaProvider().getPolicies(pfDao, p01.getName(), p01.getVersion()); + gotSt = new SimpleToscaProvider().getPolicies(pfDao, p01.getName(), null); assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getKey())); assertEquals(p02, gotSt.getTopologyTemplate().getPolicies().get(p01.getName())); @@ -774,12 +774,12 @@ public class SimpleToscaProviderTest { } private void createPolicyTypes() throws CoderException, PfModelException { - Object yamlObject = new Yaml().load( - ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml")); + Object yamlObject = new Yaml() + .load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml")); String yamlAsJsonString = new StandardCoder().encode(yamlObject); ToscaServiceTemplate toscaServiceTemplatePolicyType = - standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); + standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplatePolicyType); new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType); |