From 59b90519eda3b95b0cfc49b6349a591c7d0c78e2 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 7 Feb 2022 17:56:44 +0000 Subject: Remove JAXB and XML, use GSON for JSON This review converst apex-pdp to use GSON for JSON handling. In order to preserve backward compatibility with the JAXB format of JSON, custom handling of maps was required. Therefore, the policy-common StandardCoder could not be used. There are a lot of small changes, removing annotations from concepts and tweaking of test data. However, this cleans up the code base so it is worth doing. Issue-ID: POLICY-1820 Change-Id: I213fa64f6d7f3f1df8d10f111d9fbedbe80f9fe0 Signed-off-by: liamfallon --- model/basic-model/pom.xml | 39 +- .../model/basicmodel/concepts/AxArtifactKey.java | 14 - .../apex/model/basicmodel/concepts/AxConcept.java | 12 +- .../apex/model/basicmodel/concepts/AxKeyInfo.java | 17 +- .../basicmodel/concepts/AxKeyInformation.java | 37 +- .../apex/model/basicmodel/concepts/AxModel.java | 19 - .../model/basicmodel/concepts/AxReferenceKey.java | 134 +- .../model/basicmodel/concepts/package-info.java | 9 +- .../handling/ApexModelCustomGsonMapAdapter.java | 118 + .../ApexModelCustomGsonRefereceKeyAdapter.java | 50 + .../basicmodel/handling/ApexModelFileWriter.java | 58 +- .../model/basicmodel/handling/ApexModelReader.java | 157 +- .../model/basicmodel/handling/ApexModelSaver.java | 21 +- .../basicmodel/handling/ApexModelStringWriter.java | 71 +- .../model/basicmodel/handling/ApexModelWriter.java | 216 +- .../basicmodel/handling/ApexSchemaGenerator.java | 161 - .../basicmodel/handling/KeyInfoMarshalFilter.java | 104 - .../model/basicmodel/handling/package-info.java | 17 +- .../policy/apex/model/basicmodel/package-info.java | 4 +- .../apex/model/basicmodel/test/TestApexModel.java | 54 +- .../basicmodel/xml/AxReferenceKeyAdapter.java | 58 - .../apex/model/basicmodel/xml/package-info.java | 34 - .../basic-model/src/main/resources/xml/example.xsd | 100 - .../model/basicmodel/concepts/DummyEntity.java | 6 - .../handling/ApexModelFileWriterTest.java | 34 +- .../basicmodel/handling/ApexModelReaderTest.java | 77 +- .../basicmodel/handling/ApexModelSaverTest.java | 8 +- .../handling/ApexModelStringWriterTest.java | 29 +- .../basicmodel/handling/ApexModelWriterTest.java | 108 +- .../handling/ApexSchemaGeneratorTest.java | 95 - .../handling/SupportApexBasicModelTest.java | 5 - .../basicmodel/handling/SupportBasicModelTest.java | 8 +- .../handling/SupportConceptGetterTest.java | 24 +- .../basicmodel/xml/AxReferenceKeyAdapterTest.java | 42 - model/context-model/pom.xml | 27 +- .../contextmodel/concepts/AxContextAlbum.java | 15 - .../contextmodel/concepts/AxContextAlbums.java | 39 +- .../contextmodel/concepts/AxContextModel.java | 14 - .../contextmodel/concepts/AxContextSchema.java | 15 - .../contextmodel/concepts/AxContextSchemas.java | 62 +- .../handling/ApexContextModelTest.java | 5 - .../src/test/resources/json/ContextModel.json | 156 - model/engine-model/pom.xml | 29 +- .../model/enginemodel/concepts/AxEngineModel.java | 13 - .../model/enginemodel/concepts/AxEngineState.java | 9 +- .../model/enginemodel/concepts/AxEngineStats.java | 22 - .../model/enginemodel/concepts/package-info.java | 16 +- .../enginemodel/handling/ApexEngineModelTest.java | 5 - model/event-model/pom.xml | 27 +- .../apex/model/eventmodel/concepts/AxEvent.java | 32 +- .../model/eventmodel/concepts/AxEventModel.java | 13 - .../apex/model/eventmodel/concepts/AxEvents.java | 35 +- .../apex/model/eventmodel/concepts/AxField.java | 18 - .../model/eventmodel/concepts/AxInputField.java | 8 - .../model/eventmodel/concepts/AxOutputField.java | 8 - .../model/eventmodel/concepts/package-info.java | 9 +- .../apex/model/eventmodel/concepts/EventsTest.java | 58 +- .../eventmodel/handling/ApexEventModelTest.java | 5 - .../policy/apex/model/modelapi/ApexApiResult.java | 17 +- .../onap/policy/apex/model/modelapi/ApexModel.java | 6 +- .../apex/model/modelapi/ApexModelFactory.java | 13 +- .../apex/model/modelapi/impl/ApexModelImpl.java | 55 +- .../model/modelapi/impl/ContextAlbumFacade.java | 62 +- .../model/modelapi/impl/ContextSchemaFacade.java | 47 +- .../apex/model/modelapi/impl/EventFacade.java | 78 +- .../model/modelapi/impl/KeyInformationFacade.java | 34 +- .../apex/model/modelapi/impl/ModelFacade.java | 29 +- .../model/modelapi/impl/ModelHandlerFacade.java | 34 +- .../apex/model/modelapi/impl/PolicyFacade.java | 353 ++- .../apex/model/modelapi/impl/TaskFacade.java | 126 +- .../modelapi/ApexEditorApiContextAlbumTest.java | 26 +- .../modelapi/ApexEditorApiContextSchemaTest.java | 4 +- .../model/modelapi/ApexEditorApiEventTest.java | 29 +- .../model/modelapi/ApexEditorApiKeyInfoTest.java | 4 +- .../model/modelapi/ApexEditorApiPolicyTest.java | 179 +- .../apex/model/modelapi/ApexEditorApiTaskTest.java | 19 +- .../apex/model/modelapi/ApexModelApiTest.java | 51 +- .../apex/model/modelapi/ModelFacadeTest.java | 11 +- .../model/modelapi/ModelHandlerFacadeTest.java | 10 +- .../policy/apex/model/modelapi/RealModelTest.java | 46 + .../src/test/resources/models/PolicyModel.json | 1465 +++++----- .../src/test/resources/models/PolicyModel.xml | 697 ----- .../src/test/resources/models/RealPolicyModel.json | 3076 ++++++++++++++++++++ model/policy-model/pom.xml | 27 +- .../apex/model/policymodel/concepts/AxLogic.java | 19 - .../model/policymodel/concepts/AxPolicies.java | 60 +- .../apex/model/policymodel/concepts/AxPolicy.java | 120 +- .../model/policymodel/concepts/AxPolicyModel.java | 100 +- .../apex/model/policymodel/concepts/AxState.java | 54 +- .../concepts/AxStateFinalizerLogic.java | 8 - .../model/policymodel/concepts/AxStateOutput.java | 16 +- .../concepts/AxStateTaskOutputType.java | 14 +- .../policymodel/concepts/AxStateTaskReference.java | 16 - .../apex/model/policymodel/concepts/AxTask.java | 41 +- .../model/policymodel/concepts/AxTaskLogic.java | 8 - .../policymodel/concepts/AxTaskParameter.java | 14 - .../policymodel/concepts/AxTaskSelectionLogic.java | 8 - .../apex/model/policymodel/concepts/AxTasks.java | 53 +- .../model/policymodel/concepts/package-info.java | 17 +- .../policymodel/handling/EmptyAlbumsAdapter.java | 91 - .../model/policymodel/concepts/PoliciesTest.java | 13 +- .../apex/model/policymodel/concepts/StateTest.java | 10 +- .../apex/model/policymodel/concepts/TasksTest.java | 11 +- .../policymodel/handling/ApexPolicyModelTest.java | 5 - 104 files changed, 5110 insertions(+), 4646 deletions(-) create mode 100644 model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonMapAdapter.java create mode 100644 model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonRefereceKeyAdapter.java delete mode 100644 model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java delete mode 100644 model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/KeyInfoMarshalFilter.java delete mode 100644 model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapter.java delete mode 100644 model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/package-info.java delete mode 100644 model/basic-model/src/main/resources/xml/example.xsd delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java delete mode 100644 model/context-model/src/test/resources/json/ContextModel.json create mode 100644 model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/RealModelTest.java delete mode 100644 model/model-api/src/test/resources/models/PolicyModel.xml create mode 100644 model/model-api/src/test/resources/models/RealPolicyModel.json delete mode 100644 model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/EmptyAlbumsAdapter.java (limited to 'model') diff --git a/model/basic-model/pom.xml b/model/basic-model/pom.xml index 4d7930298..45d9978cf 100644 --- a/model/basic-model/pom.xml +++ b/model/basic-model/pom.xml @@ -18,10 +18,7 @@ ============LICENSE_END========================================================= --> - + 4.0.0 @@ -45,6 +42,12 @@ org.onap.policy.common utils + + + javax.xml.bind + jaxb-api + + org.onap.policy.apex-pdp.model @@ -77,30 +80,4 @@ test - - - - - org.codehaus.mojo - exec-maven-plugin - - - generate-xml-schema - process-classes - - java - - - org.onap.policy.apex.model.basicmodel.handling.ApexSchemaGenerator - compile - - org.onap.policy.apex.model.basicmodel.concepts.AxModel - ${project.build.directory}/model/xml/apex-basic-model.xsd - - - - - - - - + \ No newline at end of file diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java index f5d421956..1efe83db8 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java @@ -23,11 +23,6 @@ package org.onap.policy.apex.model.basicmodel.concepts; import java.util.ArrayList; import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; import org.onap.policy.common.utils.validation.Assertions; @@ -39,22 +34,13 @@ import org.onap.policy.common.utils.validation.Assertions; *

Key validation checks that the name and version fields match the NAME_REGEXP and VERSION_REGEXP * regular expressions respectively. */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "apexArtifactKey", namespace = "http://www.onap.org/policy/apex-pdp") - -@XmlType(name = "AxArtifactKey", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = - { "name", "version" }) - public class AxArtifactKey extends AxKey { private static final long serialVersionUID = 8932717618579392561L; private static final String NAME_TOKEN = "name"; private static final String VERSION_TOKEN = "version"; - @XmlElement(required = true) private String name; - - @XmlElement(required = true) private String version; /** diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java index 0e2c6bef2..37fe30b33 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019,2022 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +24,6 @@ package org.onap.policy.apex.model.basicmodel.concepts; import java.io.Serializable; import java.util.List; -import javax.xml.bind.annotation.XmlType; import org.onap.policy.common.utils.validation.Assertions; /** @@ -33,9 +32,6 @@ import org.onap.policy.common.utils.validation.Assertions; * * @author Liam Fallon (liam.fallon@ericsson.com) */ - -@XmlType(name = "AxConcept", namespace = "http://www.onap.org/policy/apex-pdp") - public abstract class AxConcept implements Serializable, Comparable { private static final long serialVersionUID = -7434939557282697490L; @@ -85,6 +81,12 @@ public abstract class AxConcept implements Serializable, Comparable { */ public abstract void clean(); + /** + * Builds references used by a concept. + */ + public void buildReferences() { + } + /** * {@inheritDoc}. */ diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java index 9b96d3398..bd3b18ec9 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java @@ -22,14 +22,10 @@ package org.onap.policy.apex.model.basicmodel.concepts; +import com.google.gson.annotations.SerializedName; import java.util.List; import java.util.Random; import java.util.UUID; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; import org.apache.commons.lang3.StringUtils; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; import org.onap.policy.common.utils.validation.Assertions; @@ -41,16 +37,9 @@ import org.onap.policy.common.utils.validation.Assertions; *

Validation checks that all fields are defined and that the key is valid. It also observes that descriptions are * blank and warns if the UUID is a zero UUID. */ - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "apexKeyInfo", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType(name = "AxKeyInfo", namespace = "http://www.onap.org/policy/apex-pdp", - propOrder = { "key", "uuid", "description" }) - public class AxKeyInfo extends AxConcept { private static final long serialVersionUID = -4023935924068914308L; - private static final int MAX_DESCRIPTION_LENGTH_8192 = 8192; private static final int UUID_BYTE_LENGTH_16 = 16; /* @@ -58,13 +47,11 @@ public class AxKeyInfo extends AxConcept { */ private static final Random sharedRandom = new Random(); // NOSONAR - @XmlElement(name = "key", required = true) private AxArtifactKey key; - @XmlElement(name = "UUID", required = true) + @SerializedName("UUID") private UUID uuid; - @XmlElement(required = true) private String description; /** diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java index d1cc99a22..439b2960f 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java @@ -30,11 +30,6 @@ import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; import java.util.UUID; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlType; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; import org.onap.policy.common.utils.validation.Assertions; @@ -48,16 +43,10 @@ import org.onap.policy.common.utils.validation.Assertions; * the map is defined, that the key in each map entry matches the key if each entry value, and that no duplicate UUIDs * exist. Each key information entry is then validated individually. */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "AxKeyInformation", namespace = "http://www.onap.org/policy/apex-pdp", - propOrder = { "key", "keyInfoMap" }) - public class AxKeyInformation extends AxConcept implements AxConceptGetter { private static final long serialVersionUID = -2746380769017043888L; - @XmlElement(name = "key", required = true) private AxArtifactKey key; - private Map keyInfoMap; /** @@ -101,22 +90,6 @@ public class AxKeyInformation extends AxConcept implements AxConceptGetter navigablekeyInfoMap = new TreeMap<>(); - navigablekeyInfoMap.putAll(keyInfoMap); - keyInfoMap = navigablekeyInfoMap; - } - /** * This method generates default key information for all keys found in the concept passed in as a parameter that do * not already have key information. @@ -159,6 +132,14 @@ public class AxKeyInformation extends AxConcept implements AxConceptGetter keyInfo.buildReferences()); + } + /** * Sets the key of this concept. * @@ -218,7 +199,7 @@ public class AxKeyInformation extends AxConcept implements AxConceptGetter, JsonDeserializer { + private static final String MAP_ENTRY_KEY = "entry"; + + @SuppressWarnings("unchecked") + @Override + public Map deserialize(JsonElement jsonElement, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + + if (!(jsonElement instanceof JsonObject)) { + throw new JsonParseException("could not parse JSON map, map is not a JsonObject"); + } + + JsonObject jsonObject = (JsonObject) jsonElement; + + if (jsonObject.size() != 1) { + throw new JsonParseException("could not parse JSON map, map must be in a JsonObject with a single member"); + } + + JsonArray mapEntryArray = (JsonArray) jsonObject.get(MAP_ENTRY_KEY); + if (mapEntryArray == null) { + throw new JsonParseException("could not parse JSON map, map \"entry\" in JsonObject not found"); + } + + return new TreeMap( + StreamSupport + .stream(mapEntryArray.spliterator(), true) + .map(element -> deserializeMapEntry(element, typeOfT, context)) + .collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue())) + ); + } + + @Override + public JsonElement serialize(Map sourceMap, Type typeOfSrc, JsonSerializationContext context) { + + // A map is stored in a JsonArray + JsonArray mapEntryArray = new JsonArray(); + + for (Object mapEntryObject : sourceMap.entrySet()) { + Entry mapEntry = (Entry) mapEntryObject; + mapEntryArray.add(serializeMapEntry(mapEntry, typeOfSrc, context)); + } + + JsonObject returnObject = new JsonObject(); + returnObject.add(MAP_ENTRY_KEY, mapEntryArray); + + return returnObject; + } + + @SuppressWarnings("unchecked") + private static Entry deserializeMapEntry(JsonElement element, Type typeOfT, JsonDeserializationContext context) { + // Get the types of the map + ParameterizedType pt = (ParameterizedType) typeOfT; + + // Type of the key and value of the map + Type keyType = pt.getActualTypeArguments()[0]; + Type valueType = pt.getActualTypeArguments()[1]; + + // Deserialize the key and value + return new AbstractMap.SimpleEntry( + context.deserialize(element.getAsJsonObject().get("key"), keyType), + context.deserialize(element.getAsJsonObject().get("value"), valueType)); + } + + private static JsonElement serializeMapEntry(Entry sourceEntry, Type typeOfSrc, JsonSerializationContext context) { + // Get the types of the map + ParameterizedType pt = (ParameterizedType) typeOfSrc; + + // Type of the key and value of the map + Type keyType = pt.getActualTypeArguments()[0]; + Type valueType = pt.getActualTypeArguments()[1]; + + JsonObject entryObject = new JsonObject(); + entryObject.add("key", context.serialize(sourceEntry.getKey(), keyType)); + entryObject.add("value", context.serialize(sourceEntry.getValue(), valueType)); + + return entryObject; + } +} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonRefereceKeyAdapter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonRefereceKeyAdapter.java new file mode 100644 index 000000000..d731c8689 --- /dev/null +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonRefereceKeyAdapter.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2022 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.apex.model.basicmodel.handling; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import java.lang.reflect.Type; +import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; + +public class ApexModelCustomGsonRefereceKeyAdapter implements JsonDeserializer { + + @Override + public AxReferenceKey deserialize(JsonElement jsonElement, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + + if (jsonElement instanceof JsonObject) { + return new AxReferenceKey( + jsonElement.getAsJsonObject().get("parentKeyName").getAsString(), + jsonElement.getAsJsonObject().get("parentKeyVersion").getAsString(), + jsonElement.getAsJsonObject().get("parentLocalName").getAsString(), + jsonElement.getAsJsonObject().get("localName").getAsString() + ); + } else { + AxReferenceKey returnKey = new AxReferenceKey(); + returnKey.setLocalName(jsonElement.getAsString()); + return returnKey; + } + } +} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriter.java index 908ad31aa..54b5651cc 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriter.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriter.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021-2022 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,6 +23,8 @@ package org.onap.policy.apex.model.basicmodel.handling; import java.io.File; import java.io.FileOutputStream; +import lombok.Getter; +import lombok.Setter; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxModel; import org.slf4j.ext.XLogger; @@ -34,42 +36,21 @@ import org.slf4j.ext.XLoggerFactory; * @author Liam Fallon (liam.fallon@ericsson.com) * @param the type of Apex model to write to file, must be a sub class of {@link AxModel} */ +@Getter +@Setter public class ApexModelFileWriter { private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelFileWriter.class); // Should models being written to files be valid - private boolean validateFlag; + private boolean validate; /** * Constructor, set the validation flag. * - * @param validateFlag indicates if validation be performed prior to output + * @param validate indicates if validation be performed prior to output */ - public ApexModelFileWriter(final boolean validateFlag) { - this.validateFlag = validateFlag; - } - - /** - * Write a model to an XML file. - * - * @param model The model to write - * @param rootModelClass The concept class - * @param modelFileName The name of the file to write to - * @throws ApexException thrown on errors - */ - public void apexModelWriteXmlFile(final M model, final Class rootModelClass, final String modelFileName) - throws ApexException { - LOGGER.debug("running apexModelWriteXMLFile . . ."); - - final ApexModelWriter modelWriter = new ApexModelWriter<>(rootModelClass); - modelWriter.setValidateFlag(validateFlag); - modelWriter.getCDataFieldSet().add("description"); - modelWriter.getCDataFieldSet().add("logic"); - modelWriter.getCDataFieldSet().add("uiLogic"); - - writeModelFile(model, modelWriter, modelFileName); - - LOGGER.debug("ran apexModelWriteXMLFile"); + public ApexModelFileWriter(final boolean validate) { + this.validate = validate; } /** @@ -85,32 +66,13 @@ public class ApexModelFileWriter { LOGGER.debug("running apexModelWriteJSONFile . . ."); final ApexModelWriter modelWriter = new ApexModelWriter<>(rootModelClass); - modelWriter.setJsonOutput(true); - modelWriter.setValidateFlag(validateFlag); + modelWriter.setValidate(validate); writeModelFile(model, modelWriter, modelFileName); LOGGER.debug("ran apexModelWriteJSONFile"); } - /** - * Checks if the validation flag is set. - * - * @return true, the validation flag is set - */ - public boolean isValidateFlag() { - return validateFlag; - } - - /** - * Sets the validate flag. - * - * @param validateFlag the validate flag value - */ - public void setValidateFlag(final boolean validateFlag) { - this.validateFlag = validateFlag; - } - /** * Write a model to a file using a model writer. * diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java index 7e136f6b3..a9bd2fe60 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2021 Nordix Foundation. + * Modifications Copyright (C) 2019-2022 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,55 +22,47 @@ package org.onap.policy.apex.model.basicmodel.handling; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.StringReader; -import java.util.regex.Pattern; -import javax.xml.XMLConstants; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.SchemaFactory; -import org.eclipse.persistence.jaxb.JAXBContextFactory; -import org.eclipse.persistence.jaxb.MarshallerProperties; -import org.eclipse.persistence.oxm.MediaType; +import java.util.Map; +import lombok.Getter; +import lombok.Setter; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; +import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.common.utils.resources.TextFileUtils; import org.onap.policy.common.utils.validation.Assertions; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** - * This class reads an Apex concept from an XML file into a Java Apex Concept {@link AxConcept}. + * This class reads an Apex concept from a file into a Java Apex Concept {@link AxConcept}. * * @author Liam Fallon (liam.fallon@ericsson.com) * @param the type of Apex concept to read, must be a sub class of {@link AxConcept} */ +@Getter +@Setter public class ApexModelReader { // Get a reference to the logger private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelReader.class); - // Regular expressions for checking input types - // (starts with - private static final String XML_INPUT_TYPE_REGEXP = "^\\s*<\\?xml.*>\\s*"; - // starts with some kind of bracket [ or ( - private static final String JSON_INPUT_TYPE_REGEXP = "^\\s*[\\(\\{\\[][\\s\\S]*[\\)\\}\\]]"; - // or {, then has something, then has - // and has a close bracket + // Use GSON to deserialize JSON + private static Gson gson = new GsonBuilder() + .registerTypeAdapter(AxReferenceKey.class, new ApexModelCustomGsonRefereceKeyAdapter()) + .registerTypeAdapter(Map.class, new ApexModelCustomGsonMapAdapter()) + .setPrettyPrinting() + .create(); //  The root class of the concept we are reading private final Class rootConceptClass; - // The unmarshaller for the Apex concepts - private Unmarshaller unmarshaller = null; - // All read concepts are validated after reading if this flag is set - private boolean validateFlag = true; + private boolean validate = true; /** * Constructor, initiates the reader with validation on. @@ -81,17 +73,6 @@ public class ApexModelReader { public ApexModelReader(final Class rootConceptClass) throws ApexModelException { // Save the root concept class this.rootConceptClass = rootConceptClass; - - try { - final var jaxbContext = JAXBContextFactory.createContext(new Class[] {rootConceptClass}, null); - - // Set up the unmarshaller to carry out validation - unmarshaller = jaxbContext.createUnmarshaller(); - unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler()); - } catch (final JAXBException e) { - LOGGER.error("Unable to set JAXB context", e); - throw new ApexModelException("Unable to set JAXB context", e); - } } /** @@ -103,36 +84,11 @@ public class ApexModelReader { */ public ApexModelReader(final Class rootConceptClass, final boolean validate) throws ApexModelException { this(rootConceptClass); - this.validateFlag = validate; - } - - /** - * Set the schema to use for reading XML files. - * - * @param schemaFileName the schema file to use - * @throws ApexModelException if the schema cannot be set - */ - public void setSchema(final String schemaFileName) throws ApexModelException { - // Has a schema been set - if (schemaFileName != null) { - try { - // Set the concept schema - final var schemaUrl = ResourceUtils.getUrlResource(schemaFileName); - final var apexConceptSchema = - SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaUrl); - unmarshaller.setSchema(apexConceptSchema); - } catch (final Exception e) { - LOGGER.error("Unable to load schema ", e); - throw new ApexModelException("Unable to load schema", e); - } - } else { - // Clear the schema - unmarshaller.setSchema(null); - } + this.validate = validate; } /** - * This method checks the specified Apex concept XML file and reads it into an Apex concept. + * This method checks the specified Apex concept file and reads it into an Apex concept. * * @param apexConceptStream the apex concept stream * @return the Apex concept @@ -179,28 +135,23 @@ public class ApexModelReader { LOGGER.entry("reading Apex concept from string . . ."); - final var apexString = apexConceptString.trim(); - - // Set the type of input for this stream - setInputType(apexString); - - // The Apex Concept C apexConcept = null; - - // Use JAXB to read and verify the Apex concept XML file try { - // Load the configuration file - final var source = new StreamSource(new StringReader(apexString)); - final JAXBElement rootElement = unmarshaller.unmarshal(source, rootConceptClass); - apexConcept = rootElement.getValue(); - } catch (final JAXBException e) { - throw new ApexModelException("Unable to unmarshal Apex concept ", e); + apexConcept = gson.fromJson(apexConceptString, rootConceptClass); + } catch (final Exception je) { + throw new ApexModelException("Unable to unmarshal Apex concept ", je); + } + + if (apexConcept == null) { + throw new ApexModelException("Unable to unmarshal Apex concept, unmarshaled model is null "); } LOGGER.debug("reading of Apex concept {} completed"); + apexConcept.buildReferences(); + // Check if the concept should be validated - if (validateFlag) { + if (validate) { // Validate the configuration file final AxValidationResult validationResult = apexConcept.validate(new AxValidationResult()); if (validationResult.isValid()) { @@ -215,54 +166,4 @@ public class ApexModelReader { return apexConcept; } } - - /** - * Gets the value of the validation flag. - * - * @return the validation flag value - */ - public boolean getValidateFlag() { - return validateFlag; - } - - /** - * Sets the validation flag. - * - * @param validateFlag the validation flag value - */ - public void setValidateFlag(final boolean validateFlag) { - this.validateFlag = validateFlag; - } - - /** - * Set the type of input for the concept reader. - * - * @param apexConceptString The stream with - * @throws ApexModelException on errors setting input type - */ - private void setInputType(final String apexConceptString) throws ApexModelException { - // Check the input type - if (Pattern.compile(JSON_INPUT_TYPE_REGEXP).matcher(apexConceptString).find()) { - // is json - try { - unmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); - unmarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true); - } catch (final Exception e) { - LOGGER.warn("JAXB error setting marshaller for JSON Input", e); - throw new ApexModelException("JAXB error setting unmarshaller for JSON input", e); - } - } else if (Pattern.compile(XML_INPUT_TYPE_REGEXP).matcher(apexConceptString).find()) { - // is xml - try { - unmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_XML); - } catch (final Exception e) { - LOGGER.warn("JAXB error setting marshaller for XML Input", e); - throw new ApexModelException("JAXB error setting unmarshaller for XML input", e); - } - } else { - LOGGER.warn("format of input for Apex concept is neither JSON nor XML"); - throw new ApexModelException("format of input for Apex concept is neither JSON nor XML"); - } - } - } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java index dea32df49..79d69bdd5 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2021 Nordix Foundation. + * Modifications Copyright (C) 2019-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** - * This class is used to save Apex models to file in XML or JSON format. + * This class is used to save Apex models to file in JSON format. * * @author Liam Fallon (liam.fallon@ericsson.com) * @param the type of Apex model to save to file, must be a sub class of {@link AxModel} @@ -51,7 +51,7 @@ public class ApexModelSaver { * @param rootModelClass the class of the model, a sub class of {@link AxModel} * @param model the model to write, an instance of a sub class of {@link AxModel} * @param writePath the directory to which models will be written. The name of the written model will be the Model - * Name for its key with the suffix {@code .xml} or {@code .json}. + * Name for its key with the suffix {@code .json}. */ public ApexModelSaver(final Class rootModelClass, final M model, final String writePath) { Assertions.argumentNotNull(rootModelClass, "argument rootModelClass may not be null"); @@ -63,21 +63,6 @@ public class ApexModelSaver { this.writePath = writePath; } - /** - * Write an Apex model to a file in XML format. The model will be written to {@code } - * - * @throws ApexException on errors writing the Apex model - */ - public void apexModelWriteXml() throws ApexException { - LOGGER.debug("running apexModelWriteXML . . ."); - - // Write the file to disk - final var xmlFile = new File(writePath + File.separatorChar + model.getKey().getName() + ".xml"); - new ApexModelFileWriter(true).apexModelWriteXmlFile(model, rootModelClass, xmlFile.getPath()); - - LOGGER.debug("ran apexModelWriteXML"); - } - /** * Write an Apex model to a file in JSON format. The model will be written to {@code } * diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java index de6a72ffd..a9df23afc 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2021 Nordix Foundation. + * Modifications Copyright (C) 2019-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,8 @@ package org.onap.policy.apex.model.basicmodel.handling; import java.io.ByteArrayOutputStream; +import lombok.Getter; +import lombok.Setter; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; import org.onap.policy.common.utils.validation.Assertions; @@ -34,19 +36,21 @@ import org.slf4j.ext.XLoggerFactory; * @author Liam Fallon (liam.fallon@ericsson.com) * @param the type of Apex concept to write to a string, must be a sub class of {@link AxConcept} */ +@Getter +@Setter public class ApexModelStringWriter { private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelStringWriter.class); // Should concepts being written to files be valid - private boolean validateFlag; + private boolean validate; /** * Constructor, set the validation flag. * - * @param validateFlag Should validation be performed prior to output + * @param validate Should validation be performed prior to output */ - public ApexModelStringWriter(final boolean validateFlag) { - this.validateFlag = validateFlag; + public ApexModelStringWriter(final boolean validate) { + this.validate = validate; } /** @@ -54,46 +58,14 @@ public class ApexModelStringWriter { * * @param concept The concept to write * @param rootConceptClass The concept class - * @param jsonFlag writes JSON if true, and a generic string if false * @return The string with the concept * @throws ApexException thrown on errors */ - public String writeString(final C concept, final Class rootConceptClass, final boolean jsonFlag) + public String writeString(final C concept, final Class rootConceptClass) throws ApexException { Assertions.argumentNotNull(concept, "concept may not be null"); - if (jsonFlag) { - return writeJsonString(concept, rootConceptClass); - } else { - return concept.toString(); - } - } - - /** - * Write a concept to an XML string. - * - * @param concept The concept to write - * @param rootConceptClass The concept class - * @return The string with the concept - * @throws ApexException thrown on errors - */ - public String writeXmlString(final C concept, final Class rootConceptClass) throws ApexException { - LOGGER.debug("running writeXMLString . . ."); - - final ApexModelWriter conceptWriter = new ApexModelWriter<>(rootConceptClass); - conceptWriter.setValidateFlag(validateFlag); - conceptWriter.getCDataFieldSet().add("description"); - conceptWriter.getCDataFieldSet().add("logic"); - conceptWriter.getCDataFieldSet().add("uiLogic"); - - try (var baOutputStream = new ByteArrayOutputStream()) { - conceptWriter.write(concept, baOutputStream); - return baOutputStream.toString(); - } catch (final Exception e) { - LOGGER.warn("error writing XML string", e); - throw new ApexException("error writing XML string", e); - } - + return writeJsonString(concept, rootConceptClass); } /** @@ -108,8 +80,7 @@ public class ApexModelStringWriter { LOGGER.debug("running writeJSONString . . ."); final ApexModelWriter conceptWriter = new ApexModelWriter<>(rootConceptClass); - conceptWriter.setJsonOutput(true); - conceptWriter.setValidateFlag(validateFlag); + conceptWriter.setValidate(validate); try (var baOutputStream = new ByteArrayOutputStream()) { conceptWriter.write(concept, baOutputStream); @@ -120,22 +91,4 @@ public class ApexModelStringWriter { } } - - /** - * Checks if is validate flag. - * - * @return true, if checks if is validate flag - */ - public boolean isValidateFlag() { - return validateFlag; - } - - /** - * Sets the validate flag. - * - * @param validateFlag the validate flag - */ - public void setValidateFlag(final boolean validateFlag) { - this.validateFlag = validateFlag; - } } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java index 9e43f76bd..349622697 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2021 Nordix Foundation. + * Modifications Copyright (C) 2019-2022 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,129 +21,67 @@ package org.onap.policy.apex.model.basicmodel.handling; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; -import java.util.Set; -import java.util.TreeSet; -import javax.xml.XMLConstants; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import org.eclipse.persistence.jaxb.JAXBContextFactory; -import org.eclipse.persistence.jaxb.MarshallerProperties; -import org.eclipse.persistence.oxm.MediaType; +import java.util.Map; +import lombok.Getter; +import lombok.Setter; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; +import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; import org.onap.policy.common.utils.validation.Assertions; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** - * This class writes an Apex concept to an XML file or JSON file from a Java Apex Concept. + * This class writes an Apex concept to a file from a Java Apex Concept. * * @param the type of Apex concept to write, must be a sub class of {@link AxConcept} * @author John Keeney (john.keeney@ericsson.com) */ +@Getter +@Setter public class ApexModelWriter { private static final String CONCEPT_MAY_NOT_BE_NULL = "concept may not be null"; private static final String CONCEPT_WRITER_MAY_NOT_BE_NULL = "concept writer may not be null"; private static final String CONCEPT_STREAM_MAY_NOT_BE_NULL = "concept stream may not be null"; + // Use GSON to serialize JSON + private static Gson gson = new GsonBuilder() + .registerTypeAdapter(AxReferenceKey.class, new ApexModelCustomGsonRefereceKeyAdapter()) + .registerTypeAdapter(Map.class, new ApexModelCustomGsonMapAdapter()) + .setPrettyPrinting() + .create(); + // Get a reference to the logger private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelWriter.class); - // Writing as JSON or XML - private boolean jsonOutput = false; - - // The list of fields to output as CDATA - private final Set cdataFieldSet = new TreeSet<>(); - - // The Marshaller for the Apex concepts - private Marshaller marshaller = null; + //  The root class of the concept we are reading + private final Class rootConceptClass; // All written concepts are validated before writing if this flag is set - private boolean validateFlag = true; + private boolean validate = true; /** - * Constructor, initiates the writer. + * Constructor, initiates the writer with validation on. * * @param rootConceptClass the root concept class for concept reading - * @throws ApexModelException the apex concept writer exception + * @throws ApexModelException the apex concept reader exception */ public ApexModelWriter(final Class rootConceptClass) throws ApexModelException { - // Set up Eclipselink for XML and JSON output - System.setProperty("javax.xml.bind.context.factory", "org.eclipse.persistence.jaxb.JAXBContextFactory"); - - try { - final var jaxbContext = JAXBContextFactory.createContext(new Class[]{rootConceptClass}, null); - - // Set up the unmarshaller to carry out validation - marshaller = jaxbContext.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - marshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler()); - } catch (final JAXBException e) { - throw new ApexModelException("JAXB marshaller creation exception", e); - } - } - - /** - * The set of fields to be output as CDATA. - * - * @return the set of fields - */ - public Set getCDataFieldSet() { - return cdataFieldSet; - } - - /** - * Return true if JSON output enabled, XML output if false. - * - * @return true for JSON output - */ - public boolean isJsonOutput() { - return jsonOutput; - } - - /** - * Set the value of JSON output, true for JSON output, false for XML output. - * - * @param jsonOutput true for JSON output - * @throws ApexModelException on errors setting output type - */ - public void setJsonOutput(final boolean jsonOutput) throws ApexModelException { - this.jsonOutput = jsonOutput; - - // Set up output specific parameters - if (this.jsonOutput) { - try { - marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); - marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true); - } catch (final Exception e) { - throw new ApexModelException("JAXB error setting marshaller for JSON output", e); - } - } else { - try { - marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_XML); - } catch (final Exception e) { - throw new ApexModelException("JAXB error setting marshaller for XML output", e); - } - } + // Save the root concept class + this.rootConceptClass = rootConceptClass; } /** * This method validates the Apex concept then writes it into a stream. * - * @param concept the concept to write + * @param concept the concept to write * @param apexConceptStream the stream to write to * @throws ApexModelException on validation or writing exceptions */ @@ -157,7 +95,7 @@ public class ApexModelWriter { /** * This method validates the Apex concept then writes it into a writer. * - * @param concept the concept to write + * @param concept the concept to write * @param apexConceptWriter the writer to write to * @throws ApexModelException on validation or writing exceptions */ @@ -166,84 +104,23 @@ public class ApexModelWriter { Assertions.argumentNotNull(apexConceptWriter, CONCEPT_WRITER_MAY_NOT_BE_NULL); // Check if we should validate the concept - if (validateFlag) { + if (validate) { // Validate the concept first final AxValidationResult validationResult = concept.validate(new AxValidationResult()); if (!validationResult.isValid()) { String message = - "Apex concept xml (" + concept.getKey().getId() + ") validation failed: " + validationResult - .toString(); + "Apex concept (" + concept.getKey().getId() + ") validation failed: " + validationResult.toString(); throw new ApexModelException(message); } } - if (jsonOutput) { - writeJson(concept, apexConceptWriter); - } else { - writeXml(concept, apexConceptWriter); - } - } - - /** - * This method writes the Apex concept into a writer in XML format. - * - * @param concept the concept to write - * @param apexConceptWriter the writer to write to - * @throws ApexModelException on validation or writing exceptions - */ - private void writeXml(final C concept, final Writer apexConceptWriter) throws ApexModelException { - Assertions.argumentNotNull(concept, CONCEPT_MAY_NOT_BE_NULL); - - LOGGER.debug("writing Apex concept XML . . ."); - - try { - // Write the concept into a DOM document, then transform to add CDATA fields and pretty - // print, then write out the result - final var docBuilderFactory = DocumentBuilderFactory.newInstance(); - docBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); - docBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); - - docBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - final var document = docBuilderFactory.newDocumentBuilder().newDocument(); - - // Marshal the concept into the empty document. - marshaller.marshal(concept, document); - - final var domTransformer = getTransformer(); - - // Convert the cDataFieldSet into a space delimited string - domTransformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, - cdataFieldSet.toString().replaceAll("[\\[\\]\\,]", " ")); - domTransformer.transform(new DOMSource(document), new StreamResult(apexConceptWriter)); - } catch (JAXBException | TransformerException | ParserConfigurationException e) { - throw new ApexModelException("Unable to marshal Apex concept to XML", e); - } - LOGGER.debug("wrote Apex concept XML"); - } - - private Transformer getTransformer() throws TransformerConfigurationException { - // Transform the DOM to the output stream - final var transformerFactory = TransformerFactory.newInstance(); - transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); - transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); - - final var domTransformer = transformerFactory.newTransformer(); - - // Pretty print - try { - domTransformer.setOutputProperty(OutputKeys.INDENT, "yes"); - // May fail if not using XALAN XSLT engine. But not in any way vital - domTransformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); - } catch (final Exception ignore) { - LOGGER.trace("Unable to set indent property", ignore); - } - return domTransformer; + writeJson(concept, apexConceptWriter); } /** * This method writes the Apex concept into a writer in JSON format. * - * @param concept the concept to write + * @param concept the concept to write * @param apexConceptWriter the writer to write to * @throws ApexModelException on validation or writing exceptions */ @@ -252,29 +129,20 @@ public class ApexModelWriter { LOGGER.debug("writing Apex concept JSON . . ."); + String modelJsonString = null; try { - marshaller.marshal(concept, apexConceptWriter); - } catch (final JAXBException e) { - throw new ApexModelException("Unable to marshal Apex concept to JSON", e); + modelJsonString = gson.toJson(concept, rootConceptClass); + } catch (Exception je) { + throw new ApexModelException("Unable to marshal Apex concept to JSON", je); } - LOGGER.debug("wrote Apex concept JSON"); - } - /** - * Gets the validation flag value. - * - * @return the validation flag value - */ - public boolean getValidateFlag() { - return validateFlag; - } + try { + apexConceptWriter.write(modelJsonString); + apexConceptWriter.close(); + } catch (IOException ioe) { + throw new ApexModelException("Unable to write Apex concept as JSON", ioe); + } - /** - * Sets the validation flag. - * - * @param validateFlag the validation flag value - */ - public void setValidateFlag(final boolean validateFlag) { - this.validateFlag = validateFlag; + LOGGER.debug("wrote Apex concept JSON"); } } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java deleted file mode 100644 index d5f34785b..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020-2021 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.apex.model.basicmodel.handling; - -import java.io.File; -import java.io.IOException; -import java.io.PrintStream; -import java.io.StringWriter; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.SchemaOutputResolver; -import javax.xml.transform.Result; -import javax.xml.transform.stream.StreamResult; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class generates the XML model schema from the given Apex concept classes. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexSchemaGenerator { - // Get a reference to the logger - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexSchemaGenerator.class); - - /** - * A Main method to allow schema generation from the command line or from maven or scripts. - * - * @param args the command line arguments, usage is {@code ApexSchemaGenerator apex-root-class [schema-file-name]} - */ - public static void main(final String[] args) { - PrintStream printStream = null; - - if (args.length == 1) { - printStream = System.out; - } else if (args.length == 2) { - final var schemaFile = new File(args[1]); - - try { - schemaFile.getParentFile().mkdirs(); - printStream = new PrintStream(schemaFile); - } catch (final Exception e) { - LOGGER.error("error on Apex schema output", e); - return; - } - } else { - LOGGER.error("usage: ApexSchemaGenerator apex-root-class [schema-file-name]"); - return; - } - - // Get the schema - final String schema = new ApexSchemaGenerator().generate(args[0]); - - // Output the schema - printStream.println(schema); - - printStream.close(); - } - - /** - * Generates the XML schema (XSD) for the Apex model described using JAXB annotations. - * - * @param rootClassName the name of the root class for schema generation - * @return The schema - */ - public String generate(final String rootClassName) { - JAXBContext jaxbContext; - try { - jaxbContext = JAXBContext.newInstance(Class.forName(rootClassName)); - } catch (final ClassNotFoundException e) { - LOGGER.error("could not create JAXB context, root class " + rootClassName + " not found", e); - return null; - } catch (final JAXBException e) { - LOGGER.error("could not create JAXB context", e); - return null; - } - - final var sor = new ApexSchemaOutputResolver(); - try { - jaxbContext.generateSchema(sor); - } catch (final IOException e) { - LOGGER.error("error generating the Apex schema (XSD) file", e); - return null; - } - - var schemaString = sor.getSchema(); - schemaString = fixForUnqualifiedBug(schemaString); - - return schemaString; - } - - /** - * There is a bug in schema generation that does not specify the elements from Java Maps as being unqualified. This - * method "hacks" those elements in the schema to fix this, the elements being {@code entry}, {@code key}, and - * {@code value} - * - * @param schemaString The schema in which elements should be fixed - * @return the string - */ - private String fixForUnqualifiedBug(final String schemaString) { - // Fix the "entry" element - var newSchemaString = schemaString.replace( - "", - ""); - - // Fix the "key" element - newSchemaString = newSchemaString.replace(" { - - private List filterList = new LinkedList<>(); - - /** - * Adds a key to the list to be filtered. - * - * @param key the key to add to the filter list - */ - public void addFilterKey(AxKey key) { - filterList.add(key); - } - - /** - * Remove a key from the list to be filtered. - * - * @param key the key to remove from the filter list - * @return true if the passed key was in the filter list and has been removed. - */ - public boolean removeFilterKey(AxKey key) { - return filterList.remove(key); - } - - /** - * Adds some keys to the list to be filtered. - * - * @param keys the keys to add to the filter list - */ - public void addFilterKeys(Collection keys) { - filterList.addAll(keys); - } - - /** - * Decide whether to unmarshall some keyinfos - Always. - * - * @param val the keyinfo - * @return the keyinfo - * @throws Exception if there is some problem unmarshalling - * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(Object) - */ - @Override - public AxKeyInformation unmarshal(AxKeyInformation val) throws Exception { - return val; - } - - /** - * Select which keyinfo entries will be marshalled - i.e. those not in the filter list. - * - * @param val the keyinfo - * @return the keyinfo - * @throws Exception if there is some problem with the marshalling - * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(Object) - */ - @Override - public AxKeyInformation marshal(AxKeyInformation val) throws Exception { - if (val == null || val.getKeyInfoMap() == null || val.getKeyInfoMap().isEmpty() || filterList.isEmpty()) { - return val; - } - //create a new keyinfo clone to avoid removing keyinfo entries from the original model - AxKeyInformation ret = new AxKeyInformation(val); - Map retmap = new TreeMap<>(ret.getKeyInfoMap()); - for (AxKey key : filterList) { - retmap.remove(key); - } - ret.setKeyInfoMap(retmap); - return ret; - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/package-info.java index 081cff540..3d6dab3b2 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/package-info.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/package-info.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,20 +18,4 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - -/** - * Contains a number of utility classes for handling APEX {@link org.onap.policy.apex.model.basicmodel.concepts.AxModel} - * models and {@link org.onap.policy.apex.model.basicmodel.concepts.AxConcept} concepts. Classes to read and write - * models to files, strings, and databases are included, as well as classes to generate XML schemas for models. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ - -@XmlSchema(namespace = "http://www.onap.org/policy/apex-pdp", elementFormDefault = XmlNsForm.QUALIFIED, - xmlns = { @XmlNs(namespaceURI = "http://www.onap.org/policy/apex-pdp", prefix = "") }) - package org.onap.policy.apex.model.basicmodel.handling; - -import javax.xml.bind.annotation.XmlNs; -import javax.xml.bind.annotation.XmlNsForm; -import javax.xml.bind.annotation.XmlSchema; diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/package-info.java index e540646d9..8ad405e25 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/package-info.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/package-info.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019,2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ * the model for APEX concepts anywhere in the system. * *

It also provides handling support to models, allowing them to be read and written to file and databases in JSON - * and XML format. + * format. * * @author Liam Fallon (liam.fallon@ericsson.com) */ diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java index 5dbf69492..9dde47d05 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java @@ -44,7 +44,7 @@ import org.slf4j.ext.XLoggerFactory; public class TestApexModel { private static final String MODEL_IS_INVALID = "model is invalid "; private static final String ERROR_PROCESSING_FILE = "error processing file "; - private static final String TEST_MODEL_UNEQUAL_STR = "test model does not equal model read from XML file "; + private static final String TEST_MODEL_UNEQUAL_STR = "test model does not equal model read from file "; private static final String TEMP_FILE_CREATE_ERR_STR = "error creating temporary file for Apex model"; private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestApexModel.class); @@ -76,55 +76,6 @@ public class TestApexModel { return modelCreator.getModel(); } - /** - * Test write and read in XML format. - * - * @throws ApexException on write/read errors - */ - public final void testApexModelWriteReadXml() throws ApexException { - LOGGER.debug("running testApexModelWriteReadXML . . ."); - - final var model = modelCreator.getModel(); - - // Write the file to disk - File xmlFile; - - try { - xmlFile = File.createTempFile("ApexModel", ".xml"); - xmlFile.deleteOnExit(); - } catch (final Exception e) { - LOGGER.warn(TEMP_FILE_CREATE_ERR_STR, e); - throw new ApexException(TEMP_FILE_CREATE_ERR_STR, e); - } - new ApexModelFileWriter(true).apexModelWriteXmlFile(model, rootModelClass, xmlFile.getPath()); - - // Read the file from disk - final ApexModelReader modelReader = new ApexModelReader<>(rootModelClass); - - try { - final var apexModelUrl = ResourceUtils.getLocalFile(xmlFile.getAbsolutePath()); - final var fileModel = modelReader.read(apexModelUrl.openStream()); - checkModelEquality(model, fileModel, TEST_MODEL_UNEQUAL_STR + xmlFile.getAbsolutePath()); - } catch (final Exception e) { - LOGGER.warn(ERROR_PROCESSING_FILE + xmlFile.getAbsolutePath(), e); - throw new ApexException(ERROR_PROCESSING_FILE + xmlFile.getAbsolutePath(), e); - } - - final ApexModelWriter modelWriter = new ApexModelWriter<>(rootModelClass); - modelWriter.getCDataFieldSet().add("description"); - modelWriter.getCDataFieldSet().add("logic"); - modelWriter.getCDataFieldSet().add("uiLogic"); - - final var baOutputStream = new ByteArrayOutputStream(); - modelWriter.write(model, baOutputStream); - final var baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray()); - final var byteArrayModel = modelReader.read(baInputStream); - - checkModelEquality(model, byteArrayModel, "test model does not equal XML marshalled and unmarshalled model"); - - LOGGER.debug("ran testApexModelWriteReadXML"); - } - /** * Test write and read in JSON format. * @@ -138,7 +89,7 @@ public class TestApexModel { // Write the file to disk File jsonFile; try { - jsonFile = File.createTempFile("ApexModel", ".xml"); + jsonFile = File.createTempFile("ApexModel", ".json"); jsonFile.deleteOnExit(); } catch (final Exception e) { LOGGER.warn(TEMP_FILE_CREATE_ERR_STR, e); @@ -159,7 +110,6 @@ public class TestApexModel { } final ApexModelWriter modelWriter = new ApexModelWriter<>(rootModelClass); - modelWriter.setJsonOutput(true); final var baOutputStream = new ByteArrayOutputStream(); modelWriter.write(model, baOutputStream); diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapter.java deleted file mode 100644 index 8515f5724..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapter.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2021 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.apex.model.basicmodel.xml; - -import java.io.Serializable; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlType; -import javax.xml.bind.annotation.adapters.XmlAdapter; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; - -/** - * This class manages marshaling and unmarshaling of Apex {@link AxReferenceKey} concepts using JAXB. The local name in - * reference keys must have specific handling. - */ -@XmlAccessorType(XmlAccessType.PROPERTY) -@XmlType(namespace = "http://www.onap.org/policy/apex-pdp") -public class AxReferenceKeyAdapter extends XmlAdapter implements Serializable { - - private static final long serialVersionUID = -3480405083900107029L; - - /** - * {@inheritDoc}. - */ - @Override - public final String marshal(final AxReferenceKey key) throws Exception { - return key.getLocalName(); - } - - /** - * {@inheritDoc}. - */ - @Override - public final AxReferenceKey unmarshal(final String key) throws Exception { - final var axReferenceKey = new AxReferenceKey(); - axReferenceKey.setLocalName(key); - return axReferenceKey; - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/package-info.java deleted file mode 100644 index 290209d89..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/xml/package-info.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -/** - * Contains utility classes for managing marshaling and unmarshaling of APEX models using JAXB. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ - -@XmlSchema(namespace = "http://www.onap.org/policy/apex-pdp", elementFormDefault = XmlNsForm.QUALIFIED, - xmlns = { @XmlNs(namespaceURI = "http://www.onap.org/policy/apex-pdp", prefix = "") }) - -package org.onap.policy.apex.model.basicmodel.xml; - -import javax.xml.bind.annotation.XmlNs; -import javax.xml.bind.annotation.XmlNsForm; -import javax.xml.bind.annotation.XmlSchema; diff --git a/model/basic-model/src/main/resources/xml/example.xsd b/model/basic-model/src/main/resources/xml/example.xsd deleted file mode 100644 index 75ecdc323..000000000 --- a/model/basic-model/src/main/resources/xml/example.xsd +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java index cd8b52ce6..2b16e89ed 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java @@ -23,17 +23,11 @@ package org.onap.policy.apex.model.basicmodel.concepts; import java.util.Arrays; import java.util.List; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter; public class DummyEntity extends AxConcept { private static final long serialVersionUID = -2962570563281067894L; - @XmlElement(name = "key", required = true) - @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class) protected AxReferenceKey key; - private double doubleValue; public DummyEntity() { diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java index 331e57f47..0f8f956ab 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020,2022 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,33 +36,27 @@ public class ApexModelFileWriterTest { public void testModelFileWriter() throws IOException, ApexException { ApexModelFileWriter modelFileWriter = new ApexModelFileWriter<>(true); - modelFileWriter.setValidateFlag(true); - assertTrue(modelFileWriter.isValidateFlag()); + modelFileWriter.setValidate(true); + assertTrue(modelFileWriter.isValidate()); File tempFile = File.createTempFile("ApexFileWriterTest", "test"); File tempDir = tempFile.getParentFile(); File jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/ApexFileWriterTest.json"); - File xmlTempFile = new File(tempDir.getAbsolutePath() + "/ccc/ApexFileWriterTest.xml"); AxModel model = new DummyApexBasicModelCreator().getModel(); modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); - modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, xmlTempFile.getAbsolutePath()); jsonTempFile.delete(); - xmlTempFile.delete(); new File(tempDir.getAbsolutePath() + "/aaa").delete(); new File(tempDir.getAbsolutePath() + "/ccc").delete(); jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json"); - xmlTempFile = new File(tempDir.getAbsolutePath() + "/ccc/ddd/ApexFileWriterTest.xml"); modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); - modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, xmlTempFile.getAbsolutePath()); jsonTempFile.delete(); - xmlTempFile.delete(); new File(tempDir.getAbsolutePath() + "/aaa/bbb").delete(); new File(tempDir.getAbsolutePath() + "/aaa").delete(); @@ -70,19 +64,14 @@ public class ApexModelFileWriterTest { new File(tempDir.getAbsolutePath() + "/ccc").delete(); File dirA = new File(tempDir.getAbsolutePath() + "/aaa"); - //File dirB = new File(tempDir.getAbsolutePath() + "/aaa/bbb"); + // File dirB = new File(tempDir.getAbsolutePath() + "/aaa/bbb"); dirA.createNewFile(); - //dirB.createNewFile(); + // dirB.createNewFile(); jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json"); - jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.xml"); final File jsonTempFile01 = jsonTempFile; - assertThatThrownBy(() -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, - jsonTempFile01.getAbsolutePath())) - .hasMessageContaining("could not create directory"); - - assertThatThrownBy(() -> modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, - jsonTempFile01.getAbsolutePath())) + assertThatThrownBy( + () -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile01.getAbsolutePath())) .hasMessageContaining("could not create directory"); dirA.delete(); @@ -93,15 +82,10 @@ public class ApexModelFileWriterTest { fileB.createNewFile(); jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json"); - jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.xml"); File jsonTempFile02 = jsonTempFile; - assertThatThrownBy(() -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, - jsonTempFile02.getAbsolutePath())) - .hasMessageContaining("error processing file"); - - assertThatThrownBy(() -> modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, - jsonTempFile02.getAbsolutePath())) + assertThatThrownBy( + () -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile02.getAbsolutePath())) .hasMessageContaining("error processing file"); fileB.delete(); diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java index d75f20253..1152771ea 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020,2022 Nordix Foundation * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,45 +34,33 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; -import java.lang.reflect.Field; -import javax.xml.bind.JAXBException; -import javax.xml.bind.PropertyException; -import javax.xml.bind.Unmarshaller; -import javax.xml.transform.stream.StreamSource; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxModel; @RunWith(MockitoJUnitRunner.class) public class ApexModelReaderTest { - @Mock - private Unmarshaller unmarshallerMock; - @Test public void testModelReader() throws IOException, ApexException { AxModel model = new DummyApexBasicModelCreator().getModel(); AxModel invalidModel = new DummyApexBasicModelCreator().getInvalidModel(); ApexModelWriter modelWriter = new ApexModelWriter(AxModel.class); - modelWriter.setValidateFlag(true); - modelWriter.setJsonOutput(true); + modelWriter.setValidate(true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); modelWriter.write(model, baos); ByteArrayOutputStream baosInvalid = new ByteArrayOutputStream(); - modelWriter.setValidateFlag(false); + modelWriter.setValidate(false); modelWriter.write(invalidModel, baosInvalid); ApexModelReader modelReader = new ApexModelReader(AxModel.class, true); - modelReader.setValidateFlag(true); - assertTrue(modelReader.getValidateFlag()); + modelReader.setValidate(true); + assertTrue(modelReader.isValidate()); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); AxModel readModel = modelReader.read(bais); @@ -81,26 +69,24 @@ public class ApexModelReaderTest { ByteArrayInputStream baisInvalid = new ByteArrayInputStream(baosInvalid.toByteArray()); assertThatThrownBy(() -> modelReader.read(baisInvalid)) .hasMessageStartingWith("Apex concept validation failed"); - modelReader.setValidateFlag(false); - assertFalse(modelReader.getValidateFlag()); + modelReader.setValidate(false); + assertFalse(modelReader.isValidate()); ByteArrayInputStream bais2 = new ByteArrayInputStream(baos.toByteArray()); AxModel readModel2 = modelReader.read(bais2); assertEquals(model, readModel2); - modelWriter.setJsonOutput(false); - - ByteArrayOutputStream baosXml = new ByteArrayOutputStream(); - modelWriter.write(model, baosXml); + ByteArrayOutputStream baosJson = new ByteArrayOutputStream(); + modelWriter.write(model, baosJson); - ByteArrayInputStream baisXml = new ByteArrayInputStream(baosXml.toByteArray()); - AxModel readModelXml = modelReader.read(baisXml); - assertEquals(model, readModelXml); + ByteArrayInputStream baisJson = new ByteArrayInputStream(baosJson.toByteArray()); + AxModel readModelJson = modelReader.read(baisJson); + assertEquals(model, readModelJson); String dummyString = "SomeDummyText"; ByteArrayInputStream baisDummy = new ByteArrayInputStream(dummyString.getBytes()); assertThatThrownBy(() -> modelReader.read(baisDummy)) - .hasMessage("format of input for Apex concept is neither JSON nor XML"); + .hasMessageContaining("Unable to unmarshal Apex concept"); ByteArrayInputStream nullBais = null; assertThatThrownBy(() -> modelReader.read(nullBais)) .hasMessage("concept stream may not be null"); @@ -115,42 +101,5 @@ public class ApexModelReaderTest { assertThatThrownBy(() -> modelReader.read(br)) .hasMessage("Unable to read Apex concept "); tempFile.delete(); - modelReader.setSchema(null); - - final File tempFileA = File.createTempFile("Apex", "Dummy"); - assertThatThrownBy(() -> modelReader.setSchema(tempFileA.getCanonicalPath())) - .hasMessage("Unable to load schema"); - tempFile.delete(); - modelReader.setSchema("xml/example.xsd"); - } - - @Test - public void testSetInputTypeError() throws ApexModelException, - NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - MockitoAnnotations.initMocks(this); - - ApexModelReader modelReader = new ApexModelReader(AxModel.class, true); - - Field marshallerField = modelReader.getClass().getDeclaredField("unmarshaller"); - marshallerField.setAccessible(true); - marshallerField.set(modelReader, unmarshallerMock); - marshallerField.setAccessible(false); - - assertThatThrownBy(() -> { - Mockito.doThrow(new JAXBException("Exception marshalling to JSON")).when(unmarshallerMock) - .unmarshal((StreamSource) Mockito.anyObject(), Mockito.anyObject()); - - modelReader.read("{Hello}"); - }).hasMessage("Unable to unmarshal Apex concept "); - assertThatThrownBy(() -> { - Mockito.doThrow(new PropertyException("Exception setting JAXB property")).when(unmarshallerMock) - .setProperty(Mockito.anyString(), Mockito.anyString()); - modelReader.read("{Hello}"); - }).hasMessage("JAXB error setting unmarshaller for JSON input"); - assertThatThrownBy(() -> { - Mockito.doThrow(new PropertyException("Exception setting JAXB property")).when(unmarshallerMock) - .setProperty(Mockito.anyString(), Mockito.anyString()); - modelReader.read(""); - }).hasMessage("JAXB error setting unmarshaller for XML input"); } } diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java index ad897832e..c95106aa8 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020,2022 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,14 +41,12 @@ public class ApexModelSaverTest { Path tempPath = Files.createTempDirectory("ApexTest"); assertNotNull(tempPath); - ApexModelSaver modelSaver = new ApexModelSaver(AxModel.class, model, - tempPath.toAbsolutePath().toString()); + ApexModelSaver modelSaver = + new ApexModelSaver(AxModel.class, model, tempPath.toAbsolutePath().toString()); assertNotNull(modelSaver); - modelSaver.apexModelWriteXml(); modelSaver.apexModelWriteJson(); Files.deleteIfExists(new File(tempPath.toAbsolutePath() + "/BasicModel.json").toPath()); - Files.deleteIfExists(new File(tempPath.toAbsolutePath() + "/BasicModel.xml").toPath()); Files.deleteIfExists(tempPath); } } diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java index 0b8d789ad..13e72d3e2 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020,2022 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,33 +38,26 @@ public class ApexModelStringWriterTest { AxModel basicModel = new DummyApexBasicModelCreator().getModel(); assertNotNull(basicModel); - AxKeyInfo intKeyInfo = basicModel.getKeyInformation().get("IntegerKIKey"); + AxKeyInfo intKeyInfo = basicModel.getKeyInformation().get("IntegerKIKey"); AxKeyInfo floatKeyInfo = basicModel.getKeyInformation().get("FloatKIKey"); // Ensure marshalling is OK ApexModelStringWriter stringWriter = new ApexModelStringWriter(true); - assertNotNull(stringWriter.writeJsonString(intKeyInfo, AxKeyInfo.class)); + assertNotNull(stringWriter.writeJsonString(intKeyInfo, AxKeyInfo.class)); assertNotNull(stringWriter.writeJsonString(floatKeyInfo, AxKeyInfo.class)); - assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class, true)); - assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class, true)); + assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class)); + assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class)); - assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class, false)); - assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class, false)); + assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class)); + assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class)); - assertNotNull(stringWriter.writeXmlString(intKeyInfo, AxKeyInfo.class)); - assertNotNull(stringWriter.writeXmlString(floatKeyInfo, AxKeyInfo.class)); - - assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class, true)) - .hasMessage("concept may not be null"); - assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class, false)) - .hasMessage("concept may not be null"); + assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class)).hasMessage("concept may not be null"); + assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class)).hasMessage("concept may not be null"); assertThatThrownBy(() -> stringWriter.writeJsonString(null, AxKeyInfo.class)) .hasMessage("error writing JSON string"); - assertThatThrownBy(() -> stringWriter.writeXmlString(null, AxKeyInfo.class)) - .hasMessage("error writing XML string"); - stringWriter.setValidateFlag(true); - assertTrue(stringWriter.isValidateFlag()); + stringWriter.setValidate(true); + assertTrue(stringWriter.isValidate()); } } diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java index 147eb206a..063855976 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020,2022 Nordix Foundation * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,65 +23,38 @@ package org.onap.policy.apex.model.basicmodel.handling; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.Writer; -import java.lang.reflect.Field; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.PropertyException; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.w3c.dom.Document; @RunWith(MockitoJUnitRunner.class) public class ApexModelWriterTest { - @Mock - private Marshaller marshallerMock; - @Test public void testModelWriter() throws IOException, ApexException { ApexModelWriter modelWriter = new ApexModelWriter(AxModel.class); - modelWriter.setValidateFlag(true); - assertTrue(modelWriter.getValidateFlag()); - assertEquals(0, modelWriter.getCDataFieldSet().size()); - - assertFalse(modelWriter.isJsonOutput()); - modelWriter.setJsonOutput(true); - assertTrue(modelWriter.isJsonOutput()); - modelWriter.setJsonOutput(false); - assertFalse(modelWriter.isJsonOutput()); + modelWriter.setValidate(true); + assertTrue(modelWriter.isValidate()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); AxModel model = new DummyApexBasicModelCreator().getModel(); modelWriter.write(model, baos); - modelWriter.setJsonOutput(true); - modelWriter.write(model, baos); - modelWriter.setJsonOutput(false); - modelWriter.setValidateFlag(false); + modelWriter.setValidate(false); modelWriter.write(model, baos); - modelWriter.setJsonOutput(true); - modelWriter.write(model, baos); - modelWriter.setJsonOutput(false); - modelWriter.setValidateFlag(true); + modelWriter.setValidate(true); model.getKeyInformation().getKeyInfoMap().clear(); assertThatThrownBy(() -> modelWriter.write(model, baos)) - .hasMessageContaining("Apex concept xml (BasicModel:0.0.1) validation failed"); + .hasMessageContaining("Apex concept (BasicModel:0.0.1) validation failed"); model.getKeyInformation().generateKeyInfo(model); assertThatThrownBy(() -> modelWriter.write(null, baos)) @@ -91,73 +64,4 @@ public class ApexModelWriterTest { assertThatThrownBy(() -> modelWriter.write(model, nullBaos)) .hasMessage("concept stream may not be null"); } - - @Test - public void testSetOutputTypeError() throws ApexModelException, NoSuchFieldException, SecurityException, - IllegalArgumentException, IllegalAccessException, PropertyException { - MockitoAnnotations.initMocks(this); - - ApexModelWriter modelWriter = new ApexModelWriter(AxModel.class); - - Field marshallerField = modelWriter.getClass().getDeclaredField("marshaller"); - marshallerField.setAccessible(true); - marshallerField.set(modelWriter, marshallerMock); - marshallerField.setAccessible(false); - Mockito.doThrow(new PropertyException("Exception setting JAXB property")).when(marshallerMock) - .setProperty(Mockito.anyString(), Mockito.anyString()); - assertThatThrownBy(() -> modelWriter.setJsonOutput(true)) - .hasMessage("JAXB error setting marshaller for JSON output"); - Mockito.doThrow(new PropertyException("Exception setting JAXB property")).when(marshallerMock) - .setProperty(Mockito.anyString(), Mockito.anyString()); - assertThatThrownBy(() -> modelWriter.setJsonOutput(false)) - .hasMessage("JAXB error setting marshaller for XML output"); - } - - @Test - public void testOutputJsonError() throws ApexModelException, NoSuchFieldException, SecurityException, - IllegalArgumentException, IllegalAccessException, JAXBException { - MockitoAnnotations.initMocks(this); - - ApexModelWriter modelWriter = new ApexModelWriter(AxModel.class); - - Field marshallerField = modelWriter.getClass().getDeclaredField("marshaller"); - marshallerField.setAccessible(true); - marshallerField.set(modelWriter, marshallerMock); - marshallerField.setAccessible(false); - - modelWriter.setValidateFlag(false); - modelWriter.setJsonOutput(true); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - AxModel model = new DummyApexBasicModelCreator().getModel(); - Mockito.doThrow(new JAXBException("Exception marshalling to JSON")).when(marshallerMock) - .marshal((AxModel) Mockito.anyObject(), (Writer) Mockito.anyObject()); - assertThatThrownBy(() -> modelWriter.write(model, baos)).hasMessage("Unable to marshal Apex concept to JSON"); - } - - @Test - public void testOutputXmlError() throws ApexModelException, NoSuchFieldException, SecurityException, - IllegalArgumentException, IllegalAccessException, JAXBException { - MockitoAnnotations.initMocks(this); - - ApexModelWriter modelWriter = new ApexModelWriter(AxModel.class); - modelWriter.setJsonOutput(false); - - Field marshallerField = modelWriter.getClass().getDeclaredField("marshaller"); - marshallerField.setAccessible(true); - marshallerField.set(modelWriter, marshallerMock); - marshallerField.setAccessible(false); - - modelWriter.setValidateFlag(false); - modelWriter.setJsonOutput(false); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - AxModel model = new DummyApexBasicModelCreator().getModel(); - - Mockito.doThrow(new JAXBException("Exception marshalling to JSON")).when(marshallerMock) - .marshal((AxModel) Mockito.anyObject(), (Document) Mockito.anyObject()); - - assertThatThrownBy(() -> modelWriter.write(model, baos)) - .hasMessage("Unable to marshal Apex concept to XML"); - } } diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java deleted file mode 100644 index 3385830e2..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileDescriptor; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import org.junit.After; -import org.junit.Test; - -public class ApexSchemaGeneratorTest { - private final PrintStream stdout = System.out; - - @After - public void tearDown() throws Exception { - System.setOut(stdout); - } - - @Test - public void test() throws IOException { - final ByteArrayOutputStream baos0 = new ByteArrayOutputStream(); - System.setOut(new PrintStream(baos0)); - - final String[] args0 = {}; - ApexSchemaGenerator.main(args0); - assertTrue(baos0.toString().contains("usage: ApexSchemaGenerator apex-root-class [schema-file-name]")); - System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); - - final ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); - System.setOut(new PrintStream(baos1)); - - final String[] args1 = { "hello", "goodbye", "here" }; - ApexSchemaGenerator.main(args1); - assertTrue(baos1.toString().contains("usage: ApexSchemaGenerator apex-root-class [schema-file-name]")); - System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); - - final ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); - System.setOut(new PrintStream(baos2)); - - final String[] args2 = { "hello", "goodbye" }; - ApexSchemaGenerator.main(args2); - assertTrue(baos2.toString().contains("error on Apex schema output")); - System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); - - final ByteArrayOutputStream baos3 = new ByteArrayOutputStream(); - System.setOut(new PrintStream(baos3)); - - final String[] args3 = { "hello" }; - ApexSchemaGenerator.main(args3); - assertTrue(baos3.toString().contains("could not create JAXB context, root class hello not found")); - System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); - - final ByteArrayOutputStream baos4 = new ByteArrayOutputStream(); - System.setOut(new PrintStream(baos4)); - - final String[] args4 = { "org.onap.policy.apex.model.basicmodel.concepts.AxModel" }; - ApexSchemaGenerator.main(args4); - assertTrue(baos4.toString().contains("targetNamespace=\"http://www.onap.org/policy/apex-pdp\"")); - System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); - - final ByteArrayOutputStream baos5 = new ByteArrayOutputStream(); - System.setOut(new PrintStream(baos5)); - - final File tempFile = File.createTempFile("ApexSchemaGeneratorTest", "xsd"); - tempFile.deleteOnExit(); - final String[] args5 = - { "org.onap.policy.apex.model.basicmodel.concepts.AxModel", tempFile.getCanonicalPath() }; - - ApexSchemaGenerator.main(args5); - assertTrue(tempFile.length() > 100); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java index bb9776fc7..68f755886 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java @@ -109,11 +109,6 @@ public class SupportApexBasicModelTest { assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString()); } - @Test - public void testModelWriteReadXml() throws Exception { - testApexModel.testApexModelWriteReadXml(); - } - @Test public void testModelWriteReadJson() throws Exception { testApexModel.testApexModelWriteReadJson(); diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java index 5fc678ac0..d55a9da29 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020-2021 Nordix Foundation + * Modifications Copyright (C) 2020-2022 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,6 @@ public class SupportBasicModelTest { testApexModel.testApexModelVaidateMalstructured(); testApexModel.testApexModelWriteReadJson(); - testApexModel.testApexModelWriteReadXml(); } @Test @@ -102,14 +101,11 @@ public class SupportBasicModelTest { } @Test - public void testModelCreator1XmlJson() throws ApexException { + public void testModelCreator1Json() throws ApexException { final TestApexModel testApexModel = new TestApexModel(AxModel.class, new SupportApexModelCreator1()); assertThatThrownBy(() -> testApexModel.testApexModelWriteReadJson()) .hasMessageStartingWith("error processing file"); - - assertThatThrownBy(() -> testApexModel.testApexModelWriteReadXml()) - .hasMessageStartingWith("error processing file"); } } diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java index 006c583ec..1783fc00f 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020-2021 Nordix Foundation. + * Modifications Copyright (C) 2020-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -156,19 +156,19 @@ public class SupportConceptGetterTest { ApexModelReader modelReader = new ApexModelReader(AxModel.class); ApexModelFileWriter modelWriter = new ApexModelFileWriter(true); - modelReader.setValidateFlag(false); - modelWriter.setValidateFlag(false); + modelReader.setValidate(false); + modelWriter.setValidate(false); - File tempXmlFile = File.createTempFile("ApexModel", "xml"); - modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempXmlFile.getCanonicalPath()); + File tempJsonFile = File.createTempFile("ApexModel", "json"); + modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempJsonFile.getCanonicalPath()); - FileInputStream xmlFileInputStream = new FileInputStream(tempXmlFile); - AxModel readXmlModel = modelReader.read(xmlFileInputStream); - xmlFileInputStream.close(); - assertEquals(basicModel, readXmlModel); - assertEquals(intKI91, readXmlModel.getKeyInformation().get("IntegerKIKey91")); - assertNotNull(readXmlModel.getKeyInformation().get("FloatKIKey")); - tempXmlFile.delete(); + FileInputStream jsonFileInputStream = new FileInputStream(tempJsonFile); + AxModel readJsonModel = modelReader.read(jsonFileInputStream); + jsonFileInputStream.close(); + assertEquals(basicModel, readJsonModel); + assertEquals(intKI91, readJsonModel.getKeyInformation().get("IntegerKIKey91")); + assertNotNull(readJsonModel.getKeyInformation().get("FloatKIKey")); + tempJsonFile.delete(); } private AxModel setTestBasicModel() { diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java deleted file mode 100644 index 12a67c803..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.xml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; - -public class AxReferenceKeyAdapterTest { - - @Test - public void test() throws Exception { - AxReferenceKeyAdapter arka = new AxReferenceKeyAdapter(); - assertNotNull(arka); - - AxReferenceKey rkey = new AxReferenceKey("Name", "0.0.1", "PLN", "LN"); - - String rkeyString = arka.marshal(rkey); - assertEquals("LN", rkeyString); - assertEquals(rkey.getLocalName(), arka.unmarshal(rkeyString).getLocalName()); - } -} diff --git a/model/context-model/pom.xml b/model/context-model/pom.xml index f38067cfa..f20808186 100644 --- a/model/context-model/pom.xml +++ b/model/context-model/pom.xml @@ -1,6 +1,7 @@ - - - - PolicyModel - 0.0.1 - - - - KeyInfoMapKey - 0.0.1 - - - - - ContextSchemas - 0.0.1 - - - - ContextSchemas - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e000 - - - - - - KeyInfoMapKey - 0.0.1 - - - - KeyInfoMapKey - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e001 - - - - - - MapType - 0.0.1 - - - - MapType - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e002 - - - - - - PolicyModel - 0.0.1 - - - - PolicyModel - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e003 - - - - - - StringType - 0.0.1 - - - - StringType - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e004 - - - - - - context - 0.0.1 - - - - context - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e005 - - - - - - contextAlbum0 - 0.0.1 - - - - contextAlbum0 - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e006 - - - - - - contextAlbum1 - 0.0.1 - - - - contextAlbum1 - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e007 - - - - - - eventContextItem0 - 0.0.1 - - - - eventContextItem0 - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e008 - - - - - - eventContextItem1 - 0.0.1 - - - - eventContextItem1 - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e009 - - - - - - events - 0.0.1 - - - - events - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e010 - - - - - - inEvent - 0.0.1 - - - - inEvent - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e011 - - - - - - outEvent0 - 0.0.1 - - - - outEvent0 - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e012 - - - - - - outEvent1 - 0.0.1 - - - - outEvent1 - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e013 - - - - - - policies - 0.0.1 - - - - policies - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e014 - - - - - - policy - 0.0.1 - - - - policy - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e015 - - - - - - task - 0.0.1 - - - - task - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e016 - - - - - - tasks - 0.0.1 - - - - tasks - 0.0.1 - - 0ce9168c-e6df-414f-9646-6da464b6e017 - - - - - - - - policies - 0.0.1 - - - - - policy - 0.0.1 - - - - policy - 0.0.1 - - - - - state - - - policy - 0.0.1 - NULL - state - - - inEvent - 0.0.1 - - - - stateOutput0 - - - policy - 0.0.1 - state - stateOutput0 - - - outEvent0 - 0.0.1 - - - NULL - 0.0.0 - NULL - NULL - - - - - - contextAlbum0 - 0.0.1 - - - contextAlbum1 - 0.0.1 - - - taskSelectionLogic - MVEL - - - - task - 0.0.1 - - - - - task - 0.0.1 - - - - policy - 0.0.1 - state - task - - DIRECT - - policy - 0.0.1 - state - stateOutput0 - - - - - - - - state - - - - - - - tasks - 0.0.1 - - - - - task - 0.0.1 - - - - task - 0.0.1 - - - - taskParameter0 - - - task - 0.0.1 - NULL - taskParameter0 - - Task parameter 0 value - - - - taskParameter1 - - - task - 0.0.1 - NULL - taskParameter1 - - Task parameter 1 value - - - - - contextAlbum0 - 0.0.1 - - - contextAlbum1 - 0.0.1 - - - taskLogic - MVEL - - - - - - - - - events - 0.0.1 - - - - - inEvent - 0.0.1 - - - - inEvent - 0.0.1 - - org.onap.policy.apex.model.policymodel.events - Source - Target - - - IEPAR0 - - IEPAR0 - - eventContextItem0 - 0.0.1 - - - - - IEPAR1 - - IEPAR1 - - eventContextItem1 - 0.0.1 - - - - - - - - - outEvent0 - 0.0.1 - - - - outEvent0 - 0.0.1 - - org.onap.policy.apex.model.policymodel.events - Source - Target - - - OE0PAR0 - - OE0PAR0 - - eventContextItem0 - 0.0.1 - - - - - OE0PAR1 - - OE0PAR1 - - eventContextItem1 - 0.0.1 - - - - - OE1PAR0 - - OE1PAR0 - - eventContextItem0 - 0.0.1 - - - - - OE1PAR1 - - OE1PAR1 - - eventContextItem1 - 0.0.1 - - - - - - - - - outEvent1 - 0.0.1 - - - - outEvent1 - 0.0.1 - - org.onap.policy.apex.model.policymodel.events - Source - Target - - - OE1PAR0 - - OE1PAR0 - - eventContextItem0 - 0.0.1 - - - - - OE1PAR1 - - OE1PAR1 - - eventContextItem1 - 0.0.1 - - - - - - - - - - - context - 0.0.1 - - - - - contextAlbum0 - 0.0.1 - - - - contextAlbum0 - 0.0.1 - - APPLICATION - true - - MapType - 0.0.1 - - - - - - contextAlbum1 - 0.0.1 - - - - contextAlbum1 - 0.0.1 - - GLOBAL - false - - StringType - 0.0.1 - - - - - - - - ContextSchemas - 0.0.1 - - - - - MapType - 0.0.1 - - - - MapType - 0.0.1 - - Java - org.onap.policy.apex.model.policymodel.concepts.TestContextItem00A - - - - - - StringType - 0.0.1 - - - - StringType - 0.0.1 - - Java - org.onap.policy.apex.model.policymodel.concepts.TestContextItem000 - - - - - - eventContextItem0 - 0.0.1 - - - - eventContextItem0 - 0.0.1 - - Java - java.lang.String - - - - - eventContextItem1 - 0.0.1 - - - - eventContextItem1 - 0.0.1 - - Java - java.lang.Long - - - - - diff --git a/model/model-api/src/test/resources/models/RealPolicyModel.json b/model/model-api/src/test/resources/models/RealPolicyModel.json new file mode 100644 index 000000000..f084747f2 --- /dev/null +++ b/model/model-api/src/test/resources/models/RealPolicyModel.json @@ -0,0 +1,3076 @@ +{ + "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" + }, + "outgoingEventReference": [ + { + "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" + }, + "outgoingEventReference": [ + { + "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" + }, + "outgoingEventReference": [ + { + "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" + }, + "outgoingEventReference": [ + { + "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" + }, + "outgoingEventReference": [ + { + "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" + }, + "outgoingEventReference": [ + { + "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" + }, + "outgoingEventReference": [ + { + "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" + }, + "outgoingEventReference": [ + { + "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" + }, + "outgoingEventReference": [ + { + "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" + }, + "outgoingEventReference": [ + { + "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" + }, + "outgoingEventReference": [ + { + "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" + }, + "inputEvent": { + "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 + } + } + ] + }, + "toscaPolicyState": "" + }, + "outputEvents": { + "entry": [ + { + "key": "VCPEStateUpdatedEvent", + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + } + ] + }, + "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" + }, + "inputEvent": { + "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 + } + } + ] + }, + "toscaPolicyState": "" + }, + "outputEvents": { + "entry": [ + { + "key": "APPCRestartVNFRequestEvent", + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + } + ] + }, + "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" + }, + "inputEvent": { + "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 + } + } + ] + }, + "toscaPolicyState": "" + }, + "outputEvents": { + "entry": [ + { + "key": "VCPEStateUpdatedEvent", + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + } + ] + }, + "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" + }, + "inputEvent": { + "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 + } + } + ] + }, + "toscaPolicyState": "" + }, + "outputEvents": { + "entry": [ + { + "key": "VCPEStateUpdatedEvent", + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + } + ] + }, + "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" + }, + "inputEvent": { + "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 + } + } + ] + }, + "toscaPolicyState": "" + }, + "outputEvents": { + "entry": [ + { + "key": "ControlLoopLogEvent", + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + } + ] + }, + "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" + }, + "inputEvent": { + "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 + } + } + ] + }, + "toscaPolicyState": "" + }, + "outputEvents": { + "entry": [ + { + "key": "VCPEStateUpdatedEvent", + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + } + ] + }, + "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" + }, + "inputEvent": { + "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 + } + } + ] + }, + "toscaPolicyState": "" + }, + "outputEvents": { + "entry": [ + { + "key": "VCPEStateUpdatedEvent", + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + } + ] + }, + "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" + }, + "inputEvent": { + "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 + } + } + ] + }, + "toscaPolicyState": "" + }, + "outputEvents": { + "entry": [ + { + "key": "GuardRequestEvent", + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + } + ] + }, + "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" + }, + "inputEvent": { + "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 + } + } + ] + }, + "toscaPolicyState": "" + }, + "outputEvents": { + "entry": [ + { + "key": "VCPEStateUpdatedEvent", + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + } + ] + }, + "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" + }, + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + }, + { + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + }, + { + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + }, + { + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + }, + { + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + }, + { + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + }, + { + "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 + } + } + ] + }, + "toscaPolicyState": "" + } + } + ] + } + }, + "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" + } + } + ] + } + } +} diff --git a/model/policy-model/pom.xml b/model/policy-model/pom.xml index 3fbf8b1dc..cde0fa83c 100644 --- a/model/policy-model/pom.xml +++ b/model/policy-model/pom.xml @@ -1,6 +1,7 @@