summaryrefslogtreecommitdiffstats
path: root/model/engine-model/src/main
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@ericsson.com>2018-05-28 10:58:07 +0100
committerwaqas.ikram <waqas.ikram@ericsson.com>2018-05-28 14:35:30 +0100
commit55d93a12cc5575c872724f48585304b5eec77fea (patch)
treeac5e44c5670bbcc5e68cceb1694f87348c371e1b /model/engine-model/src/main
parent6029d25f5f3ad43fe02ffe1a4beb1eda0a6ae5e3 (diff)
Adding policy-model, model-api & engine-model
Change-Id: I56702b8f0953457d493f894d155b2a6ddc87b10c Issue-ID: POLICY-856 Signed-off-by: waqas.ikram <waqas.ikram@ericsson.com>
Diffstat (limited to 'model/engine-model/src/main')
-rw-r--r--model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineModel.java395
-rw-r--r--model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java46
-rw-r--r--model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java545
-rw-r--r--model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/package-info.java34
4 files changed, 1020 insertions, 0 deletions
diff --git a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineModel.java b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineModel.java
new file mode 100644
index 000000000..b7733c6a3
--- /dev/null
+++ b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineModel.java
@@ -0,0 +1,395 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.model.enginemodel.concepts;
+
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Enumerated;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+import org.onap.policy.apex.model.utilities.Assertions;
+
+/**
+ * A container class for an Apex engine model. This class is a container class that allows an Apex
+ * model to be constructed that contains the current context {@link AxContextModel}, current state
+ * {@link AxEngineState} and current statistics {@link AxEngineStats} of an Apex engine. This model
+ * is used by an Apex engine to pass its current execution state to any system that wishes to query
+ * that information. The time stamp of the engine model is the time at which the state and
+ * statistics of the engine were read.
+ * <p>
+ * Validation checks that the current state {@link AxEngineState} is defined and that the time stamp
+ * is set on the engine model.
+ */
+@Entity
+@Table(name = "AxEngineModel")
+@XmlRootElement(name = "apexEngineModel", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "AxEngineModel", namespace = "http://www.onap.org/policy/apex-pdp",
+ propOrder = {"timestamp", "state", "stats"})
+
+public class AxEngineModel extends AxContextModel {
+ private static final long serialVersionUID = 6381235864606564046L;
+ private static final int HASH_CODE_PRIME = 32;
+
+ @Column(name = "timestamp")
+ private long timestamp;
+
+ @Enumerated
+ @Column(name = "state")
+ @XmlElement(required = true)
+ private AxEngineState state;
+
+ // @formatter:off
+ @JoinColumns({
+ @JoinColumn(name = "statsParentKeyName", referencedColumnName = "parentKeyName", updatable = false,
+ insertable = false),
+ @JoinColumn(name = "statsParentKeyVersion", referencedColumnName = "parentKeyVersion", updatable = false,
+ insertable = false),
+ @JoinColumn(name = "statsParentLocalName ", referencedColumnName = "parentLocalName", updatable = false,
+ insertable = false),
+ @JoinColumn(name = "statsLocalName", referencedColumnName = "localName", updatable = false,
+ insertable = false)})
+ private AxEngineStats stats;
+ // @formatter:on
+
+ /**
+ * The Default Constructor creates an engine model with a null key and all its fields undefined.
+ */
+ public AxEngineModel() {
+ this(new AxArtifactKey());
+ timestamp = -1;
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public AxEngineModel(final AxEngineModel copyConcept) {
+ super(copyConcept);
+ }
+
+ /**
+ * The Keyed Constructor creates an engine model with the given key and all its fields
+ * undefined.
+ *
+ * @param key the engine model key
+ */
+ public AxEngineModel(final AxArtifactKey key) {
+ this(key, new AxContextSchemas(new AxArtifactKey(key.getName() + "_DataTypes", key.getVersion())),
+ new AxKeyInformation(new AxArtifactKey(key.getName() + "_KeyInfo", key.getVersion())),
+ new AxContextAlbums(new AxArtifactKey(key.getName() + "_Context", key.getVersion())));
+ }
+
+ /**
+ * This Constructor creates an engine model with its context model data types all defined, the
+ * state of the engine model is undefined.
+ *
+ * @param key the engine model key
+ * @param contextSchemas the context schemas used by the engine model
+ * @param keyInformation the key information used by the engine model
+ * @param contextAlbums the context albums used by the engine model
+ */
+ public AxEngineModel(final AxArtifactKey key, final AxContextSchemas contextSchemas,
+ final AxKeyInformation keyInformation, final AxContextAlbums contextAlbums) {
+ this(key, contextSchemas, keyInformation, contextAlbums, AxEngineState.UNDEFINED,
+ new AxEngineStats(new AxReferenceKey(key, "_EngineStats", key.getVersion())));
+ }
+
+ /**
+ * This Constructor creates an engine model with all its fields defined.
+ *
+ * @param key the engine model key
+ * @param contextSchemas the context schemas used by the engine model
+ * @param keyInformation the key information used by the engine model
+ * @param contextAlbums the context albums used by the engine model
+ * @param state the state of the engine in the engine model
+ * @param stats the statistics of the engine in the engine model
+ */
+ public AxEngineModel(final AxArtifactKey key, final AxContextSchemas contextSchemas,
+ final AxKeyInformation keyInformation, final AxContextAlbums contextAlbums, final AxEngineState state,
+ final AxEngineStats stats) {
+ super(key, contextSchemas, contextAlbums, keyInformation);
+ Assertions.argumentNotNull(state, "state may not be null");
+ Assertions.argumentNotNull(stats, "stats may not be null");
+
+ this.state = state;
+ this.stats = stats;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#getKeys()
+ */
+ @Override
+ public List<AxKey> getKeys() {
+ final List<AxKey> keyList = super.getKeys();
+ keyList.addAll(stats.getKeys());
+ return keyList;
+ }
+
+ /**
+ * Gets the time stamp at which the engine model measurements were taken.
+ *
+ * @return the time stamp at which the engine model measurements were taken
+ */
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ /**
+ * Gets the time stamp at which the engine model measurements were taken as a string.
+ *
+ * @return the time stamp string
+ */
+ public String getTimeStampString() {
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(timestamp);
+ }
+
+ /**
+ * Sets the time stamp at which the engine model measurements were taken.
+ *
+ * @param timestamp the time stamp at which the engine model measurements were taken
+ */
+ public void setTimestamp(final long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ /**
+ * Gets the state of the engine at the time the measurements were taken.
+ *
+ * @return the state of the engine at the time the measurements were taken
+ */
+ public AxEngineState getState() {
+ return state;
+ }
+
+ /**
+ * Sets the state of the engine.
+ *
+ * @param state the state of the engine
+ */
+ public void setState(final AxEngineState state) {
+ Assertions.argumentNotNull(state, "state may not be null");
+ this.state = state;
+ }
+
+ /**
+ * Gets the statistics of the engine at the time the measurements were taken.
+ *
+ * @return the statistics of the engine at the time the measurements were taken
+ */
+ public AxEngineStats getStats() {
+ return stats;
+ }
+
+ /**
+ * Sets the the statistics of the engine.
+ *
+ * @param stats the the statistics of the engine
+ */
+ public void setStats(final AxEngineStats stats) {
+ Assertions.argumentNotNull(stats, "stats may not be null");
+ this.stats = stats;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#validate(org.onap.policy.apex
+ * .model .basicmodel.concepts.AxValidationResult)
+ */
+ @Override
+ public AxValidationResult validate(final AxValidationResult resultIn) {
+ AxValidationResult result = resultIn;
+
+ result = stats.validate(result);
+
+ if (timestamp == -1) {
+ result.addValidationMessage(new AxValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ this.getClass().getSimpleName() + " - timestamp is not set"));
+ }
+
+ if (state == AxEngineState.UNDEFINED) {
+ result.addValidationMessage(new AxValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ this.getClass().getSimpleName() + " - state is UNDEFINED"));
+ }
+
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#clean()
+ */
+ @Override
+ public void clean() {
+ super.clean();
+ stats.clean();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#toString()
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(this.getClass().getSimpleName());
+ builder.append(":(");
+ builder.append(super.toString());
+ builder.append(",timestamp=");
+ builder.append(timestamp);
+ builder.append(",state=");
+ builder.append(state);
+ builder.append(",stats=");
+ builder.append(stats);
+ builder.append(")");
+ return builder.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @Override
+ public AxConcept copyTo(final AxConcept targetObject) {
+ Assertions.argumentNotNull(targetObject, "target may not be null");
+
+ final Object copyObject = targetObject;
+ Assertions.instanceOf(copyObject, AxEngineModel.class);
+
+ final AxEngineModel copy = ((AxEngineModel) copyObject);
+ super.copyTo(targetObject);
+ copy.timestamp = timestamp;
+ copy.setState(state);
+ copy.setStats(new AxEngineStats(stats));
+
+ return copy;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + super.hashCode();
+ result = prime * result + (int) (timestamp ^ (timestamp >>> HASH_CODE_PRIME));
+ result = prime * result + state.hashCode();
+ result = prime * result + stats.hashCode();
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null) {
+ throw new IllegalArgumentException("comparison object may not be null");
+ }
+
+ if (this == obj) {
+ return true;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ final AxEngineModel other = (AxEngineModel) obj;
+ if (!super.equals(other)) {
+ return false;
+ }
+ if (timestamp != other.timestamp) {
+ return false;
+ }
+ if (!state.equals(other.state)) {
+ return false;
+ }
+ return stats.equals(other.stats);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#compareTo(org.onap.policy.
+ * apex.model.basicmodel.concepts.AxConcept)
+ */
+ @Override
+ public int compareTo(final AxConcept otherObj) {
+ Assertions.argumentNotNull(otherObj, "comparison object may not be null");
+
+ if (this == otherObj) {
+ return 0;
+ }
+ if (getClass() != otherObj.getClass()) {
+ return this.hashCode() - otherObj.hashCode();
+ }
+
+ final AxEngineModel other = (AxEngineModel) otherObj;
+ if (!super.equals(other)) {
+ return super.compareTo(other);
+ }
+ if (timestamp != other.timestamp) {
+ return (int) (timestamp - other.timestamp);
+ }
+ if (!state.equals(other.state)) {
+ return state.compareTo(other.state);
+ }
+ return stats.compareTo(other.stats);
+ }
+}
diff --git a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java
new file mode 100644
index 000000000..f77fe1910
--- /dev/null
+++ b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.model.enginemodel.concepts;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * This enumeration indicates the execution state of an Apex engine.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "AxEngineState", namespace = "http://www.onap.org/policy/apex-pdp")
+public enum AxEngineState {
+ /** The state of the engine is not known. */
+ UNDEFINED,
+ /** The engine is stopped. */
+ STOPPED,
+ /** The engine is running and is waiting to execute a policy. */
+ READY,
+ /** The engine is running and is executing a policy. */
+ EXECUTING,
+ /** The engine has been ordered to stop and is stoping. */
+ STOPPING;
+}
diff --git a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java
new file mode 100644
index 000000000..b7593e751
--- /dev/null
+++ b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java
@@ -0,0 +1,545 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.model.enginemodel.concepts;
+
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+import org.onap.policy.apex.model.utilities.Assertions;
+
+/**
+ * This class is a java bean that is used to record statistics on Apex engines as they execute.
+ * Statistics on the number of events, the amount of time taken to execute the last policy, the
+ * average policy execution time, the up time of the engine, and the time stamp of the last engine
+ * start are recorded.
+ */
+
+@Entity
+@Table(name = "AxEngineStats")
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexEngineStats", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxEngineStats", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = {"key", "timeStamp",
+ "eventCount", "lastExecutionTime", "averageExecutionTime", "upTime", "lastStart"})
+public class AxEngineStats extends AxConcept {
+ private static final long serialVersionUID = -6981129081962785368L;
+ private static final int HASH_CODE_PRIME = 32;
+
+ @EmbeddedId
+ @XmlElement(name = "key", required = true)
+ private AxReferenceKey key;
+
+ @Column
+ @XmlElement(required = true)
+ private long timeStamp;
+
+ @Column
+ @XmlElement(required = true)
+ private long eventCount;
+
+ @Column
+ @XmlElement(required = true)
+ private long lastExecutionTime;
+
+ @Column
+ @XmlElement(required = true)
+ private double averageExecutionTime;
+
+ @Column
+ @XmlElement(required = true)
+ private long upTime;
+
+ @Transient
+ private transient long lastEnterTime;
+
+ @Column
+ @XmlElement(required = true)
+ private long lastStart;
+
+ /**
+ * The Default Constructor creates an engine statistics instance with a null key and with all
+ * values cleared.
+ */
+ public AxEngineStats() {
+ this(new AxReferenceKey());
+ timeStamp = 0;
+ eventCount = 0;
+ lastExecutionTime = 0;
+ averageExecutionTime = 0;
+ upTime = 0;
+ lastEnterTime = 0;
+ lastStart = 0;
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public AxEngineStats(final AxEngineStats copyConcept) {
+ super(copyConcept);
+ }
+
+ /**
+ * The Keyed Constructor creates an engine statistics instance with the given key and all values
+ * cleared.
+ *
+ * @param key the key
+ */
+ public AxEngineStats(final AxReferenceKey key) {
+ this(key, 0, 0, 0, 0, 0, 0);
+ }
+
+ /**
+ * This Constructor creates an engine statistics instance with all its fields set.
+ *
+ * @param key the engine statistics key
+ * @param timeStamp the time stamp at which the statistics were recorded
+ * @param eventCount the number of events processed by the engine
+ * @param lastExecutionTime the amount of time taken to execute the last policy
+ * @param averageExecutionTime the average amount of time taken to execute a policy
+ * @param upTime the time that has elapsed since the policy engine was started
+ * @param lastStart the time at which the policy engine was last started
+ */
+ public AxEngineStats(final AxReferenceKey key, final long timeStamp, final long eventCount,
+ final long lastExecutionTime, final double averageExecutionTime, final long upTime, final long lastStart) {
+ super();
+ Assertions.argumentNotNull(key, "key may not be null");
+
+ this.key = key;
+ this.timeStamp = timeStamp;
+ this.eventCount = eventCount;
+ this.lastExecutionTime = lastExecutionTime;
+ this.averageExecutionTime = averageExecutionTime;
+ this.upTime = upTime;
+ this.lastStart = lastStart;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxReferenceKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @Override
+ public List<AxKey> getKeys() {
+ return key.getKeys();
+ }
+
+ /**
+ * Sets the engine statistics key.
+ *
+ * @param key the engine statistics key
+ */
+ public void setKey(final AxReferenceKey key) {
+ Assertions.argumentNotNull(key, "key may not be null");
+ this.key = key;
+ }
+
+ /**
+ * Gets the time stamp at which the statistics were recorded.
+ *
+ * @return the time stamp at which the statistics were recorded
+ */
+ public long getTimeStamp() {
+ return timeStamp;
+ }
+
+ /**
+ * Gets the time stamp at which the statistics were recorded as a string.
+ *
+ * @return the time stamp at which the statistics were recorded as a string
+ */
+ public String getTimeStampString() {
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(timeStamp);
+ }
+
+ /**
+ * Sets the time stamp at which the statistics were recorded.
+ *
+ * @param timeStamp the time stamp at which the statistics were recorded
+ */
+ public void setTimeStamp(final long timeStamp) {
+ this.timeStamp = timeStamp;
+ }
+
+ /**
+ * Gets the number of events processed by the engine.
+ *
+ * @return the number of events processed by the engine
+ */
+ public long getEventCount() {
+ return eventCount;
+ }
+
+ /**
+ * Sets the number of events processed by the engine.
+ *
+ * @param eventCount the number of events processed by the engine
+ */
+ public void setEventCount(final long eventCount) {
+ this.eventCount = eventCount;
+ }
+
+ /**
+ * Gets the amount of time taken to execute the last policy.
+ *
+ * @return the amount of time taken to execute the last policy
+ */
+ public long getLastExecutionTime() {
+ return lastExecutionTime;
+ }
+
+ /**
+ * Sets the amount of time taken to execute the last policy.
+ *
+ * @param lastExecutionTime the amount of time taken to execute the last policy
+ */
+ public void setLastExecutionTime(final long lastExecutionTime) {
+ this.lastExecutionTime = lastExecutionTime;
+ }
+
+ /**
+ * Gets the average amount of time taken to execute a policy.
+ *
+ * @return the average amount of time taken to execute a policy
+ */
+ public double getAverageExecutionTime() {
+ return averageExecutionTime;
+ }
+
+ /**
+ * Sets the average amount of time taken to execute a policy.
+ *
+ * @param averageExecutionTime the average amount of time taken to execute a policy
+ */
+ public void setAverageExecutionTime(final double averageExecutionTime) {
+ this.averageExecutionTime = averageExecutionTime;
+ }
+
+ /**
+ * Gets the time that has elapsed since the policy engine was started.
+ *
+ * @return the time that has elapsed since the policy engine was started
+ */
+ public long getUpTime() {
+ if (this.getLastStart() != 0) {
+ return upTime + (timeStamp - this.getLastStart());
+ }
+ return upTime;
+ }
+
+ /**
+ * Sets the time that has elapsed since the policy engine was started.
+ *
+ * @param upTime the time that has elapsed since the policy engine was started
+ */
+ public void setUpTime(final long upTime) {
+ this.upTime = upTime;
+ }
+
+ /**
+ * Sets the time at which the policy engine was last started.
+ *
+ * @param lastStart the time at which the policy engine was last started
+ */
+ private void setLastStart(final long lastStart) {
+ this.lastStart = lastStart;
+ }
+
+ /**
+ * Gets the time at which the policy engine was last started.
+ *
+ * @return the time at which the policy engine was last started
+ */
+ private long getLastStart() {
+ return lastStart;
+ }
+
+ /**
+ * Resets all the statistic values to zero.
+ */
+ public synchronized void reset() {
+ timeStamp = 0;
+ eventCount = 0;
+ lastExecutionTime = 0;
+ averageExecutionTime = 0;
+ upTime = 0;
+ lastEnterTime = 0;
+ lastStart = 0;
+ }
+
+ /**
+ * Updates the statistics when called, used by the Apex engine when it starts executing a
+ * policy.
+ *
+ * @param eventkey the key of the event that is being executed
+ */
+ public synchronized void executionEnter(final AxArtifactKey eventkey) {
+ final long now = System.currentTimeMillis();
+ eventCount++;
+ if (eventCount < 0) {
+ eventCount = 2;
+ }
+ lastEnterTime = now;
+ timeStamp = now;
+ }
+
+ /**
+ * Updates the statistics when called, used by the Apex engine when it completes executing a
+ * policy.
+ */
+ public synchronized void executionExit() {
+ final long now = System.currentTimeMillis();
+ lastExecutionTime = now - lastEnterTime;
+
+ averageExecutionTime = ((averageExecutionTime * (eventCount - 1.0)) + lastExecutionTime) / eventCount;
+ lastEnterTime = 0;
+ timeStamp = System.currentTimeMillis();
+ }
+
+ /**
+ * Updates the statistics when called, used by the Apex engine when it is started.
+ */
+ public synchronized void engineStart() {
+ final long now = System.currentTimeMillis();
+ timeStamp = now;
+ this.setLastStart(now);
+ }
+
+ /**
+ * Updates the statistics when called, used by the Apex engine when it is stopped.
+ */
+ public synchronized void engineStop() {
+ final long now = System.currentTimeMillis();
+ timeStamp = now;
+ upTime += (timeStamp - this.getLastStart());
+ this.setLastStart(0);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxValidationResult)
+ */
+ @Override
+ public AxValidationResult validate(final AxValidationResult result) {
+ if (key.equals(AxReferenceKey.getNullKey())) {
+ result.addValidationMessage(
+ new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ return key.validate(result);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ key.clean();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(this.getClass().getSimpleName());
+ builder.append(":(");
+ builder.append("engineKey=");
+ builder.append(key);
+ builder.append(",timeStamp=");
+ builder.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(timeStamp));
+ builder.append(",eventCount=");
+ builder.append(eventCount);
+ builder.append(",lastExecutionTime=");
+ builder.append(lastExecutionTime);
+ builder.append(",averageExecutionTime=");
+ builder.append(averageExecutionTime);
+ builder.append(",upTime=");
+ builder.append(getUpTime());
+ builder.append(")");
+ return builder.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @Override
+ public AxConcept copyTo(final AxConcept targetObject) {
+ Assertions.argumentNotNull(targetObject, "target may not be null");
+
+ final Object copyObject = targetObject;
+ Assertions.instanceOf(copyObject, AxEngineStats.class);
+
+ final AxEngineStats copy = ((AxEngineStats) copyObject);
+ copy.setKey(new AxReferenceKey(key));
+ copy.setTimeStamp(timeStamp);
+ copy.setEventCount(eventCount);
+ copy.setLastExecutionTime(lastExecutionTime);
+ copy.setAverageExecutionTime(averageExecutionTime);
+ copy.setUpTime(upTime);
+ copy.setLastStart(lastStart);
+
+ return copy;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + key.hashCode();
+ result = prime * result + (int) (timeStamp ^ (timeStamp >>> HASH_CODE_PRIME));
+ result = prime * result + (int) (eventCount ^ (eventCount >>> HASH_CODE_PRIME));
+ result = prime * result + (int) (lastExecutionTime ^ (lastExecutionTime >>> HASH_CODE_PRIME));
+ result = prime * result + ((int) averageExecutionTime ^ ((int) averageExecutionTime >>> HASH_CODE_PRIME));
+ result = prime * result + (int) (upTime ^ (upTime >>> HASH_CODE_PRIME));
+ result = prime * result + (int) (getLastStart() ^ (getLastStart() >>> HASH_CODE_PRIME));
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (this == obj) {
+ return true;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ final AxEngineStats other = (AxEngineStats) obj;
+ if (!key.equals(other.key)) {
+ return false;
+ }
+ if (timeStamp != other.timeStamp) {
+ return false;
+ }
+ if (eventCount != other.eventCount) {
+ return false;
+ }
+ if (lastExecutionTime != other.lastExecutionTime) {
+ return false;
+ }
+ if (averageExecutionTime != other.averageExecutionTime) {
+ return false;
+ }
+ if (upTime != other.upTime) {
+ return false;
+ }
+ return getLastStart() == other.getLastStart();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(final AxConcept otherObj) {
+ if (otherObj == null) {
+ return -1;
+ }
+ if (this == otherObj) {
+ return 0;
+ }
+ if (getClass() != otherObj.getClass()) {
+ return this.hashCode() - otherObj.hashCode();
+ }
+
+ final AxEngineStats other = (AxEngineStats) otherObj;
+ if (!key.equals(other.key)) {
+ return key.compareTo(other.key);
+ }
+ if (timeStamp != other.timeStamp) {
+ return (int) (timeStamp - other.timeStamp);
+ }
+ if (eventCount != other.eventCount) {
+ return (int) (eventCount - other.eventCount);
+ }
+ if (lastExecutionTime != other.lastExecutionTime) {
+ return (int) (lastExecutionTime - other.lastExecutionTime);
+ }
+ if (averageExecutionTime != other.averageExecutionTime) {
+ return (int) (averageExecutionTime - other.averageExecutionTime);
+ }
+ if (upTime != other.upTime) {
+ return (int) (upTime - other.upTime);
+ }
+ if (getLastStart() != other.getLastStart()) {
+ return (int) (getLastStart() - other.getLastStart());
+ }
+
+ return 0;
+ }
+}
diff --git a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/package-info.java b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/package-info.java
new file mode 100644
index 000000000..ea47c6993
--- /dev/null
+++ b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/package-info.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+/**
+ * Contains the concepts required to receive state information and statistcs from running APEX
+ * engines.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+@XmlSchema(namespace = "http://www.onap.org/policy/apex-pdp", elementFormDefault = XmlNsForm.QUALIFIED,
+ xmlns = {@XmlNs(namespaceURI = "http://www.onap.org/policy/apex-pdp", prefix = "")})
+
+package org.onap.policy.apex.model.enginemodel.concepts;
+
+import javax.xml.bind.annotation.XmlNs;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlSchema;