diff options
16 files changed, 98 insertions, 60 deletions
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java index 16680d800..e9a10a134 100644 --- a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java +++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java @@ -648,19 +648,20 @@ public class DefaultPfDao implements PfDao { * Check that a query returned one and only one entry and return that entry. * * @param someClass the class being searched for - * @param conceptName the concept name being searched for + * @param searchFilter the search filter * @param resultList the result list returned by the query * @return the single unique result */ - private <T extends PfConcept> T getSingleResult(final Class<T> someClass, final String searchFilter, List<T> ret) { - if (ret == null || ret.isEmpty()) { + private <T extends PfConcept> T getSingleResult(final Class<T> someClass, final String searchFilter, + List<T> resultList) { + if (resultList == null || resultList.isEmpty()) { return null; } - if (ret.size() > 1) { + if (resultList.size() > 1) { throw new IllegalArgumentException("More than one result was returned query on " + someClass - + " with filter " + searchFilter + ": " + ret); + + " with filter " + searchFilter + ": " + resultList); } - return ret.get(0); + return resultList.get(0); } /** @@ -668,7 +669,7 @@ public class DefaultPfDao implements PfDao { * * @param <T> the type of the object to get, a subclass of {@link PfConcept} * @param someClass the class of the object to get, a subclass of {@link PfConcept} - * @param t the object that was retrieved from the database + * @param objToCheck the object that was retrieved from the database * @return the checked object or null */ private <T extends PfConcept> T checkAndReturn(final Class<T> someClass, final T objToCheck) { diff --git a/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperation.java b/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperation.java index c3aae6879..5d256e8ae 100644 --- a/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperation.java +++ b/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperation.java @@ -119,7 +119,7 @@ public class AppcLcmOperation extends BidirectionalTopicOperation<AppcLcmDmaapWr * decoded into an object. * * @param source source from which to get the values - * @param map where to place the decoded values + * @param request where to place the decoded values */ private void convertPayload(Map<String, Object> source, AppcLcmInput request) { try { diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java index c4d5cca33..5765f35ba 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java @@ -177,9 +177,8 @@ public abstract class BidirectionalTopicOperation<Q, S> extends OperationPartial /** * Processes a response. * - * @param infra communication infrastructure on which the response was received * @param outcome outcome to be populated - * @param response raw response to process + * @param rawResponse raw response to process * @param scoResponse response, as a {@link StandardCoderObject} * @return the outcome, or {@code null} if still waiting for completion */ diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java index 4812e7739..047e3d1c8 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java @@ -214,7 +214,7 @@ public abstract class HttpOperation<T> extends OperationPartial { * * @param outcome outcome to be populate * @param url URL to which to request was sent - * @param response raw response to process + * @param rawResponse raw response to process * @return a future to cancel or await the outcome */ protected CompletableFuture<OperationOutcome> processResponse(OperationOutcome outcome, String url, diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java index 5fbf7d2df..4f2ab0267 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java @@ -217,7 +217,6 @@ public abstract class OperationPartial implements Operation { /** * Starts the operation attempt, without doing any retries. * - * @param params operation parameters * @param attempt attempt number, typically starting with 1 * @return a future that will return the result of a single operation attempt */ diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java index 117b4097b..553fd1726 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java @@ -437,7 +437,6 @@ public class HttpOperationTest { /** * Initializes the configuration. * - * @param operator operator to be initialized * @param clientName name of the client which it should use */ private void initConfig(String clientName) { @@ -447,7 +446,6 @@ public class HttpOperationTest { /** * Initializes the configuration with a real client. * - * @param operator operator to be initialized * @param clientName name of the client which it should use */ private void initConfig(String clientName, HttpClientFactory factory) { @@ -458,7 +456,6 @@ public class HttpOperationTest { /** * Initializes the configuration with a real client. * - * @param operator operator to be initialized * @param clientName name of the client which it should use */ private void initRealConfig(String clientName) { diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/Pdp.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/Pdp.java index 034374c29..978dd7cc8 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/Pdp.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/Pdp.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ package org.onap.policy.models.pdp.concepts; +import java.time.Instant; import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -48,6 +49,13 @@ public class Pdp { private String message; /** + * Time when the record was last updated as a result of receiving a message from the + * PDP. + */ + private Instant lastUpdate; + + + /** * Constructs the object, creating a deep copy of the fields from the source. * * @param source source from which to copy the fields @@ -57,5 +65,6 @@ public class Pdp { this.pdpState = source.pdpState; this.healthy = source.healthy; this.message = source.message; + this.lastUpdate = source.lastUpdate; } } diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java index ad64deb21..5373ace1d 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroupFilter.java @@ -186,7 +186,7 @@ public class PdpGroupFilter implements PfObjectFilter<PdpGroup> { * Filter PDP groups on PDP state. * * @param pdpGroup the PDP group to check - * @param policyFilter the policy regular expressions to check for + * @param pdpState the PDP state of interest * @return true if the filter should let this PDP group through */ private boolean filterOnPdpState(final PdpGroup pdpGroup, final PdpState pdpState) { diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java index daa327d9f..7c584f3e6 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java @@ -24,6 +24,7 @@ package org.onap.policy.models.pdp.persistence.concepts; import java.io.Serializable; +import java.util.Date; import java.util.List; import javax.persistence.Column; import javax.persistence.EmbeddedId; @@ -31,10 +32,12 @@ import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; -import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.builder.CompareToBuilder; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.parameters.annotations.NotBlank; import org.onap.policy.common.parameters.annotations.NotNull; @@ -77,6 +80,10 @@ public class JpaPdp extends PfConcept implements PfAuthorative<Pdp>, Serializabl @NotBlank private String message; + @Column(precision = 0) + @Temporal(TemporalType.TIMESTAMP) + private Date lastUpdate; + /** * The Default Constructor creates a {@link JpaPdp} object with a null key. */ @@ -101,10 +108,11 @@ public class JpaPdp extends PfConcept implements PfAuthorative<Pdp>, Serializabl * @param healthy the health state of the PDP */ public JpaPdp(@NonNull final PfReferenceKey key, @NonNull final PdpState pdpState, - @NonNull PdpHealthStatus healthy) { + @NonNull PdpHealthStatus healthy) { this.key = key; this.pdpState = pdpState; this.healthy = healthy; + this.lastUpdate = new Date(); } /** @@ -118,6 +126,7 @@ public class JpaPdp extends PfConcept implements PfAuthorative<Pdp>, Serializabl this.pdpState = copyConcept.pdpState; this.healthy = copyConcept.healthy; this.message = copyConcept.message; + this.lastUpdate = copyConcept.lastUpdate; } /** @@ -137,6 +146,7 @@ public class JpaPdp extends PfConcept implements PfAuthorative<Pdp>, Serializabl pdp.setPdpState(pdpState); pdp.setHealthy(healthy); pdp.setMessage(message); + pdp.setLastUpdate(lastUpdate.toInstant()); return pdp; } @@ -151,6 +161,12 @@ public class JpaPdp extends PfConcept implements PfAuthorative<Pdp>, Serializabl this.setPdpState(pdp.getPdpState()); this.setHealthy(pdp.getHealthy()); this.setMessage(pdp.getMessage()); + + if (pdp.getLastUpdate() == null) { + this.setLastUpdate(new Date()); + } else { + this.setLastUpdate(Date.from(pdp.getLastUpdate())); + } } @Override @@ -193,20 +209,15 @@ public class JpaPdp extends PfConcept implements PfAuthorative<Pdp>, Serializabl } final JpaPdp other = (JpaPdp) otherConcept; - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - - int result = ObjectUtils.compare(pdpState, other.pdpState); - if (result != 0) { - return result; - } - - result = ObjectUtils.compare(healthy, other.healthy); - if (result != 0) { - return result; - } - return ObjectUtils.compare(message, other.message); + // @formatter:off + return new CompareToBuilder() + .append(this.key, other.key) + .append(this.pdpState, other.pdpState) + .append(this.healthy, other.healthy) + .append(this.message, other.message) + .append(this.lastUpdate, other.lastUpdate) + .toComparison(); + // @formatter:on } } diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java index fec8ec572..681e39e71 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java @@ -358,7 +358,7 @@ public class PdpProvider { /** * Convert JPA PDP group list to an authorative PDP group list. * - * @param foundPdpGroups the list to convert + * @param jpaPdpGroupList the list to convert * @return the authorative list */ private List<PdpGroup> asPdpGroupList(List<JpaPdpGroup> jpaPdpGroupList) { diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java index b5b29d30b..ab592f510 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2021 Nordix Foundation. - * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.util.Date; import org.junit.Test; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfReferenceKey; @@ -47,6 +48,7 @@ public class JpaPdpTest { private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; private static final String PDP1 = "ThePDP"; + private static final Date CURRENT_DATE = new Date(); @Test public void testJpaPdp() { @@ -79,10 +81,6 @@ public class JpaPdpTest { }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { - new JpaPdp(null, null, PdpHealthStatus.UNKNOWN); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { new JpaPdp((Pdp) null); }).hasMessageMatching("authorativeConcept is marked .*ull but is null"); @@ -175,7 +173,7 @@ public class JpaPdpTest { } @Test - public void testJpaPdpCompare() { + public void testJpaPdpCompare_testToAuthorative() { JpaPdp testJpaPdp = setUpJpaPdp(); JpaPdp otherJpaPdp = new JpaPdp(testJpaPdp); @@ -204,7 +202,15 @@ public class JpaPdpTest { testJpaPdp.setMessage("Valid Message"); assertEquals(0, testJpaPdp.compareTo(otherJpaPdp)); + testJpaPdp.setLastUpdate(new Date(0)); + assertEquals(-1, testJpaPdp.compareTo(otherJpaPdp)); + testJpaPdp.setLastUpdate(CURRENT_DATE); + assertEquals(0, testJpaPdp.compareTo(otherJpaPdp)); + assertEquals(testJpaPdp, new JpaPdp(testJpaPdp)); + + otherJpaPdp.fromAuthorative(testJpaPdp.toAuthorative()); + assertEquals(0, testJpaPdp.compareTo(otherJpaPdp)); } private JpaPdp setUpJpaPdp() { @@ -218,6 +224,7 @@ public class JpaPdpTest { testJpaPdp.setPdpState(PdpState.ACTIVE); testJpaPdp.setHealthy(PdpHealthStatus.HEALTHY); testJpaPdp.setMessage("Valid Message"); + testJpaPdp.setLastUpdate(CURRENT_DATE); return testJpaPdp; } } diff --git a/models-pdp/src/test/resources/testdata/PdpGroups0.json b/models-pdp/src/test/resources/testdata/PdpGroups0.json index 01e140cd8..be3d80086 100644 --- a/models-pdp/src/test/resources/testdata/PdpGroups0.json +++ b/models-pdp/src/test/resources/testdata/PdpGroups0.json @@ -32,11 +32,12 @@ "instanceId": "apex-0", "pdpState": "ACTIVE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" } ] } ] } ] -}
\ No newline at end of file +} diff --git a/models-pdp/src/test/resources/testdata/PdpGroups0Update.json b/models-pdp/src/test/resources/testdata/PdpGroups0Update.json index 05594fa47..06d0aeff0 100644 --- a/models-pdp/src/test/resources/testdata/PdpGroups0Update.json +++ b/models-pdp/src/test/resources/testdata/PdpGroups0Update.json @@ -32,19 +32,22 @@ "instanceId": "apex-0", "pdpState": "ACTIVE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" }, { "instanceId": "apex-1", "pdpState": "ACTIVE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" }, { "instanceId": "apex-2", "pdpState": "ACTIVE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" } ] }, @@ -72,11 +75,12 @@ "instanceId": "drools-0", "pdpState": "ACTIVE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" } ] } ] } ] -}
\ No newline at end of file +} diff --git a/models-pdp/src/test/resources/testdata/PdpGroupsForFiltering.json b/models-pdp/src/test/resources/testdata/PdpGroupsForFiltering.json index f1d4378fd..dfc8308b3 100644 --- a/models-pdp/src/test/resources/testdata/PdpGroupsForFiltering.json +++ b/models-pdp/src/test/resources/testdata/PdpGroupsForFiltering.json @@ -44,25 +44,29 @@ "instanceId": "apex-0", "pdpState": "ACTIVE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" }, { "instanceId": "apex-1", "pdpState": "PASSIVE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" }, { "instanceId": "apex-2", "pdpState": "SAFE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" }, { "instanceId": "apex-3", "pdpState": "TEST", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" } ] } @@ -108,7 +112,8 @@ "instanceId": "apex-0", "pdpState": "ACTIVE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" } ] } @@ -154,7 +159,8 @@ "instanceId": "apex-0", "pdpState": "SAFE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" } ] }, @@ -182,7 +188,8 @@ "instanceId": "apex-0", "pdpState": "SAFE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" } ] } @@ -224,7 +231,8 @@ "instanceId": "apex-0", "pdpState": "PASSIVE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" } ] } @@ -262,7 +270,8 @@ "instanceId": "apex-0", "pdpState": "TEST", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" } ] }, @@ -290,7 +299,8 @@ "instanceId": "apex-0", "pdpState": "PASSIVE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" } ] }, @@ -318,7 +328,8 @@ "instanceId": "apex-0", "pdpState": "ACTIVE", "healthy": "NOT_HEALTHY", - "message": "message from PDP" + "message": "message from PDP", + "lastUpdate": "1970-01-01T00:00:00Z" } ] } diff --git a/models-pdp/src/test/resources/testdata/PdpGroupsNoPDPs.json b/models-pdp/src/test/resources/testdata/PdpGroupsNoPDPs.json index e37b6c5a6..eaeb30145 100644 --- a/models-pdp/src/test/resources/testdata/PdpGroupsNoPDPs.json +++ b/models-pdp/src/test/resources/testdata/PdpGroupsNoPDPs.json @@ -32,4 +32,4 @@ ] } ] -}
\ No newline at end of file +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java index 902437447..769b623c7 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java @@ -417,7 +417,6 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp /** * Validate that all data types referenced in policy types exist. * - * @param result the validation result object to use for the validation result * @param result where the results are added */ private void validateReferencedDataTypes(final BeanValidationResult result) { |