aboutsummaryrefslogtreecommitdiffstats
path: root/models-pdp/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'models-pdp/src/main')
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java7
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java44
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java45
3 files changed, 68 insertions, 28 deletions
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java
index f7a0e7d91..c9c4cda0e 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java
@@ -1,8 +1,7 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +21,7 @@
package org.onap.policy.models.pdp.concepts;
+
import java.time.Instant;
import java.util.List;
import lombok.Data;
@@ -40,6 +40,7 @@ public class PdpStatistics {
private String pdpInstanceId;
private Instant timeStamp;
+ private Long generatedId;
private String pdpGroupName;
private String pdpSubGroupName;
private long policyDeployCount;
@@ -58,6 +59,7 @@ public class PdpStatistics {
public PdpStatistics(@NonNull PdpStatistics source) {
this.pdpInstanceId = source.pdpInstanceId;
this.timeStamp = source.timeStamp;
+ this.generatedId = source.generatedId;
this.pdpGroupName = source.pdpGroupName;
this.pdpSubGroupName = source.pdpSubGroupName;
this.policyDeployCount = source.policyDeployCount;
@@ -68,5 +70,4 @@ public class PdpStatistics {
this.policyExecutedSuccessCount = source.policyExecutedSuccessCount;
this.engineStats = PfUtils.mapList(source.engineStats, PdpEngineWorkerStatistics::new, null);
}
-
}
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java
index c3329cfa4..ae859325d 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatistics.java
@@ -25,6 +25,7 @@ package org.onap.policy.models.pdp.persistence.concepts;
import java.io.Serializable;
import java.time.Instant;
+import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
@@ -33,16 +34,19 @@ import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.apache.commons.lang3.builder.CompareToBuilder;
+import org.eclipse.persistence.annotations.Index;
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.PfGeneratedIdKey;
import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.base.PfTimestampKey;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.base.validation.annotations.VerifyKey;
import org.onap.policy.models.pdp.concepts.PdpEngineWorkerStatistics;
@@ -55,6 +59,7 @@ import org.onap.policy.models.pdp.concepts.PdpStatistics;
*/
@Entity
@Table(name = "PdpStatistics")
+@Index(name = "IDX_TSIDX1", columnNames = {"timeStamp", "name", "version"})
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@AllArgsConstructor
@@ -66,7 +71,11 @@ public class JpaPdpStatistics extends PfConcept implements PfAuthorative<PdpStat
@EmbeddedId
@VerifyKey
@NotNull
- private PfTimestampKey key;
+ private PfGeneratedIdKey key;
+
+ @Column(precision = 3)
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date timeStamp;
@Column(length = 120)
private String pdpGroupName;
@@ -99,7 +108,7 @@ public class JpaPdpStatistics extends PfConcept implements PfAuthorative<PdpStat
* The Default Constructor creates a {@link JpaPdpStatistics} object with a null key.
*/
public JpaPdpStatistics() {
- this(new PfTimestampKey());
+ this(new PfGeneratedIdKey());
}
/**
@@ -107,11 +116,10 @@ public class JpaPdpStatistics extends PfConcept implements PfAuthorative<PdpStat
*
* @param key the key
*/
- public JpaPdpStatistics(@NonNull final PfTimestampKey key) {
- this(key, NULL_NAME, NULL_NAME, 0L, 0L, 0L, 0L, 0L, 0L, null);
+ public JpaPdpStatistics(@NonNull final PfGeneratedIdKey key) {
+ this(key, null, NULL_NAME, NULL_NAME, 0L, 0L, 0L, 0L, 0L, 0L, null);
}
-
/**
* Copy constructor.
*
@@ -119,7 +127,8 @@ public class JpaPdpStatistics extends PfConcept implements PfAuthorative<PdpStat
*/
public JpaPdpStatistics(@NonNull final JpaPdpStatistics copyConcept) {
super(copyConcept);
- this.key = new PfTimestampKey(copyConcept.key);
+ this.key = new PfGeneratedIdKey(copyConcept.key);
+ this.timeStamp = copyConcept.timeStamp;
this.pdpGroupName = copyConcept.pdpGroupName;
this.pdpSubGroupName = copyConcept.pdpSubGroupName;
this.policyDeployCount = copyConcept.policyDeployCount;
@@ -153,7 +162,10 @@ public class JpaPdpStatistics extends PfConcept implements PfAuthorative<PdpStat
}
final JpaPdpStatistics other = (JpaPdpStatistics) otherConcept;
- return new CompareToBuilder().append(this.key, other.key).append(this.pdpGroupName, other.pdpGroupName)
+ return new CompareToBuilder()
+ .append(this.key, other.key)
+ .append(this.timeStamp, other.timeStamp)
+ .append(this.pdpGroupName, other.pdpGroupName)
.append(this.pdpSubGroupName, other.pdpSubGroupName)
.append(this.policyDeployCount, other.policyDeployCount)
.append(this.policyDeployFailCount, other.policyDeployFailCount)
@@ -167,7 +179,8 @@ public class JpaPdpStatistics extends PfConcept implements PfAuthorative<PdpStat
public PdpStatistics toAuthorative() {
PdpStatistics pdpStatistics = new PdpStatistics();
pdpStatistics.setPdpInstanceId(key.getName());
- pdpStatistics.setTimeStamp(key.getInstant());
+ pdpStatistics.setGeneratedId(key.getGeneratedId());
+ pdpStatistics.setTimeStamp(timeStamp.toInstant());
pdpStatistics.setPdpGroupName(pdpGroupName);
pdpStatistics.setPdpSubGroupName(pdpSubGroupName);
pdpStatistics.setPolicyDeployCount(policyDeployCount);
@@ -183,9 +196,16 @@ public class JpaPdpStatistics extends PfConcept implements PfAuthorative<PdpStat
@Override
public void fromAuthorative(@NonNull final PdpStatistics pdpStatistics) {
- if (this.key == null || this.getKey().isNullKey()) {
- this.setKey(new PfTimestampKey(pdpStatistics.getPdpInstanceId(), PfKey.NULL_KEY_VERSION,
- pdpStatistics.getTimeStamp() == null ? Instant.EPOCH : pdpStatistics.getTimeStamp()));
+ if (pdpStatistics.getGeneratedId() == null) {
+ this.setKey(new PfGeneratedIdKey(pdpStatistics.getPdpInstanceId(), PfKey.NULL_KEY_VERSION));
+ } else {
+ this.setKey(new PfGeneratedIdKey(pdpStatistics.getPdpInstanceId(),
+ PfKey.NULL_KEY_VERSION, pdpStatistics.getGeneratedId()));
+ }
+ if (pdpStatistics.getTimeStamp() == null) {
+ this.setTimeStamp(Date.from(Instant.EPOCH));
+ } else {
+ this.setTimeStamp(Date.from(pdpStatistics.getTimeStamp()));
}
this.setPdpGroupName(pdpStatistics.getPdpGroupName());
this.setPdpSubGroupName(pdpStatistics.getPdpSubGroupName());
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java
index e030d089d..ece09b088 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java
@@ -32,10 +32,10 @@ import java.util.stream.Collectors;
import javax.ws.rs.core.Response;
import lombok.NonNull;
import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.models.base.PfGeneratedIdKey;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.base.PfTimestampKey;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics;
@@ -58,13 +58,32 @@ public class PdpStatisticsProvider {
* @return the PDP statistics found
* @throws PfModelException on errors getting PDP statistics
*/
- public List<PdpStatistics> getPdpStatistics(@NonNull final PfDao dao, final String name, final Instant timestamp)
+ public List<PdpStatistics> getPdpStatistics(@NonNull final PfDao dao, final String name, final Instant timeStamp)
+ throws PfModelException {
+ List<PdpStatistics> pdpStatistics = new ArrayList<>();
+ if (name != null && timeStamp != null) {
+ return asPdpStatisticsList(dao.getByTimestamp(JpaPdpStatistics.class,
+ new PfGeneratedIdKey(name, PfKey.NULL_KEY_VERSION), timeStamp));
+ } else {
+ return asPdpStatisticsList(dao.getAll(JpaPdpStatistics.class));
+ }
+ }
+
+ /**
+ * Get PDP statistics.
+ *
+ * @param dao the DAO to use to access the database
+ * @param name the name of the PDP statistics to get, null to get all PDPs
+ * @return the PDP statistics found
+ * @throws PfModelException on errors getting PDP statistics
+ */
+ public List<PdpStatistics> getPdpStatistics(@NonNull final PfDao dao, final String name)
throws PfModelException {
List<PdpStatistics> pdpStatistics = new ArrayList<>();
if (name != null) {
pdpStatistics
- .add(dao.get(JpaPdpStatistics.class, new PfTimestampKey(name, PfKey.NULL_KEY_VERSION, timestamp))
+ .add(dao.get(JpaPdpStatistics.class, new PfGeneratedIdKey(name, PfKey.NULL_KEY_VERSION))
.toAuthorative());
} else {
return asPdpStatisticsList(dao.getAll(JpaPdpStatistics.class));
@@ -95,7 +114,8 @@ public class PdpStatisticsProvider {
filterMap.put("pdpSubGroupName", pdpSubGroup);
}
- return asPdpStatisticsList(dao.getFiltered(JpaPdpStatistics.class, name, PfKey.NULL_KEY_VERSION, startTimeStamp,
+ return asPdpStatisticsList(dao.getFiltered(JpaPdpStatistics.class, name,
+ PfKey.NULL_KEY_VERSION, startTimeStamp,
endTimeStamp, filterMap, sortOrder, getRecordNum));
}
@@ -109,17 +129,16 @@ public class PdpStatisticsProvider {
*/
public List<PdpStatistics> createPdpStatistics(@NonNull final PfDao dao,
@NonNull final List<PdpStatistics> pdpStatisticsList) throws PfModelException {
-
for (PdpStatistics pdpStatistics : pdpStatisticsList) {
JpaPdpStatistics jpaPdpStatistics = new JpaPdpStatistics();
jpaPdpStatistics.fromAuthorative(pdpStatistics);
-
BeanValidationResult validationResult = jpaPdpStatistics.validate("pdp statistics");
if (!validationResult.isValid()) {
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
dao.create(jpaPdpStatistics);
+ pdpStatistics.setGeneratedId(jpaPdpStatistics.getKey().getGeneratedId());
}
// Return the created PDP statistics
@@ -127,11 +146,10 @@ public class PdpStatisticsProvider {
for (PdpStatistics pdpStatisticsItem : pdpStatisticsList) {
JpaPdpStatistics jpaPdpStatistics =
- dao.get(JpaPdpStatistics.class, new PfTimestampKey(pdpStatisticsItem.getPdpInstanceId(),
- PfKey.NULL_KEY_VERSION, pdpStatisticsItem.getTimeStamp()));
+ dao.get(JpaPdpStatistics.class, new PfGeneratedIdKey(pdpStatisticsItem.getPdpInstanceId(),
+ PfKey.NULL_KEY_VERSION, pdpStatisticsItem.getGeneratedId()));
pdpStatistics.add(jpaPdpStatistics.toAuthorative());
}
-
return pdpStatistics;
}
@@ -163,8 +181,8 @@ public class PdpStatisticsProvider {
for (PdpStatistics pdpStatisticsItem : pdpStatisticsList) {
JpaPdpStatistics jpaPdpStatistics =
- dao.get(JpaPdpStatistics.class, new PfTimestampKey(pdpStatisticsItem.getPdpInstanceId(),
- PfKey.NULL_KEY_VERSION, pdpStatisticsItem.getTimeStamp()));
+ dao.get(JpaPdpStatistics.class, new PfGeneratedIdKey(pdpStatisticsItem.getPdpInstanceId(),
+ PfKey.NULL_KEY_VERSION, pdpStatisticsItem.getGeneratedId()));
pdpStatistics.add(jpaPdpStatistics.toAuthorative());
}
@@ -182,11 +200,12 @@ public class PdpStatisticsProvider {
*/
public List<PdpStatistics> deletePdpStatistics(@NonNull final PfDao dao, @NonNull final String name,
final Instant timestamp) {
- List<PdpStatistics> pdpStatisticsListToDel = asPdpStatisticsList(dao.getFiltered(JpaPdpStatistics.class, name,
+ List<PdpStatistics> pdpStatisticsListToDel = asPdpStatisticsList(
+ dao.getFiltered(JpaPdpStatistics.class, name,
PfKey.NULL_KEY_VERSION, timestamp, timestamp, null, DESC_ORDER, 0));
pdpStatisticsListToDel.stream().forEach(s -> dao.delete(JpaPdpStatistics.class,
- new PfTimestampKey(s.getPdpInstanceId(), PfKey.NULL_KEY_VERSION, s.getTimeStamp())));
+ new PfGeneratedIdKey(s.getPdpInstanceId(), PfKey.NULL_KEY_VERSION, s.getGeneratedId())));
return pdpStatisticsListToDel;
}