diff options
Diffstat (limited to 'models')
26 files changed, 6 insertions, 1902 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatistics.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatistics.java deleted file mode 100644 index d1b1e31e8..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatistics.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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.clamp.models.acm.concepts; - -import java.io.Serializable; -import java.time.Instant; -import java.util.UUID; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import lombok.ToString; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -@NoArgsConstructor -@Data -@ToString -public class AcElementStatistics implements Serializable { - - private static final long serialVersionUID = 3284285693112271055L; - - @NonNull - private UUID id = UUID.randomUUID(); - - @NonNull - private ToscaConceptIdentifier participantId; - - @NonNull - private Instant timeStamp; - - @NonNull - private AutomationCompositionState state; - - private long acElementUptime; - -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsList.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsList.java deleted file mode 100644 index 3b8feb5f6..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsList.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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.clamp.models.acm.concepts; - -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -public class AcElementStatisticsList { - private List<AcElementStatistics> acElementStatistics; -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java index f6134782b..4736d3190 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * 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. @@ -20,10 +20,8 @@ package org.onap.policy.clamp.models.acm.concepts; -import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.stream.Collectors; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -98,20 +96,4 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut elements.values().forEach(element -> element.setOrderedState(orderedState)); } - - /** - * Get a list of automation composition element statistics. - * - * @param automationComposition the automation composition - * @return List of AcElementStatistics - */ - public List<AcElementStatistics> getAutomationCompositionElementStatisticsList( - final AutomationComposition automationComposition) { - if (MapUtils.isEmpty(automationComposition.elements)) { - return List.of(); - } - - return automationComposition.elements.values().stream() - .map(AutomationCompositionElement::getAcElementStatistics).collect(Collectors.toList()); - } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java index 046b77f76..7033abac2 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * 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. @@ -63,8 +63,6 @@ public class AutomationCompositionElement { private String description; - private AcElementStatistics acElementStatistics; - // A map indexed by the property name. Each map entry is the serialized value of the property, // which can be deserialized into an instance of the type of the property. private Map<String, ToscaProperty> propertiesMap = new LinkedHashMap<>(); @@ -83,7 +81,6 @@ public class AutomationCompositionElement { this.orderedState = otherElement.orderedState; this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment; this.description = otherElement.description; - this.acElementStatistics = otherElement.acElementStatistics; this.propertiesMap = PfUtils.mapMap(otherElement.propertiesMap, UnaryOperator.identity()); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java index dba8f553c..14aee1dd8 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * 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. @@ -37,8 +37,6 @@ public class AutomationCompositionInfo { private AutomationCompositionState state = AutomationCompositionState.UNINITIALISED; - private AutomationCompositionStatistics automationCompositionStatistics; - /** * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. * @@ -47,6 +45,5 @@ public class AutomationCompositionInfo { public AutomationCompositionInfo(final AutomationCompositionInfo otherElement) { this.automationCompositionId = otherElement.automationCompositionId; this.state = otherElement.state; - this.automationCompositionStatistics = otherElement.automationCompositionStatistics; } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionStatistics.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionStatistics.java deleted file mode 100644 index 8f73328ad..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionStatistics.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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.clamp.models.acm.concepts; - -import java.time.Instant; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import lombok.ToString; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -@NoArgsConstructor -@Data -@ToString -public class AutomationCompositionStatistics { - - @NonNull - private ToscaConceptIdentifier automationCompositionId; - - @NonNull - private Instant timeStamp; - - @NonNull - private AcElementStatisticsList acElementStatisticsList; - - private long eventCount; - private long lastExecutionTime; - private double averageExecutionTime; - private long upTime; - private long lastEnterTime; - private long lastStart; -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatistics.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatistics.java deleted file mode 100644 index 4d3b96db7..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatistics.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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.clamp.models.acm.concepts; - -import java.io.Serializable; -import java.time.Instant; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import lombok.ToString; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -@NoArgsConstructor -@Data -@ToString -public class ParticipantStatistics implements Serializable { - private static final long serialVersionUID = 744036598792333124L; - - - @NonNull - private ToscaConceptIdentifier participantId; - - @NonNull - private Instant timeStamp; - - private ParticipantState state; - private ParticipantHealthStatus healthStatus; - private long eventCount; - private long lastExecutionTime; - private double averageExecutionTime; - private long upTime; - private long lastEnterTime; - private long lastStart; -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsList.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsList.java deleted file mode 100644 index 4abdf4a63..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsList.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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.clamp.models.acm.concepts; - -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -public class ParticipantStatisticsList { - private List<ParticipantStatistics> statisticsList; -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatus.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatus.java index 32b95e11b..1d57c24e8 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatus.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatus.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * 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. @@ -29,7 +29,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; -import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics; import org.onap.policy.models.base.PfUtils; /** @@ -44,12 +43,10 @@ public class ParticipantStatus extends ParticipantMessage { private ParticipantState state; private ParticipantHealthStatus healthStatus; - private ParticipantStatistics participantStatistics; - // A list of ParticipantDefinition updates, returned in response to ParticipantStatusReq only private List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>(); - // List of AutomationCompositionInfo types with AutomationCompositionId, its state and statistics + // List of AutomationCompositionInfo types with AutomationCompositionId and its state private List<AutomationCompositionInfo> automationCompositionInfoList = new ArrayList<>(); /** @@ -70,7 +67,6 @@ public class ParticipantStatus extends ParticipantMessage { this.state = source.state; this.healthStatus = source.healthStatus; - this.participantStatistics = (source.participantStatistics == null ? null : new ParticipantStatistics()); this.participantDefinitionUpdates = PfUtils.mapList(source.participantDefinitionUpdates, ParticipantDefinition::new); this.automationCompositionInfoList = diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatistics.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatistics.java deleted file mode 100644 index 4a046052e..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatistics.java +++ /dev/null @@ -1,196 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Modifications Copyright (C) 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. - * 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.clamp.models.acm.persistence.concepts; - -import java.io.Serializable; -import java.util.List; -import java.util.UUID; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.Inheritance; -import javax.persistence.InheritanceType; -import javax.persistence.Table; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import org.apache.commons.lang3.builder.CompareToBuilder; -import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.common.parameters.annotations.NotNull; -import org.onap.policy.models.base.PfAuthorative; -import org.onap.policy.models.base.PfConcept; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.base.PfReferenceTimestampKey; -import org.onap.policy.models.base.validation.annotations.VerifyKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to represent automation composition element statistics in the database. - * - * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech) - */ -@Entity -@Table(name = "AcElementStatistics") -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) -@Data -@AllArgsConstructor -@EqualsAndHashCode(callSuper = false) -public class JpaAcElementStatistics extends PfConcept implements PfAuthorative<AcElementStatistics>, Serializable { - - private static final long serialVersionUID = 621426717868738629L; - - @EmbeddedId - @VerifyKey - @NotNull - private PfReferenceTimestampKey key = new PfReferenceTimestampKey(); - - - @VerifyKey - @NotNull - // @formatter:off - @AttributeOverride(name = "name", column = @Column(name = "participant_name")) - @AttributeOverride(name = "version", column = @Column(name = "participant_version")) - private PfConceptKey participantId; - // @formatter: on - - @Column - @NotNull - private AutomationCompositionState state; - - @Column - private long acElementUptime; - - - /** - * The Default Constructor creates a {@link JpaAcElementStatistics} object with a null key. - */ - public JpaAcElementStatistics() { - this(new PfReferenceTimestampKey()); - } - - - /** - * The Key Constructor creates a {@link JpaAcElementStatistics} object with the given Reference Timestamp key. - * - * @param key the key - */ - public JpaAcElementStatistics(@NonNull final PfReferenceTimestampKey key) { - this(key, new PfConceptKey(), AutomationCompositionState.PASSIVE, 0L); - } - - /** - * The Key Constructor creates a {@link JpaAcElementStatistics} object with all mandatory fields. - * - * @param key the key - * @param participantId the TOSCA definition of the automation composition element - */ - public JpaAcElementStatistics(@NonNull final PfReferenceTimestampKey key, - @NonNull final PfConceptKey participantId) { - this.key = key; - this.participantId = participantId; - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public JpaAcElementStatistics(@NonNull final JpaAcElementStatistics copyConcept) { - super(copyConcept); - this.key = new PfReferenceTimestampKey(copyConcept.key); - this.participantId = new PfConceptKey(copyConcept.participantId); - this.state = copyConcept.state; - this.acElementUptime = copyConcept.acElementUptime; - } - - - /** - * Authorative constructor. - * - * @param authorativeConcept the authorative concept to copy from - */ - public JpaAcElementStatistics(@NonNull final AcElementStatistics authorativeConcept) { - this.fromAuthorative(authorativeConcept); - } - - - - @Override - public AcElementStatistics toAuthorative() { - var acElementStatistics = new AcElementStatistics(); - acElementStatistics.setId(UUID.fromString(getKey().getReferenceKey().getLocalName())); - acElementStatistics.setTimeStamp(key.getInstant()); - acElementStatistics.setParticipantId(new ToscaConceptIdentifier(participantId)); - acElementStatistics.setState(state); - acElementStatistics.setAcElementUptime(acElementUptime); - - return acElementStatistics; - } - - @Override - public void fromAuthorative(@NonNull AcElementStatistics acElementStatistics) { - // @formatter:off - if (this.key == null || this.getKey().isNullKey()) { - this.setKey(new PfReferenceTimestampKey(acElementStatistics.getParticipantId().getName(), - acElementStatistics.getParticipantId().getVersion(), acElementStatistics.getId().toString(), - acElementStatistics.getTimeStamp())); - } - // @formatter:on - this.setParticipantId(acElementStatistics.getParticipantId().asConceptKey()); - this.setState(acElementStatistics.getState()); - this.setAcElementUptime(acElementStatistics.getAcElementUptime()); - } - - @Override - public List<PfKey> getKeys() { - return getKey().getKeys(); - } - - @Override - public void clean() { - key.clean(); - participantId.clean(); - } - - - @Override - public int compareTo(PfConcept otherConcept) { - if (otherConcept == null) { - return -1; - } - if (this == otherConcept) { - return 0; - } - if (getClass() != otherConcept.getClass()) { - return getClass().getName().compareTo(otherConcept.getClass().getName()); - } - - final JpaAcElementStatistics other = (JpaAcElementStatistics) otherConcept; - return new CompareToBuilder().append(this.key, other.key).append(this.state, other.state) - .append(this.acElementUptime, other.acElementUptime).toComparison(); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatistics.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatistics.java deleted file mode 100644 index a076433bb..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatistics.java +++ /dev/null @@ -1,239 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Modifications Copyright (C) 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. - * 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.clamp.models.acm.persistence.concepts; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.Inheritance; -import javax.persistence.InheritanceType; -import javax.persistence.Table; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import org.apache.commons.lang3.builder.CompareToBuilder; -import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; -import org.onap.policy.clamp.models.acm.concepts.ParticipantState; -import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics; -import org.onap.policy.common.parameters.annotations.NotNull; -import org.onap.policy.models.base.PfAuthorative; -import org.onap.policy.models.base.PfConcept; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.base.PfTimestampKey; -import org.onap.policy.models.base.validation.annotations.VerifyKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to represent a participant statistics in the database. - * - * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech) - */ -@Entity -@Table(name = "ParticipantStatistics") -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) -@Data -@AllArgsConstructor -@EqualsAndHashCode(callSuper = false) -public class JpaParticipantStatistics extends PfConcept implements PfAuthorative<ParticipantStatistics>, Serializable { - - private static final long serialVersionUID = -5992214428190133190L; - - @EmbeddedId - @VerifyKey - @NotNull - private PfTimestampKey key; - - @VerifyKey - @NotNull - @AttributeOverride(name = "name", column = @Column(name = "participant_name")) - @AttributeOverride(name = "version", column = @Column(name = "participant_version")) - private PfConceptKey participantId; - - @Column - @NotNull - private ParticipantState state; - - @Column - @NotNull - private ParticipantHealthStatus healthStatus; - - @Column - private long eventCount; - - @Column - private long lastExecutionTime; - - @Column - private double averageExecutionTime; - - @Column - private long upTime; - - @Column - private long lastEnterTime; - - @Column - private long lastStart; - - - /** - * The Default Constructor creates a {@link JpaParticipantStatistics} object with a null key. - */ - public JpaParticipantStatistics() { - this(new PfTimestampKey()); - } - - /** - * The Key Constructor creates a {@link JpaParticipantStatistics} object with the given Timestamp key. - * - * @param key the key - */ - public JpaParticipantStatistics(@NonNull final PfTimestampKey key) { - this(key, new PfConceptKey(), ParticipantState.PASSIVE, ParticipantHealthStatus.HEALTHY, 0L, 0L, 0.0d, 0L, 0L, - 0L); - } - - - /** - * The Key Constructor creates a {@link JpaParticipantStatistics} object with all mandatory fields. - * - * @param key the key - * @param participantId the TOSCA definition of the participant - */ - public JpaParticipantStatistics(@NonNull final PfTimestampKey key, @NonNull final PfConceptKey participantId) { - this.key = key; - this.participantId = participantId; - } - - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public JpaParticipantStatistics(@NonNull final JpaParticipantStatistics copyConcept) { - super(copyConcept); - this.key = new PfTimestampKey(copyConcept.key); - this.participantId = new PfConceptKey(copyConcept.participantId); - this.state = copyConcept.state; - this.healthStatus = copyConcept.healthStatus; - this.eventCount = copyConcept.eventCount; - this.lastExecutionTime = copyConcept.lastExecutionTime; - this.averageExecutionTime = copyConcept.averageExecutionTime; - this.upTime = copyConcept.upTime; - this.lastEnterTime = copyConcept.lastEnterTime; - this.lastStart = copyConcept.lastStart; - } - - /** - * Authorative constructor. - * - * @param authorativeConcept the authorative concept to copy from - */ - public JpaParticipantStatistics(@NonNull final ParticipantStatistics authorativeConcept) { - this.fromAuthorative(authorativeConcept); - } - - - @Override - public int compareTo(PfConcept otherConcept) { - if (otherConcept == null) { - return -1; - } - if (this == otherConcept) { - return 0; - } - if (getClass() != otherConcept.getClass()) { - return getClass().getName().compareTo(otherConcept.getClass().getName()); - } - - final JpaParticipantStatistics other = (JpaParticipantStatistics) otherConcept; - // @formatter:off - return new CompareToBuilder() - .append(this.key, other.key) - .append(this.participantId, other.participantId) - .append(this.state, other.state) - .append(this.healthStatus, other.healthStatus) - .append(this.eventCount, other.eventCount) - .append(this.lastExecutionTime, other.lastExecutionTime) - .append(this.averageExecutionTime, other.averageExecutionTime) - .append(this.upTime, other.upTime) - .append(this.lastEnterTime, other.lastEnterTime) - .append(this.lastStart, other.lastStart).toComparison(); - // @formatter:on - } - - @Override - public ParticipantStatistics toAuthorative() { - var participantStatistics = new ParticipantStatistics(); - participantStatistics.setTimeStamp(key.getTimeStamp().toInstant()); - participantStatistics.setParticipantId(new ToscaConceptIdentifier(participantId)); - participantStatistics.setState(state); - participantStatistics.setHealthStatus(healthStatus); - participantStatistics.setAverageExecutionTime(averageExecutionTime); - participantStatistics.setEventCount(eventCount); - participantStatistics.setLastExecutionTime(lastExecutionTime); - participantStatistics.setUpTime(upTime); - participantStatistics.setLastEnterTime(lastEnterTime); - participantStatistics.setLastStart(lastStart); - - return participantStatistics; - } - - @Override - public void fromAuthorative(@NonNull final ParticipantStatistics participantStatistics) { - if (this.key == null || this.getKey().isNullKey()) { - this.setKey(new PfTimestampKey(participantStatistics.getParticipantId().getName(), - participantStatistics.getParticipantId().getVersion(), participantStatistics.getTimeStamp())); - } - this.setParticipantId(participantStatistics.getParticipantId().asConceptKey()); - this.setState(participantStatistics.getState()); - this.setHealthStatus(participantStatistics.getHealthStatus()); - this.setAverageExecutionTime(participantStatistics.getAverageExecutionTime()); - this.setEventCount(participantStatistics.getEventCount()); - this.setLastExecutionTime(participantStatistics.getLastExecutionTime()); - this.setUpTime(participantStatistics.getUpTime()); - this.setLastEnterTime(participantStatistics.getLastEnterTime()); - this.setLastStart(participantStatistics.getLastStart()); - - } - - @Override - public List<PfKey> getKeys() { - List<PfKey> keyList = getKey().getKeys(); - keyList.addAll(participantId.getKeys()); - return keyList; - } - - @Override - public void clean() { - key.clean(); - participantId.clean(); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProvider.java deleted file mode 100644 index 59ddcc2ea..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProvider.java +++ /dev/null @@ -1,139 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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.clamp.models.acm.persistence.provider; - -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import javax.ws.rs.core.Response.Status; -import lombok.AllArgsConstructor; -import lombok.NonNull; -import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; -import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAcElementStatistics; -import org.onap.policy.clamp.models.acm.persistence.repository.AcElementStatisticsRepository; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.base.PfReferenceTimestampKey; -import org.onap.policy.models.dao.PfFilterParameters; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * This class provides the provision of information on automation composition element statistics in the database to - * callers. - * - * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech) - */ -@Service -@Transactional -@AllArgsConstructor -public class AcElementStatisticsProvider { - - private AcElementStatisticsRepository acElementStatisticsRepository; - - /** - * Creates automation composition element statistics. - * - * @param acElementStatisticsList a specification of the statistics to create - * @return the Element statistics created - * @throws PfModelException on initiation errors - */ - public List<AcElementStatistics> createAcElementStatistics( - @NonNull final List<AcElementStatistics> acElementStatisticsList) throws PfModelException { - - try { - var jpaAcElementStatisticsList = ProviderUtils.getJpaAndValidateList(acElementStatisticsList, - JpaAcElementStatistics::new, "automation composition element statistics"); - - var jpaAcElementStatisticsSaved = acElementStatisticsRepository.saveAll(jpaAcElementStatisticsList); - - // Return the saved automation composition element statistics - return asAcElementStatisticsList(jpaAcElementStatisticsSaved); - } catch (IllegalArgumentException e) { - throw new PfModelException(Status.BAD_REQUEST, "Error in save automation composition element statistics", - e); - } - } - - /** - * Convert JPA acElement statistics list to acElement statistics list. - * - * @param jpaAcElementStatistics the list to convert - * @return the acElement statistics list - */ - private List<AcElementStatistics> asAcElementStatisticsList(List<JpaAcElementStatistics> jpaAcElementStatistics) { - return jpaAcElementStatistics.stream().map(JpaAcElementStatistics::toAuthorative).collect(Collectors.toList()); - } - - /** - * Get acElement statistics. - * - * @param name the name of the participant - * @param version version of the participant - * @param id of the automation composition element - * @param timestamp timestamp of the statistics - * @return the acElement statistics found - */ - @Transactional(readOnly = true) - public List<AcElementStatistics> getAcElementStatistics(final String name, final String version, final String id, - final Instant timestamp) { - if (name != null && version != null && timestamp != null && id != null) { - return asAcElementStatisticsList(acElementStatisticsRepository - .findAllById(List.of(new PfReferenceTimestampKey(name, version, id, timestamp)))); - } else if (name != null) { - return getFilteredAcElementStatistics(name, version, null, null, null, "DESC", 0); - } - return asAcElementStatisticsList(acElementStatisticsRepository.findAll()); - } - - /** - * Get filtered acElement statistics. - * - * @param name the acElement name for the statistics to get - * @param version the acElement version for the statistics to get - * @param startTimeStamp startTimeStamp to filter statistics - * @param endTimeStamp endTimeStamp to filter statistics - * @param sortOrder sortOrder to query database - * @param getRecordNum Total query count from database - * @param filterMap the filters to apply to the get operation - * @return the acElement statistics found - */ - @Transactional(readOnly = true) - public List<AcElementStatistics> getFilteredAcElementStatistics(final String name, final String version, - final Instant startTimeStamp, final Instant endTimeStamp, Map<String, Object> filterMap, final String sortOrder, - final int getRecordNum) { - - // @formatter:off - PfFilterParameters filterParams = PfFilterParameters - .builder() - .name(name) - .version(version) - .startTime(startTimeStamp) - .endTime(endTimeStamp) - .filterMap(filterMap) - .sortOrder(sortOrder) - .recordNum(getRecordNum) - .build(); - // @formatter:on - return asAcElementStatisticsList( - acElementStatisticsRepository.getFiltered(JpaAcElementStatistics.class, filterParams)); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProvider.java deleted file mode 100644 index a5a0ce176..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProvider.java +++ /dev/null @@ -1,138 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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.clamp.models.acm.persistence.provider; - -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import javax.ws.rs.core.Response.Status; -import lombok.AllArgsConstructor; -import lombok.NonNull; -import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics; -import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipantStatistics; -import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantStatisticsRepository; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.base.PfTimestampKey; -import org.onap.policy.models.dao.PfFilterParameters; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * This class provides the provision of information on participant statistics in the database to callers. - */ -@Service -@Transactional -@AllArgsConstructor -public class ParticipantStatisticsProvider { - - private ParticipantStatisticsRepository participantStatisticsRepository; - - /** - * Get Participant statistics. - * - * @param name the name of the participant statistics to get, null to get all stats - * @param version the version of the participant statistics to get, null to get all stats for a name - * @param timestamp the time stamp for the stats to get - * @return the participant statistics found - */ - @Transactional(readOnly = true) - public List<ParticipantStatistics> getParticipantStatistics(final String name, final String version, - final Instant timestamp) { - if (name != null && version != null && timestamp != null) { - return asParticipantStatisticsList( - participantStatisticsRepository.findAllById(List.of(new PfTimestampKey(name, version, timestamp)))); - } else if (name != null) { - return getFilteredParticipantStatistics(name, version, timestamp, null, null, "DESC", 0); - } - return asParticipantStatisticsList(participantStatisticsRepository.findAll()); - } - - /** - * Get filtered participant statistics. - * - * @param name the participant name for the statistics to get - * @param version the participant version for the statistics to get - * @param startTimeStamp startTimeStamp to filter statistics - * @param endTimeStamp endTimeStamp to filter statistics - * @param sortOrder sortOrder to query database - * @param getRecordNum Total query count from database - * @param filterMap the filters to apply to the get operation - * @return the participant statistics found - */ - @Transactional(readOnly = true) - public List<ParticipantStatistics> getFilteredParticipantStatistics(final String name, final String version, - final Instant startTimeStamp, final Instant endTimeStamp, Map<String, Object> filterMap, - final String sortOrder, final int getRecordNum) { - - // @formatter:off - PfFilterParameters filterParams = PfFilterParameters - .builder() - .name(name) - .version(version) - .startTime(startTimeStamp) - .endTime(endTimeStamp) - .filterMap(filterMap) - .sortOrder(sortOrder) - .recordNum(getRecordNum) - .build(); - // @formatter:on - - return asParticipantStatisticsList( - participantStatisticsRepository.getFiltered(JpaParticipantStatistics.class, filterParams)); - } - - /** - * Creates Participant statistics. - * - * @param participantStatisticsList a specification of the statistics to create - * @return the participant statistics created - * @throws PfModelException on errors creating participant statistics - */ - public List<ParticipantStatistics> createParticipantStatistics( - @NonNull final List<ParticipantStatistics> participantStatisticsList) throws PfModelException { - - try { - var jpaParticipantStatisticsList = ProviderUtils.getJpaAndValidateList(participantStatisticsList, - JpaParticipantStatistics::new, "Participant Statistics"); - - var jpaParticipantStatisticsSaved = participantStatisticsRepository.saveAll(jpaParticipantStatisticsList); - - // Return the saved participant statistics - return asParticipantStatisticsList(jpaParticipantStatisticsSaved); - } catch (IllegalArgumentException e) { - throw new PfModelException(Status.BAD_REQUEST, "Error in save participant statistics", e); - } - } - - /** - * Convert JPA participant statistics list to participant statistics list. - * - * @param jpaParticipantStatisticsList the list to convert - * @return the participant statistics list - */ - private List<ParticipantStatistics> asParticipantStatisticsList( - List<JpaParticipantStatistics> jpaParticipantStatisticsList) { - - return jpaParticipantStatisticsList.stream().map(JpaParticipantStatistics::toAuthorative) - .collect(Collectors.toList()); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AcElementStatisticsRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AcElementStatisticsRepository.java deleted file mode 100644 index 13001114f..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AcElementStatisticsRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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.clamp.models.acm.persistence.repository; - -import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAcElementStatistics; -import org.onap.policy.models.base.PfReferenceTimestampKey; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface AcElementStatisticsRepository - extends JpaRepository<JpaAcElementStatistics, PfReferenceTimestampKey>, FilterRepository { - -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantStatisticsRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantStatisticsRepository.java deleted file mode 100644 index 9cba62a70..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantStatisticsRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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.clamp.models.acm.persistence.repository; - -import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipantStatistics; -import org.onap.policy.models.base.PfTimestampKey; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface ParticipantStatisticsRepository - extends JpaRepository<JpaParticipantStatistics, PfTimestampKey>, FilterRepository { - -} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsTest.java deleted file mode 100644 index 070fa8dc8..000000000 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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. - * 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.clamp.models.acm.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class AcElementStatisticsTest { - @Test - void testAcElementStatisticsLombok() { - assertNotNull(new AcElementStatistics()); - AcElementStatistics aces0 = new AcElementStatistics(); - - assertThat(aces0.toString()).contains("AcElementStatistics("); - assertThat(aces0.hashCode()).isNotZero(); - assertEquals(aces0, aces0); - assertNotEquals(null, aces0); - - AcElementStatistics aces1 = new AcElementStatistics(); - aces1.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); - aces1.setTimeStamp(Instant.now()); - - assertThat(aces1.toString()).contains("AcElementStatistics("); - assertNotEquals(0, aces1.hashCode()); - assertNotEquals(aces1, aces0); - assertNotEquals(null, aces1); - - assertNotEquals(aces1, aces0); - - AcElementStatistics aces2 = new AcElementStatistics(); - aces2.setId(UUID.randomUUID()); - - // @formatter:off - assertThatThrownBy(() -> aces2.setParticipantId(null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> aces2.setTimeStamp(null)).isInstanceOf(NullPointerException.class); - // @formatter:on - - assertNotEquals(aces2, aces0); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java index 49953f1af..aaa8368d7 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java @@ -27,9 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -import java.time.Instant; import java.util.LinkedHashMap; -import java.util.List; import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.models.base.PfKey; @@ -104,43 +102,6 @@ class AutomationCompositionTest { } - @Test - void testAutomationCompositionElementStatisticsList() { - var ac = new AutomationComposition(); - List<AcElementStatistics> emptylist = ac.getAutomationCompositionElementStatisticsList(ac); - assertEquals(List.of(), emptylist); - - var ac1 = getAutomationCompositionTest(); - List<AcElementStatistics> list = ac1.getAutomationCompositionElementStatisticsList(ac1); - assertNotNull(list); - assertEquals(2, list.size()); - assertEquals(AutomationCompositionState.UNINITIALISED, list.get(0).getState()); - } - - private AutomationComposition getAutomationCompositionTest() { - var ac = new AutomationComposition(); - ac.setDefinition(new ToscaConceptIdentifier("defName", "1.2.3")); - ac.setDescription("Description"); - ac.setElements(new LinkedHashMap<>()); - ac.setName("Name"); - ac.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - ac.setState(AutomationCompositionState.UNINITIALISED); - ac.setVersion("0.0.1"); - - var uuid = UUID.randomUUID(); - var id = new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "1.0.1"); - var acElement = getAutomationCompositionElementTest(uuid, id); - - var uuid2 = UUID.randomUUID(); - var id2 = new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipantIntermediary", - "0.0.1"); - var acElement2 = getAutomationCompositionElementTest(uuid2, id2); - - ac.getElements().put(uuid, acElement); - ac.getElements().put(uuid2, acElement2); - return ac; - } - private AutomationCompositionElement getAutomationCompositionElementTest(UUID uuid, ToscaConceptIdentifier id) { var acElement = new AutomationCompositionElement(); acElement.setId(uuid); @@ -148,13 +109,6 @@ class AutomationCompositionTest { acElement.setDefinition(id); acElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - var acElementStatistics = new AcElementStatistics(); - acElementStatistics.setParticipantId(id); - acElementStatistics.setState(AutomationCompositionState.UNINITIALISED); - acElementStatistics.setTimeStamp(Instant.now()); - - acElement.setAcElementStatistics(acElementStatistics); - return acElement; } } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsTest.java deleted file mode 100644 index 727ab7033..000000000 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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. - * 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.clamp.models.acm.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.time.Instant; -import org.junit.jupiter.api.Test; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantStatisticsTest { - @Test - void testParticipantStatisticsLombok() { - assertNotNull(new ParticipantStatistics()); - ParticipantStatistics ps0 = new ParticipantStatistics(); - - assertThat(ps0.toString()).contains("ParticipantStatistics("); - assertThat(ps0.hashCode()).isNotZero(); - assertEquals(ps0, ps0); - assertNotEquals(null, ps0); - - - ParticipantStatistics ps1 = new ParticipantStatistics(); - ps1.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); - ps1.setTimeStamp(Instant.now()); - - assertThat(ps1.toString()).contains("ParticipantStatistics("); - assertNotEquals(0, ps1.hashCode()); - assertNotEquals(ps1, ps0); - assertNotEquals(null, ps1); - - assertNotEquals(ps1, ps0); - - ParticipantStatistics ps2 = new ParticipantStatistics(); - - // @formatter:off - assertThatThrownBy(() -> ps2.setParticipantId(null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ps2.setTimeStamp(null)). isInstanceOf(NullPointerException.class); - // @formatter:on - - assertEquals(ps2, ps0); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java index 37cde2549..eeb8ba3dd 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java @@ -30,12 +30,9 @@ import java.util.List; import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; -import org.onap.policy.clamp.models.acm.concepts.AcElementStatisticsList; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionStatistics; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; @@ -88,23 +85,6 @@ class ParticipantStatusTest { acInfo.setState(AutomationCompositionState.PASSIVE2RUNNING); acInfo.setAutomationCompositionId(id); - AutomationCompositionStatistics acStatistics = new AutomationCompositionStatistics(); - acStatistics.setAutomationCompositionId(id); - acStatistics.setAverageExecutionTime(12345); - acStatistics.setEventCount(12345); - acStatistics.setLastEnterTime(12345); - acStatistics.setLastExecutionTime(12345); - acStatistics.setLastStart(12345); - acStatistics.setTimeStamp(Instant.ofEpochMilli(3000)); - acStatistics.setUpTime(12345); - AcElementStatisticsList acElementStatisticsList = new AcElementStatisticsList(); - AcElementStatistics acElementStatistics = new AcElementStatistics(); - acElementStatistics.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); - acElementStatistics.setTimeStamp(Instant.now()); - acElementStatisticsList.setAcElementStatistics(List.of(acElementStatistics)); - acStatistics.setAcElementStatisticsList(acElementStatisticsList); - - acInfo.setAutomationCompositionStatistics(acStatistics); return acInfo; } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAcElementStatisticsChild.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAcElementStatisticsChild.java deleted file mode 100644 index ebbaf1d42..000000000 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAcElementStatisticsChild.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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.clamp.models.acm.persistence.concepts; - -/** - * Test class for {@link JpaAcElementStatistics} comparisons. - */ -class DummyJpaAcElementStatisticsChild extends JpaAcElementStatistics { - private static final long serialVersionUID = -5101743610779424064L; -} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantStatisticsChild.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantStatisticsChild.java deleted file mode 100644 index 95082cac7..000000000 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantStatisticsChild.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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.clamp.models.acm.persistence.concepts; - -/** - * Test class for {@link JpaParticipantStatistics} comparisons. - */ -class DummyJpaParticipantStatisticsChild extends JpaParticipantStatistics { - private static final long serialVersionUID = -5101743610779424064L; -} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatisticsTest.java deleted file mode 100644 index d00d98ae0..000000000 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatisticsTest.java +++ /dev/null @@ -1,190 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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. - * 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.clamp.models.acm.persistence.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.concepts.Participant; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfReferenceTimestampKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Test the {@link JpaAcElementStatistics} class. - */ -class JpaAcElementStatisticsTest { - - private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; - - @Test - void testJpaAcElementStatisticsConstructor() { - assertThatThrownBy(() -> { - new JpaAcElementStatistics((JpaAcElementStatistics) null); - }).hasMessageMatching("copyConcept is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaAcElementStatistics((PfReferenceTimestampKey) null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaAcElementStatistics(null, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaAcElementStatistics(null, new PfConceptKey()); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaAcElementStatistics(new PfReferenceTimestampKey(), null); - }).hasMessageMatching("participantId is marked .*ull but is null"); - - assertNotNull(new JpaAcElementStatistics()); - assertNotNull(new JpaAcElementStatistics((new PfReferenceTimestampKey()))); - assertNotNull(new JpaAcElementStatistics(new PfReferenceTimestampKey(), new PfConceptKey())); - } - - @Test - void testJpaAcElementStatistics() { - JpaAcElementStatistics testJpaAcElementStatistics = createJpaAcElementStatisticsInstance(); - - AcElementStatistics aces = createAcElementStatisticsInstance(); - assertEquals(aces, testJpaAcElementStatistics.toAuthorative()); - - assertThatThrownBy(() -> { - testJpaAcElementStatistics.fromAuthorative(null); - }).hasMessageMatching("acElementStatistics is marked .*ull but is null"); - - assertThatThrownBy(() -> new JpaAcElementStatistics((JpaAcElementStatistics) null)) - .isInstanceOf(NullPointerException.class); - - JpaAcElementStatistics testJpaAcElementStatisticsFa = new JpaAcElementStatistics(); - testJpaAcElementStatisticsFa.setKey(null); - testJpaAcElementStatisticsFa.fromAuthorative(aces); - assertEquals(testJpaAcElementStatistics, testJpaAcElementStatisticsFa); - testJpaAcElementStatisticsFa.setKey(PfReferenceTimestampKey.getNullKey()); - testJpaAcElementStatisticsFa.fromAuthorative(aces); - assertEquals(testJpaAcElementStatistics, testJpaAcElementStatisticsFa); - testJpaAcElementStatisticsFa.setKey(new PfReferenceTimestampKey("elementName", "0.0.1", - "a95757ba-b34a-4049-a2a8-46773abcbe5e", Instant.ofEpochSecond(123456L))); - testJpaAcElementStatisticsFa.fromAuthorative(aces); - assertEquals(testJpaAcElementStatistics, testJpaAcElementStatisticsFa); - - testJpaAcElementStatisticsFa = new JpaAcElementStatistics(aces); - assertEquals(testJpaAcElementStatistics, testJpaAcElementStatisticsFa); - - assertEquals(1, testJpaAcElementStatistics.getKeys().size()); - - assertEquals("elementName", testJpaAcElementStatistics.getKey().getReferenceKey().getParentKeyName()); - - testJpaAcElementStatistics.clean(); - assertEquals("elementName", testJpaAcElementStatistics.getKey().getReferenceKey().getParentKeyName()); - - JpaAcElementStatistics testJpaAcElementStatistics2 = new JpaAcElementStatistics(testJpaAcElementStatistics); - assertEquals(testJpaAcElementStatistics, testJpaAcElementStatistics2); - } - - @Test - void testJpaAcElementStatisticsValidation() { - JpaAcElementStatistics testJpaAcElementStatistics = createJpaAcElementStatisticsInstance(); - - assertThatThrownBy(() -> { - testJpaAcElementStatistics.validate(null); - }).hasMessageMatching("fieldName is marked .*ull but is null"); - - assertTrue(testJpaAcElementStatistics.validate("").isValid()); - } - - @Test - void testJpaAcElementStatisticsCompareTo() { - JpaAcElementStatistics testJpaAcElementStatistics = createJpaAcElementStatisticsInstance(); - - JpaAcElementStatistics otherJpaAcElementStatistics = new JpaAcElementStatistics(testJpaAcElementStatistics); - assertEquals(0, testJpaAcElementStatistics.compareTo(otherJpaAcElementStatistics)); - assertEquals(-1, testJpaAcElementStatistics.compareTo(null)); - assertEquals(0, testJpaAcElementStatistics.compareTo(testJpaAcElementStatistics)); - assertNotEquals(0, testJpaAcElementStatistics.compareTo(new DummyJpaAcElementStatisticsChild())); - - testJpaAcElementStatistics.setState(AutomationCompositionState.PASSIVE); - assertNotEquals(0, testJpaAcElementStatistics.compareTo(otherJpaAcElementStatistics)); - testJpaAcElementStatistics.setState(AutomationCompositionState.UNINITIALISED); - assertEquals(0, testJpaAcElementStatistics.compareTo(otherJpaAcElementStatistics)); - - assertEquals(testJpaAcElementStatistics, new JpaAcElementStatistics(testJpaAcElementStatistics)); - } - - @Test - void testJpaAcElementStatisticsLombok() { - assertNotNull(new Participant()); - JpaAcElementStatistics aces0 = new JpaAcElementStatistics(); - - assertThat(aces0.toString()).contains("JpaAcElementStatistics("); - assertThat(aces0.hashCode()).isNotZero(); - assertEquals(aces0, aces0); - assertNotEquals(null, aces0); - - - JpaAcElementStatistics aces11 = new JpaAcElementStatistics(); - - aces11.setState(AutomationCompositionState.UNINITIALISED); - - assertThat(aces11.toString()).contains("JpaAcElementStatistics("); - assertNotEquals(0, aces11.hashCode()); - assertNotEquals(aces11, aces0); - assertNotEquals(null, aces11); - - assertNotEquals(aces11, aces0); - - JpaAcElementStatistics aces2 = new JpaAcElementStatistics(); - assertEquals(aces2, aces0); - } - - private JpaAcElementStatistics createJpaAcElementStatisticsInstance() { - AcElementStatistics testAces = createAcElementStatisticsInstance(); - JpaAcElementStatistics testJpaAcElementStatistics = new JpaAcElementStatistics(); - testJpaAcElementStatistics.setKey(null); - testJpaAcElementStatistics.fromAuthorative(testAces); - testJpaAcElementStatistics.setKey(PfReferenceTimestampKey.getNullKey()); - testJpaAcElementStatistics.fromAuthorative(testAces); - - return testJpaAcElementStatistics; - } - - private AcElementStatistics createAcElementStatisticsInstance() { - AcElementStatistics acElementStatistics = new AcElementStatistics(); - acElementStatistics.setParticipantId(new ToscaConceptIdentifier("elementName", "0.0.1")); - acElementStatistics.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e")); - acElementStatistics.setTimeStamp(Instant.ofEpochSecond(123456L)); - acElementStatistics.setState(AutomationCompositionState.UNINITIALISED); - - return acElementStatistics; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatisticsTest.java deleted file mode 100644 index 921f9b2b0..000000000 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatisticsTest.java +++ /dev/null @@ -1,192 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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. - * 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.clamp.models.acm.persistence.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.time.Instant; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.models.acm.concepts.Participant; -import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; -import org.onap.policy.clamp.models.acm.concepts.ParticipantState; -import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics; -import org.onap.policy.common.parameters.BeanValidationResult; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfTimestampKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Test the {@link JpaParticipantStatistics} class. - */ -class JpaParticipantStatisticsTest { - - private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; - - @Test - void testJpaParticipantStatisticsConstructor() { - assertThatThrownBy(() -> { - new JpaParticipantStatistics((JpaParticipantStatistics) null); - }).hasMessageMatching("copyConcept is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaParticipantStatistics((PfTimestampKey) null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipantStatistics(null, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipantStatistics(null, new PfConceptKey()); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipantStatistics(new PfTimestampKey(), null); - }).hasMessageMatching("participantId is marked .*ull but is null"); - - assertNotNull(new JpaParticipantStatistics()); - assertNotNull(new JpaParticipantStatistics((new PfTimestampKey()))); - assertNotNull(new JpaParticipantStatistics(new PfTimestampKey(), new PfConceptKey())); - } - - @Test - void testJpaParticipantStatistics() { - JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance(); - - ParticipantStatistics aces = createParticipantStatisticsInstance(); - assertEquals(aces, testJpaParticipantStatistics.toAuthorative()); - - assertThatThrownBy(() -> { - testJpaParticipantStatistics.fromAuthorative(null); - }).hasMessageMatching("participantStatistics is marked .*ull but is null"); - - assertThatThrownBy(() -> new JpaParticipantStatistics((JpaParticipantStatistics) null)) - .isInstanceOf(NullPointerException.class); - - JpaParticipantStatistics testJpaParticipantStatisticsFa = new JpaParticipantStatistics(); - testJpaParticipantStatisticsFa.setKey(null); - testJpaParticipantStatisticsFa.fromAuthorative(aces); - assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); - testJpaParticipantStatisticsFa.setKey(PfTimestampKey.getNullKey()); - testJpaParticipantStatisticsFa.fromAuthorative(aces); - assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); - testJpaParticipantStatisticsFa - .setKey(new PfTimestampKey("participantName", "0.0.1", Instant.ofEpochMilli(123456L))); - testJpaParticipantStatisticsFa.fromAuthorative(aces); - assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); - - testJpaParticipantStatisticsFa = new JpaParticipantStatistics(aces); - assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); - - assertEquals(2, testJpaParticipantStatistics.getKeys().size()); - - assertEquals("participantName", testJpaParticipantStatistics.getKey().getName()); - - testJpaParticipantStatistics.clean(); - assertEquals("participantName", testJpaParticipantStatistics.getKey().getName()); - - JpaParticipantStatistics testJpaParticipantStatistics2 = - new JpaParticipantStatistics(testJpaParticipantStatistics); - assertEquals(testJpaParticipantStatistics, testJpaParticipantStatistics2); - } - - @Test - void testJpaParticipantStatisticsValidation() { - JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance(); - - assertThatThrownBy(() -> { - testJpaParticipantStatistics.validate(null); - }).hasMessageMatching("fieldName is marked .*ull but is null"); - - BeanValidationResult validationResult = testJpaParticipantStatistics.validate(""); - assertTrue(validationResult.isValid()); - } - - @Test - void testJpaParticipantStatisticsConmpareTo() { - JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance(); - - JpaParticipantStatistics otherJpaParticipantStatistics = - new JpaParticipantStatistics(testJpaParticipantStatistics); - assertEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics)); - assertEquals(-1, testJpaParticipantStatistics.compareTo(null)); - assertEquals(0, testJpaParticipantStatistics.compareTo(testJpaParticipantStatistics)); - assertNotEquals(0, testJpaParticipantStatistics.compareTo(new DummyJpaParticipantStatisticsChild())); - - testJpaParticipantStatistics.setState(ParticipantState.UNKNOWN); - assertNotEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics)); - testJpaParticipantStatistics.setState(ParticipantState.PASSIVE); - assertEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics)); - - assertEquals(testJpaParticipantStatistics, new JpaParticipantStatistics(testJpaParticipantStatistics)); - } - - @Test - void testJpaParticipantStatisticsLombok() { - assertNotNull(new Participant()); - JpaParticipantStatistics ps0 = new JpaParticipantStatistics(); - - assertThat(ps0.toString()).contains("JpaParticipantStatistics("); - assertThat(ps0.hashCode()).isNotZero(); - assertEquals(ps0, ps0); - assertNotEquals(null, ps0); - - JpaParticipantStatistics ps1 = new JpaParticipantStatistics(); - - ps1.setState(ParticipantState.UNKNOWN); - - assertThat(ps1.toString()).contains("JpaParticipantStatistics("); - assertNotEquals(0, ps1.hashCode()); - assertNotEquals(ps1, ps0); - assertNotEquals(null, ps1); - - assertNotEquals(ps1, ps0); - - JpaParticipantStatistics ps2 = new JpaParticipantStatistics(); - assertEquals(ps2, ps0); - } - - private JpaParticipantStatistics createJpaParticipantStatisticsInstance() { - ParticipantStatistics testAces = createParticipantStatisticsInstance(); - JpaParticipantStatistics testJpaParticipantStatistics = new JpaParticipantStatistics(); - testJpaParticipantStatistics.setKey(null); - testJpaParticipantStatistics.fromAuthorative(testAces); - testJpaParticipantStatistics.setKey(PfTimestampKey.getNullKey()); - testJpaParticipantStatistics.fromAuthorative(testAces); - - return testJpaParticipantStatistics; - } - - private ParticipantStatistics createParticipantStatisticsInstance() { - ParticipantStatistics participantStatistics = new ParticipantStatistics(); - participantStatistics.setParticipantId(new ToscaConceptIdentifier("participantName", "0.0.1")); - participantStatistics.setTimeStamp(Instant.ofEpochMilli(123456L)); - participantStatistics.setState(ParticipantState.PASSIVE); - participantStatistics.setHealthStatus(ParticipantHealthStatus.HEALTHY); - - return participantStatistics; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProviderTest.java deleted file mode 100644 index 7daf3fbcf..000000000 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProviderTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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. - * 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.clamp.models.acm.persistence.provider; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.time.Instant; -import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; -import org.onap.policy.clamp.models.acm.concepts.AcElementStatisticsList; -import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAcElementStatistics; -import org.onap.policy.clamp.models.acm.persistence.repository.AcElementStatisticsRepository; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class AcElementStatisticsProviderTest { - private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; - private static final Coder CODER = new StandardCoder(); - private static final String AC_ELEMENT_STATS_JSON = "src/test/resources/providers/TestAcElementStatistics.json"; - - private AcElementStatisticsProvider acElementStatisticsProvider; - private AcElementStatisticsList inputAcElementStats; - private final String originalJson = ResourceUtils.getResourceAsString(AC_ELEMENT_STATS_JSON); - - /** - * Set up test AcElement statistics provider. - * - * @throws Exception on errors - */ - @BeforeEach - void beforeSetupDao() throws Exception { - - inputAcElementStats = CODER.decode(originalJson, AcElementStatisticsList.class); - var acElementStatisticsRepository = mock(AcElementStatisticsRepository.class); - - var jpaAcElementStatisticsList = - ProviderUtils.getJpaAndValidateList(inputAcElementStats.getAcElementStatistics(), - JpaAcElementStatistics::new, "automation composition element statistics"); - - for (var acElementStat : jpaAcElementStatisticsList) { - when(acElementStatisticsRepository.getById(eq(acElementStat.getKey()))).thenReturn(acElementStat); - when(acElementStatisticsRepository.findAllById(eq(List.of(acElementStat.getKey())))) - .thenReturn(List.of(acElementStat)); - } - - when(acElementStatisticsRepository.saveAll(anyList())).thenReturn(jpaAcElementStatisticsList); - - when(acElementStatisticsRepository.getFiltered(eq(JpaAcElementStatistics.class), any())) - .thenReturn(List.of(jpaAcElementStatisticsList.get(0))); - - acElementStatisticsProvider = new AcElementStatisticsProvider(acElementStatisticsRepository); - } - - @Test - void testAcElementStatisticsCreate() throws Exception { - assertThatThrownBy(() -> acElementStatisticsProvider.createAcElementStatistics(null)) - .hasMessageMatching(LIST_IS_NULL); - - AcElementStatisticsList createdAcElementStats = new AcElementStatisticsList(); - createdAcElementStats.setAcElementStatistics( - acElementStatisticsProvider.createAcElementStatistics(inputAcElementStats.getAcElementStatistics())); - - assertEquals(inputAcElementStats.toString().replaceAll("\\s+", ""), - createdAcElementStats.toString().replaceAll("\\s+", "")); - } - - @Test - void testGetAcElementStatistics() throws Exception { - - List<AcElementStatistics> getResponse; - - // Return empty list when no data present in db - getResponse = acElementStatisticsProvider.getAcElementStatistics(null, null, null, null); - assertThat(getResponse).isEmpty(); - - acElementStatisticsProvider.createAcElementStatistics(inputAcElementStats.getAcElementStatistics()); - ToscaConceptIdentifier identifier = inputAcElementStats.getAcElementStatistics().get(0).getParticipantId(); - Instant instant = inputAcElementStats.getAcElementStatistics().get(0).getTimeStamp(); - String id = inputAcElementStats.getAcElementStatistics().get(0).getId().toString(); - assertEquals(1, acElementStatisticsProvider - .getAcElementStatistics(identifier.getName(), identifier.getVersion(), id, instant).size()); - - assertEquals(1, acElementStatisticsProvider - .getFilteredAcElementStatistics("name2", "1.0.1", null, null, null, "DESC", 1).size()); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProviderTest.java deleted file mode 100644 index 839c14e83..000000000 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProviderTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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. - * 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.clamp.models.acm.persistence.provider; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.time.Instant; -import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics; -import org.onap.policy.clamp.models.acm.concepts.ParticipantStatisticsList; -import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipantStatistics; -import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantStatisticsRepository; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantStatisticsProviderTest { - - private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; - private static final Coder CODER = new StandardCoder(); - private static final String PARTICIPANT_STATS_JSON = "src/test/resources/providers/TestParticipantStatistics.json"; - - private ParticipantStatisticsProvider participantStatisticsProvider; - private ParticipantStatisticsList inputParticipantStatistics; - private final String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_STATS_JSON); - - @BeforeEach - void beforeSetupDao() throws Exception { - var participantStatisticsRepository = mock(ParticipantStatisticsRepository.class); - participantStatisticsProvider = new ParticipantStatisticsProvider(participantStatisticsRepository); - inputParticipantStatistics = CODER.decode(originalJson, ParticipantStatisticsList.class); - - var jpaParticipantStatisticsList = - ProviderUtils.getJpaAndValidateList(inputParticipantStatistics.getStatisticsList(), - JpaParticipantStatistics::new, "Participant Statistics"); - - for (var participantStat : jpaParticipantStatisticsList) { - when(participantStatisticsRepository.getById(eq(participantStat.getKey()))).thenReturn(participantStat); - when(participantStatisticsRepository.findAllById(eq(List.of(participantStat.getKey())))) - .thenReturn(List.of(participantStat)); - } - - when(participantStatisticsRepository.getFiltered(eq(JpaParticipantStatistics.class), any())) - .thenReturn(List.of(jpaParticipantStatisticsList.get(0))); - - when(participantStatisticsRepository.saveAll(anyList())).thenReturn(jpaParticipantStatisticsList); - } - - @Test - void testParticipantStatisticsCreate() throws Exception { - assertThatThrownBy(() -> { - participantStatisticsProvider.createParticipantStatistics(null); - }).hasMessageMatching(LIST_IS_NULL); - - ParticipantStatisticsList createdStatsList = new ParticipantStatisticsList(); - createdStatsList.setStatisticsList(participantStatisticsProvider - .createParticipantStatistics(inputParticipantStatistics.getStatisticsList())); - - assertEquals(inputParticipantStatistics.toString().replaceAll("\\s+", ""), - createdStatsList.toString().replaceAll("\\s+", "")); - } - - @Test - void testGetAutomationCompositions() throws Exception { - // Return empty list when no data present in db - List<ParticipantStatistics> getResponse = - participantStatisticsProvider.getParticipantStatistics(null, null, null); - assertThat(getResponse).isEmpty(); - - participantStatisticsProvider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList()); - ToscaConceptIdentifier identifier = inputParticipantStatistics.getStatisticsList().get(0).getParticipantId(); - Instant instant = inputParticipantStatistics.getStatisticsList().get(0).getTimeStamp(); - assertEquals(1, participantStatisticsProvider - .getParticipantStatistics(identifier.getName(), identifier.getVersion(), instant).size()); - - assertEquals(1, participantStatisticsProvider - .getFilteredParticipantStatistics("name2", "1.0.1", null, null, null, "DESC", 1).size()); - } -} diff --git a/models/src/test/resources/META-INF/persistence.xml b/models/src/test/resources/META-INF/persistence.xml index 9bd136229..f36a5823a 100644 --- a/models/src/test/resources/META-INF/persistence.xml +++ b/models/src/test/resources/META-INF/persistence.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- ============LICENSE_START======================================================= - Copyright (C) 2021 Nordix Foundation. + 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. @@ -27,7 +27,6 @@ <class>org.onap.policy.models.dao.converters.Uuid2String</class> <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class> <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class> - <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics</class> <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class> <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignment</class> <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignments</class> @@ -55,24 +54,11 @@ <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition</class> <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement</class> <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant</class> - <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipantStatistics</class> - <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaClElementStatistics</class> <properties> <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> <property name="eclipselink.ddl-generation.output-mode" value="database" /> <property name="eclipselink.logging.level" value="INFO" /> - - <!-- <property name="eclipselink.logging.level" value="ALL" /> - <property name="eclipselink.logging.level.jpa" value="ALL" /> - <property name="eclipselink.logging.level.ddl" value="ALL" /> - <property name="eclipselink.logging.level.connection" value="ALL" /> - <property name="eclipselink.logging.level.sql" value="ALL" /> - <property name="eclipselink.logging.level.transaction" value="ALL" /> - <property name="eclipselink.logging.level.sequencing" value="ALL" /> - <property name="eclipselink.logging.level.server" value="ALL" /> - <property name="eclipselink.logging.level.query" value="ALL" /> - <property name="eclipselink.logging.level.properties" value="ALL"/> --> </properties> </persistence-unit> </persistence> |