diff options
9 files changed, 39 insertions, 146 deletions
diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/params/ControlLoopParams.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/params/ControlLoopParams.java deleted file mode 100644 index 36f804f6e..000000000 --- a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/params/ControlLoopParams.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * AppcLcmActorServiceProvider - * ================================================================================ - * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.controlloop.params; - -import java.io.Serializable; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -public class ControlLoopParams implements Serializable { - - private static final long serialVersionUID = 970755684770982776L; - - private String closedLoopControlName; - private String controlLoopYaml; - private String policyName; - private String policyScope; - private String policyVersion; - - /** - * Construct an instance from an existing instance. - * - * @param params the existing instance - */ - public ControlLoopParams(ControlLoopParams params) { - this.closedLoopControlName = params.closedLoopControlName; - this.controlLoopYaml = params.controlLoopYaml; - this.policyName = params.policyName; - this.policyScope = params.policyScope; - this.policyVersion = params.policyVersion; - } -} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/params/ControlLoopParamsTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/params/ControlLoopParamsTest.java deleted file mode 100644 index fd17f782e..000000000 --- a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/params/ControlLoopParamsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * controlloop - * ================================================================================ - * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.controlloop.params; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; - -public class ControlLoopParamsTest { - - @Test - public void test() { - ControlLoopParams params = new ControlLoopParams(); - assertNotNull(params); - - params.setClosedLoopControlName("name"); - params.setControlLoopYaml("yaml"); - params.setPolicyName("name"); - params.setPolicyScope("scope"); - params.setPolicyVersion("1"); - - ControlLoopParams params2 = new ControlLoopParams(params); - - assertEquals("name", params2.getClosedLoopControlName()); - assertEquals("yaml", params2.getControlLoopYaml()); - assertEquals("name", params2.getPolicyName()); - assertEquals("scope", params2.getPolicyScope()); - assertEquals("1", params2.getPolicyVersion()); - - } -} diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java index e50694b93..5b1566d8b 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,15 +23,16 @@ package org.onap.policy.models.pdp.concepts; import java.util.ArrayList; import java.util.List; + import lombok.Getter; import lombok.Setter; import lombok.ToString; + import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.pdp.enums.PdpHealthStatus; import org.onap.policy.models.pdp.enums.PdpMessageType; import org.onap.policy.models.pdp.enums.PdpState; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; /** * Class to represent the PDP_STATUS message that all the PDP's will send to PAP. @@ -48,11 +49,10 @@ public class PdpStatus extends PdpMessage { private PdpHealthStatus healthy; /** - * Description of the PDP or the PDP type. May be left {@code null}. + * Description of the PDP or the PDP type. May be left {@code null}. */ private String description; - private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes; private List<ToscaPolicyIdentifier> policies; private String deploymentInstanceInfo; private String properties; @@ -72,15 +72,13 @@ public class PdpStatus extends PdpMessage { * * @param source source from which to copy */ - public PdpStatus(PdpStatus source) { + public PdpStatus(final PdpStatus source) { super(source); this.pdpType = source.pdpType; this.state = source.state; this.healthy = source.healthy; this.description = source.description; - this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, ToscaPolicyTypeIdentifier::new, - new ArrayList<>(0)); this.policies = PfUtils.mapList(source.policies, ToscaPolicyIdentifier::new, new ArrayList<>(0)); this.deploymentInstanceInfo = source.deploymentInstanceInfo; this.properties = source.properties; diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatusTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatusTest.java index 3284d95ff..68af3d3b7 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatusTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatusTest.java @@ -1,8 +1,9 @@ -/* +/*- * ============LICENSE_START======================================================= * ONAP Policy Models * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,11 +27,11 @@ import static org.onap.policy.models.pdp.concepts.PdpMessageUtils.removeVariable import java.util.Arrays; import java.util.Collections; + import org.junit.Test; import org.onap.policy.models.pdp.enums.PdpHealthStatus; import org.onap.policy.models.pdp.enums.PdpState; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; public class PdpStatusTest { @@ -38,10 +39,9 @@ public class PdpStatusTest { public void testCopyConstructor() { assertThatThrownBy(() -> new PdpStatus(null)).isInstanceOf(NullPointerException.class); - PdpStatus orig = new PdpStatus(); + final PdpStatus orig = new PdpStatus(); // verify with null values - orig.setSupportedPolicyTypes(Collections.emptyList()); orig.setPolicies(Collections.emptyList()); assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpStatus(orig).toString())); @@ -56,17 +56,16 @@ public class PdpStatusTest { orig.setPolicies(Arrays.asList(new ToscaPolicyIdentifier("policy-A", "1.0.0"))); orig.setProperties("my-properties"); - PdpResponseDetails resp = new PdpResponseDetails(); + final PdpResponseDetails resp = new PdpResponseDetails(); resp.setResponseMessage("my-response"); orig.setResponse(resp); orig.setState(PdpState.SAFE); - PdpStatistics stats = new PdpStatistics(); + final PdpStatistics stats = new PdpStatistics(); stats.setPdpInstanceId("my-pdp-id"); orig.setStatistics(stats); - orig.setSupportedPolicyTypes(Arrays.asList(new ToscaPolicyTypeIdentifier("type-A", "2.0.0"))); assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpStatus(orig).toString())); } diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java index 7b8f29c4b..855919e71 100644 --- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java +++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,6 +23,7 @@ package org.onap.policy.models.sim.pdp.handler; import java.util.ArrayList; import java.util.List; + import org.onap.policy.common.utils.services.Registry; import org.onap.policy.models.pdp.concepts.PdpResponseDetails; import org.onap.policy.models.pdp.concepts.PdpStatus; @@ -59,7 +60,6 @@ public class PdpMessageHandler { pdpStatus.setHealthy(PdpHealthStatus.HEALTHY); pdpStatus.setDescription(pdpStatusParameters.getDescription()); pdpStatus.setName(instanceId); - pdpStatus.setSupportedPolicyTypes(getSupportedPolicyTypesFromParameters(pdpStatusParameters)); return pdpStatus; } @@ -94,7 +94,6 @@ public class PdpMessageHandler { pdpStatus.setState(pdpStatusContext.getState()); pdpStatus.setHealthy(pdpStatusContext.getHealthy()); pdpStatus.setDescription(pdpStatusContext.getDescription()); - pdpStatus.setSupportedPolicyTypes(pdpStatusContext.getSupportedPolicyTypes()); pdpStatus.setPolicies(pdpStatusContext.getPolicies()); pdpStatus.setPdpGroup(pdpStatusContext.getPdpGroup()); pdpStatus.setPdpSubgroup(pdpStatusContext.getPdpSubgroup()); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java index e9590072e..86d67e4d8 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java @@ -28,14 +28,18 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; + import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; +import javax.persistence.Lob; import javax.persistence.Table; + import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; + import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; @@ -67,6 +71,7 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen private List<JpaToscaConstraint> constraints; @ElementCollection + @Lob private Map<String, JpaToscaProperty> properties; /** @@ -142,7 +147,7 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen if (toscaDataType.getConstraints() != null) { constraints = new ArrayList<>(); - for (ToscaConstraint toscaConstraint: toscaDataType.getConstraints()) { + for (ToscaConstraint toscaConstraint : toscaDataType.getConstraints()) { constraints.add(JpaToscaConstraint.newInstance(toscaConstraint)); } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java index 0a7983c47..508b47060 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java @@ -189,7 +189,7 @@ public class SimpleToscaProvider { serviceTemplate.getPolicyTypes().getConceptMap().putAll(asConceptMap(jpaPolicyTypeList)); // Return all data types - // TODO: In the next review, return just the data types used by the policy types on the policy type list + // TODO: In an upcoming review, return just the data types used by the policy types on the policy type list List<JpaToscaDataType> jpaDataTypeList = dao.getFiltered(JpaToscaDataType.class, null, null); if (!CollectionUtils.isEmpty(jpaDataTypeList)) { serviceTemplate.setDataTypes(new JpaToscaDataTypes()); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java index 5ba42fef5..0e1d8e96b 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java @@ -20,6 +20,8 @@ package org.onap.policy.models.tosca.utils; +import java.util.function.Function; + import javax.ws.rs.core.Response; import org.onap.policy.models.base.PfModelRuntimeException; @@ -102,8 +104,8 @@ public final class ToscaUtils { * @param serviceTemplate the service template containing policy types to be checked */ public static void assertExist(final JpaToscaServiceTemplate serviceTemplate, - final ToscaChecker<JpaToscaServiceTemplate> checkerFunction) { - String message = checkerFunction.check(serviceTemplate); + final Function<JpaToscaServiceTemplate, String> checkerFunction) { + String message = checkerFunction.apply(serviceTemplate); if (message != null) { LOGGER.warn(message); throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, message); @@ -116,14 +118,14 @@ public final class ToscaUtils { * @param serviceTemplate the service template containing policy types to be checked */ public static boolean doExist(final JpaToscaServiceTemplate serviceTemplate, - final ToscaChecker<JpaToscaServiceTemplate> checkerFunction) { - return checkerFunction.check(serviceTemplate) == null; + final Function<JpaToscaServiceTemplate, String> checkerFunction) { + return checkerFunction.apply(serviceTemplate) == null; } /** * Check if data types have been specified correctly. */ - public static ToscaChecker<JpaToscaServiceTemplate> checkDataTypesExist() { + public static Function<JpaToscaServiceTemplate, String> checkDataTypesExist() { return serviceTemplate -> { if (serviceTemplate.getDataTypes() == null) { return "no data types specified on service template"; @@ -140,7 +142,7 @@ public final class ToscaUtils { /** * Check if policy types have been specified correctly. */ - public static ToscaChecker<JpaToscaServiceTemplate> checkPolicyTypesExist() { + public static Function<JpaToscaServiceTemplate, String> checkPolicyTypesExist() { return serviceTemplate -> { if (serviceTemplate.getPolicyTypes() == null) { return "no policy types specified on service template"; @@ -157,7 +159,7 @@ public final class ToscaUtils { /** * Check if policies have been specified correctly. */ - public static ToscaChecker<JpaToscaServiceTemplate> checkPoliciesExist() { + public static Function<JpaToscaServiceTemplate, String> checkPoliciesExist() { return serviceTemplate -> { if (serviceTemplate.getTopologyTemplate() == null) { return "topology template not specified on service template"; @@ -174,9 +176,4 @@ public final class ToscaUtils { return null; }; } - - @FunctionalInterface - interface ToscaChecker<T> { - String check(final T serviceTemplate); - } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java index ebe01a65c..9b8eff13e 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java @@ -47,7 +47,7 @@ public class ToscaUtilsTest { assertFalse(ToscaUtils.doDataTypesExist(jpaToscaServiceTemplate)); assertEquals("no data types specified on service template", - ToscaUtils.checkDataTypesExist().check(jpaToscaServiceTemplate)); + ToscaUtils.checkDataTypesExist().apply(jpaToscaServiceTemplate)); assertThatThrownBy(() -> { ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate); }).hasMessage("no data types specified on service template"); @@ -56,7 +56,7 @@ public class ToscaUtilsTest { assertFalse(ToscaUtils.doDataTypesExist(jpaToscaServiceTemplate)); assertEquals("list of data types specified on service template is empty", - ToscaUtils.checkDataTypesExist().check(jpaToscaServiceTemplate)); + ToscaUtils.checkDataTypesExist().apply(jpaToscaServiceTemplate)); assertThatThrownBy(() -> { ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate); }).hasMessage("list of data types specified on service template is empty"); @@ -64,7 +64,7 @@ public class ToscaUtilsTest { jpaToscaServiceTemplate.getDataTypes().getConceptMap().put(new PfConceptKey(), null); assertTrue(ToscaUtils.doDataTypesExist(jpaToscaServiceTemplate)); - assertEquals(null, ToscaUtils.checkDataTypesExist().check(jpaToscaServiceTemplate)); + assertEquals(null, ToscaUtils.checkDataTypesExist().apply(jpaToscaServiceTemplate)); assertThatCode(() -> { ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate); }).doesNotThrowAnyException(); @@ -77,7 +77,7 @@ public class ToscaUtilsTest { assertFalse(ToscaUtils.doPolicyTypesExist(jpaToscaServiceTemplate)); assertEquals("no policy types specified on service template", - ToscaUtils.checkPolicyTypesExist().check(jpaToscaServiceTemplate)); + ToscaUtils.checkPolicyTypesExist().apply(jpaToscaServiceTemplate)); assertThatThrownBy(() -> { ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate); }).hasMessage("no policy types specified on service template"); @@ -86,7 +86,7 @@ public class ToscaUtilsTest { assertFalse(ToscaUtils.doPolicyTypesExist(jpaToscaServiceTemplate)); assertEquals("list of policy types specified on service template is empty", - ToscaUtils.checkPolicyTypesExist().check(jpaToscaServiceTemplate)); + ToscaUtils.checkPolicyTypesExist().apply(jpaToscaServiceTemplate)); assertThatThrownBy(() -> { ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate); }).hasMessage("list of policy types specified on service template is empty"); @@ -94,7 +94,7 @@ public class ToscaUtilsTest { jpaToscaServiceTemplate.getPolicyTypes().getConceptMap().put(new PfConceptKey(), null); assertTrue(ToscaUtils.doPolicyTypesExist(jpaToscaServiceTemplate)); - assertEquals(null, ToscaUtils.checkPolicyTypesExist().check(jpaToscaServiceTemplate)); + assertEquals(null, ToscaUtils.checkPolicyTypesExist().apply(jpaToscaServiceTemplate)); assertThatCode(() -> { ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate); }).doesNotThrowAnyException(); @@ -106,7 +106,7 @@ public class ToscaUtilsTest { assertFalse(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate)); assertEquals("topology template not specified on service template", - ToscaUtils.checkPoliciesExist().check(jpaToscaServiceTemplate)); + ToscaUtils.checkPoliciesExist().apply(jpaToscaServiceTemplate)); assertThatThrownBy(() -> { ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate); }).hasMessage("topology template not specified on service template"); @@ -115,7 +115,7 @@ public class ToscaUtilsTest { assertFalse(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate)); assertEquals("no policies specified on topology template of service template", - ToscaUtils.checkPoliciesExist().check(jpaToscaServiceTemplate)); + ToscaUtils.checkPoliciesExist().apply(jpaToscaServiceTemplate)); assertThatThrownBy(() -> { ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate); }).hasMessage("no policies specified on topology template of service template"); @@ -124,7 +124,7 @@ public class ToscaUtilsTest { assertFalse(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate)); assertEquals("list of policies specified on topology template of service template is empty", - ToscaUtils.checkPoliciesExist().check(jpaToscaServiceTemplate)); + ToscaUtils.checkPoliciesExist().apply(jpaToscaServiceTemplate)); assertThatThrownBy(() -> { ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate); }).hasMessage("list of policies specified on topology template of service template is empty"); @@ -132,7 +132,7 @@ public class ToscaUtilsTest { jpaToscaServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(new PfConceptKey(), null); assertTrue(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate)); - assertEquals(null, ToscaUtils.checkPoliciesExist().check(jpaToscaServiceTemplate)); + assertEquals(null, ToscaUtils.checkPoliciesExist().apply(jpaToscaServiceTemplate)); assertThatCode(() -> { ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate); }).doesNotThrowAnyException(); |