summaryrefslogtreecommitdiffstats
path: root/model/engine-model/src
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2022-02-10 12:06:25 +0000
committerliamfallon <liam.fallon@est.tech>2022-02-10 13:48:15 +0000
commit8534756d13531ffec9c2d7b2ffe0a53ee1d3aaef (patch)
treea35f6b3f7766d47900ee6691111acff1418bb747 /model/engine-model/src
parent2f2c5465cd23c8c3300a5c3d185806bb3e7d73c1 (diff)
Collapse apex-pdp maven model submodules
This review collapses all the code in six podel submodules into a single model module. There are no code changes, just files moved around. This change reduces the complexity of the code structure and speeds up the build. Issue-ID: POLICY-1820 Change-Id: Ifb644e8ec85ae6d0987378f4616fbc8a8858a9a8 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'model/engine-model/src')
-rw-r--r--model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineModel.java338
-rw-r--r--model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java52
-rw-r--r--model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java533
-rw-r--r--model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/package-info.java28
-rw-r--r--model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java176
-rw-r--r--model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java267
-rw-r--r--model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java81
-rw-r--r--model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/DummyTestApexEngineModelCreator.java129
-rw-r--r--model/engine-model/src/test/resources/logback-test.xml70
9 files changed, 0 insertions, 1674 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
deleted file mode 100644
index 1a590a411..000000000
--- a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineModel.java
+++ /dev/null
@@ -1,338 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019,2022 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.apex.model.enginemodel.concepts;
-
-import java.text.SimpleDateFormat;
-import java.util.List;
-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.common.utils.validation.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.
- */
-public class AxEngineModel extends AxContextModel {
- private static final long serialVersionUID = 6381235864606564046L;
- private static final int HASH_CODE_PRIME = 32;
-
- private long timestamp;
- private AxEngineState state;
- private AxEngineStats stats;
-
- /**
- * 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;
- }
-
- /**
- * {@inheritDoc}.
- */
- @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;
- }
-
- /**
- * {@inheritDoc}.
- */
- @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;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void clean() {
- super.clean();
- stats.clean();
- }
-
- /**
- * {@inheritDoc}.
- */
- @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();
- }
-
- /**
- * {@inheritDoc}.
- */
- @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;
- }
-
- /**
- * {@inheritDoc}.
- */
- @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;
- }
-
- /**
- * {@inheritDoc}.
- */
- @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);
- }
-
- /**
- * {@inheritDoc}.
- */
- @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
deleted file mode 100644
index 24c564b96..000000000
--- a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
- * Modifications Copyright (C) 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.apex.model.enginemodel.concepts;
-
-/**
- * This enumeration indicates the execution state of an Apex engine.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-
-public enum AxEngineState {
- /** The state of the engine is not known. */
- UNDEFINED(0),
- /** The engine is stopped. */
- STOPPED(1),
- /** The engine is running and is waiting to execute a policy. */
- READY(2),
- /** The engine is running and is executing a policy. */
- EXECUTING(3),
- /** The engine has been ordered to stop and is stopping. */
- STOPPING(4);
-
- private final int stateIdentifier;
-
- AxEngineState(int stateIdentifier) {
- this.stateIdentifier = stateIdentifier;
- }
-
- public int getStateIdentifier() {
- return stateIdentifier;
- }
-}
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
deleted file mode 100644
index 1420d1e0d..000000000
--- a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java
+++ /dev/null
@@ -1,533 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation.
- * Modifications Copyright (C) 2022 Bell Canada.
- * ================================================================================
- * 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 io.prometheus.client.Gauge;
-import io.prometheus.client.Histogram;
-import java.text.SimpleDateFormat;
-import java.util.List;
-import lombok.Getter;
-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.common.utils.resources.PrometheusUtils;
-import org.onap.policy.common.utils.validation.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.
- */
-
-public class AxEngineStats extends AxConcept {
- private static final long serialVersionUID = -6981129081962785368L;
- private static final int HASH_CODE_PRIME = 32;
- static final String ENGINE_INSTANCE_ID = "engine_instance_id";
- static final Gauge ENGINE_EVENT_EXECUTIONS = Gauge.build().name("engine_event_executions")
- .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID)
- .help("Total number of APEX events processed by the engine.").register();
- static final Gauge ENGINE_UPTIME = Gauge.build().name("engine_uptime")
- .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID)
- .help("Time elapsed since the engine was started.").register();
- static final Gauge ENGINE_START_TIMESTAMP = Gauge.build().name("engine_last_start_timestamp_epoch")
- .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID)
- .help("Epoch timestamp of the instance when engine was last started.").register();
- static final Gauge ENGINE_AVG_EXECUTION_TIME = Gauge.build().name("engine_average_execution_time_seconds")
- .namespace(PrometheusUtils.PdpType.PDPA.getNamespace()).labelNames(ENGINE_INSTANCE_ID)
- .help("Average time taken to execute an APEX policy in seconds.").register();
- static final Histogram ENGINE_LAST_EXECUTION_TIME = Histogram.build()
- .namespace(PrometheusUtils.PdpType.PDPA.getNamespace())
- .name("engine_last_execution_time").labelNames(ENGINE_INSTANCE_ID)
- .help("Time taken to execute the last APEX policy in seconds.").register();
-
- private AxReferenceKey key;
- private long timeStamp;
- private long eventCount;
- private long lastExecutionTime;
- private double averageExecutionTime;
- private long upTime;
-
- @Getter
- private transient long lastEnterTime;
- 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;
- initEngineMetricsWithPrometheus();
- }
-
- /**
- * Register the APEX engine metrics with Prometheus.
- */
- private void initEngineMetricsWithPrometheus() {
- var engineId = getKey().getParentArtifactKey().getId();
- if (engineId.startsWith(AxKey.NULL_KEY_NAME)) {
- return;
- }
- ENGINE_UPTIME.labels(engineId).set(upTime / 1000d);
- ENGINE_EVENT_EXECUTIONS.labels(engineId).set(this.eventCount);
- ENGINE_START_TIMESTAMP.labels(engineId).set(this.lastStart);
- ENGINE_AVG_EXECUTION_TIME.labels(engineId).set(this.averageExecutionTime / 1000d);
- ENGINE_LAST_EXECUTION_TIME.labels(engineId).observe(this.lastExecutionTime / 1000d);
- }
-
- /**
- * 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;
- initEngineMetricsWithPrometheus();
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public AxReferenceKey getKey() {
- return key;
- }
-
- /**
- * {@inheritDoc}.
- */
- @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;
- ENGINE_EVENT_EXECUTIONS.labels(getKey().getParentArtifactKey().getId())
- .set(this.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;
- ENGINE_LAST_EXECUTION_TIME.labels(getKey().getParentArtifactKey().getId())
- .observe(this.lastExecutionTime / 1000d);
- }
-
- /**
- * 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;
- ENGINE_AVG_EXECUTION_TIME.labels(getKey().getParentArtifactKey().getId())
- .set(this.averageExecutionTime / 1000d);
- }
-
- /**
- * 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;
- ENGINE_UPTIME.labels(getKey().getParentArtifactKey().getId()).set(this.upTime / 1000d);
- }
-
- /**
- * 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;
- ENGINE_START_TIMESTAMP.labels(getKey().getParentArtifactKey().getId()).set(this.lastStart);
- }
-
- /**
- * Gets the time at which the policy engine was last started.
- *
- * @return the time at which the policy engine was last started
- */
- public 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;
- initEngineMetricsWithPrometheus();
- }
-
- /**
- * 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;
- ENGINE_EVENT_EXECUTIONS.labels(getKey().getParentArtifactKey().getId()).set(this.eventCount);
- }
-
- /**
- * 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;
- ENGINE_LAST_EXECUTION_TIME.labels(getKey().getParentArtifactKey().getId())
- .observe(this.lastExecutionTime / 1000d);
-
- averageExecutionTime = ((averageExecutionTime * (eventCount - 1.0)) + lastExecutionTime) / eventCount;
- lastEnterTime = 0;
- timeStamp = System.currentTimeMillis();
- ENGINE_AVG_EXECUTION_TIME.labels(getKey().getParentArtifactKey().getId())
- .set(this.averageExecutionTime / 1000d);
- }
-
- /**
- * 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);
- ENGINE_UPTIME.labels(getKey().getParentArtifactKey().getId()).set(this.upTime / 1000d);
- }
-
- /**
- * {@inheritDoc}.
- */
- @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);
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void clean() {
- key.clean();
- }
-
- /**
- * {@inheritDoc}.
- */
- @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();
- }
-
- /**
- * {@inheritDoc}.
- */
- @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);
- initEngineMetricsWithPrometheus();
-
- return copy;
- }
-
- /**
- * {@inheritDoc}.
- */
- @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;
- }
-
- /**
- * {@inheritDoc}.
- */
- @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 (Double.compare(averageExecutionTime, other.averageExecutionTime) != 0) {
- return false;
- }
- if (upTime != other.upTime) {
- return false;
- }
- return getLastStart() == other.getLastStart();
- }
-
- /**
- * {@inheritDoc}.
- */
- @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);
- }
- final int result = Double.compare(averageExecutionTime, other.averageExecutionTime);
- if (result != 0) {
- return result;
- }
- if (upTime != other.upTime) {
- return (int) (upTime - other.upTime);
- }
-
- return Long.compare(lastStart, other.lastStart);
- }
-}
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
deleted file mode 100644
index 4557af7db..000000000
--- a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/package-info.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 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=========================================================
- */
-
-/**
- * Contains the concepts required to receive state information and statistcs from running APEX
- * engines.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-package org.onap.policy.apex.model.enginemodel.concepts;
diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java
deleted file mode 100644
index c23687bb1..000000000
--- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 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.apex.model.enginemodel.concepts;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-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.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.AxContextSchemas;
-
-/**
- * Test engine models.
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-public class EngineModelTest {
-
- @Test
- public void testEnginetModel() {
- assertNotNull(new AxEngineModel());
- assertNotNull(new AxEngineModel(new AxArtifactKey()));
- assertNotNull(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(),
- new AxContextAlbums()));
- assertNotNull(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(),
- new AxContextAlbums(), AxEngineState.UNDEFINED, new AxEngineStats()));
-
- final AxArtifactKey modelKey = new AxArtifactKey("ModelName", "0.0.1");
- final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
- final AxArtifactKey albumKey = new AxArtifactKey("AlbumKey", "0.0.1");
- final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
- final AxEngineStats stats = new AxEngineStats(new AxReferenceKey(modelKey, "EngineStats"));
- final AxEngineStats otherStats = new AxEngineStats();
- otherStats.setAverageExecutionTime(100);
-
- final AxEngineModel model = new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats);
- model.register();
-
- assertThatThrownBy(() -> model.setKey(null))
- .hasMessage("key may not be null");
- model.setKey(modelKey);
- assertEquals("ModelName:0.0.1", model.getKey().getId());
- assertEquals("ModelName:0.0.1", model.getKeys().get(0).getId());
-
- final long timestamp = System.currentTimeMillis();
- model.setTimestamp(timestamp);
- assertEquals(timestamp, model.getTimestamp());
- model.setTimestamp(-1);
- assertTrue(model.getTimeStampString().matches("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}"));
-
- assertThatThrownBy(() -> model.setState(null))
- .hasMessage("state may not be null");
- for (final AxEngineState state : AxEngineState.values()) {
- model.setState(state);
- assertEquals(state, model.getState());
- }
-
- model.setState(AxEngineState.READY);
- assertEquals(AxEngineState.READY, model.getState());
-
- assertThatThrownBy(() -> model.setStats(null))
- .hasMessage("stats may not be null");
- model.setStats(stats);
- assertEquals(stats, model.getStats());
-
- model.clean();
- assertNotNull(model);
- assertThat(model.toString()).startsWith("AxEngineModel:(AxContextModel(super=AxEngineModel:(key=A");
-
- final AxEngineModel clonedModel = new AxEngineModel(model);
-
- assertNotEquals(0, model.hashCode());
-
- // disabling sonar because this code tests the equals() method
- assertEquals(model, model); // NOSONAR
- assertEquals(model, clonedModel);
- assertNotEquals(model, (Object) "Hello");
- assertNotEquals(model, new AxEngineModel(new AxArtifactKey()));
- assertNotEquals(model, new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(schemasKey),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats));
- assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey),
- new AxContextAlbums(albumKey), AxEngineState.READY, stats));
- assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(),
- new AxContextAlbums(albumKey), AxEngineState.READY, stats));
- assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(), AxEngineState.READY, stats));
- assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.STOPPED, stats));
- assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, otherStats));
- model.setTimestamp(timestamp);
- assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats));
- model.setTimestamp(0);
- assertEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats));
-
- model.setTimestamp(-1);
- assertEquals(0, model.compareTo(model));
- assertEquals(0, model.compareTo(clonedModel));
- assertNotEquals(0, model.compareTo(new AxArtifactKey()));
- assertNotEquals(model, new AxEngineModel(new AxArtifactKey()));
- assertNotEquals(0, model.compareTo(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(schemasKey),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
- assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
- assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
- new AxKeyInformation(), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
- assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(), AxEngineState.READY, stats)));
- assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.STOPPED, stats)));
- assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, otherStats)));
- model.setTimestamp(timestamp);
- assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
- model.setTimestamp(0);
- assertEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
- new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
-
- model.setTimestamp(timestamp);
- AxValidationResult result = new AxValidationResult();
- result = model.validate(result);
- assertEquals(ValidationResult.VALID, result.getValidationResult());
-
- model.setTimestamp(-1);
- result = new AxValidationResult();
- result = model.validate(result);
- assertEquals(ValidationResult.INVALID, result.getValidationResult());
-
- model.setTimestamp(timestamp);
- result = new AxValidationResult();
- result = model.validate(result);
- assertEquals(ValidationResult.VALID, result.getValidationResult());
-
- model.setState(AxEngineState.UNDEFINED);
- result = new AxValidationResult();
- result = model.validate(result);
- assertEquals(ValidationResult.INVALID, result.getValidationResult());
-
- model.setState(AxEngineState.READY);
- result = new AxValidationResult();
- result = model.validate(result);
- assertEquals(ValidationResult.VALID, result.getValidationResult());
- }
-}
diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java
deleted file mode 100644
index 3eca27c08..000000000
--- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2022 Bell Canada.
- * ================================================================================
- * 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 static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import io.prometheus.client.CollectorRegistry;
-import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
-import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
-import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
-
-/**
- * Test the engine statistics.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-public class EngineStatsTest {
- private static final Object WAIT_LOCK = new Object();
- private static final String ENGINE_KEY = "EngineKey";
- private static final String ENGINE_VERSION = "0.0.1";
-
- @Test
- public void testEngineStats() {
- assertNotNull(new AxEngineStats());
- assertNotNull(new AxEngineStats(new AxReferenceKey()));
-
- final AxReferenceKey statsKey = new AxReferenceKey(ENGINE_KEY, ENGINE_VERSION, "EngineStats");
- final AxEngineStats stats = new AxEngineStats(statsKey);
-
- assertThatThrownBy(() -> stats.setKey(null))
- .hasMessage("key may not be null");
- stats.setKey(statsKey);
- assertEquals("EngineKey:0.0.1:NULL:EngineStats", stats.getKey().getId());
- assertEquals("EngineKey:0.0.1:NULL:EngineStats", stats.getKeys().get(0).getId());
-
- stats.setAverageExecutionTime(123.45);
- assertEquals(Double.valueOf(123.45), Double.valueOf(stats.getAverageExecutionTime()));
- checkAvgExecTimeMetric(stats);
-
- stats.setEventCount(987);
- assertEquals(987, stats.getEventCount());
- checkEventsCountMetric(stats);
-
- final long lastExecutionTime = System.currentTimeMillis();
- stats.setLastExecutionTime(lastExecutionTime);
- assertEquals(lastExecutionTime, stats.getLastExecutionTime());
- checkLastExecTimeMetric(stats);
-
- final long timestamp = System.currentTimeMillis();
- stats.setTimeStamp(timestamp);
- assertEquals(timestamp, stats.getTimeStamp());
- assertNotNull(stats.getTimeStampString());
-
- final long upTime = System.currentTimeMillis() - timestamp;
- stats.setUpTime(upTime);
- assertEquals(upTime, stats.getUpTime());
- checkUpTimeMetric(stats);
-
- stats.engineStart();
- assertTrue(stats.getUpTime() > -1);
- checkEngineStartTimestampMetric(stats);
- checkLastExecTimeMetric(stats);
- stats.engineStop();
- assertTrue(stats.getUpTime() >= 0);
-
- stats.engineStop();
- checkUpTimeMetric(stats);
- checkEngineStartTimestampMetric(stats);
-
- stats.reset();
-
- stats.setEventCount(-2);
- stats.executionEnter(new AxArtifactKey());
- assertEquals(2, stats.getEventCount());
- checkEventsCountMetric(stats);
-
- stats.setEventCount(10);
- stats.executionEnter(new AxArtifactKey());
- assertEquals(11, stats.getEventCount());
- checkEventsCountMetric(stats);
-
- stats.reset();
- stats.engineStart();
- stats.setEventCount(4);
- checkUpTimeMetric(stats);
- stats.executionEnter(new AxArtifactKey());
- checkEventsCountMetric(stats);
- checkAvgExecTimeMetric(stats);
- checkEngineStartTimestampMetric(stats);
-
- synchronized (WAIT_LOCK) {
- try {
- WAIT_LOCK.wait(10);
- } catch (InterruptedException e) {
- fail("test should not throw an exception");
- }
- }
-
- stats.executionExit();
- final double avExecutionTime = stats.getAverageExecutionTime();
- assertTrue(avExecutionTime >= 2.0 && avExecutionTime < 10.0);
- stats.engineStop();
- checkUpTimeMetric(stats);
-
- AxValidationResult result = new AxValidationResult();
- result = stats.validate(result);
- assertEquals(ValidationResult.VALID, result.getValidationResult());
-
- stats.setKey(new AxReferenceKey());
- result = new AxValidationResult();
- result = stats.validate(result);
- assertEquals(ValidationResult.INVALID, result.getValidationResult());
-
- stats.setKey(statsKey);
- result = new AxValidationResult();
- result = stats.validate(result);
- assertEquals(ValidationResult.VALID, result.getValidationResult());
-
- stats.clean();
- stats.reset();
- checkAllPrometheusMetrics(stats);
-
- final AxEngineStats clonedStats = new AxEngineStats(stats);
- assertEquals("AxEngineStats:(engineKey=AxReferenceKey:(parentKey", clonedStats.toString().substring(0, 50));
-
- assertNotNull(stats.getKeys());
-
- assertNotEquals(0, stats.hashCode());
-
- // disabling sonar because this code tests the equals() method
- assertEquals(stats, stats); // NOSONAR
- assertEquals(stats, clonedStats);
- assertNotNull(stats);
- checkAllPrometheusMetrics(clonedStats);
-
- Object helloObject = "Hello";
- assertNotEquals(stats, helloObject);
- assertNotEquals(stats, new AxEngineStats(new AxReferenceKey()));
-
- assertEquals(0, stats.compareTo(stats));
- assertEquals(0, stats.compareTo(clonedStats));
- assertNotEquals(0, stats.compareTo(new AxArtifactKey()));
- assertNotEquals(0, stats.compareTo(null));
- assertNotEquals(0, stats.compareTo(new AxEngineStats(new AxReferenceKey())));
-
- stats.setTimeStamp(1);
- assertNotEquals(stats, new AxEngineStats(statsKey));
- assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
- stats.setTimeStamp(0);
- assertEquals(stats, new AxEngineStats(statsKey));
- assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
- checkAllPrometheusMetrics(clonedStats);
-
- stats.setEventCount(1);
- assertNotEquals(stats, new AxEngineStats(statsKey));
- assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
- stats.setEventCount(0);
- assertEquals(stats, new AxEngineStats(statsKey));
- assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
-
- stats.setLastExecutionTime(1);
- assertNotEquals(stats, new AxEngineStats(statsKey));
- assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
- stats.setLastExecutionTime(0);
- assertEquals(stats, new AxEngineStats(statsKey));
- assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
-
- stats.setAverageExecutionTime(1);
- assertNotEquals(stats, new AxEngineStats(statsKey));
- assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
- stats.setAverageExecutionTime(0);
- assertEquals(stats, new AxEngineStats(statsKey));
- assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
-
- stats.setUpTime(1);
- assertNotEquals(stats, new AxEngineStats(statsKey));
- assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
- stats.setUpTime(0);
- assertEquals(stats, new AxEngineStats(statsKey));
- assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
-
- assertEquals(-1, stats.compareTo(new AxEngineStats(statsKey, 0, 0, 0, 0.0, 0, 1)));
-
- stats.engineStart();
- assertNotEquals(stats, new AxEngineStats(statsKey));
- final AxEngineStats newStats = new AxEngineStats(statsKey);
- newStats.setTimeStamp(stats.getTimeStamp());
- assertNotEquals(stats, newStats);
- assertNotEquals(0, stats.compareTo(newStats));
- stats.engineStop();
- checkUpTimeMetric(stats);
- checkEngineStartTimestampMetric(stats);
- stats.reset();
- assertEquals(stats, new AxEngineStats(statsKey));
- assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
- checkAllPrometheusMetrics(stats);
- }
-
- private void checkUpTimeMetric(AxEngineStats stats) {
- Double upTimeMetric = CollectorRegistry.defaultRegistry.getSampleValue("pdpa_engine_uptime",
- new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
- assertEquals(upTimeMetric.longValue(), stats.getUpTime());
- }
-
- private void checkEventsCountMetric(AxEngineStats stats) {
- Double eventsCountMetric = CollectorRegistry.defaultRegistry.getSampleValue("pdpa_engine_event_executions",
- new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION});
- assertEquals(eventsCountMetric.longValue(), stats.getEventCount());
- }
-
- private void checkLastExecTimeMetric(AxEngineStats stats) {
- Double lastExecTimeMetric = CollectorRegistry.defaultRegistry
- .getSampleValue("pdpa_engine_last_execution_time_sum", new String[]{AxEngineStats.ENGINE_INSTANCE_ID},
- new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
- assertEquals(lastExecTimeMetric.longValue(), stats.getLastExecutionTime());
- }
-
- private void checkEngineStartTimestampMetric(AxEngineStats stats) {
- Double engineStartTimestampMetric = CollectorRegistry.defaultRegistry
- .getSampleValue("pdpa_engine_last_start_timestamp_epoch",
- new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION});
- assertEquals(engineStartTimestampMetric.longValue(), stats.getLastStart());
- }
-
- private void checkAvgExecTimeMetric(AxEngineStats stats) {
- Double avgExecTimeMetric = CollectorRegistry.defaultRegistry
- .getSampleValue("pdpa_engine_average_execution_time_seconds",
- new String[]{AxEngineStats.ENGINE_INSTANCE_ID},
- new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
- assertEquals(avgExecTimeMetric, Double.valueOf(stats.getAverageExecutionTime()));
- }
-
- private void checkAllPrometheusMetrics(AxEngineStats stats) {
- checkEventsCountMetric(stats);
- checkUpTimeMetric(stats);
- checkAvgExecTimeMetric(stats);
- checkEngineStartTimestampMetric(stats);
- checkEngineStartTimestampMetric(stats);
- }
-} \ No newline at end of file
diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java
deleted file mode 100644
index e7fdd2d93..000000000
--- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020,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.apex.model.enginemodel.handling;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
-import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
-import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
-
-public class ApexEngineModelTest {
- private static final String VALID_MODEL_STRING = "***validation of model successful***";
-
- private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
- + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
- + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
- + "AxEngineModel - state is UNDEFINED\n" + "********************************";
-
- private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
- + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
- + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
- + "AxEngineModel - timestamp is not set\n" + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
- + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
- + "AxEngineModel - state is UNDEFINED\n" + "********************************";
-
- TestApexModel<AxEngineModel> testApexModel;
-
- /**
- * Set up the test.
- *
- * @throws Exception errors from test setup
- */
- @Before
- public void setup() throws Exception {
- testApexModel = new TestApexModel<AxEngineModel>(AxEngineModel.class, new DummyTestApexEngineModelCreator());
- }
-
- @Test
- public void testModelValid() throws Exception {
- final AxValidationResult result = testApexModel.testApexModelValid();
- assertEquals(VALID_MODEL_STRING, result.toString());
- }
-
- @Test
- public void testModelVaidateInvalidModel() throws Exception {
- final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
- assertEquals(INVALID_MODEL_STRING, result.toString());
- }
-
- @Test
- public void testModelVaidateMalstructured() throws Exception {
- final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
- assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
- }
-
- @Test
- public void testModelWriteReadJson() throws Exception {
- testApexModel.testApexModelWriteReadJson();
- }
-}
diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/DummyTestApexEngineModelCreator.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/DummyTestApexEngineModelCreator.java
deleted file mode 100644
index 9e7d99b72..000000000
--- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/DummyTestApexEngineModelCreator.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*-
- * ============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.handling;
-
-import java.util.UUID;
-import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
-import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
-import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
-import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator;
-import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
-import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
-import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
-import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
-import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
-import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState;
-import org.onap.policy.apex.model.enginemodel.concepts.AxEngineStats;
-
-public class DummyTestApexEngineModelCreator implements TestApexModelCreator<AxEngineModel> {
-
- @Override
- public AxEngineModel getModel() {
- final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
- "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
- final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
- "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
-
- final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("ContextSchemas", "0.0.1"));
- schemas.getSchemasMap().put(schema0.getKey(), schema0);
- schemas.getSchemasMap().put(schema1.getKey(), schema1);
-
- final AxContextAlbum album0 =
- new AxContextAlbum(new AxArtifactKey("contextAlbum0", "0.0.1"), "APPLICATION", true, schema1.getKey());
-
- final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("context", "0.0.1"));
- albums.getAlbumsMap().put(album0.getKey(), album0);
-
- final AxEngineModel engineModel = new AxEngineModel(new AxArtifactKey("AnEngine", "0.0.1"));
- engineModel.setSchemas(schemas);
- engineModel.setAlbums(albums);
- engineModel.setTimestamp(System.currentTimeMillis());
- engineModel.setState(AxEngineState.EXECUTING);
- engineModel.setStats(new AxEngineStats(new AxReferenceKey(engineModel.getKey(), "EngineStats"),
- System.currentTimeMillis(), 100, 205, 200, 12345, 9876));
- engineModel.getKeyInformation().generateKeyInfo(engineModel);
-
- final AxValidationResult result = new AxValidationResult();
- engineModel.validate(result);
-
- return engineModel;
- }
-
- @Override
- public AxEngineModel getInvalidModel() {
- final AxEngineModel engineModel = getModel();
-
- engineModel.setTimestamp(System.currentTimeMillis());
- engineModel.setState(AxEngineState.UNDEFINED);
- engineModel.setStats(new AxEngineStats(new AxReferenceKey(engineModel.getKey(), "EngineStats"),
- System.currentTimeMillis(), 100, 205, 200, 12345, 9876));
- engineModel.getKeyInformation().generateKeyInfo(engineModel);
-
- return engineModel;
- }
-
- /**
- * Get a malstructured model.
- */
- public AxEngineModel getMalstructuredModel() {
- final AxEngineModel engineModel = getModel();
-
- engineModel.setTimestamp(-1);
- engineModel.setState(AxEngineState.UNDEFINED);
-
- return engineModel;
- }
-
- @Override
- public AxEngineModel getObservationModel() {
- final AxEngineModel engineModel = getModel();
-
- final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
- "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
- final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
- "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
-
- engineModel.getKeyInformation().getKeyInfoMap().put(schema0.getKey(),
- new AxKeyInfo(schema0.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000001"), ""));
- engineModel.getKeyInformation().getKeyInfoMap().put(schema1.getKey(),
- new AxKeyInfo(schema1.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000002"), ""));
-
- return engineModel;
- }
-
- @Override
- public AxEngineModel getWarningModel() {
- final AxEngineModel engineModel = getModel();
-
- final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
- "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
- final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
- "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
-
- engineModel.getKeyInformation().getKeyInfoMap().put(schema0.getKey(),
- new AxKeyInfo(schema0.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000000"), ""));
- engineModel.getKeyInformation().getKeyInfoMap().put(schema1.getKey(),
- new AxKeyInfo(schema1.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000001"), ""));
-
- return engineModel;
- }
-}
diff --git a/model/engine-model/src/test/resources/logback-test.xml b/model/engine-model/src/test/resources/logback-test.xml
deleted file mode 100644
index c52f2ded6..000000000
--- a/model/engine-model/src/test/resources/logback-test.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============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=========================================================
--->
-
-<configuration>
-
- <contextName>Apex</contextName>
- <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
- <property name="LOG_DIR" value="${java.io.tmpdir}/apex_logging/" />
-
- <!-- USE FOR STD OUT ONLY -->
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <encoder>
- <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
- </encoder>
- </appender>
-
- <root level="INFO">
- <appender-ref ref="STDOUT" />
- </root>
-
- <logger name="org.infinispan" level="INFO" additivity="false">
- <appender-ref ref="STDOUT" />
- </logger>
-
- <logger name="org.apache.zookeeper.ClientCnxn" level="OFF" additivity="false">
- <appender-ref ref="STDOUT" />
- </logger>
-
- <appender name="FILE" class="ch.qos.logback.core.FileAppender">
- <file>${LOG_DIR}/apex.log</file>
- <encoder>
- <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level
- %logger{26} - %msg %n %ex{full}</pattern>
- </encoder>
- </appender>
-
- <appender name="CTXT_FILE" class="ch.qos.logback.core.FileAppender">
- <file>${LOG_DIR}/apex_ctxt.log</file>
- <encoder>
- <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level
- %logger{26} - %msg %n %ex{full}</pattern>
- </encoder>
- </appender>
-
- <logger name="org.onap.policy.apex.core.context.impl.monitoring" level="INFO" additivity="false">
- <appender-ref ref="CTXT_FILE" />
- </logger>
-
- <logger name="org.onap.policy.apex.core.context" level="INFO" additivity="false">
- <appender-ref ref="STDOUT" />
- </logger>
-</configuration>