diff options
94 files changed, 8727 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore index 67ad92d6d..a159c8426 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .project .buildpath .idea +.checkstyle *.iml ui-react/node_modules ui-react/build diff --git a/tosca-controlloop/common/src/main/java/org/onap/policy/clamp/controlloop/common/ControlLoopConstants.java b/tosca-controlloop/common/src/main/java/org/onap/policy/clamp/controlloop/common/ControlLoopConstants.java new file mode 100644 index 000000000..aa8b720bc --- /dev/null +++ b/tosca-controlloop/common/src/main/java/org/onap/policy/clamp/controlloop/common/ControlLoopConstants.java @@ -0,0 +1,32 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.common; + +/** + * Names of various items contained in the Registry. + */ +public class ControlLoopConstants { + + // Registry keys + public static final String REG_CLRUNTIME_ACTIVATOR = "object:activator/clruntime"; + + private ControlLoopConstants() { + super(); + } +} diff --git a/tosca-controlloop/common/src/main/java/org/onap/policy/clamp/controlloop/common/exception/ControlLoopException.java b/tosca-controlloop/common/src/main/java/org/onap/policy/clamp/controlloop/common/exception/ControlLoopException.java new file mode 100644 index 000000000..05b913b22 --- /dev/null +++ b/tosca-controlloop/common/src/main/java/org/onap/policy/clamp/controlloop/common/exception/ControlLoopException.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.common.exception; + +import javax.ws.rs.core.Response; +import lombok.Getter; +import lombok.ToString; +import org.onap.policy.models.errors.concepts.ErrorResponse; +import org.onap.policy.models.errors.concepts.ErrorResponseInfo; +import org.onap.policy.models.errors.concepts.ErrorResponseUtils; + +/** + * This class is a base exception from which all control loop exceptions are sub classes. + */ +@Getter +@ToString +public class ControlLoopException extends Exception implements ErrorResponseInfo { + private static final long serialVersionUID = -8507246953751956974L; + + // The error response of the exception + private final ErrorResponse errorResponse = new ErrorResponse(); + + // The object on which the exception was thrown + private final transient Object object; + + /** + * Instantiates a new control loop exception. + * + * @param statusCode the return code for the exception + * @param message the message on the exception + */ + public ControlLoopException(final Response.Status statusCode, final String message) { + this(statusCode, message, null); + } + + /** + * Instantiates a new control loop exception. + * + * @param statusCode the return code for the exception + * @param message the message on the exception + * @param object the object that the exception was thrown on + */ + public ControlLoopException(final Response.Status statusCode, final String message, final Object object) { + super(message); + errorResponse.setResponseCode(statusCode); + ErrorResponseUtils.getExceptionMessages(errorResponse, this); + this.object = object; + } + + /** + * Instantiates a new control loop exception. + * + * @param statusCode the return code for the exception + * @param message the message on the exception + * @param exception the exception that caused this exception + */ + public ControlLoopException(final Response.Status statusCode, final String message, final Exception exception) { + this(statusCode, message, exception, null); + } + + /** + * Instantiates a new exception. + * + * @param statusCode the return code for the exception + * @param message the message on the exception + * @param exception the exception that caused this exception + * @param object the object that the exception was thrown on + */ + public ControlLoopException(final Response.Status statusCode, final String message, final Exception exception, + final Object object) { + super(message, exception); + errorResponse.setResponseCode(statusCode); + ErrorResponseUtils.getExceptionMessages(errorResponse, this); + this.object = object; + } +} diff --git a/tosca-controlloop/common/src/main/java/org/onap/policy/clamp/controlloop/common/exception/ControlLoopRuntimeException.java b/tosca-controlloop/common/src/main/java/org/onap/policy/clamp/controlloop/common/exception/ControlLoopRuntimeException.java new file mode 100644 index 000000000..b110a4362 --- /dev/null +++ b/tosca-controlloop/common/src/main/java/org/onap/policy/clamp/controlloop/common/exception/ControlLoopRuntimeException.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.common.exception; + +import javax.ws.rs.core.Response; +import lombok.Getter; +import lombok.ToString; +import org.onap.policy.models.errors.concepts.ErrorResponse; +import org.onap.policy.models.errors.concepts.ErrorResponseInfo; +import org.onap.policy.models.errors.concepts.ErrorResponseUtils; + +/** + * This class is a base control loop run time exception from which all control loop run time exceptions are sub classes. + */ +@Getter +@ToString +public class ControlLoopRuntimeException extends RuntimeException implements ErrorResponseInfo { + private static final long serialVersionUID = -8507246953751956974L; + + // The error response of the exception + private final ErrorResponse errorResponse = new ErrorResponse(); + + // The object on which the exception was thrown + private final transient Object object; + + /** + * Instantiates a new control loop runtime exception. + * + * @param statusCode the return code for the exception + * @param message the message on the exception + */ + public ControlLoopRuntimeException(final Response.Status statusCode, final String message) { + this(statusCode, message, null); + } + + /** + * Instantiates a new control loop runtime exception. + * + * @param statusCode the return code for the exception + * @param message the message on the exception + * @param object the object that the exception was thrown on + */ + public ControlLoopRuntimeException(final Response.Status statusCode, final String message, final Object object) { + super(message); + this.object = object; + errorResponse.setResponseCode(statusCode); + ErrorResponseUtils.getExceptionMessages(errorResponse, this); + } + + /** + * Instantiates a new control loop runtime exception. + * + * @param statusCode the return code for the exception + * @param message the message on the exception + * @param exception the exception that caused this control loop exception + */ + public ControlLoopRuntimeException(final Response.Status statusCode, final String message, + final Exception exception) { + this(statusCode, message, exception, null); + } + + /** + * Instantiates a new model runtime exception from a ControlLoopException instance. + * + * @param exception the exception that caused this control loop exception + */ + public ControlLoopRuntimeException(final ControlLoopException exception) { + super(exception.getMessage(), exception); + this.object = exception.getObject(); + errorResponse.setResponseCode(exception.getErrorResponse().getResponseCode()); + ErrorResponseUtils.getExceptionMessages(errorResponse, this); + } + + /** + * Instantiates a new control loop runtime exception. + * + * @param statusCode the return code for the exception + * @param message the message on the exception + * @param exception the exception that caused this control loop exception + * @param object the object that the exception was thrown on + */ + public ControlLoopRuntimeException(final Response.Status statusCode, final String message, + final Exception exception, final Object object) { + super(message, exception); + this.object = object; + errorResponse.setResponseCode(statusCode); + ErrorResponseUtils.getExceptionMessages(errorResponse, this); + } +} diff --git a/tosca-controlloop/common/src/main/java/org/onap/policy/clamp/controlloop/common/handler/ControlLoopHandler.java b/tosca-controlloop/common/src/main/java/org/onap/policy/clamp/controlloop/common/handler/ControlLoopHandler.java new file mode 100644 index 000000000..2751f2441 --- /dev/null +++ b/tosca-controlloop/common/src/main/java/org/onap/policy/clamp/controlloop/common/handler/ControlLoopHandler.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.common.handler; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import lombok.Getter; +import lombok.NonNull; +import org.onap.policy.common.endpoints.event.comm.TopicSink; +import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher; +import org.onap.policy.common.utils.services.Registry; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; + +/** + * Abstract class for handlers for sub components in the control loop system + * + * <p>Instances are effectively singletons that are started at system start. + */ +public abstract class ControlLoopHandler { + @Getter + private final PolicyModelsProviderParameters databaseProviderParameters; + + /** + * Create a handler. + * + * @param databaseProviderParameters the parameters for access to the database + */ + protected ControlLoopHandler(@NonNull PolicyModelsProviderParameters databaseProviderParameters) { + this.databaseProviderParameters = databaseProviderParameters; + + Registry.register(this.getClass().getName(), this); + } + + public void close() { + Registry.unregister(this.getClass().getName()); + } + + /** + * Get the provider classes that are used in instantiation. + * + * @return the provider classes + */ + public Set<Class<?>> getProviderClasses() { + // No REST interfaces are the default + return new HashSet<>(); + } + + /** + * Start any topic message listeners for this handler. + * + * @param msgDispatcher the message dispatcher with which to register the listener + */ + public abstract void startAndRegisterListeners(MessageTypeDispatcher msgDispatcher); + + /** + * Start any topic message publishers for this handler. + * + * @param topicSinks the topic sinks on which the publisher can publish + */ + public abstract void startAndRegisterPublishers(List<TopicSink> topicSinks); + + /** + * Stop any topic message publishers for this handler. + */ + public abstract void stopAndUnregisterPublishers(); + + /** + * Stop any topic message listeners for this handler. + * + * @param msgDispatcher the message dispatcher from which to unregister the listener + */ + public abstract void stopAndUnregisterListeners(MessageTypeDispatcher msgDispatcher); +} diff --git a/tosca-controlloop/common/src/main/resources/examples/controlloop/PMSubscriptionHandling.yaml b/tosca-controlloop/common/src/main/resources/examples/controlloop/PMSubscriptionHandling.yaml new file mode 100644 index 000000000..2b2a4ae3e --- /dev/null +++ b/tosca-controlloop/common/src/main/resources/examples/controlloop/PMSubscriptionHandling.yaml @@ -0,0 +1,171 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2021 Nordix Foundation. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +tosca_definitions_version: tosca_simple_yaml_1_3 +data_types: + onap.datatypes.ToscaConceptIdentifier: + derived_from: tosca.datatypes.Root + properties: + name: + type: string + required: true + version: + type: string + required: true +node_types: + org.onap.policy.clamp.controlloop.Participant: + version: 1.0.1 + derived_from: tosca.nodetypes.Root + properties: + provider: + type: string + requred: false + org.onap.policy.clamp.controlloop.ControlLoopElement: + version: 1.0.1 + derived_from: tosca.nodetypes.Root + properties: + provider: + type: string + requred: false + participant_id: + type: onap.datatypes.ToscaConceptIdentifier + requred: true + org.onap.policy.clamp.controlloop.ControlLoop: + version: 1.0.1 + derived_from: tosca.nodetypes.Root + properties: + provider: + type: string + requred: false + elements: + type: list + required: true + entry_schema: + type: onap.datatypes.ToscaConceptIdentifier + org.onap.policy.clamp.controlloop.DCAEMicroserviceControlLoopElement: + version: 1.0.1 + derived_from: org.onap.policy.clamp.controlloop.ControlLoopElement + properties: + dcae_blueprint_id: + type: onap.datatypes.ToscaConceptIdentifier + requred: true + org.onap.policy.clamp.controlloop.PolicyTypeControlLoopElement: + version: 1.0.1 + derived_from: org.onap.policy.clamp.controlloop.ControlLoopElement + properties: + policy_type_id: + type: onap.datatypes.ToscaConceptIdentifier + requred: true + org.onap.policy.clamp.controlloop.CDSControlLoopElement: + version: 1.0.1 + derived_from: org.onap.policy.clamp.controlloop.ControlLoopElement + properties: + cds_blueprint_id: + type: onap.datatypes.ToscaConceptIdentifier + requred: true +topology_template: + node_templates: + org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant: + version: 2.3.4 + type: org.onap.policy.clamp.controlloop.Participant + type_version: 1.0.1 + description: Participant for DCAE microservices + properties: + provider: ONAP + org.onap.policy.controlloop.PolicyControlLoopParticipant: + version: 2.3.1 + type: org.onap.policy.clamp.controlloop.Participant + type_version: 1.0.1 + description: Participant for DCAE microservices + properties: + provider: ONAP + org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant: + version: 2.2.1 + type: org.onap.policy.clamp.controlloop.Participant + type_version: 1.0.1 + description: Participant for DCAE microservices + properties: + provider: ONAP + org.onap.domain.pmsh.PMSH_DCAEMicroservice: + version: 1.2.3 + type: org.onap.policy.clamp.controlloop.DCAEMicroserviceControlLoopElement + type_version: 1.0.0 + description: Control loop element for the DCAE microservice for Performance Management Subscription Handling + properties: + provider: Ericsson + participant_id: + name: org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant + version: 2.3.4 + dcae_blueprint_id: + name: org.onap.dcae.blueprints.PMSHBlueprint + version: 1.0.0 + org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement: + version: 1.2.3 + type: org.onap.policy.clamp.controlloop.PolicyTypeControlLoopElement + type_version: 1.0.0 + description: Control loop element for the monitoring policy for Performance Management Subscription Handling + properties: + provider: Ericsson + participant_id: + name: org.onap.policy.controlloop.PolicyControlLoopParticipant + version: 2.3.1 + policy_type_id: + name: onap.policies.monitoring.pm-subscription-handler + version: 1.0.0 + org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement: + version: 1.2.3 + type: org.onap.policy.clamp.controlloop.PolicyTypeControlLoopElement + type_version: 1.0.0 + description: Control loop element for the operational policy for Performance Management Subscription Handling + properties: + provider: Ericsson + participant_id: + name: org.onap.policy.controlloop.PolicyControlLoopParticipant + version: 2.2.1 + policy_type_id: + name: onap.policies.operational.pm-subscription-handler + version: 1.0.0 + org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement: + version: 1.2.3 + type: org.onap.policy.clamp.controlloop.CDSControlLoopElement + type_version: 1.0.0 + description: Control loop element for CDS for Performance Management Subscription Handling + properties: + provider: Ericsson + participant_Id: + name: org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant + version: 3.2.1 + cds_blueprint_id: + name: org.onap.ccsdk.cds.PMSHCdsBlueprint + version: 1.0.0 + org.onap.domain.pmsh.PMSHControlLoopDefinition: + version: 1.2.3 + type: org.onap.policy.clamp.controlloop.ControlLoop + type_version: 1.0.0 + description: Control loop for Performance Management Subscription Handling + properties: + provider: Ericsson + elements: + - name: org.onap.domain.pmsh.PMSH_DCAEMicroservice + version: 1.2.3 + - name: org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement + version: 1.2.3 + - name: org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement + version: 1.2.3 + - name: org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement + version: 1.2.3
\ No newline at end of file diff --git a/tosca-controlloop/common/src/main/resources/examples/controlloop/PMSubscriptionHandling_GuilinFormat.yaml b/tosca-controlloop/common/src/main/resources/examples/controlloop/PMSubscriptionHandling_GuilinFormat.yaml new file mode 100644 index 000000000..51e369696 --- /dev/null +++ b/tosca-controlloop/common/src/main/resources/examples/controlloop/PMSubscriptionHandling_GuilinFormat.yaml @@ -0,0 +1,455 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2021 Nordix Foundation. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +tosca_definitions_version: tosca_simple_yaml_1_3 +capability_types: + org.onap.EventProducer: + properties: + carrier_protocol_type: + type: string + required: true + constraints: + - valid_values: + - DMAAP_message_router + - SOMETHING_ELSE + - REST + data_format: + type: string + required: true + constraints: + - valid_values: + - JSON + - YAML + - JMS + event_format: + type: string + required: true + event_format_version: + type: string + required: false + config_keys: + type: list + required: false + entry_schema: + type: string + constraints: + - valid_values: + - all valid values should be added here + - if not specified, events of any config key may be generated + - 'examples for config_key: ves-measurement, ves-syslog, tca_handle_out, + etc.' + version: 0.0.1 + derived_from: tosca.capabilities.Root + org.onap.EventConsumer: + properties: + responding_capability: + type: string + required: false + carrier_protocol_type: + type: string + required: true + constraints: + - valid_values: + - DMAAP_message_router + - SOMETHING_ELSE + - REST + data_format: + type: string + required: true + constraints: + - valid_values: + - JSON + - YAML + - JMS + - all valid values should be added here + event_format: + type: string + description: 'examples for event_format: Ves_specification, LinkUp, VnfConfigured, + etc.' + required: true + event_format_version: + type: string + description: 'examples for event_format_version: 5.28.4, 7.30.1, etc.' + required: false + config_keys: + type: list + required: false + entry_schema: + type: string + constraints: + - valid_values: + - all valid values should be added here + - if not specified, events of any config key may be generated + - 'examples for config_key: ves-measurement, ves-syslog, tca_handle_out, + etc.' + version: 0.0.1 + derived_from: tosca.capabilities.Root +node_types: + org.onap.DynamicConfig: + properties: + application_name: + type: string + description: Value used to tie the config to an application ? should we be + using a relationship here instead? + required: true + application_version: + type: string + required: true + application_provider: + type: string + required: false + data_types: + type: object + required: false + schema: + type: object + required: false + version: 0.0.1 + derived_from: tosca.nodes.Root + org.onap.APP: + properties: + application_name: + type: string + description: Human readable name for the application Product + required: false + provider: + type: string + description: Provider of the application and of the descriptor + required: true + application_version: + type: string + description: Software version of the application + required: true + blueprint_id: + type: string + description: A reference to the app blueprint + required: false + monitoring_policy: + type: string + description: A reference to the monitoring policy + required: false + requirements: + - receive: + capability: org.onap.EventProducer + relationship: org.onap.PropagateEvent + occurrences: + - 0 + - UNBOUNDED + - send: + capability: org.onap.EventConsumer + relationship: org.onap.PropagateEvent + occurrences: + - 0 + - UNBOUNDED + version: 0.0.1 + derived_from: tosca.nodes.Root + org.onap.EventRelay: + properties: + event_format: + type: string + description: 'examples for event_format: Ves_specification, etc.' + required: true + event_format_version: + type: string + description: 'examples for event_format_version: 5.28.4, 7.30.1, etc.' + required: true + config_keys: + type: list + required: false + entry_schema: + type: string + constraints: + - valid_values: + - all valid values should be added here + - if not specified, events of any config key is relayed + - 'examples for config_key: ves-measurement, ves-syslog, tca_handle_out, + etc.' + supported_carrier_protocols: + type: map + description: 'A map describing supported carrier protocols and translations. + The tuples define what protocol combinations are supported on the producer + and consumer side: e.g. { REST: REST, DMAAP: REST, DMAAP: DMAAP}' + required: true + key_schema: + type: string + constraints: + - valid_values: + - DMAAP_message_router + - SOMETHING_ELSE + - REST + - all valid values should be added here + entry_schema: + type: string + constraints: + - valid_values: + - DMAAP_message_router + - SOMETHING_ELSE + - REST + - all valid values should be added here + supported_data_formats: + type: map + description: 'Is a map describing supported data formats and translation. + The tuples define what protocol combinations are supported on the producer + and consumer side: e.g. { JSON: JSON, JMS: JSON, YAML:YAML }' + required: true + key_schema: + type: string + constraints: + - valid_values: + - JSON + - JMS + - YAML + - etc + - all valid values should be added here + entry_schema: + type: string + constraints: + - valid_values: + - JSON + - JMS + - YAML + - etc + - all valid values should be added here + requirements: + - receive: + capability: org.onap.EventProducer + relationship: org.onap.PropagateEvent + occurrences: + - 0 + - UNBOUNDED + - send: + capability: org.onap.EventConsumer + relationship: org.onap.PropagateEvent + occurrences: + - 0 + - UNBOUNDED + version: 0.0.1 + derived_from: tosca.nodes.Root +relationship_types: + org.onap.PropagateEvent: + properties: + config_keys: + type: list + description: The relationship type used on requirements to org.onap.EventProducer + and org.onap.EventConsumer capabilities. Filters events by specific config_keys + to be transferred by this relationship. That is, any event with a specific + config_key found in the list is transferred. If list is not defined or is + empty, events with all config_keys are transferred. + required: false + entry_schema: + type: string + version: 0.0.1 + derived_from: tosca.relationships.Root +topology_template: + inputs: + pm_subscription_topic: + type: string + pm_subscription_response_topic: + type: string + pm_subscription_handler_blueprint_id: + type: string + pm_subscription_operational_policy_id: + type: string + pm_subscription_cds_blueprint_id: + type: string + enable_tls: + type: string + node_templates: + org.onap.PM_Subscription_Handler: + type: org.onap.polcy.clamp.ControlLoopElement + properties: + application_name: PM Subscription Handler + provider: Ericsson + application_version: 1.0.0 + artifact_id: + get_input: pm_subscription_handler_blueprint_id + description: Is this a reference to the DCAE Cloudify Blueprint that is + already stored(or will be stored before CL configuration & instatiation) + in DCAE Inventory? + artifact_config: + enable_tls: + get_input: enable_tls + pmsh_publish_topic_name: + get_input: pm_subscription_topic + capabilities: + pm-subscription-event-publisher: + properties: + carrier_protocol_type: DMAAP_message_router + data_format: JSON + event_format: pm-subscription-event-format + event_format_version: 1.0.0 + attributes: + type: org.onap.EventProducer + occurrences: + - 0 + - UNBOUNDED + pm-subscription-event-receiver: + properties: + carrier_protocol_type: DMAAP_message_router + data_format: JSON + event_format: pm-subscription-event-response-format + event_format_version: 1.0.0 + relationships: + - type: tosca.relationships.DependsOn + - description: any ideas on a better realtionship ? or is it better to + just use the root realtionship ? + - target: org.onap.PM_Monitoring_Policy + attributes: + type: org.onap.EventConsumer + occurrences: + - 0 + - UNBOUNDED + org.onap.PM_Monitoring_Policy: + type: org.onap.DynamicConfig + properties: + application_name: PM Subscription Handler + application_version: 1.0.0 + provider: Ericsson + data_types: + measurementType: + type: string + DN: + type: string + nfFilter: + properties: + nfNames: + type: list + entry_schema: string + modelInvariantIDs: + type: list + entry_schema: + type: string + modelVersionIDs: + type: list + entry_schema: + type: string + measurementGroup: + properties: + masurementTypes: + type: list + entry_schema: + type: measurementType + managedObjectDNsBasic: + type: list + entry_schema: + type: DN + schema: + subscription: + subscriptionName: + type: string + required: true + administrativeState: + type: string + required: true + filebasedGP: + type: integer + required: true + fileLocation: + type: string + required: true + nfFilter: + type: nfFilter + measurementGroups: + type: list + entry_schema: + type: measurementGroup + description: Should I be showing a dependency between PM Subscription Handler + and the PM Monitoring Policy + org.onap.PM_Policy: + type: org.onap.APP + properties: + application_name: PM Subscription Operational Policy + provider: Ericsson + application_version: 1.0.0 + artifact_id: + get_input: pm_subscription_operational_policy_id + artifact_config: NOT_DEFINED + requirements: + - receive_0: + capability: pm-subscription-event-publisher + node: org.onap.PM_Subscription_Handler + relationship: NOT_DEFINED + properties: + config_keys: + - topic_name: + get_input: pm_subscription_topic + - send_0: + capability: cds-rest-receive + node: org.onap.CDS + - receive_1: + capability: cds-rest-response + node: org.onap.CDS + - send_1: + capability: pm-subscription-event-receiver + node: org.onap.PM_Subscription_Handler + relationship: NOT_DEFINED + properties: + config_keys: + - topic_name: + get_input: pm_subscription_response_topic + capabilities: + pm-subscription-response-event-publisher: + properties: + type: org.onap.EventProducer + carrier_protocol_type: DMAAP_message_router + data_format: JSON + event_format: pm-subscription-event-response-format + event_format_version: 1.0.0 + occurrences: + - 0 + - UNBOUNDED + org.onap.PM_CDS_Blueprint: + type: org.onap.APP + properties: + application_name: PM Subscription CDS Blueprint + provider: Ericsson + application_version: 1.0.0 + artifact_id: + get_input: pm_subscription_cds_blueprint_id + capabilities: + cds-rest-receive: + properties: + type: org.onap.EventConsumer + protocol_type: REST + data_format: JSON + event_format: cds_action_format + event_format_version: 1.0.0 + responding_capability: cds-rest-response + occurrences: + - 0 + - UNBOUNDED + cds-rest-response: + properties: + type: org.onap.EventProducer + protocol_type: REST + data_format: JSON + event_format: cds_action_response_format + event_format_version: 1.0.0 + occurrences: + - 0 + org.onap.controlloop0: + version: 1.2.3 + type: org.onap.policy.clamp.ControlLoop + properties: + application_name: Test Control Loop + provider: Ericsson + application_version: 1.0.0 + status: NOT_DEPLOYED + elements: + element1: org.onap.PM_Monitoring_Policy + diff --git a/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_DCAE_VES_TCA_substitution.yaml b/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_DCAE_VES_TCA_substitution.yaml new file mode 100644 index 000000000..96ea133c2 --- /dev/null +++ b/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_DCAE_VES_TCA_substitution.yaml @@ -0,0 +1,83 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2021 Nordix Foundation. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +tosca_definitions_version: tosca_simple_yaml_1_3 + +imports: + - cloop_base_types.yaml + - cloop_dcae_types.yaml + +topology_template: + inputs: + some_property_input: + type: string + + substitution_mappings: + node_type: org.onap.DCAE_VES_TCA + properties: + some_property: { get_input: some_property_input } + capabilities: + VES-5.28.4-publisher: [ node1_VES_Collector, VES-5.28.4-publisher ] + VES-7.30.1-publisher: [ node1_VES_Collector, VES-7.30.1-publisher ] + TCA-handle-out-publisher: [ node2_TCA_GEN_2, TCA-handle-out-publisher ] + VES_specification-subscriber: [ node2_TCA_GEN_2, VES_specification-subscriber ] + + node_templates: + ################################################################################ + #alt1: without relay + + node1_VES_Collector: + type: org.onap.VESCollector + + node2_TCA_GEN_2: + type: org.onap.TCA_GEN_2 + requirements: + - receive: + capability: VES-5.28.4-publisher + node: node1_VES_Collector + relationship: + type: org.onap.PropagateEvent + properties: + config-keys: [ ves-measurement ] + + + ################################################################################ + #alt2: with relay + + node1_VES_Collector: + type: org.onap.VESCollector + + node2_TCA_GEN_2: + type: org.onap.TCA_GEN_2 + + node3_Relay: + type: org.onap.EventRelay + properties: + event_format: "VES_specification" + event_format_version: "5.28.4" + supported_carrier_protocols: [{ DMAAP_message_router: DMAAP_message_router }] + supported_data_formats: [{ JSON: JSON }] + requirements: + - receive: + node: node1_VES_Collector + properties: + config_keys: [ ves-measurement ] + - send: + node: node2_TCA_GEN_2 + properties: + config_keys: [ ves-measurement ] diff --git a/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_base_types.yaml b/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_base_types.yaml new file mode 100644 index 000000000..4f29e5635 --- /dev/null +++ b/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_base_types.yaml @@ -0,0 +1,210 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2021 Nordix Foundation. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +tosca_definitions_version: tosca_simple_yaml_1_2 + +capability_types: + #producer capability type + org.onap.EventProducer: + derived_from: tosca.capabilities.Root + properties: + carrier_protocol_type: + type: string + required: true + constraints: + valid_values: [ DMAAP_message_router, REST ] + #all valid values should be added here + data_format: + type: string + required: true + constraints: + valid_values: [ JSON, YAML, JMS ] + #all valid values should be added here + event_format: + type: string + required: true + #examples for event_format: Ves_specification, etc. + event_format_version: + type: string + #examples for event_format_version: 5.28.4, 7.30.1, etc. + config_keys: + type: list + required: false + entry_schema: + type: string + constraints: + #valid_values: [ ] + #all valid values should be added here + #if not specified, events of any config key may be generated + #examples for config_key: ves-measurement, ves-syslog, tca_handle_out, etc. + + + #consumer capability type + org.onap.EventConsumer: + derived_from: tosca.capabilities.Root + properties: + carrier_protocol_type: + type: string + required: true + constraints: + valid_values: [ DMAAP_message_router, REST ] + #all valid values should be added here + data_format: + type: string + required: true + constraints: + valid_values: [ JSON, YAML, JMS ] + #all valid values should be added here + event_format: + type: string + required: true + #examples for event_format: Ves_specification, LinkUp, VnfConfigured, etc. + event_format_version: + type: string + #examples for event_format_version: 5.28.4, 7.30.1, etc. + config_keys: + type: list + required: false + entry_schema: + type: string + constraints: + #valid_values: [ ] + #all valid values should be added here + #if not specified, events of any config key may be generated + #examples for config_key: ves-measurement, ves-syslog, tca_handle_out, etc. + + +relationship_types: + #the relationship type used on requirements to org.onap.EventProducer and org.onap.EventConsumer capabilities + org.onap.PropagateEvent: + derived_from: tosca.relationships.Root + properties: + config_keys: + type: list + required: false + description: > + Filters events by specific config_keys to be transferred by this relationship. + That is, any event with a specific config_key found in the list is transferred. + If list is not defined or is empty, events with all config_keys are transferred. + entry_schema: string + + + +node_types: + #base app node type + org.onap.APP: + derived_from: tosca.nodes.Root + properties: + application_name: + type: string + description: Human readable name for the application Product + required: false + provider: + type: string + description: Provider of the application and of the descriptor + required: true + application_version: + type: string + description: Software version of the application + required: true + blueprint_id: + type: string + description: A reference to the app blueprint + monitoring_policy: + type: string + required: false + description: A reference to the monitoring policy + requirements: + - receive: + capability: org.onap.EventProducer + relationship: org.onap.PropagateEvent + occurrences: [0, UNBOUNDED] + - send: + capability: org.onap.EventConsumer + relationship: org.onap.PropagateEvent + occurrences: [0, UNBOUNDED] + + #the event relay node type + org.onap.EventRelay: + derived_from: tosca.nodes.Root + properties: + event_format: + type: string + required: true + #examples for event_format: Ves_specification, etc. + event_format_version: + type: string + required: true + #examples for event_format_version: 5.28.4, 7.30.1, etc. + config_keys: + type: list + required: false + entry_schema: + type: string + constraints: + #valid_values: [ ] + #all valid values should be added here + #if not specified, events of any config key is relayed + #examples for config_key: ves-measurement, ves-syslog, tca_handle_out, etc. + supported_carrier_protocols: + type: map + required: true + description: > + A map describing supported carrier protocols and translations. The + tuples define what protocol combinations are supported on the producer + and consumer side: e.g. { REST: REST, DMAAP: REST, DMAAP: DMAAP} + key_schema: + type: string + constraints: + valid_values: [ DMAAP_message_router, REST ] + #all valid values should be added here + entry_schema: + type: string + constraints: + valid_values: [ DMAAP_message_router, REST ] + #all valid values should be added here + supported_data_formats: + type: map + required: true + description: > + Is a map describing supported data formats and translation. The tuples + define what protocol combinations are supported on the producer and + consumer side: e.g. { JSON: JSON, JMS: JSON, YAML:YAML } + key_schema: + type: string + constraints: + valid_values: [ JSON, JMS, YAML, etc ] + #all valid values should be added here + entry_schema: + type: string + constraints: + valid_values: [ JSON, JMS, YAML, etc ] + #all valid values should be added here + requirements: + - receive: + capability: org.onap.EventProducer + relationship: org.onap.PropagateEvent + occurrences: [1, UNBOUNDED] + - send: + capability: org.onap.EventConsumer + relationship: org.onap.PropagateEvent + occurrences: [1, UNBOUNDED] + + + + diff --git a/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_dcae_example.yaml b/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_dcae_example.yaml new file mode 100644 index 000000000..4629f6f75 --- /dev/null +++ b/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_dcae_example.yaml @@ -0,0 +1,50 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2021 Nordix Foundation. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +tosca_definitions_version: tosca_simple_yaml_1_3 + +imports: + - cloop_base_types.yaml + - cloop_dcae_types.yaml + - cloop_other_types.yaml + +topology_template: + node_templates: + + node1_DCAE_VES_TCA: + type: org.onap.DCAE_VES_TCA + directives: + - substitute + + node2_PolicyFramework: + type: org.onap.ApexPolicyFramework + requirements: + - receive: + capability: TCA-handle-out-publisher + node: node1_DCAE_VES_TCA + relationship: + properties: + config_keys: [ ves-measurement ] + - send: + capability: SelfService + node: org.onap.CDS + relationship: + properties: + config_keys: [ ves-measurement ] + + #if this closed loop to subscribe to other events via the VesCollector, should we not add that? diff --git a/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_dcae_types.yaml b/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_dcae_types.yaml new file mode 100644 index 000000000..5f96cd5df --- /dev/null +++ b/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_dcae_types.yaml @@ -0,0 +1,140 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2021 Nordix Foundation. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +tosca_definitions_version: tosca_simple_yaml_1_3 + +imports: + - cloop_types.yaml + +node_types: + + #node type for VES_Collector + org.onap.VES_Collector: + derived_from: org.onap.APP + capabilities: + VES-5.28.4-publisher: + type: org.onap.EventProducer + occurrences: [ 0, UNBOUNDED ] + properties: + carrier_protocol_type: "DMAAP_message_router" + data_format: "JSON" + event_format: "VES_specification" + event_format_version: "5.28.4" + config_keys: + - "ves-fault" + - "ves-measurement" + - "ves-syslog" + - "ves-heartbeat" + - "ves-other" + - "ves-mobileflow" + - "ves-statechange" + - "ves-thresholdCrossingAlert" + - "ves-voicequality" + - "ves-sipsignaling" + VES-7.30.1-publisher: + type: org.onap.EventProducer + occurrences: [ 0, UNBOUNDED ] + properties: + carrier_protocol_type: "DMAAP_message_router" + data_format: "JSON" + event_format: "VES_specification" + event_format_version: "7.30.1" + config_keys: + - "ves-fault" + - "ves-pnfRegistration" + - "ves-notification" + - "ves-perf3gpp" + + #node type for TCA_GEN_2 + org.onap.TCA_GEN_2: + derived_from: org.onap.APP + capabilities: + TCA-handle-out-publisher: + type: org.onap.EventProducer + occurrences: [ 0, UNBOUNDED ] + properties: + carrier_protocol_type: "DMAAP_message_router" + data_format: "JSON" + event_format: "DCAE_CL_Output" + event_format_version: "1.0.1" + config_keys: [ "tca_handle_out" ] + VES_specification-subscriber: + type: org.onap.EventConsumer + occurrences: [ 0, UNBOUNDED ] + properties: + carrier_protocol_type: "DMAAP_message_router" + data_format: "JSON" + event_format: "VES_specification" + event_format_version: "5.28.4" + config_keys: [ "tca_handle_in" ] + + + + #node type for the composed VES_Collector and TCA_GEN_2 + org.onap.DCAE_VES_TCA: + derived_from: org.onap.APP + capabilities: + VES-5.28.4-publisher: + type: org.onap.EventProducer + occurrences: [ 0, UNBOUNDED ] + properties: + carrier_protocol_type: "DMAAP_message_router" + data_format: "JSON" + event_format: "VES_specification" + event_format_version: "5.28.4" + config_keys: + - "ves-fault" + - "ves-measurement" + - "ves-syslog" + - "ves-heartbeat" + - "ves-other" + - "ves-mobileflow" + - "ves-statechange" + - "ves-thresholdCrossingAlert" + - "ves-voicequality" + - "ves-sipsignaling" + VES-7.30.1-publisher: + type: org.onap.EventProducer + occurrences: [ 0, UNBOUNDED ] + properties: + carrier_protocol_type: "DMAAP_message_router" + data_format: "JSON" + event_format: "VES_specification" + event_format_version: "7.30.1" + config_keys: + - "ves-pnfRegistration" + - "ves-notification" + - "ves-perf3gpp" + TCA-handle-out-publisher: + type: org.onap.EventProducer + occurrences: [ 0, UNBOUNDED ] + properties: + carrier_protocol_type: "DMAAP_message_router" + data_format: "JSON" + event_format: "DCAE_CL_Output" + event_format_version: "1.0.1" + config_keys: [ "tca_handle_out" ] + VES_specification-subscriber: + type: org.onap.EventConsumer + occurrences: [ 0, UNBOUNDED ] + properties: + carrier_protocol_type: "DMAAP_message_router" + data_format: "JSON" + event_format: "VES_specification" + event_format_version: "5.28.4" + config_keys: [ "tca_handle_in" ] diff --git a/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_other_types.yaml b/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_other_types.yaml new file mode 100644 index 000000000..d743f499f --- /dev/null +++ b/tosca-controlloop/common/src/main/resources/examples/controlloop/original/cloop_other_types.yaml @@ -0,0 +1,63 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2021 Nordix Foundation. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +tosca_definitions_version: tosca_simple_yaml_1_2 + +imports: + - cloop_base_types.yaml + +node_types: + #node type for Policy + org.onap.PolicyFramework: + derived_from: org.onap.APP + + #node type for Apex Policy + org.onap.ApexPolicyFramework: + derived_from: org.onap.PolicyFramework + + #node type for CDS + org.onap.CDS: + derived_from: org.onap.APP + capabilities: + #consumer capability for CDS for events of type ResourceAndTemplate management API + ResourceAndTemplateManagement: + type: org.onap.EventConsumer + properties: + carrier_protocol_type: "DMAAP_message_router" + data_format: "JSON" + event_format: "ResourceAndTemplate" + event_format_version: "x.xx.x" + occurrences: [ 0, UNBOUNDED ] + #consumer capability for CDS for events of type SelfService API + SelfService: + type: org.onap.EventConsumer + properties: + carrier_protocol_type: "DMAAP_message_router" + data_format: "JSON" + event_format: "SelfService" + event_format_version: "x.xx.x" + occurrences: [ 0, UNBOUNDED ] + #producer capability for CDS for events of type PNFControl + PNFcontrolEventsProducer: + type: org.onap.EventProducer + properties: + carrier_protocol_type: "DMAAP_message_router" + data_format: "JSON" + event_format: "PNFcontrol" + event_format_version: "x.xx.x" + occurrences: [ 0, UNBOUNDED ] diff --git a/tosca-controlloop/common/src/test/java/org/onap/policy/clamp/controlloop/common/exception/ExceptionsTest.java b/tosca-controlloop/common/src/test/java/org/onap/policy/clamp/controlloop/common/exception/ExceptionsTest.java new file mode 100644 index 000000000..3c1688582 --- /dev/null +++ b/tosca-controlloop/common/src/test/java/org/onap/policy/clamp/controlloop/common/exception/ExceptionsTest.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.common.exception; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import org.junit.Test; +import org.onap.policy.models.errors.concepts.ErrorResponse; + +public class ExceptionsTest { + + private static final String STRING_TEXT = "String"; + private static final String MESSAGE = "Message"; + + @Test + public void testExceptions() { + assertNotNull(new ControlLoopException(Response.Status.OK, MESSAGE)); + assertNotNull(new ControlLoopException(Response.Status.OK, MESSAGE, STRING_TEXT)); + assertNotNull(new ControlLoopException(Response.Status.OK, MESSAGE, new IOException())); + assertNotNull(new ControlLoopException(Response.Status.OK, MESSAGE, new IOException(), STRING_TEXT)); + + String key = "A String"; + ControlLoopException ae = + new ControlLoopException(Response.Status.OK, MESSAGE, new IOException("IO exception message"), key); + ErrorResponse errorResponse = ae.getErrorResponse(); + assertEquals("Message\nIO exception message", String.join("\n", errorResponse.getErrorDetails())); + assertEquals(key, ae.getObject()); + + assertNotNull(new ControlLoopRuntimeException(Response.Status.OK, MESSAGE)); + assertNotNull(new ControlLoopRuntimeException(Response.Status.OK, MESSAGE, STRING_TEXT)); + assertNotNull(new ControlLoopRuntimeException(Response.Status.OK, MESSAGE, new IOException())); + assertNotNull(new ControlLoopRuntimeException(Response.Status.OK, MESSAGE, new IOException(), STRING_TEXT)); + + String rkey = "A String"; + ControlLoopRuntimeException re = new ControlLoopRuntimeException(Response.Status.OK, "Runtime Message", + new IOException("IO runtime exception message"), rkey); + errorResponse = re.getErrorResponse(); + assertEquals("Runtime Message\nIO runtime exception message", + String.join("\n", errorResponse.getErrorDetails())); + assertEquals(key, re.getObject()); + + ControlLoopRuntimeException clre = new ControlLoopRuntimeException(ae); + assertEquals(ae.getErrorResponse().getResponseCode(), clre.getErrorResponse().getResponseCode()); + assertEquals(ae.getMessage(), clre.getMessage()); + + try { + try { + throw new ControlLoopException(Status.BAD_GATEWAY, "An Exception"); + } catch (ControlLoopException cle) { + throw new ControlLoopRuntimeException(cle); + } + } catch (ControlLoopRuntimeException clred) { + assertEquals(Status.BAD_GATEWAY, clred.getErrorResponse().getResponseCode()); + assertEquals("An Exception", clred.getMessage()); + assertEquals(ControlLoopException.class.getName(), clred.getCause().getClass().getName()); + } + + assertThat(ae.toString()).contains("A String"); + assertThat(re.toString()).contains("A String"); + } +} diff --git a/tosca-controlloop/common/src/test/java/org/onap/policy/clamp/controlloop/common/handler/ControlLoopHandlerTest.java b/tosca-controlloop/common/src/test/java/org/onap/policy/clamp/controlloop/common/handler/ControlLoopHandlerTest.java new file mode 100644 index 000000000..845bc8df0 --- /dev/null +++ b/tosca-controlloop/common/src/test/java/org/onap/policy/clamp/controlloop/common/handler/ControlLoopHandlerTest.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.common.handler; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.common.utils.services.Registry; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; + +public class ControlLoopHandlerTest { + + @Test + public void testControlLoopHandler() { + assertThatThrownBy(() -> new DummyControlLoopHandler(null)).isInstanceOf(NullPointerException.class); + + assertNotNull(new DummyControlLoopHandler(new PolicyModelsProviderParameters())); + Registry.unregister(DummyControlLoopHandler.class.getName()); + + String dummyClassName = DummyControlLoopHandler.class.getName(); + assertThatThrownBy(() -> Registry.get(dummyClassName)).isInstanceOf(IllegalArgumentException.class); + + PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters(); + + DummyControlLoopHandler dclh = new DummyControlLoopHandler(pars); + assertNotNull(dclh); + + assertEquals(pars, dclh.getDatabaseProviderParameters()); + assertEquals(0, dclh.getProviderClasses().size()); + + dclh.close(); + assertThatThrownBy(() -> Registry.get(dummyClassName)).isInstanceOf(IllegalArgumentException.class); + } +} diff --git a/tosca-controlloop/common/src/test/java/org/onap/policy/clamp/controlloop/common/handler/DummyControlLoopHandler.java b/tosca-controlloop/common/src/test/java/org/onap/policy/clamp/controlloop/common/handler/DummyControlLoopHandler.java new file mode 100644 index 000000000..fb26333b4 --- /dev/null +++ b/tosca-controlloop/common/src/test/java/org/onap/policy/clamp/controlloop/common/handler/DummyControlLoopHandler.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.common.handler; + +import java.util.List; +import org.onap.policy.common.endpoints.event.comm.TopicSink; +import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; + +public class DummyControlLoopHandler extends ControlLoopHandler { + + public DummyControlLoopHandler(PolicyModelsProviderParameters databaseProviderParameters) { + super(databaseProviderParameters); + } + + @Override + public void startAndRegisterListeners(MessageTypeDispatcher msgDispatcher) { + // Do nothing on this dummy class + } + + @Override + public void startAndRegisterPublishers(List<TopicSink> topicSinks) { + // Do nothing on this dummy class + } + + @Override + public void stopAndUnregisterPublishers() { + // Do nothing on this dummy class + } + + @Override + public void stopAndUnregisterListeners(MessageTypeDispatcher msgDispatcher) { + // Do nothing on this dummy class + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatistics.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatistics.java new file mode 100644 index 000000000..1e264ef99 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatistics.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.concepts; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.ToString; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +@NoArgsConstructor +@Data +@ToString +public class ClElementStatistics implements Serializable { + + private static final long serialVersionUID = 3284285693112271055L; + + @NonNull + private ToscaConceptIdentifier controlLoopElementId; + + @NonNull + private Date timeStamp; + + @NonNull + private ControlLoopState controlLoopState; + + private long clElementUptime; + +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsList.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsList.java new file mode 100644 index 000000000..166f1e48f --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsList.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.concepts; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +public class ClElementStatisticsList { + private List<ClElementStatistics> clElementStatistics; +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java new file mode 100644 index 000000000..417e02a5a --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java @@ -0,0 +1,110 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.concepts; + +import java.util.List; +import java.util.UUID; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import org.apache.commons.collections4.CollectionUtils; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; + +/** + * Class to represent a control loop instance. + */ +@NoArgsConstructor +@Data +@EqualsAndHashCode(callSuper = true) +public class ControlLoop extends ToscaEntity implements Comparable<ControlLoop> { + @NonNull + private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_NAME); + + @NonNull + private ControlLoopState state = ControlLoopState.UNINITIALISED; + + @NonNull + private ControlLoopOrderedState orderedState = ControlLoopOrderedState.UNINITIALISED; + + private List<ControlLoopElement> elements; + + @Override + public String getType() { + return definition.getName(); + } + + @Override + public String getTypeVersion() { + return definition.getVersion(); + } + + /** + * Copy contructor, does a deep copy. + * + * @param otherControlLoop the other element to copy from + */ + public ControlLoop(final ControlLoop otherControlLoop) { + super(otherControlLoop); + this.definition = new ToscaConceptIdentifier(otherControlLoop.definition); + this.state = otherControlLoop.state; + this.orderedState = otherControlLoop.orderedState; + this.elements = PfUtils.mapList(otherControlLoop.elements, ControlLoopElement::new); + } + + @Override + public int compareTo(final ControlLoop other) { + return compareNameVersion(this, other); + } + + /** + * Set the ordered state on the control loop and on all its control loop elements. + * + * @param orderedState the state we want the control loop to transition to + */ + public void setCascadedOrderedState(final ControlLoopOrderedState orderedState) { + this.orderedState = orderedState; + + if (CollectionUtils.isEmpty(elements)) { + return; + } + + elements.forEach(element -> element.setOrderedState(orderedState)); + } + + /** + * Find the element with a given UUID for the control loop. + * + * @param id the UUID to search for + * @return the element or null if its not found + */ + + public ControlLoopElement getElement(final UUID id) { + if (CollectionUtils.isEmpty(elements)) { + return null; + } + + return elements.stream().filter(element -> id.equals(element.getId())).findAny().orElse(null); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java new file mode 100644 index 000000000..a8d317c2b --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.concepts; + +import java.util.UUID; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.ToString; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent a control loop instance. + */ +@NoArgsConstructor +@Data +@ToString +public class ControlLoopElement { + @NonNull + private UUID id = UUID.randomUUID(); + + @NonNull + private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_NAME); + + @NonNull + private ToscaConceptIdentifier participantId = new ToscaConceptIdentifier(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_NAME); + + @NonNull + private ControlLoopState state = ControlLoopState.UNINITIALISED; + + @NonNull + private ControlLoopOrderedState orderedState = ControlLoopOrderedState.UNINITIALISED; + + private String description; + + /** + * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. + * + * @param otherElement the other element to copy from + */ + public ControlLoopElement(final ControlLoopElement otherElement) { + this.id = otherElement.id; + this.definition = new ToscaConceptIdentifier(otherElement.definition); + this.participantId = new ToscaConceptIdentifier(otherElement.participantId); + this.state = otherElement.state; + this.orderedState = otherElement.orderedState; + this.description = otherElement.description; + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopOrderedState.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopOrderedState.java new file mode 100644 index 000000000..91f90275e --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopOrderedState.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.concepts; + +public enum ControlLoopOrderedState { + /** + * The control loop or control loop element should become uninitialised on participants, it should not exist on + * participants. + */ + UNINITIALISED, + /** + * The control loop or control loop element should initialised on the participants and be passive, that is, it is + * not handling control loop messages yet. + */ + PASSIVE, + /** The control loop or control loop element should running and is executing control loops. */ + RUNNING; + + public boolean equalsControlLoopState(final ControlLoopState controlLoopState) { + return this.name().equals(controlLoopState.name()); + } + + public ControlLoopState asState() { + return ControlLoopState.valueOf(this.name()); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopState.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopState.java new file mode 100644 index 000000000..ff0d553af --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopState.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.concepts; + +public enum ControlLoopState { + /** + * The control loop or control loop element is not initialised on participants, it does not exist on participants. + */ + UNINITIALISED, + /** + * The control loop or control loop element is changing from unitialised to passive, it is being initialised onto + * participants. + */ + UNINITIALISED2PASSIVE, + /** + * The control loop or control loop element is initialised on the participants but is passive, that is, it is not + * handling control loop messages yet. + */ + PASSIVE, + /** + * The control loop or control loop element is changing from passive to running, the participants are preparing to + * execute control loops. + */ + PASSIVE2RUNNING, + /** The control loop or control loop element is running and is executing control loops. */ + RUNNING, + /** + * The control loop or control loop element is completing execution of current control loops but will not start + * running any more control loops and will become passive. + */ + RUNNING2PASSIVE, + /** + * The control loop or control loop element is changing from passive to unitialised, the control loop is being + * removed from participants. + */ + PASSIVE2UNINITIALISED; + + public boolean equalsControlLoopOrderedState(final ControlLoopOrderedState controlLoopOrderedState) { + return this.name().equals(controlLoopOrderedState.name()); + } + + public ControlLoopOrderedState asOrderedState() { + return ControlLoopOrderedState.valueOf(this.name()); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoops.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoops.java new file mode 100644 index 000000000..7fb6a1ad2 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoops.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.concepts; + +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class ControlLoops { + private List<ControlLoop> controlLoopList; +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/Participant.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/Participant.java new file mode 100644 index 000000000..43ad49b7c --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/Participant.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.concepts; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; + +/** + * Class to represent details of a running participant instance. + */ +@NoArgsConstructor +@Data +@EqualsAndHashCode(callSuper = true) +public class Participant extends ToscaEntity implements Comparable<Participant> { + @NonNull + private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_NAME); + + @NonNull + private ParticipantState participantState = ParticipantState.UNKNOWN; + + @NonNull + private ParticipantHealthStatus healthStatus = ParticipantHealthStatus.UNKNOWN; + + @Override + public String getType() { + return definition.getName(); + } + + @Override + public String getTypeVersion() { + return definition.getVersion(); + } + + @Override + public int compareTo(final Participant other) { + return compareNameVersion(this, other); + } + + /** + * Copy constructor. + * + * @param otherParticipant the participant to copy from + */ + public Participant(Participant otherParticipant) { + super(otherParticipant); + this.definition = new ToscaConceptIdentifier(otherParticipant.definition); + this.participantState = otherParticipant.participantState; + this.healthStatus = otherParticipant.healthStatus; + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantHealthStatus.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantHealthStatus.java new file mode 100644 index 000000000..0cf41c9cd --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantHealthStatus.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.concepts; + +/** + * Class to hold the possible values for health status of Participant. + */ +public enum ParticipantHealthStatus { + + /** + * Participant is healthy and working fine. + */ + HEALTHY, + + /** + * Participant is not healthy. + */ + NOT_HEALTHY, + + /** + * Participant is currently under test state and performing tests. + */ + TEST_IN_PROGRESS, + + /** + * The health status of the Participant is unknown. + */ + UNKNOWN +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantState.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantState.java new file mode 100644 index 000000000..1af32660d --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantState.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.concepts; + +/** + * Class to hold the possible values for mode of participant. + */ +public enum ParticipantState { + + /** + * Control Loop execution is unknown. + */ + UNKNOWN, + + /** + * Control Loop execution is always rejected. + */ + PASSIVE, + + /** + * Control Loop execution execution proceeds, but changes to domain state or context are not carried out. The + * participant returns an indication that it is running in SAFE mode together with the action it would have + * performed if it was operating in ACTIVE mode. + */ + SAFE, + + /** + * Control Loop execution execution proceeds and changes to domain and state are carried out in a test environment. + * The participant returns an indication that it is running in TEST mode together with the action it has performed + * on the test environment. + */ + TEST, + + /** + * Control Loop execution execution is executed in the live environment by the participant. + */ + ACTIVE, + + /** + * Control Loop execution execution is terminated and not available. + */ + TERMINATED +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatistics.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatistics.java new file mode 100644 index 000000000..0b895d418 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatistics.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.concepts; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.ToString; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +@NoArgsConstructor +@Data +@ToString +public class ParticipantStatistics implements Serializable { + private static final long serialVersionUID = 744036598792333124L; + + + @NonNull + private ToscaConceptIdentifier participantId; + + @NonNull + private Date timeStamp; + + private ParticipantState state; + private ParticipantHealthStatus healthStatus; + private long eventCount; + private long lastExecutionTime; + private double averageExecutionTime; + private long upTime; + private long lastEnterTime; + private long lastStart; +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsList.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsList.java new file mode 100644 index 000000000..a69f96f85 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsList.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.concepts; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +public class ParticipantStatisticsList { + private List<ParticipantStatistics> statisticsList; +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatistics.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatistics.java new file mode 100644 index 000000000..badf02066 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatistics.java @@ -0,0 +1,187 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import org.apache.commons.lang3.builder.CompareToBuilder; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfTimestampKey; +import org.onap.policy.models.base.validation.annotations.VerifyKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent a controlloop element statistics in the database. + * + * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech) + */ +@Entity +@Table(name = "ClElementStatistics") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class JpaClElementStatistics extends PfConcept implements PfAuthorative<ClElementStatistics>, Serializable { + + private static final long serialVersionUID = 621426717868738629L; + + @EmbeddedId + @VerifyKey + @NotNull + private PfTimestampKey key = new PfTimestampKey(); + + @VerifyKey + @NotNull + // @formatter:off + @AttributeOverrides({ + @AttributeOverride(name = "name", column = @Column(name = "cl_element_name")), + @AttributeOverride(name = "version", column = @Column(name = "cl_element_version")) + }) + private PfConceptKey clElementId; + // @formatter: on + + @Column + @NotNull + private ControlLoopState state; + + @Column + private long clElementUptime; + + /** + * The Key Constructor creates a {@link JpaClElementStatistics} object with the given Timestamp key. + * + * @param key the key + */ + public JpaClElementStatistics(@NonNull final PfTimestampKey key) { + this(key, new PfConceptKey()); + } + + /** + * The Key Constructor creates a {@link JpaClElementStatistics} object with all mandatory fields. + * + * @param key the key + * @param clElementId the TOSCA definition of the control loop element + */ + public JpaClElementStatistics(@NonNull final PfTimestampKey key, @NonNull final PfConceptKey clElementId) { + this.key = key; + this.clElementId = clElementId; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaClElementStatistics(@NonNull final JpaClElementStatistics copyConcept) { + super(copyConcept); + this.key = new PfTimestampKey(copyConcept.key); + this.clElementId = new PfConceptKey(copyConcept.clElementId); + this.state = copyConcept.state; + this.clElementUptime = copyConcept.clElementUptime; + } + + + /** + * Authorative constructor. + * + * @param authorativeConcept the authorative concept to copy from + */ + public JpaClElementStatistics(@NonNull final ClElementStatistics authorativeConcept) { + this.fromAuthorative(authorativeConcept); + } + + + + @Override + public ClElementStatistics toAuthorative() { + ClElementStatistics clElementStatistics = new ClElementStatistics(); + clElementStatistics.setTimeStamp(new Date(key.getTimeStamp().getTime())); + clElementStatistics.setControlLoopElementId(new ToscaConceptIdentifier(clElementId)); + clElementStatistics.setControlLoopState(state); + clElementStatistics.setClElementUptime(clElementUptime); + + return clElementStatistics; + } + + @Override + public void fromAuthorative(@NonNull ClElementStatistics clElementStatistics) { + // @formatter:off + if (this.key == null || this.getKey().isNullKey()) { + this.setKey( + new PfTimestampKey( + clElementStatistics.getControlLoopElementId().getName(), + clElementStatistics.getControlLoopElementId().getVersion(), + clElementStatistics.getTimeStamp())); + } + // @formatter:on + this.setClElementId(clElementStatistics.getControlLoopElementId().asConceptKey()); + this.setState(clElementStatistics.getControlLoopState()); + this.setClElementUptime(clElementStatistics.getClElementUptime()); + } + + @Override + public List<PfKey> getKeys() { + return getKey().getKeys(); + } + + @Override + public void clean() { + key.clean(); + clElementId.clean(); + } + + + @Override + public int compareTo(PfConcept otherConcept) { + if (otherConcept == null) { + return -1; + } + if (this == otherConcept) { + return 0; + } + if (getClass() != otherConcept.getClass()) { + return getClass().getName().compareTo(otherConcept.getClass().getName()); + } + + final JpaClElementStatistics other = (JpaClElementStatistics) otherConcept; + return new CompareToBuilder().append(this.key, other.key).append(this.state, other.state) + .append(this.clElementUptime, other.clElementUptime).toComparison(); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoop.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoop.java new file mode 100644 index 000000000..3f54ac2bb --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoop.java @@ -0,0 +1,267 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.CascadeType; +import javax.persistence.CollectionTable; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import org.apache.commons.lang3.ObjectUtils; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.annotations.Valid; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfReferenceKey; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.base.validation.annotations.VerifyKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent a control loop in the database. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +@Entity +@Table(name = "ControlLoop") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@EqualsAndHashCode(callSuper = false) +public class JpaControlLoop extends PfConcept implements PfAuthorative<ControlLoop> { + private static final long serialVersionUID = -4725410933242154805L; + + @EmbeddedId + @VerifyKey + @NotNull + private PfConceptKey key; + + // @formatter:off + @VerifyKey + @NotNull + @AttributeOverrides({ + @AttributeOverride(name = "name", column = @Column(name = "definition_name")), + @AttributeOverride(name = "version", column = @Column(name = "definition_version")) + } + ) + private PfConceptKey definition; + // @formatter:on + + @Column + @NotNull + private ControlLoopState state; + + @Column + @NotNull + private ControlLoopOrderedState orderedState; + + @Column + private String description; + + // @formatter:off + @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) + @CollectionTable(joinColumns = { + @JoinColumn(name = "controlLoopParentKeyName", referencedColumnName = "parentKeyName"), + @JoinColumn(name = "controlLoopParentKeyVersion", referencedColumnName = "parentKeyVersion"), + @JoinColumn(name = "controlLoopParentLocalName", referencedColumnName = "parentLocalName"), + @JoinColumn(name = "controlLoopLocalUUID", referencedColumnName = "localUUID") + }) + // @formatter:on + @NotNull + private List<@NotNull @Valid JpaControlLoopElement> elements; + + /** + * The Default Constructor creates a {@link JpaControlLoop} object with a null key. + */ + public JpaControlLoop() { + this(new PfConceptKey()); + } + + /** + * The Key Constructor creates a {@link JpaControlLoop} object with the given concept key. + * + * @param key the key + */ + public JpaControlLoop(@NonNull final PfConceptKey key) { + this(key, new PfConceptKey(), ControlLoopState.UNINITIALISED, new ArrayList<>()); + } + + /** + * The Key Constructor creates a {@link JpaControlLoop} object with all mandatory fields. + * + * @param key the key + * @param definition the TOSCA definition of the control loop + * @param state the state of the control loop + * @param elements the elements of the control looop in participants + */ + public JpaControlLoop(@NonNull final PfConceptKey key, @NonNull final PfConceptKey definition, + @NonNull final ControlLoopState state, @NonNull final List<JpaControlLoopElement> elements) { + this.key = key; + this.definition = definition; + this.state = state; + this.elements = elements; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaControlLoop(@NonNull final JpaControlLoop copyConcept) { + super(copyConcept); + this.key = new PfConceptKey(copyConcept.key); + this.definition = new PfConceptKey(copyConcept.definition); + this.state = copyConcept.state; + this.orderedState = copyConcept.orderedState; + this.description = copyConcept.description; + this.elements = PfUtils.mapList(copyConcept.elements, JpaControlLoopElement::new, new ArrayList<>(0)); + } + + /** + * Authorative constructor. + * + * @param authorativeConcept the authorative concept to copy from + */ + public JpaControlLoop(@NonNull final ControlLoop authorativeConcept) { + this.fromAuthorative(authorativeConcept); + } + + @Override + public ControlLoop toAuthorative() { + ControlLoop controlLoop = new ControlLoop(); + + controlLoop.setName(getKey().getName()); + controlLoop.setVersion(getKey().getVersion()); + controlLoop.setDefinition(new ToscaConceptIdentifier(definition)); + controlLoop.setState(state); + controlLoop.setOrderedState(orderedState != null ? orderedState : state.asOrderedState()); + controlLoop.setDescription(description); + + controlLoop + .setElements(elements.stream().map(JpaControlLoopElement::toAuthorative).collect(Collectors.toList())); + + return controlLoop; + } + + @Override + public void fromAuthorative(@NonNull final ControlLoop controlLoop) { + if (this.key == null || this.getKey().isNullKey()) { + this.setKey(new PfConceptKey(controlLoop.getName(), controlLoop.getVersion())); + } + + this.definition = controlLoop.getDefinition().asConceptKey(); + this.state = controlLoop.getState(); + this.orderedState = controlLoop.getOrderedState(); + this.description = controlLoop.getDescription(); + + this.elements = new ArrayList<>(controlLoop.getElements().size()); + for (ControlLoopElement element : controlLoop.getElements()) { + JpaControlLoopElement jpaControlLoopElement = new JpaControlLoopElement(); + jpaControlLoopElement.setKey(new PfReferenceKey(getKey(), element.getId().toString())); + jpaControlLoopElement.fromAuthorative(element); + this.elements.add(jpaControlLoopElement); + } + } + + @Override + public List<PfKey> getKeys() { + List<PfKey> keyList = getKey().getKeys(); + + keyList.add(definition); + + for (JpaControlLoopElement element : elements) { + keyList.addAll(element.getKeys()); + } + + return keyList; + } + + @Override + public void clean() { + key.clean(); + definition.clean(); + description = (description == null ? null : description.trim()); + + for (JpaControlLoopElement element : elements) { + element.clean(); + } + } + + @Override + public int compareTo(final PfConcept otherConcept) { + if (otherConcept == null) { + return -1; + } + if (this == otherConcept) { + return 0; + } + if (getClass() != otherConcept.getClass()) { + return this.getClass().getName().compareTo(otherConcept.getClass().getName()); + } + + final JpaControlLoop other = (JpaControlLoop) otherConcept; + int result = key.compareTo(other.key); + if (result != 0) { + return result; + } + + result = definition.compareTo(other.definition); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(state, other.state); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(orderedState, other.orderedState); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(description, other.description); + if (result != 0) { + return result; + } + + return PfUtils.compareObjects(elements, other.elements); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElement.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElement.java new file mode 100644 index 000000000..042cb16e1 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElement.java @@ -0,0 +1,243 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts; + +import java.util.List; +import java.util.UUID; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import org.apache.commons.lang3.ObjectUtils; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfReferenceKey; +import org.onap.policy.models.base.validation.annotations.VerifyKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent a participant control loop element in the database. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +@Entity +@Table(name = "ControlLoopElement") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@EqualsAndHashCode(callSuper = false) +public class JpaControlLoopElement extends PfConcept implements PfAuthorative<ControlLoopElement> { + private static final long serialVersionUID = -1791732273187890213L; + + @EmbeddedId + @VerifyKey + @NotNull + private PfReferenceKey key; + + // @formatter:off + @VerifyKey + @NotNull + @AttributeOverrides({ + @AttributeOverride(name = "name", column = @Column(name = "definition_name")), + @AttributeOverride(name = "version", column = @Column(name = "definition_version")) + } + ) + private PfConceptKey definition; + + @VerifyKey + @NotNull + @AttributeOverrides({ + @AttributeOverride(name = "name", column = @Column(name = "participant_name")), + @AttributeOverride(name = "version", column = @Column(name = "participant_version")) + } + ) + private PfConceptKey participantId; + // @formatter:on + + @Column + @NotNull + private ControlLoopState state; + + @Column + @NotNull + private ControlLoopOrderedState orderedState; + + @Column + private String description; + + /** + * The Default Constructor creates a {@link JpaControlLoopElement} object with a null key. + */ + public JpaControlLoopElement() { + this(new PfReferenceKey()); + } + + /** + * The Key Constructor creates a {@link JpaControlLoopElement} object with the given concept key. + * + * @param key the key + */ + public JpaControlLoopElement(@NonNull final PfReferenceKey key) { + this(key, new PfConceptKey(), new PfConceptKey(), ControlLoopState.UNINITIALISED); + } + + /** + * The Key Constructor creates a {@link JpaControlLoopElement} object with all mandatory fields. + * + * @param key the key + * @param definition the TOSCA definition of the control loop element + * @param participantId the TOSCA definition of the participant running the control loop element + * @param state the state of the control loop + */ + public JpaControlLoopElement(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey definition, + @NonNull final PfConceptKey participantId, @NonNull final ControlLoopState state) { + this.key = key; + this.definition = definition; + this.participantId = participantId; + this.state = state; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaControlLoopElement(@NonNull final JpaControlLoopElement copyConcept) { + super(copyConcept); + this.key = new PfReferenceKey(copyConcept.key); + this.definition = new PfConceptKey(copyConcept.definition); + this.participantId = new PfConceptKey(copyConcept.participantId); + this.state = copyConcept.state; + this.orderedState = copyConcept.orderedState; + this.description = copyConcept.description; + } + + /** + * Authorative constructor. + * + * @param authorativeConcept the authorative concept to copy from + */ + public JpaControlLoopElement(@NonNull final ControlLoopElement authorativeConcept) { + this.fromAuthorative(authorativeConcept); + } + + @Override + public ControlLoopElement toAuthorative() { + ControlLoopElement element = new ControlLoopElement(); + + element.setId(UUID.fromString(getKey().getLocalName())); + element.setDefinition(new ToscaConceptIdentifier(definition)); + element.setParticipantId(new ToscaConceptIdentifier(participantId)); + element.setState(state); + element.setOrderedState(orderedState != null ? orderedState : state.asOrderedState()); + element.setDescription(description); + + return element; + } + + @Override + public void fromAuthorative(@NonNull final ControlLoopElement element) { + if (this.key == null || this.getKey().isNullKey()) { + this.setKey(new PfReferenceKey()); + getKey().setLocalName(element.getId().toString()); + } + + this.definition = element.getDefinition().asConceptKey(); + this.participantId = element.getParticipantId().asConceptKey(); + this.state = element.getState(); + this.orderedState = element.getOrderedState(); + this.description = element.getDescription(); + } + + @Override + public List<PfKey> getKeys() { + List<PfKey> keyList = getKey().getKeys(); + + keyList.add(definition); + keyList.add(participantId); + + return keyList; + } + + @Override + public void clean() { + key.clean(); + definition.clean(); + participantId.clean(); + + if (description != null) { + description = description.trim(); + } + } + + @Override + public int compareTo(final PfConcept otherConcept) { + if (otherConcept == null) { + return -1; + } + if (this == otherConcept) { + return 0; + } + if (getClass() != otherConcept.getClass()) { + return this.getClass().getName().compareTo(otherConcept.getClass().getName()); + } + + final JpaControlLoopElement other = (JpaControlLoopElement) otherConcept; + int result = key.compareTo(other.key); + if (result != 0) { + return result; + } + + result = definition.compareTo(other.definition); + if (result != 0) { + return result; + } + + result = participantId.compareTo(other.participantId); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(state, other.state); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(orderedState, other.orderedState); + if (result != 0) { + return result; + } + + return ObjectUtils.compare(description, other.description); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipant.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipant.java new file mode 100644 index 000000000..69b565266 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipant.java @@ -0,0 +1,220 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import org.apache.commons.lang3.ObjectUtils; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.validation.annotations.VerifyKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent a participant in the database. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +@Entity +@Table(name = "Participant") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@EqualsAndHashCode(callSuper = false) +public class JpaParticipant extends PfConcept implements PfAuthorative<Participant>, Serializable { + private static final long serialVersionUID = -4697758484642403483L; + + @EmbeddedId + @VerifyKey + @NotNull + private PfConceptKey key; + + // @formatter:off + @VerifyKey + @NotNull + @AttributeOverrides({ + @AttributeOverride(name = "name", column = @Column(name = "definition_name")), + @AttributeOverride(name = "version", column = @Column(name = "definition_version")) + } + ) + private PfConceptKey definition; + // @formatter:on + + @Column + @NotNull + private ParticipantState participantState; + + @Column + @NotNull + private ParticipantHealthStatus healthStatus; + + @Column + private String description; + + /** + * The Default Constructor creates a {@link JpaParticipant} object with a null key. + */ + public JpaParticipant() { + this(new PfConceptKey()); + } + + /** + * The Key Constructor creates a {@link JpaParticipant} object with the given concept key. + * + * @param key the key + */ + public JpaParticipant(@NonNull final PfConceptKey key) { + this(key, new PfConceptKey(), ParticipantState.PASSIVE, ParticipantHealthStatus.UNKNOWN); + } + + /** + * The Key Constructor creates a {@link JpaParticipant} object with all mandatory fields. + * + * @param key the key + * @param definition the TOSCA definition of the participant + * @param participantState the state of the participant + * @param healthStatus the health state of the participant + */ + public JpaParticipant(@NonNull final PfConceptKey key, @NonNull final PfConceptKey definition, + @NonNull final ParticipantState participantState, @NonNull ParticipantHealthStatus healthStatus) { + this.key = key; + this.definition = definition; + this.participantState = participantState; + this.healthStatus = healthStatus; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaParticipant(@NonNull final JpaParticipant copyConcept) { + super(copyConcept); + this.key = new PfConceptKey(copyConcept.key); + this.definition = new PfConceptKey(copyConcept.definition); + this.participantState = copyConcept.participantState; + this.healthStatus = copyConcept.healthStatus; + this.description = copyConcept.description; + } + + /** + * Authorative constructor. + * + * @param authorativeConcept the authorative concept to copy from + */ + public JpaParticipant(@NonNull final Participant authorativeConcept) { + this.fromAuthorative(authorativeConcept); + } + + @Override + public Participant toAuthorative() { + Participant participant = new Participant(); + + participant.setName(key.getName()); + participant.setVersion(key.getVersion()); + participant.setDefinition(new ToscaConceptIdentifier(definition)); + participant.setParticipantState(participantState); + participant.setHealthStatus(healthStatus); + participant.setDescription(description); + + return participant; + } + + @Override + public void fromAuthorative(@NonNull final Participant participant) { + if (this.key == null || this.getKey().isNullKey()) { + this.setKey(new PfConceptKey(participant.getName(), participant.getVersion())); + } + + this.definition = participant.getDefinition().asConceptKey(); + this.setParticipantState(participant.getParticipantState()); + this.setHealthStatus(participant.getHealthStatus()); + this.setDescription(participant.getDescription()); + } + + @Override + public List<PfKey> getKeys() { + List<PfKey> keyList = getKey().getKeys(); + + keyList.add(definition); + + return keyList; + } + + @Override + public void clean() { + key.clean(); + definition.clean(); + description = (description == null ? null : description.trim()); + } + + @Override + public int compareTo(final PfConcept otherConcept) { + if (otherConcept == null) { + return -1; + } + if (this == otherConcept) { + return 0; + } + if (getClass() != otherConcept.getClass()) { + return getClass().getName().compareTo(otherConcept.getClass().getName()); + } + + final JpaParticipant other = (JpaParticipant) otherConcept; + int result = key.compareTo(other.key); + if (result != 0) { + return result; + } + + result = definition.compareTo(other.definition); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(participantState, other.participantState); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(healthStatus, other.healthStatus); + if (result != 0) { + return result; + } + + return ObjectUtils.compare(description, other.description); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatistics.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatistics.java new file mode 100644 index 000000000..1877d98a1 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatistics.java @@ -0,0 +1,244 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import org.apache.commons.lang3.builder.CompareToBuilder; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfTimestampKey; +import org.onap.policy.models.base.validation.annotations.VerifyKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent a control loop statistics in the database. + * + * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech) + */ +@Entity +@Table(name = "ControlLoopStatistics") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class JpaParticipantStatistics extends PfConcept + implements PfAuthorative<ParticipantStatistics>, Serializable { + + private static final long serialVersionUID = -5992214428190133190L; + + @EmbeddedId + @VerifyKey + @NotNull + private PfTimestampKey key; + + @VerifyKey + @NotNull + @AttributeOverrides({ + @AttributeOverride(name = "name", column = @Column(name = "participant_name")), + @AttributeOverride(name = "version", column = @Column(name = "participant_version")) + } + ) + private PfConceptKey participantId; + + @Column + @NotNull + private ParticipantState state; + + @Column + @NotNull + private ParticipantHealthStatus healthStatus; + + @Column + private long eventCount; + + @Column + private long lastExecutionTime; + + @Column + private double averageExecutionTime; + + @Column + private long upTime; + + @Column + private long lastEnterTime; + + @Column + private long lastStart; + + + /** + * The Default Constructor creates a {@link JpaParticipantStatistics} object with a null key. + */ + public JpaParticipantStatistics() { + this(new PfTimestampKey()); + } + + /** + * The Key Constructor creates a {@link JpaParticipantStatistics} object with the given Timestamp key. + * + * @param key the key + */ + public JpaParticipantStatistics(@NonNull final PfTimestampKey key) { + this(key, new PfConceptKey(), ParticipantState.PASSIVE, ParticipantHealthStatus.HEALTHY, 0L, 0L, + 0.0d, 0L, 0L, 0L); + } + + + /** + * The Key Constructor creates a {@link JpaParticipantStatistics} object with all mandatory fields. + * + * @param key the key + * @param participantId the TOSCA definition of the control loop participant + */ + public JpaParticipantStatistics(@NonNull final PfTimestampKey key, @NonNull final PfConceptKey participantId) { + this.key = key; + this.participantId = participantId; + } + + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaParticipantStatistics(@NonNull final JpaParticipantStatistics copyConcept) { + super(copyConcept); + this.key = new PfTimestampKey(copyConcept.key); + this.participantId = new PfConceptKey(copyConcept.participantId); + this.state = copyConcept.state; + this.healthStatus = copyConcept.healthStatus; + this.eventCount = copyConcept.eventCount; + this.lastExecutionTime = copyConcept.lastExecutionTime; + this.averageExecutionTime = copyConcept.averageExecutionTime; + this.upTime = copyConcept.upTime; + this.lastEnterTime = copyConcept.lastEnterTime; + this.lastStart = copyConcept.lastStart; + } + + /** + * Authorative constructor. + * + * @param authorativeConcept the authorative concept to copy from + */ + public JpaParticipantStatistics(@NonNull final ParticipantStatistics authorativeConcept) { + this.fromAuthorative(authorativeConcept); + } + + + @Override + public int compareTo(PfConcept otherConcept) { + if (otherConcept == null) { + return -1; + } + if (this == otherConcept) { + return 0; + } + if (getClass() != otherConcept.getClass()) { + return getClass().getName().compareTo(otherConcept.getClass().getName()); + } + + final JpaParticipantStatistics other = (JpaParticipantStatistics) otherConcept; + // @formatter:off + return new CompareToBuilder() + .append(this.key, other.key) + .append(this.participantId, other.participantId) + .append(this.state, other.state) + .append(this.healthStatus, other.healthStatus) + .append(this.eventCount, other.eventCount) + .append(this.lastExecutionTime, other.lastExecutionTime) + .append(this.averageExecutionTime, other.averageExecutionTime) + .append(this.upTime, other.upTime) + .append(this.lastEnterTime, other.lastEnterTime) + .append(this.lastStart, other.lastStart).toComparison(); + // @formatter:on + } + + @Override + public ParticipantStatistics toAuthorative() { + ParticipantStatistics participantStatistics = new ParticipantStatistics(); + participantStatistics.setTimeStamp(new Date(key.getTimeStamp().getTime())); + participantStatistics.setParticipantId(new ToscaConceptIdentifier(participantId)); + participantStatistics.setState(state); + participantStatistics.setHealthStatus(healthStatus); + participantStatistics.setAverageExecutionTime(averageExecutionTime); + participantStatistics.setEventCount(eventCount); + participantStatistics.setLastExecutionTime(lastExecutionTime); + participantStatistics.setUpTime(upTime); + participantStatistics.setLastEnterTime(lastEnterTime); + participantStatistics.setLastStart(lastStart); + + return participantStatistics; + } + + @Override + public void fromAuthorative(@NonNull final ParticipantStatistics participantStatistics) { + if (this.key == null || this.getKey().isNullKey()) { + this.setKey(new PfTimestampKey(participantStatistics.getParticipantId().getName(), + participantStatistics.getParticipantId().getVersion(), + participantStatistics.getTimeStamp())); + } + this.setParticipantId(participantStatistics.getParticipantId().asConceptKey()); + this.setState(participantStatistics.getState()); + this.setHealthStatus(participantStatistics.getHealthStatus()); + this.setAverageExecutionTime(participantStatistics.getAverageExecutionTime()); + this.setEventCount(participantStatistics.getEventCount()); + this.setLastExecutionTime(participantStatistics.getLastExecutionTime()); + this.setUpTime(participantStatistics.getUpTime()); + this.setLastEnterTime(participantStatistics.getLastEnterTime()); + this.setLastStart(participantStatistics.getLastStart()); + + } + + @Override + public List<PfKey> getKeys() { + List<PfKey> keyList = getKey().getKeys(); + keyList.addAll(participantId.getKeys()); + return keyList; + } + + @Override + public void clean() { + key.clean(); + participantId.clean(); + } +}
\ No newline at end of file diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProvider.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProvider.java new file mode 100644 index 000000000..b1cdf62b0 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProvider.java @@ -0,0 +1,147 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import javax.ws.rs.core.Response; +import lombok.NonNull; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; +import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaClElementStatistics; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.base.PfTimestampKey; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.provider.impl.AbstractModelsProvider; + +/** + * This class provides the provision of information on control loop element statistics in the database to callers. + * + * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech) + */ +public class ClElementStatisticsProvider extends AbstractModelsProvider { + + /** + * Create a provider for control loop element statistics. + * + * @param parameters the parameters for database access + * @throws PfModelException on initiation errors + */ + public ClElementStatisticsProvider(@NonNull PolicyModelsProviderParameters parameters) throws PfModelException { + super(parameters); + this.init(); + } + + /** + * Creates control loop element statistics. + * + * @param clElementStatisticsList a specification of the CL element statistics to create + * @return the clElement statistics created + * @throws PfModelException on errors creating clElement statistics + */ + public List<ClElementStatistics> createClElementStatistics( + @NonNull final List<ClElementStatistics> clElementStatisticsList) throws PfModelException { + + BeanValidationResult validationResult = + new BeanValidationResult("control loop element statistics list", clElementStatisticsList); + for (ClElementStatistics clElementStatistics : clElementStatisticsList) { + JpaClElementStatistics jpaClElementStatistics = new JpaClElementStatistics(); + jpaClElementStatistics.fromAuthorative(clElementStatistics); + + validationResult.addResult(jpaClElementStatistics.validate("control loop element statistics")); + } + + if (!validationResult.isValid()) { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); + } + + for (ClElementStatistics clElementStatistics : clElementStatisticsList) { + JpaClElementStatistics jpaClElementStatistics = new JpaClElementStatistics(); + jpaClElementStatistics.fromAuthorative(clElementStatistics); + + getPfDao().create(jpaClElementStatistics); + } + + // Return the created control loop element statistics + List<ClElementStatistics> elementStatistics = new ArrayList<>(clElementStatisticsList.size()); + + for (ClElementStatistics clElementStat : clElementStatisticsList) { + JpaClElementStatistics jpaClElementStatistics = getPfDao().get(JpaClElementStatistics.class, + new PfTimestampKey(clElementStat.getControlLoopElementId().getName(), + clElementStat.getControlLoopElementId().getVersion(), clElementStat.getTimeStamp())); + elementStatistics.add(jpaClElementStatistics.toAuthorative()); + } + + return elementStatistics; + } + + /** + * Convert JPA clElement statistics list to clElement statistics list. + * + * @param jpaClElementStatistics the list to convert + * @return the clElement statistics list + */ + private List<ClElementStatistics> asClElementStatisticsList(List<JpaClElementStatistics> jpaClElementStatistics) { + return jpaClElementStatistics.stream().map(JpaClElementStatistics::toAuthorative).collect(Collectors.toList()); + } + + /** + * Get clElement statistics. + * + * @param name the name of the clElement statistics to get, null to get all stats + * @return the clElement statistics found + * @throws PfModelException on errors getting clElement statistics + */ + public List<ClElementStatistics> getClElementStatistics(final String name, final String version, + final Date timestamp) throws PfModelException { + + if (name != null && version != null && timestamp != null) { + List<ClElementStatistics> clElementStatistics = new ArrayList<>(1); + clElementStatistics.add(getPfDao() + .get(JpaClElementStatistics.class, new PfTimestampKey(name, version, timestamp)).toAuthorative()); + return clElementStatistics; + } else { + return asClElementStatisticsList(getPfDao().getAll(JpaClElementStatistics.class)); + } + } + + /** + * Get filtered clElement statistics. + * + * @param name the clElement name for the statistics to get + * @param startTimeStamp startTimeStamp to filter statistics + * @param endTimeStamp endTimeStamp to filter statistics + * @param sortOrder sortOrder to query database + * @param getRecordNum Total query count from database + * @return the clElement statistics found + * @throws PfModelException on errors getting policies + */ + public List<ClElementStatistics> getFilteredClElementStatistics(final String name, final String version, + final Date startTimeStamp, final Date endTimeStamp, Map<String, Object> filterMap, final String sortOrder, + final int getRecordNum) { + return asClElementStatisticsList(getPfDao().getFiltered(JpaClElementStatistics.class, name, version, + startTimeStamp, endTimeStamp, filterMap, sortOrder, getRecordNum)); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java new file mode 100644 index 000000000..b2a5e43a3 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java @@ -0,0 +1,218 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import javax.ws.rs.core.Response; +import lombok.NonNull; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; +import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoop; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.provider.impl.AbstractModelsProvider; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; + +/** + * This class provides information on control loop concepts in the database to callers. + */ +public class ControlLoopProvider extends AbstractModelsProvider { + + /** + * Create a provider for control loops. + * + * @param parameters the parameters for database access + * @throws PfModelException on initiation errors + */ + public ControlLoopProvider(@NonNull PolicyModelsProviderParameters parameters) throws PfModelException { + super(parameters); + this.init(); + } + + /** + * Get Control Loop. + * + * @param controlLoopId the ID of the control loop to get + * @return the control loop found + * @throws PfModelException on errors getting the control loop + */ + public ControlLoop getControlLoop(final ToscaConceptIdentifier controlLoopId) throws PfModelException { + JpaControlLoop jpaControlLoop = getPfDao().get(JpaControlLoop.class, controlLoopId.asConceptKey()); + + return jpaControlLoop == null ? null : jpaControlLoop.toAuthorative(); + } + + /** + * Update Control Loop. + * + * @param controlLoop the control loop to update + * @return the updated control loop + * @throws PfModelException on errors updating the control loop + */ + public ControlLoop updateControlLoop(final ControlLoop controlLoop) throws PfModelException { + return updateControlLoops(Collections.singletonList(controlLoop)).get(0); + } + + /** + * Get Control Loops. + * + * @param name the name of the control loop to get, null to get all control loops + * @param version the version of the control loop to get, null to get all control loops + * @return the control loops found + * @throws PfModelException on errors getting control loops + */ + public List<ControlLoop> getControlLoops(final String name, final String version) throws PfModelException { + + return asControlLoopList(getPfDao().getFiltered(JpaControlLoop.class, name, version)); + } + + /** + * Get filtered control loops. + * + * @param filter the filter for the control loops to get + * @return the control loops found + * @throws PfModelException on errors getting policies + */ + public List<ControlLoop> getFilteredControlLoops(@NonNull final ToscaTypedEntityFilter<ControlLoop> filter) { + + return filter.filter(asControlLoopList( + getPfDao().getFiltered(JpaControlLoop.class, filter.getName(), PfKey.NULL_KEY_VERSION))); + } + + /** + * Creates control loops. + * + * @param controlLoops a specification of the control loops to create + * @return the control loops created + * @throws PfModelException on errors creating control loops + */ + public List<ControlLoop> createControlLoops(@NonNull final List<ControlLoop> controlLoops) throws PfModelException { + + BeanValidationResult validationResult = new BeanValidationResult("control loops", controlLoops); + + for (ControlLoop controlLoop : controlLoops) { + JpaControlLoop jpaControlLoop = new JpaControlLoop(); + jpaControlLoop.fromAuthorative(controlLoop); + + validationResult.addResult(jpaControlLoop.validate("control loop")); + } + + if (!validationResult.isValid()) { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); + } + + for (ControlLoop controlLoop : controlLoops) { + JpaControlLoop jpaControlLoop = new JpaControlLoop(); + jpaControlLoop.fromAuthorative(controlLoop); + + getPfDao().create(jpaControlLoop); + } + + // Return the created control loops + List<ControlLoop> returnControlLoops = new ArrayList<>(controlLoops.size()); + + for (ControlLoop controlLoop : controlLoops) { + JpaControlLoop jpaControlLoop = getPfDao().get(JpaControlLoop.class, + new PfConceptKey(controlLoop.getName(), controlLoop.getVersion())); + returnControlLoops.add(jpaControlLoop.toAuthorative()); + } + + return returnControlLoops; + } + + /** + * Updates control loops. + * + * @param controlLoops a specification of the control loops to update + * @return the control loops updated + * @throws PfModelException on errors updating control loops + */ + public List<ControlLoop> updateControlLoops(@NonNull final List<ControlLoop> controlLoops) throws PfModelException { + + BeanValidationResult validationResult = new BeanValidationResult("control loops", controlLoops); + + for (ControlLoop controlLoop : controlLoops) { + JpaControlLoop jpaControlLoop = new JpaControlLoop(); + jpaControlLoop.fromAuthorative(controlLoop); + + validationResult.addResult(jpaControlLoop.validate("control loop")); + } + + if (!validationResult.isValid()) { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); + } + + // Return the created control loops + List<ControlLoop> returnControlLoops = new ArrayList<>(controlLoops.size()); + + for (ControlLoop controlLoop : controlLoops) { + JpaControlLoop jpaControlLoop = new JpaControlLoop(); + jpaControlLoop.fromAuthorative(controlLoop); + + JpaControlLoop returnJpaControlLoop = getPfDao().update(jpaControlLoop); + returnControlLoops.add(returnJpaControlLoop.toAuthorative()); + } + + return returnControlLoops; + } + + /** + * Delete a control loop. + * + * @param name the name of the control loop to delete + * @param version the version of the control loop to delete + * @return the control loop deleted + * @throws PfModelException on errors deleting the control loop + */ + public ControlLoop deleteControlLoop(@NonNull final String name, @NonNull final String version) { + + PfConceptKey controlLoopKey = new PfConceptKey(name, version); + + JpaControlLoop jpaDeleteControlLoop = getPfDao().get(JpaControlLoop.class, controlLoopKey); + + if (jpaDeleteControlLoop == null) { + String errorMessage = + "delete of control loop \"" + controlLoopKey.getId() + "\" failed, control loop does not exist"; + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); + } + + getPfDao().delete(jpaDeleteControlLoop); + + return jpaDeleteControlLoop.toAuthorative(); + } + + /** + * Convert JPA control loop list to an authorative control loop list. + * + * @param jpaControlLoopList the list to convert + * @return the authorative list + */ + private List<ControlLoop> asControlLoopList(List<JpaControlLoop> jpaControlLoopList) { + return jpaControlLoopList.stream().map(JpaControlLoop::toAuthorative).collect(Collectors.toList()); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProvider.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProvider.java new file mode 100644 index 000000000..e82956f93 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProvider.java @@ -0,0 +1,195 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import javax.ws.rs.core.Response; +import lombok.NonNull; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; +import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipant; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.provider.impl.AbstractModelsProvider; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; + +/** + * This class provides information on participant concepts in the database to callers. + */ +public class ParticipantProvider extends AbstractModelsProvider { + /** + * Create a provider for participants. + * + * @param parameters the parameters for database access + * @throws PfModelException on initiation errors + */ + public ParticipantProvider(@NonNull PolicyModelsProviderParameters parameters) throws PfModelException { + super(parameters); + this.init(); + } + + /** + * Get participants. + * + * @param name the name of the participant to get, null to get all participants + * @param version the version of the participant to get, null to get all participants + * @return the participants found + * @throws PfModelException on errors getting participants + */ + public List<Participant> getParticipants(final String name, final String version) throws PfModelException { + + return asParticipantList(getPfDao().getFiltered(JpaParticipant.class, name, version)); + } + + /** + * Get filtered participants. + * + * @param filter the filter for the participants to get + * @return the participants found + * @throws PfModelException on errors getting policies + */ + public List<Participant> getFilteredParticipants(@NonNull final ToscaTypedEntityFilter<Participant> filter) { + + return filter.filter(asParticipantList( + getPfDao().getFiltered(JpaParticipant.class, filter.getName(), filter.getVersion()))); + } + + /** + * Creates participants. + * + * @param participants a specification of the participants to create + * @return the participants created + * @throws PfModelException on errors creating participants + */ + public List<Participant> createParticipants(@NonNull final List<Participant> participants) throws PfModelException { + + BeanValidationResult validationResult = new BeanValidationResult("participants", participants); + + for (Participant participant : participants) { + JpaParticipant jpaParticipant = new JpaParticipant(); + jpaParticipant.fromAuthorative(participant); + + validationResult.addResult(jpaParticipant.validate("participant")); + } + + if (!validationResult.isValid()) { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); + } + + for (Participant participant : participants) { + JpaParticipant jpaParticipant = new JpaParticipant(); + jpaParticipant.fromAuthorative(participant); + + getPfDao().create(jpaParticipant); + } + + // Return the created participants + List<Participant> returnParticipants = new ArrayList<>(participants.size()); + + for (Participant participant : participants) { + JpaParticipant jpaParticipant = getPfDao().get(JpaParticipant.class, + new PfConceptKey(participant.getName(), participant.getVersion())); + returnParticipants.add(jpaParticipant.toAuthorative()); + } + + return returnParticipants; + } + + /** + * Updates participants. + * + * @param participants a specification of the participants to update + * @return the participants updated + * @throws PfModelException on errors updating participants + */ + public List<Participant> updateParticipants(@NonNull final List<Participant> participants) throws PfModelException { + + BeanValidationResult validationResult = new BeanValidationResult("participants", participants); + + for (Participant participant : participants) { + JpaParticipant jpaParticipant = new JpaParticipant(); + jpaParticipant.fromAuthorative(participant); + + validationResult.addResult(jpaParticipant.validate("participant")); + } + + if (!validationResult.isValid()) { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); + } + + for (Participant participant : participants) { + JpaParticipant jpaParticipant = new JpaParticipant(); + jpaParticipant.fromAuthorative(participant); + + getPfDao().update(jpaParticipant); + } + + // Return the created participants + List<Participant> returnParticipants = new ArrayList<>(participants.size()); + + for (Participant participant : participants) { + JpaParticipant jpaParticipant = getPfDao().get(JpaParticipant.class, + new PfConceptKey(participant.getName(), participant.getVersion())); + returnParticipants.add(jpaParticipant.toAuthorative()); + } + + return returnParticipants; + } + + /** + * Delete a participant. + * + * @param name the name of the participant to delete + * @param version the version of the participant to get + * @return the participant deleted + * @throws PfModelException on errors deleting participants + */ + public Participant deleteParticipant(@NonNull final String name, @NonNull final String version) { + + PfConceptKey participantKey = new PfConceptKey(name, version); + + JpaParticipant jpaDeleteParticipant = getPfDao().get(JpaParticipant.class, participantKey); + + if (jpaDeleteParticipant == null) { + String errorMessage = + "delete of participant \"" + participantKey.getId() + "\" failed, participant does not exist"; + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); + } + + getPfDao().delete(jpaDeleteParticipant); + + return jpaDeleteParticipant.toAuthorative(); + } + + /** + * Convert JPA participant list to an authorative participant list. + * + * @param foundParticipants the list to convert + * @return the authorative list + */ + private List<Participant> asParticipantList(List<JpaParticipant> jpaParticipantList) { + return jpaParticipantList.stream().map(JpaParticipant::toAuthorative).collect(Collectors.toList()); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProvider.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProvider.java new file mode 100644 index 000000000..5a0bb011c --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProvider.java @@ -0,0 +1,156 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import javax.ws.rs.core.Response; +import lombok.NonNull; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics; +import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipantStatistics; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.base.PfTimestampKey; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.provider.impl.AbstractModelsProvider; + +/** + * This class provides the provision of information on participant statistics in the database to callers. + * + * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech) + */ +public class ParticipantStatisticsProvider extends AbstractModelsProvider { + + /** + * Create a provider for control loops statistics. + * + * @param parameters the parameters for database access + * @throws PfModelException on initiation errors + */ + public ParticipantStatisticsProvider(@NonNull PolicyModelsProviderParameters parameters) throws PfModelException { + super(parameters); + this.init(); + } + + /** + * Get Participant statistics. + * + * @param name the name of the participant statistics to get, null to get all stats + * @return the participant statistics found + * @throws PfModelException on errors getting participant statistics + */ + public List<ParticipantStatistics> getParticipantStatistics(final String name, final String version, + final Date timestamp) throws PfModelException { + + if (name != null && version != null && timestamp != null) { + List<ParticipantStatistics> participantStatistics = new ArrayList<>(1); + participantStatistics.add(getPfDao() + .get(JpaParticipantStatistics.class, new PfTimestampKey(name, version, timestamp)).toAuthorative()); + return participantStatistics; + } else { + return asParticipantStatisticsList(getPfDao().getAll(JpaParticipantStatistics.class)); + } + } + + + /** + * Get filtered participant statistics. + * + * @param name the participant name for the statistics to get + * @param startTimeStamp startTimeStamp to filter statistics + * @param endTimeStamp endTimeStamp to filter statistics + * @param sortOrder sortOrder to query database + * @param getRecordNum Total query count from database + * @return the participant statistics found + * @throws PfModelException on errors getting policies + */ + public List<ParticipantStatistics> getFilteredParticipantStatistics(final String name, final String version, + final Date startTimeStamp, final Date endTimeStamp, Map<String, Object> filterMap, final String sortOrder, + final int getRecordNum) { + + return asParticipantStatisticsList(getPfDao().getFiltered(JpaParticipantStatistics.class, name, version, + startTimeStamp, endTimeStamp, filterMap, sortOrder, getRecordNum)); + } + + + /** + * Creates Participant statistics. + * + * @param participantStatisticsList a specification of the CL statistics to create + * @return the participant statistics created + * @throws PfModelException on errors creating participant statistics + */ + public List<ParticipantStatistics> createParticipantStatistics( + @NonNull final List<ParticipantStatistics> participantStatisticsList) throws PfModelException { + + BeanValidationResult validationResult = + new BeanValidationResult("participant statistics List", participantStatisticsList); + + for (ParticipantStatistics participantStatistics : participantStatisticsList) { + JpaParticipantStatistics jpaParticipantStatistics = new JpaParticipantStatistics(); + jpaParticipantStatistics.fromAuthorative(participantStatistics); + + validationResult.addResult(jpaParticipantStatistics.validate("participant statistics")); + } + + if (!validationResult.isValid()) { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); + } + + for (ParticipantStatistics participantStatistics : participantStatisticsList) { + JpaParticipantStatistics jpaParticipantStatistics = new JpaParticipantStatistics(); + jpaParticipantStatistics.fromAuthorative(participantStatistics); + + getPfDao().create(jpaParticipantStatistics); + } + + // Return the created participant statistics + List<ParticipantStatistics> participantStatistics = new ArrayList<>(participantStatisticsList.size()); + + for (ParticipantStatistics participantStatisticsItem : participantStatisticsList) { + JpaParticipantStatistics jpaParticipantStatistics = getPfDao().get(JpaParticipantStatistics.class, + new PfTimestampKey(participantStatisticsItem.getParticipantId().getName(), + participantStatisticsItem.getParticipantId().getVersion(), + participantStatisticsItem.getTimeStamp())); + participantStatistics.add(jpaParticipantStatistics.toAuthorative()); + } + + return participantStatistics; + } + + + /** + * Convert JPA participant statistics list to participant statistics list. + * + * @param jpaParticipantStatisticsList the list to convert + * @return the participant statistics list + */ + private List<ParticipantStatistics> asParticipantStatisticsList( + List<JpaParticipantStatistics> jpaParticipantStatisticsList) { + + return jpaParticipantStatisticsList.stream().map(JpaParticipantStatistics::toAuthorative) + .collect(Collectors.toList()); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotification.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotification.java new file mode 100644 index 000000000..c6bbd81d6 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotification.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.notification; + +import com.google.gson.annotations.SerializedName; +import java.util.ArrayList; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.collections4.CollectionUtils; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ControlLoopNotification { + + /** + * Status of control loops that are being added to participants. + */ + @SerializedName("deployed-control-loops") + private List<ControlLoopStatus> added = new ArrayList<>(); + + /** + * Status of policies that are being deleted from PDPs. + */ + @SerializedName("undeployed-control-loops") + private List<ControlLoopStatus> deleted = new ArrayList<>(); + + + /** + * Determines if the notification is empty (i.e., has no added or delete control loop + * notifications). + * + * @return {@code true} if the notification is empty, {@code false} otherwise + */ + public boolean isEmpty() { + return (CollectionUtils.isEmpty(added) && CollectionUtils.isEmpty(deleted)); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatus.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatus.java new file mode 100644 index 000000000..033843e75 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatus.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.notification; + +import com.google.gson.annotations.SerializedName; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ControlLoopStatus { + @SerializedName("control-loop-id") + private UUID id; + + private ToscaConceptIdentifier definition; +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChange.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChange.java new file mode 100644 index 000000000..1a9a891f6 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChange.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; + +/** + * Class to represent the PARTICIPANT_CONTROL_LOOP_STATE_CHANGE message that the control loop runtime will send to + * participants to change the state of a control loop they are running. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantControlLoopStateChange extends ParticipantMessage { + private ControlLoopOrderedState orderedState; + + /** + * Constructor for instantiating ParticipantControlLoopStateChange class with message name. + * + */ + public ParticipantControlLoopStateChange() { + super(ParticipantMessageType.PARTICIPANT_CONTROL_LOOP_STATE_CHANGE); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantControlLoopStateChange(ParticipantControlLoopStateChange source) { + super(source); + + this.orderedState = source.orderedState; + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdate.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdate.java new file mode 100644 index 000000000..ed729a64b --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdate.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; + +/** + * Class to represent the PARTICIPANT_CONTROL_LOOP_UPDATE message that the control loop runtime sends to a participant. + * When a participant receives this message, it creates the control loop elements contained in the message and sets them + * to state PASSIVE. subsequent PARTICIPANT_CONTROL_LOOP_STATE_CHANGE messages are used to activate the control loops. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantControlLoopUpdate extends ParticipantMessage { + // The control loop + private ControlLoop controlLoop; + + // A service template containing a complete definition of the control loop + private ToscaServiceTemplate controlLoopDefinition; + + /** + * Constructor for instantiating ParticipantControlLoopUpdate class with message name. + * + */ + public ParticipantControlLoopUpdate() { + super(ParticipantMessageType.PARTICIPANT_CONTROL_LOOP_UPDATE); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantControlLoopUpdate(ParticipantControlLoopUpdate source) { + super(source); + + this.controlLoop = new ControlLoop(source.controlLoop); + this.controlLoopDefinition = new ToscaServiceTemplate(source.controlLoopDefinition); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheck.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheck.java new file mode 100644 index 000000000..e472e15fe --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheck.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; + +/** + * Class to represent the PARTICIPANT_HEALTHCHECK message that the control loop runtime will send to + * participants to change the state of a control loop they are running. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantHealthCheck extends ParticipantMessage { + private ParticipantState state; + + /** + * Constructor for instantiating ParticipantHealthCheck class with message name. + * + */ + public ParticipantHealthCheck() { + super(ParticipantMessageType.PARTICIPANT_HEALTH_CHECK); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantHealthCheck(ParticipantHealthCheck source) { + super(source); + + this.state = source.state; + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java new file mode 100644 index 000000000..2146f7dc2 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java @@ -0,0 +1,96 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import java.util.UUID; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent the base class for various messages that will be exchanged between + * the control loop runtime and participants. + */ +@Getter +@Setter +@ToString +public class ParticipantMessage { + @Setter(AccessLevel.NONE) + private ParticipantMessageType messageType; + + private UUID requestId = UUID.randomUUID(); + + /** + * Time-stamp, in milliseconds, when the message was created. Defaults to the current + * time. + */ + private long timestampMs = System.currentTimeMillis(); + + /** + * Participant ID, or {@code null} for state-change broadcast messages. + */ + private ToscaConceptIdentifier participantId; + + /** + * Control loop ID. For state-change messages, this may be {@code null}. + */ + private ToscaConceptIdentifier controlLoopId; + + /** + * Constructor for instantiating a participant message class. + * + * @param messageType the message type + */ + public ParticipantMessage(final ParticipantMessageType messageType) { + this.messageType = messageType; + } + + /** + * Constructs the object, making a deep copy. Does <i>not</i> copy the request id or + * the time stamp. + * + * @param source source from which to copy + */ + public ParticipantMessage(final ParticipantMessage source) { + this.messageType = source.messageType; + this.participantId = source.participantId; + this.controlLoopId = source.controlLoopId; + } + + /** + * Determines if this message applies to this participant. + * + * @param participantId id of the participant to match against + * @return {@code true} if this message applies to this participant, {@code false} otherwise + */ + public boolean appliesTo(@NonNull final ToscaConceptIdentifier participantId) { + if (participantId.equals(this.participantId)) { + return true; + } + + // false: message included a participant ID, but it does not match + // true: its a broadcast message + return this.participantId == null; + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageType.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageType.java new file mode 100644 index 000000000..77a50bd36 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageType.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +/** + * Class to hold the possible values for the type of participant messages. + */ +public enum ParticipantMessageType { + + /** + * Used by participants to report status to the control loop runtime. + */ + PARTICIPANT_STATUS, + + /** + * Used by the control loop runtime to change the state of participants, triggers a PARTICIPANT_STATUS message with + * the result of the PARTICIPANT_STATE_CHANGE operation. + */ + PARTICIPANT_STATE_CHANGE, + + /** + * Used by the control loop runtime to update the control loops running on participants, triggers a + * PARTICIPANT_STATUS message with the result of the PARTICIPANT_CONTROL_LOOP_UPDATE operation. + */ + PARTICIPANT_CONTROL_LOOP_UPDATE, + + /** + * Used by the control loop runtime to change the state of control loops in participants, triggers a + * PARTICIPANT_STATUS message with the result of the PARTICIPANT_CONTROL_LOOP_STATE_CHANGE operation. + */ + PARTICIPANT_CONTROL_LOOP_STATE_CHANGE, + + /** + * Used by the control loop runtime to order a health check on participants, triggers a PARTICIPANT_STATUS message + * with the result of the PARTICIPANT_HEALTH_CHECK operation. + */ + PARTICIPANT_HEALTH_CHECK +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseDetails.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseDetails.java new file mode 100644 index 000000000..2c9bcd911 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseDetails.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import java.util.UUID; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +/** + * Class to represent participant response details. + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +public class ParticipantResponseDetails { + + // The responseTo field should match the original request id in the request. + private UUID responseTo; + private ParticipantResponseStatus responseStatus; + private String responseMessage; + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantResponseDetails(ParticipantResponseDetails source) { + this.responseMessage = source.responseMessage; + this.responseStatus = source.responseStatus; + this.responseTo = source.responseTo; + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseStatus.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseStatus.java new file mode 100644 index 000000000..95e9d7429 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseStatus.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +/** + * Class to hold the possible values for participant response status. + */ +public enum ParticipantResponseStatus { + + /** + * participant operation was successful. + */ + SUCCESS, + + /** + * participant operation failed. + */ + FAIL +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChange.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChange.java new file mode 100644 index 000000000..5f5150077 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChange.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; + +/** + * Class to represent the PARTICIPANT_STATE_CHANGE message that the control loop runtime will send to participants + * to change their state. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantStateChange extends ParticipantMessage { + private ParticipantState state; + + /** + * Constructor for instantiating ParticipantStateChange class with message name. + * + */ + public ParticipantStateChange() { + super(ParticipantMessageType.PARTICIPANT_STATE_CHANGE); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantStateChange(ParticipantStateChange source) { + super(source); + + this.state = source.state; + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java new file mode 100644 index 000000000..4bc865c3f --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.UUID; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent the PARTICIPANT_STATUS message that all the participants send to the control loop runtime. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantStatus extends ParticipantMessage { + // The response should be completed if this message is a response to a request from the Control Loop Runtime + private ParticipantResponseDetails response; + + // State and health status of the participant + private ParticipantState state; + private ParticipantHealthStatus healthStatus; + + // This map is a map of the state of all control loop elements the participant has. The ToscaConceptIdentifier key + // of the outer map is a key that identifies the control loop. There is an inner map for each control loop the + // participant has. Each inner map has the UUID that identifies the ControlLoopElement instance, and the value is + // the ControlLoopInstance itself. + private Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElement>> elements; + + // Description. May be left {@code null}. + private String message; + + /** + * Constructor for instantiating ParticipantStatus class with message name. + * + */ + public ParticipantStatus() { + super(ParticipantMessageType.PARTICIPANT_STATUS); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantStatus(final ParticipantStatus source) { + super(source); + + this.state = source.state; + this.healthStatus = source.healthStatus; + this.message = source.message; + this.elements = PfUtils.mapMap(elements, LinkedHashMap::new); + this.response = (source.response == null ? null : new ParticipantResponseDetails(source.response)); + } +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/SimpleResponse.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/SimpleResponse.java new file mode 100644 index 000000000..2bd09c632 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/SimpleResponse.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.rest; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * Response returned when no extra output fields are needed. + */ +@Getter +@Setter +@ToString +public class SimpleResponse { + + /** + * Optional detailed message in error cases. + */ + private String errorDetails; +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/commissioning/CommissioningResponse.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/commissioning/CommissioningResponse.java new file mode 100644 index 000000000..6363db8d2 --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/commissioning/CommissioningResponse.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.rest.commissioning; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Response to Commissioning requests that affect a change. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class CommissioningResponse extends SimpleResponse { + private List<ToscaConceptIdentifier> affectedControlLoopDefinitions; +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommand.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommand.java new file mode 100644 index 000000000..71b7ab92c --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommand.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.rest.instantiation; + +import java.util.List; +import lombok.Data; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +@Data +public class InstantiationCommand { + // The state to which the control loops are to be set + private ControlLoopOrderedState orderedState; + + // The list of control loops on which the command is to be issued + private List<ToscaConceptIdentifier> controlLoopIdentifierList; +} diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationResponse.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationResponse.java new file mode 100644 index 000000000..d932f29ac --- /dev/null +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationResponse.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.rest.instantiation; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Response to Commissioning requests that affect a change. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class InstantiationResponse extends SimpleResponse { + private List<ToscaConceptIdentifier> affectedControlLoops; +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java new file mode 100644 index 000000000..1fd304b79 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.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 java.util.Date; +import org.junit.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public class ClElementStatisticsTest { + @Test + public void testClElementStatisticsLombok() { + assertNotNull(new ClElementStatistics()); + ClElementStatistics cles0 = new ClElementStatistics(); + + assertThat(cles0.toString()).contains("ClElementStatistics("); + assertThat(cles0.hashCode()).isNotZero(); + assertEquals(true, cles0.equals(cles0)); + assertEquals(false, cles0.equals(null)); + + + ClElementStatistics cles1 = new ClElementStatistics(); + cles1.setControlLoopElementId(new ToscaConceptIdentifier("defName", "0.0.1")); + cles1.setTimeStamp(new Date(System.currentTimeMillis())); + + assertThat(cles1.toString()).contains("ClElementStatistics("); + assertEquals(false, cles1.hashCode() == 0); + assertEquals(false, cles1.equals(cles0)); + assertEquals(false, cles1.equals(null)); + + assertNotEquals(cles1, cles0); + + ClElementStatistics cles2 = new ClElementStatistics(); + + // @formatter:off + assertThatThrownBy(() -> cles2.setControlLoopElementId(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> cles2.setTimeStamp(null)). isInstanceOf(NullPointerException.class); + // @formatter:on + + assertEquals(cles2, cles0); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopConceptPojosTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopConceptPojosTest.java new file mode 100644 index 000000000..908c91417 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopConceptPojosTest.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.concepts; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.EqualsAndHashCodeMatchRule; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.NoPublicFieldsExceptStaticFinalRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import java.util.List; +import org.junit.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +public class ControlLoopConceptPojosTest { + + @Test + public void testPojos() { + List<PojoClass> pojoClasses = + PojoClassFactory.getPojoClasses(ControlLoopConceptPojosTest.class.getPackageName()); + + // @formatter:off + final Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new EqualsAndHashCodeMatchRule()) + .with(new NoPublicFieldsExceptStaticFinalRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .with(new ToStringTester()) + .build(); + + validator.validate(pojoClasses); + // @formatter:on + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java new file mode 100644 index 000000000..2264f6dc2 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.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 java.util.UUID; +import org.junit.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public class ControlLoopElementTest { + @Test + public void testControlLoopElement() { + + ControlLoopElement cle0 = new ControlLoopElement(); + + ControlLoopElement cle1 = new ControlLoopElement(cle0); + assertEquals(cle0, cle1); + } + + @Test + public void testControlLoopElementLombok() { + assertNotNull(new ControlLoopElement()); + ControlLoopElement cle0 = new ControlLoopElement(); + + assertThat(cle0.toString()).contains("ControlLoopElement("); + assertThat(cle0.hashCode()).isNotZero(); + assertEquals(true, cle0.equals(cle0)); + assertEquals(false, cle0.equals(null)); + + ControlLoopElement cle1 = new ControlLoopElement(); + + cle1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); + cle1.setDescription("Description"); + cle1.setId(UUID.randomUUID()); + cle1.setOrderedState(ControlLoopOrderedState.UNINITIALISED); + cle1.setParticipantId(new ToscaConceptIdentifier("id", "1.2.3")); + cle1.setState(ControlLoopState.UNINITIALISED); + + assertThat(cle1.toString()).contains("ControlLoopElement("); + assertEquals(false, cle1.hashCode() == 0); + assertEquals(false, cle1.equals(cle0)); + assertEquals(false, cle1.equals(null)); + + assertNotEquals(cle1, cle0); + + ControlLoopElement cle2 = new ControlLoopElement(); + + // @formatter:off + assertThatThrownBy(() -> cle2.setDefinition(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> cle2.setId(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> cle2.setOrderedState(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> cle2.setParticipantId(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> cle2.setState(null)). isInstanceOf(NullPointerException.class); + // @formatter:on + + assertNotEquals(cle2, cle0); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java new file mode 100644 index 000000000..05721b6a4 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.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.assertNull; + +import java.util.ArrayList; +import java.util.UUID; +import org.junit.Test; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public class ControlLoopTest { + @Test + public void testControlLoop() { + ControlLoop cl0 = new ControlLoop(); + cl0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3")); + assertEquals("dfName", cl0.getType()); + assertEquals("1.2.3", cl0.getTypeVersion()); + + ControlLoop cl1 = new ControlLoop(cl0); + assertEquals(cl0, cl1); + + assertEquals(0, cl0.compareTo(cl1)); + } + + @Test + public void testControlLoopLombok() { + assertNotNull(new ControlLoop()); + ControlLoop cl0 = new ControlLoop(); + + assertThat(cl0.toString()).contains("ControlLoop("); + assertEquals(false, cl0.hashCode() == 0); + assertEquals(true, cl0.equals(cl0)); + assertEquals(false, cl0.equals(null)); + + ControlLoop cl1 = new ControlLoop(); + + cl1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); + cl1.setDescription("Description"); + cl1.setElements(new ArrayList<>()); + cl1.setName("Name"); + cl1.setOrderedState(ControlLoopOrderedState.UNINITIALISED); + cl1.setState(ControlLoopState.UNINITIALISED); + cl1.setVersion("0.0.1"); + + assertThat(cl1.toString()).contains("ControlLoop("); + assertEquals(false, cl1.hashCode() == 0); + assertEquals(false, cl1.equals(cl0)); + assertEquals(false, cl1.equals(null)); + + assertNotEquals(cl1, cl0); + + ControlLoop cl2 = new ControlLoop(); + + // @formatter:off + assertThatThrownBy(() -> cl2.setDefinition(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> cl2.setOrderedState(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> cl2.setState(null)). isInstanceOf(NullPointerException.class); + // @formatter:on + + assertEquals(cl2, cl0); + + cl1.setCascadedOrderedState(ControlLoopOrderedState.PASSIVE); + assertEquals(ControlLoopOrderedState.PASSIVE, cl1.getOrderedState()); + + cl1.getElements().add(new ControlLoopElement()); + cl1.setCascadedOrderedState(ControlLoopOrderedState.RUNNING); + assertEquals(ControlLoopOrderedState.RUNNING, cl1.getOrderedState()); + assertEquals(ControlLoopOrderedState.RUNNING, cl1.getElements().get(0).getOrderedState()); + + assertNull(cl0.getElement(UUID.randomUUID())); + assertNull(cl1.getElement(UUID.randomUUID())); + assertEquals(cl1.getElements().get(0), cl1.getElement(cl1.getElements().get(0).getId())); + + assertEquals(PfKey.NULL_KEY_NAME, cl0.getDefinition().getName()); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java new file mode 100644 index 000000000..6f6913667 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.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 java.util.Date; +import org.junit.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public class ParticipantStatisticsTest { + @Test + public void testParticipantStatisticsLombok() { + assertNotNull(new ParticipantStatistics()); + ParticipantStatistics ps0 = new ParticipantStatistics(); + + assertThat(ps0.toString()).contains("ParticipantStatistics("); + assertThat(ps0.hashCode()).isNotZero(); + assertEquals(true, ps0.equals(ps0)); + assertEquals(false, ps0.equals(null)); + + + ParticipantStatistics ps1 = new ParticipantStatistics(); + ps1.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); + ps1.setTimeStamp(new Date(System.currentTimeMillis())); + + assertThat(ps1.toString()).contains("ParticipantStatistics("); + assertEquals(false, ps1.hashCode() == 0); + assertEquals(false, ps1.equals(ps0)); + assertEquals(false, ps1.equals(null)); + + assertNotEquals(ps1, ps0); + + ParticipantStatistics ps2 = new ParticipantStatistics(); + + // @formatter:off + assertThatThrownBy(() -> ps2.setParticipantId(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ps2.setTimeStamp(null)). isInstanceOf(NullPointerException.class); + // @formatter:on + + assertEquals(ps2, ps0); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantTest.java new file mode 100644 index 000000000..1eb80db09 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantTest.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.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 org.junit.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public class ParticipantTest { + @Test + public void testParticipant() { + + Participant p0 = new Participant(); + p0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3")); + assertEquals("dfName", p0.getType()); + assertEquals("1.2.3", p0.getTypeVersion()); + + Participant p1 = new Participant(p0); + assertEquals(p0, p1); + + assertEquals(0, p0.compareTo(p1)); + } + + @Test + public void testParticipantLombok() { + assertNotNull(new Participant()); + Participant p0 = new Participant(); + + assertThat(p0.toString()).contains("Participant("); + assertThat(p0.hashCode()).isNotZero(); + assertEquals(true, p0.equals(p0)); + assertEquals(false, p0.equals(null)); + + + Participant p1 = new Participant(); + + p1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); + p1.setDescription("Description"); + p1.setHealthStatus(ParticipantHealthStatus.HEALTHY); + p1.setName("Name"); + p1.setParticipantState(ParticipantState.ACTIVE); + p1.setVersion("0.0.1"); + + assertThat(p1.toString()).contains("Participant("); + assertEquals(false, p1.hashCode() == 0); + assertEquals(false, p1.equals(p0)); + assertEquals(false, p1.equals(null)); + + assertNotEquals(p1, p0); + + Participant p2 = new Participant(); + + // @formatter:off + assertThatThrownBy(() -> p2.setDefinition(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> p2.setHealthStatus(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> p2.setParticipantState(null)).isInstanceOf(NullPointerException.class); + // @formatter:on + + assertEquals(p2, p0); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaClElementStatisticsChild.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaClElementStatisticsChild.java new file mode 100644 index 000000000..b90ccba5b --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaClElementStatisticsChild.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts; + +/** + * Test class for {@link JpaClElementStatistics} comparisons. + */ +public class DummyJpaClElementStatisticsChild extends JpaClElementStatistics { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopChild.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopChild.java new file mode 100644 index 000000000..c4eb364d3 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopChild.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts; + +/** + * Test class for {@link JpaControlLoop} comparisons. + */ +public class DummyJpaControlLoopChild extends JpaControlLoop { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopElementChild.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopElementChild.java new file mode 100644 index 000000000..2082ff41c --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopElementChild.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts; + +/** + * Test class for {@link JpaControlLoopElement} comparisons. + */ +public class DummyJpaControlLoopElementChild extends JpaControlLoopElement { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantChild.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantChild.java new file mode 100644 index 000000000..e6bc92efb --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantChild.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts; + +/** + * Test class for {@link JpaParticipant} comparisons. + */ +public class DummyJpaParticipantChild extends JpaParticipant { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantStatisticsChild.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantStatisticsChild.java new file mode 100644 index 000000000..74dd40034 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantStatisticsChild.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts; + +/** + * Test class for {@link JpaParticipantStatistics} comparisons. + */ +public class DummyJpaParticipantStatisticsChild extends JpaParticipantStatistics { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java new file mode 100644 index 000000000..6f0b48585 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java @@ -0,0 +1,186 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.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 java.util.Date; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfTimestampKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the {@link JpaClElementStatistics} class. + */ +public class JpaClElementStatisticsTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + public void testJpaClElementStatisticsConstructor() { + assertThatThrownBy(() -> { + new JpaClElementStatistics((JpaClElementStatistics) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaClElementStatistics((PfTimestampKey) null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaClElementStatistics(null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaClElementStatistics(null, new PfConceptKey()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaClElementStatistics(new PfTimestampKey(), null); + }).hasMessageMatching("clElementId is marked .*ull but is null"); + + assertNotNull(new JpaClElementStatistics()); + assertNotNull(new JpaClElementStatistics((new PfTimestampKey()))); + assertNotNull(new JpaClElementStatistics(new PfTimestampKey(), new PfConceptKey())); + } + + @Test + public void testJpaClElementStatistics() { + JpaClElementStatistics testJpaClElementStatistics = createJpaClElementStatisticsInstance(); + + ClElementStatistics cles = createClElementStatisticsInstance(); + assertEquals(cles, testJpaClElementStatistics.toAuthorative()); + + assertThatThrownBy(() -> { + testJpaClElementStatistics.fromAuthorative(null); + }).hasMessageMatching("clElementStatistics is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaClElementStatistics((JpaClElementStatistics) null)) + .isInstanceOf(NullPointerException.class); + + JpaClElementStatistics testJpaClElementStatisticsFa = new JpaClElementStatistics(); + testJpaClElementStatisticsFa.setKey(null); + testJpaClElementStatisticsFa.fromAuthorative(cles); + assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa); + testJpaClElementStatisticsFa.setKey(PfTimestampKey.getNullKey()); + testJpaClElementStatisticsFa.fromAuthorative(cles); + assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa); + testJpaClElementStatisticsFa.setKey(new PfTimestampKey("elementName", "0.0.1", new Date(123456L))); + testJpaClElementStatisticsFa.fromAuthorative(cles); + assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa); + + testJpaClElementStatisticsFa = new JpaClElementStatistics(cles); + assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa); + + assertEquals(1, testJpaClElementStatistics.getKeys().size()); + + assertEquals("elementName", testJpaClElementStatistics.getKey().getName()); + + testJpaClElementStatistics.clean(); + assertEquals("elementName", testJpaClElementStatistics.getKey().getName()); + + JpaClElementStatistics testJpaClElementStatistics2 = new JpaClElementStatistics(testJpaClElementStatistics); + assertEquals(testJpaClElementStatistics, testJpaClElementStatistics2); + } + + @Test + public void testJpaClElementStatisticsValidation() { + JpaClElementStatistics testJpaClElementStatistics = createJpaClElementStatisticsInstance(); + + assertThatThrownBy(() -> { + testJpaClElementStatistics.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + assertTrue(testJpaClElementStatistics.validate("").isValid()); + } + + @Test + public void testJpaClElementStatisticsConmpareTo() { + JpaClElementStatistics testJpaClElementStatistics = createJpaClElementStatisticsInstance(); + + JpaClElementStatistics otherJpaClElementStatistics = new JpaClElementStatistics(testJpaClElementStatistics); + assertEquals(0, testJpaClElementStatistics.compareTo(otherJpaClElementStatistics)); + assertEquals(-1, testJpaClElementStatistics.compareTo(null)); + assertEquals(0, testJpaClElementStatistics.compareTo(testJpaClElementStatistics)); + assertNotEquals(0, testJpaClElementStatistics.compareTo(new DummyJpaClElementStatisticsChild())); + + testJpaClElementStatistics.setState(ControlLoopState.PASSIVE); + assertNotEquals(0, testJpaClElementStatistics.compareTo(otherJpaClElementStatistics)); + testJpaClElementStatistics.setState(ControlLoopState.UNINITIALISED); + assertEquals(0, testJpaClElementStatistics.compareTo(otherJpaClElementStatistics)); + + assertEquals(testJpaClElementStatistics, new JpaClElementStatistics(testJpaClElementStatistics)); + } + + @Test + public void testJpaClElementStatisticsLombok() { + assertNotNull(new Participant()); + JpaClElementStatistics cles0 = new JpaClElementStatistics(); + + assertThat(cles0.toString()).contains("JpaClElementStatistics("); + assertThat(cles0.hashCode()).isNotZero(); + assertEquals(true, cles0.equals(cles0)); + assertEquals(false, cles0.equals(null)); + + + JpaClElementStatistics cles11 = new JpaClElementStatistics(); + + cles11.setState(ControlLoopState.UNINITIALISED); + + assertThat(cles11.toString()).contains("JpaClElementStatistics("); + assertEquals(false, cles11.hashCode() == 0); + assertEquals(false, cles11.equals(cles0)); + assertEquals(false, cles11.equals(null)); + + assertNotEquals(cles11, cles0); + + JpaClElementStatistics cles2 = new JpaClElementStatistics(); + assertEquals(cles2, cles0); + } + + private JpaClElementStatistics createJpaClElementStatisticsInstance() { + ClElementStatistics testCles = createClElementStatisticsInstance(); + JpaClElementStatistics testJpaClElementStatistics = new JpaClElementStatistics(); + testJpaClElementStatistics.setKey(null); + testJpaClElementStatistics.fromAuthorative(testCles); + testJpaClElementStatistics.setKey(PfTimestampKey.getNullKey()); + testJpaClElementStatistics.fromAuthorative(testCles); + + return testJpaClElementStatistics; + } + + private ClElementStatistics createClElementStatisticsInstance() { + ClElementStatistics clElementStatistics = new ClElementStatistics(); + clElementStatistics.setControlLoopElementId(new ToscaConceptIdentifier("elementName", "0.0.1")); + clElementStatistics.setTimeStamp(new Date(123456L)); + clElementStatistics.setControlLoopState(ControlLoopState.UNINITIALISED); + + return clElementStatistics; + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java new file mode 100644 index 000000000..cd105a671 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java @@ -0,0 +1,300 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.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.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.util.UUID; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfReferenceKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the {@link JpaControlLoopElement} class. + */ +public class JpaControlLoopElementTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + public void testJpaControlLoopElementConstructor() { + assertThatThrownBy(() -> { + new JpaControlLoopElement((JpaControlLoopElement) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoopElement((PfReferenceKey) null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(null, null, null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(null, null, null, ControlLoopState.UNINITIALISED); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(null, null, new PfConceptKey("participant", "0.0.1"), null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(null, null, new PfConceptKey("participant", "0.0.1"), + ControlLoopState.UNINITIALISED); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(null, new PfConceptKey(), null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(null, new PfConceptKey(), null, ControlLoopState.UNINITIALISED); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"), null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"), + ControlLoopState.UNINITIALISED); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(new PfReferenceKey(), null, null, null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(new PfReferenceKey(), null, null, ControlLoopState.UNINITIALISED); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"), null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"), + ControlLoopState.UNINITIALISED); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), null, null); + }).hasMessageMatching("participantId is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), null, ControlLoopState.UNINITIALISED); + }).hasMessageMatching("participantId is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), + new PfConceptKey("participant", "0.0.1"), null); + }).hasMessageMatching("state is marked .*ull but is null"); + + assertNotNull(new JpaControlLoopElement()); + assertNotNull(new JpaControlLoopElement((new PfReferenceKey()))); + assertNotNull(new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), + new PfConceptKey("participant", "0.0.1"), ControlLoopState.UNINITIALISED)); + } + + @Test + public void testJpaControlLoopElement() { + JpaControlLoopElement testJpaControlLoopElement = createJpaControlLoopElementInstance(); + + ControlLoopElement cle = createControlLoopElementInstance(); + assertEquals(cle, testJpaControlLoopElement.toAuthorative()); + + assertThatThrownBy(() -> { + testJpaControlLoopElement.fromAuthorative(null); + }).hasMessageMatching("element is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaControlLoopElement((JpaControlLoopElement) null)) + .isInstanceOf(NullPointerException.class); + + JpaControlLoopElement testJpaControlLoopElementFa = new JpaControlLoopElement(); + testJpaControlLoopElementFa.setKey(null); + testJpaControlLoopElementFa.fromAuthorative(cle); + assertEquals(testJpaControlLoopElement, testJpaControlLoopElementFa); + testJpaControlLoopElementFa.setKey(PfReferenceKey.getNullKey()); + testJpaControlLoopElementFa.fromAuthorative(cle); + assertEquals(testJpaControlLoopElement, testJpaControlLoopElementFa); + testJpaControlLoopElementFa.setKey(new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, + "a95757ba-b34a-4049-a2a8-46773abcbe5e")); + testJpaControlLoopElementFa.fromAuthorative(cle); + assertEquals(testJpaControlLoopElement, testJpaControlLoopElementFa); + + assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", testJpaControlLoopElement.getKey().getLocalName()); + assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", + new JpaControlLoopElement(createControlLoopElementInstance()).getKey().getLocalName()); + assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", + ((PfReferenceKey) new JpaControlLoopElement(createControlLoopElementInstance()).getKeys().get(0)) + .getLocalName()); + + testJpaControlLoopElement.clean(); + assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", testJpaControlLoopElement.getKey().getLocalName()); + + testJpaControlLoopElement.setDescription(" A Message "); + testJpaControlLoopElement.clean(); + assertEquals("A Message", testJpaControlLoopElement.getDescription()); + + JpaControlLoopElement testJpaControlLoopElement2 = new JpaControlLoopElement(testJpaControlLoopElement); + assertEquals(testJpaControlLoopElement, testJpaControlLoopElement2); + } + + @Test + public void testJpaControlLoopElementOrderedState() throws CoderException { + ControlLoopElement testControlLoopElement = createControlLoopElementInstance(); + JpaControlLoopElement testJpaControlLoopElement = createJpaControlLoopElementInstance(); + + testJpaControlLoopElement.setOrderedState(null); + assertEquals(testControlLoopElement, testJpaControlLoopElement.toAuthorative()); + testJpaControlLoopElement.setOrderedState(ControlLoopOrderedState.UNINITIALISED); + + ControlLoopElement noOrderedStateCle = new StandardCoder().decode( + new File("src/test/resources/json/ControlLoopElementNoOrderedState.json"), ControlLoopElement.class); + + JpaControlLoopElement noOrderedStateJpaCle = new JpaControlLoopElement(noOrderedStateCle); + assertNull(noOrderedStateJpaCle.getOrderedState()); + noOrderedStateCle.setOrderedState(ControlLoopOrderedState.UNINITIALISED); + noOrderedStateJpaCle = new JpaControlLoopElement(noOrderedStateCle); + assertEquals(testJpaControlLoopElement, noOrderedStateJpaCle); + } + + @Test + public void testJpaControlLoopElementValidation() { + JpaControlLoopElement testJpaControlLoopElement = createJpaControlLoopElementInstance(); + + assertThatThrownBy(() -> { + testJpaControlLoopElement.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + assertTrue(testJpaControlLoopElement.validate("").isValid()); + } + + @Test + public void testJpaControlLoopElementCompareTo() { + JpaControlLoopElement testJpaControlLoopElement = createJpaControlLoopElementInstance(); + + JpaControlLoopElement otherJpaControlLoopElement = new JpaControlLoopElement(testJpaControlLoopElement); + assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); + assertEquals(-1, testJpaControlLoopElement.compareTo(null)); + assertEquals(0, testJpaControlLoopElement.compareTo(testJpaControlLoopElement)); + assertNotEquals(0, testJpaControlLoopElement.compareTo(new DummyJpaControlLoopElementChild())); + + testJpaControlLoopElement + .setKey(new PfReferenceKey("BadValue", "0.0.1", "a95757ba-b34a-4049-a2a8-46773abcbe5e")); + assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); + testJpaControlLoopElement.setKey(new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, + "a95757ba-b34a-4049-a2a8-46773abcbe5e")); + assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); + + testJpaControlLoopElement.setDefinition(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); + testJpaControlLoopElement.setDefinition(new PfConceptKey("cleDef", "0.0.1")); + assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); + + testJpaControlLoopElement.setDescription("Description"); + assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); + testJpaControlLoopElement.setDescription(null); + assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); + + testJpaControlLoopElement.setOrderedState(ControlLoopOrderedState.PASSIVE); + assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); + testJpaControlLoopElement.setOrderedState(ControlLoopOrderedState.UNINITIALISED); + assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); + + testJpaControlLoopElement.setState(ControlLoopState.PASSIVE); + assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); + testJpaControlLoopElement.setState(ControlLoopState.UNINITIALISED); + assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); + + testJpaControlLoopElement.setParticipantId(new PfConceptKey("dummy", "0.0.1")); + assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); + testJpaControlLoopElement.setParticipantId(new PfConceptKey("participant", "0.0.1")); + assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); + + assertEquals(testJpaControlLoopElement, new JpaControlLoopElement(testJpaControlLoopElement)); + } + + @Test + public void testJpaControlLoopElementLombok() { + assertNotNull(new Participant()); + JpaControlLoopElement cle0 = new JpaControlLoopElement(); + + assertThat(cle0.toString()).contains("JpaControlLoopElement("); + assertThat(cle0.hashCode()).isNotZero(); + assertEquals(true, cle0.equals(cle0)); + assertEquals(false, cle0.equals(null)); + + + JpaControlLoopElement cle1 = new JpaControlLoopElement(); + + cle1.setDefinition(new PfConceptKey("defName", "0.0.1")); + cle1.setDescription("Description"); + cle1.setOrderedState(ControlLoopOrderedState.UNINITIALISED); + cle1.setState(ControlLoopState.UNINITIALISED); + cle1.setParticipantId(new PfConceptKey("participant", "0.0.1")); + + assertThat(cle1.toString()).contains("ControlLoopElement("); + assertEquals(false, cle1.hashCode() == 0); + assertEquals(false, cle1.equals(cle0)); + assertEquals(false, cle1.equals(null)); + + assertNotEquals(cle1, cle0); + + JpaControlLoopElement cle2 = new JpaControlLoopElement(); + assertEquals(cle2, cle0); + } + + private JpaControlLoopElement createJpaControlLoopElementInstance() { + ControlLoopElement testCle = createControlLoopElementInstance(); + JpaControlLoopElement testJpaControlLoopElement = new JpaControlLoopElement(); + testJpaControlLoopElement.setKey(null); + testJpaControlLoopElement.fromAuthorative(testCle); + testJpaControlLoopElement.setKey(PfReferenceKey.getNullKey()); + testJpaControlLoopElement.fromAuthorative(testCle); + + return testJpaControlLoopElement; + } + + private ControlLoopElement createControlLoopElementInstance() { + ControlLoopElement controlLoopElement = new ControlLoopElement(); + controlLoopElement.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e")); + controlLoopElement.setDefinition(new ToscaConceptIdentifier("cleDef", "0.0.1")); + controlLoopElement.setParticipantId(new ToscaConceptIdentifier("participant", "0.0.1")); + + return controlLoopElement; + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java new file mode 100644 index 000000000..7ef7e3276 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java @@ -0,0 +1,296 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +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.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.util.ArrayList; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the {@link JpaControlLoopTest} class. + */ +public class JpaControlLoopTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + public void testJpaControlLoopConstructor() { + assertThatThrownBy(() -> { + new JpaControlLoop((JpaControlLoop) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoop((PfConceptKey) null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoop(null, null, null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoop(null, null, null, new ArrayList<>()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoop(null, null, ControlLoopState.UNINITIALISED, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoop(null, null, ControlLoopState.UNINITIALISED, new ArrayList<>()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoop(null, new PfConceptKey(), null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoop(null, new PfConceptKey(), null, new ArrayList<>()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoop(null, new PfConceptKey(), ControlLoopState.UNINITIALISED, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoop(null, new PfConceptKey(), ControlLoopState.UNINITIALISED, new ArrayList<>()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaControlLoop(new PfConceptKey(), null, null, null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoop(new PfConceptKey(), null, null, new ArrayList<>()); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoop(new PfConceptKey(), null, ControlLoopState.UNINITIALISED, null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoop(new PfConceptKey(), null, ControlLoopState.UNINITIALISED, new ArrayList<>()); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), null, null); + }).hasMessageMatching("state is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), null, new ArrayList<>()); + }).hasMessageMatching("state is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), ControlLoopState.UNINITIALISED, null); + }).hasMessageMatching("elements is marked .*ull but is null"); + + assertNotNull(new JpaControlLoop()); + assertNotNull(new JpaControlLoop((new PfConceptKey()))); + assertNotNull(new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), ControlLoopState.UNINITIALISED, + new ArrayList<>())); + } + + @Test + public void testJpaControlLoop() { + JpaControlLoop testJpaControlLoop = createJpaControlLoopInstance(); + + ControlLoop participant = createControlLoopInstance(); + assertEquals(participant, testJpaControlLoop.toAuthorative()); + + assertThatThrownBy(() -> { + testJpaControlLoop.fromAuthorative(null); + }).hasMessageMatching("controlLoop is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaControlLoop((JpaControlLoop) null)).isInstanceOf(NullPointerException.class); + + JpaControlLoop testJpaControlLoopFa = new JpaControlLoop(); + testJpaControlLoopFa.setKey(null); + testJpaControlLoopFa.fromAuthorative(participant); + assertEquals(testJpaControlLoop, testJpaControlLoopFa); + testJpaControlLoopFa.setKey(PfConceptKey.getNullKey()); + testJpaControlLoopFa.fromAuthorative(participant); + assertEquals(testJpaControlLoop, testJpaControlLoopFa); + testJpaControlLoopFa.setKey(new PfConceptKey("control-loop", "0.0.1")); + testJpaControlLoopFa.fromAuthorative(participant); + assertEquals(testJpaControlLoop, testJpaControlLoopFa); + + assertEquals("control-loop", testJpaControlLoop.getKey().getName()); + assertEquals("control-loop", new JpaControlLoop(createControlLoopInstance()).getKey().getName()); + assertEquals("control-loop", + ((PfConceptKey) new JpaControlLoop(createControlLoopInstance()).getKeys().get(0)).getName()); + + testJpaControlLoop.clean(); + assertEquals("control-loop", testJpaControlLoop.getKey().getName()); + + testJpaControlLoop.setDescription(" A Message "); + testJpaControlLoop.clean(); + assertEquals("A Message", testJpaControlLoop.getDescription()); + + JpaControlLoop testJpaControlLoop2 = new JpaControlLoop(testJpaControlLoop); + assertEquals(testJpaControlLoop, testJpaControlLoop2); + } + + @Test + public void testJpaControlLoopElementOrderedState() throws CoderException { + ControlLoop testControlLoop = createControlLoopInstance(); + JpaControlLoop testJpaControlLoop = createJpaControlLoopInstance(); + + testJpaControlLoop.setOrderedState(null); + assertEquals(testControlLoop, testJpaControlLoop.toAuthorative()); + testJpaControlLoop.setOrderedState(ControlLoopOrderedState.UNINITIALISED); + + ControlLoop noOrderedStateCl = new StandardCoder() + .decode(new File("src/test/resources/json/ControlLoopNoOrderedState.json"), ControlLoop.class); + + JpaControlLoop noOrderedStateJpaCl = new JpaControlLoop(noOrderedStateCl); + assertNull(noOrderedStateJpaCl.getOrderedState()); + noOrderedStateCl.setOrderedState(ControlLoopOrderedState.UNINITIALISED); + noOrderedStateJpaCl = new JpaControlLoop(noOrderedStateCl); + assertEquals(testJpaControlLoop, noOrderedStateJpaCl); + + ControlLoops controlLoopsWithElements = new StandardCoder() + .decode(new File("src/test/resources/providers/TestControlLoops.json"), ControlLoops.class); + + JpaControlLoop jpaControlLoopWithElements = + new JpaControlLoop(controlLoopsWithElements.getControlLoopList().get(0)); + assertEquals(4, jpaControlLoopWithElements.getElements().size()); + assertEquals(14, jpaControlLoopWithElements.getKeys().size()); + assertThatCode(() -> jpaControlLoopWithElements.clean()).doesNotThrowAnyException(); + + assertEquals(controlLoopsWithElements.getControlLoopList().get(0), jpaControlLoopWithElements.toAuthorative()); + } + + @Test + public void testJpaControlLoopValidation() { + JpaControlLoop testJpaControlLoop = createJpaControlLoopInstance(); + + assertThatThrownBy(() -> { + testJpaControlLoop.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + assertTrue(testJpaControlLoop.validate("").isValid()); + } + + @Test + public void testJpaControlLoopCompareTo() { + JpaControlLoop testJpaControlLoop = createJpaControlLoopInstance(); + + JpaControlLoop otherJpaControlLoop = new JpaControlLoop(testJpaControlLoop); + assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); + assertEquals(-1, testJpaControlLoop.compareTo(null)); + assertEquals(0, testJpaControlLoop.compareTo(testJpaControlLoop)); + assertNotEquals(0, testJpaControlLoop.compareTo(new DummyJpaControlLoopChild())); + + testJpaControlLoop.setKey(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); + testJpaControlLoop.setKey(new PfConceptKey("control-loop", "0.0.1")); + assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); + + testJpaControlLoop.setDefinition(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); + testJpaControlLoop.setDefinition(new PfConceptKey("controlLoopDefinitionName", "0.0.1")); + assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); + + testJpaControlLoop.setState(ControlLoopState.PASSIVE); + assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); + testJpaControlLoop.setState(ControlLoopState.UNINITIALISED); + assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); + + testJpaControlLoop.setOrderedState(ControlLoopOrderedState.PASSIVE); + assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); + testJpaControlLoop.setOrderedState(ControlLoopOrderedState.UNINITIALISED); + assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); + + testJpaControlLoop.setDescription("A description"); + assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); + testJpaControlLoop.setDescription(null); + assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); + + assertEquals(testJpaControlLoop, new JpaControlLoop(testJpaControlLoop)); + } + + @Test + public void testJpaControlLoopLombok() { + assertNotNull(new ControlLoop()); + JpaControlLoop cl0 = new JpaControlLoop(); + + assertThat(cl0.toString()).contains("JpaControlLoop("); + assertThat(cl0.hashCode()).isNotZero(); + assertEquals(true, cl0.equals(cl0)); + assertEquals(false, cl0.equals(null)); + + + JpaControlLoop cl1 = new JpaControlLoop(); + + cl1.setDefinition(new PfConceptKey("defName", "0.0.1")); + cl1.setDescription("Description"); + cl1.setElements(new ArrayList<>()); + cl1.setKey(new PfConceptKey("participant", "0.0.1")); + cl1.setState(ControlLoopState.UNINITIALISED); + + assertThat(cl1.toString()).contains("ControlLoop("); + assertEquals(false, cl1.hashCode() == 0); + assertEquals(false, cl1.equals(cl0)); + assertEquals(false, cl1.equals(null)); + + assertNotEquals(cl1, cl0); + + JpaControlLoop cl2 = new JpaControlLoop(); + assertEquals(cl2, cl0); + } + + private JpaControlLoop createJpaControlLoopInstance() { + ControlLoop testControlLoop = createControlLoopInstance(); + JpaControlLoop testJpaControlLoop = new JpaControlLoop(); + testJpaControlLoop.setKey(null); + testJpaControlLoop.fromAuthorative(testControlLoop); + testJpaControlLoop.setKey(PfConceptKey.getNullKey()); + testJpaControlLoop.fromAuthorative(testControlLoop); + + return testJpaControlLoop; + } + + private ControlLoop createControlLoopInstance() { + ControlLoop testControlLoop = new ControlLoop(); + testControlLoop.setName("control-loop"); + testControlLoop.setVersion("0.0.1"); + testControlLoop.setDefinition(new ToscaConceptIdentifier("controlLoopDefinitionName", "0.0.1")); + testControlLoop.setElements(new ArrayList<>()); + + return testControlLoop; + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java new file mode 100644 index 000000000..464e97c49 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java @@ -0,0 +1,192 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.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 java.util.Date; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfTimestampKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the {@link JpaParticipantStatistics} class. + */ +public class JpaParticipantStatisticsTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + public void testJpaParticipantStatisticsConstructor() { + assertThatThrownBy(() -> { + new JpaParticipantStatistics((JpaParticipantStatistics) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipantStatistics((PfTimestampKey) null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipantStatistics(null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipantStatistics(null, new PfConceptKey()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipantStatistics(new PfTimestampKey(), null); + }).hasMessageMatching("participantId is marked .*ull but is null"); + + assertNotNull(new JpaParticipantStatistics()); + assertNotNull(new JpaParticipantStatistics((new PfTimestampKey()))); + assertNotNull(new JpaParticipantStatistics(new PfTimestampKey(), new PfConceptKey())); + } + + @Test + public void testJpaParticipantStatistics() { + JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance(); + + ParticipantStatistics cles = createParticipantStatisticsInstance(); + assertEquals(cles, testJpaParticipantStatistics.toAuthorative()); + + assertThatThrownBy(() -> { + testJpaParticipantStatistics.fromAuthorative(null); + }).hasMessageMatching("participantStatistics is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaParticipantStatistics((JpaParticipantStatistics) null)) + .isInstanceOf(NullPointerException.class); + + JpaParticipantStatistics testJpaParticipantStatisticsFa = new JpaParticipantStatistics(); + testJpaParticipantStatisticsFa.setKey(null); + testJpaParticipantStatisticsFa.fromAuthorative(cles); + assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); + testJpaParticipantStatisticsFa.setKey(PfTimestampKey.getNullKey()); + testJpaParticipantStatisticsFa.fromAuthorative(cles); + assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); + testJpaParticipantStatisticsFa.setKey(new PfTimestampKey("participantName", "0.0.1", new Date(123456L))); + testJpaParticipantStatisticsFa.fromAuthorative(cles); + assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); + + testJpaParticipantStatisticsFa = new JpaParticipantStatistics(cles); + assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); + + assertEquals(2, testJpaParticipantStatistics.getKeys().size()); + + assertEquals("participantName", testJpaParticipantStatistics.getKey().getName()); + + testJpaParticipantStatistics.clean(); + assertEquals("participantName", testJpaParticipantStatistics.getKey().getName()); + + JpaParticipantStatistics testJpaParticipantStatistics2 = + new JpaParticipantStatistics(testJpaParticipantStatistics); + assertEquals(testJpaParticipantStatistics, testJpaParticipantStatistics2); + } + + @Test + public void testJpaParticipantStatisticsValidation() { + JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance(); + + assertThatThrownBy(() -> { + testJpaParticipantStatistics.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + BeanValidationResult validationResult = testJpaParticipantStatistics.validate(""); + assertTrue(validationResult.isValid()); + } + + @Test + public void testJpaParticipantStatisticsConmpareTo() { + JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance(); + + JpaParticipantStatistics otherJpaParticipantStatistics = + new JpaParticipantStatistics(testJpaParticipantStatistics); + assertEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics)); + assertEquals(-1, testJpaParticipantStatistics.compareTo(null)); + assertEquals(0, testJpaParticipantStatistics.compareTo(testJpaParticipantStatistics)); + assertNotEquals(0, testJpaParticipantStatistics.compareTo(new DummyJpaParticipantStatisticsChild())); + + testJpaParticipantStatistics.setState(ParticipantState.UNKNOWN); + assertNotEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics)); + testJpaParticipantStatistics.setState(ParticipantState.PASSIVE); + assertEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics)); + + assertEquals(testJpaParticipantStatistics, new JpaParticipantStatistics(testJpaParticipantStatistics)); + } + + @Test + public void testJpaParticipantStatisticsLombok() { + assertNotNull(new Participant()); + JpaParticipantStatistics ps0 = new JpaParticipantStatistics(); + + assertThat(ps0.toString()).contains("JpaParticipantStatistics("); + assertThat(ps0.hashCode()).isNotZero(); + assertEquals(true, ps0.equals(ps0)); + assertEquals(false, ps0.equals(null)); + + + JpaParticipantStatistics ps1 = new JpaParticipantStatistics(); + + ps1.setState(ParticipantState.UNKNOWN); + + assertThat(ps1.toString()).contains("JpaParticipantStatistics("); + assertEquals(false, ps1.hashCode() == 0); + assertEquals(false, ps1.equals(ps0)); + assertEquals(false, ps1.equals(null)); + + assertNotEquals(ps1, ps0); + + JpaParticipantStatistics ps2 = new JpaParticipantStatistics(); + assertEquals(ps2, ps0); + } + + private JpaParticipantStatistics createJpaParticipantStatisticsInstance() { + ParticipantStatistics testCles = createParticipantStatisticsInstance(); + JpaParticipantStatistics testJpaParticipantStatistics = new JpaParticipantStatistics(); + testJpaParticipantStatistics.setKey(null); + testJpaParticipantStatistics.fromAuthorative(testCles); + testJpaParticipantStatistics.setKey(PfTimestampKey.getNullKey()); + testJpaParticipantStatistics.fromAuthorative(testCles); + + return testJpaParticipantStatistics; + } + + private ParticipantStatistics createParticipantStatisticsInstance() { + ParticipantStatistics participantStatistics = new ParticipantStatistics(); + participantStatistics.setParticipantId(new ToscaConceptIdentifier("participantName", "0.0.1")); + participantStatistics.setTimeStamp(new Date(123456L)); + participantStatistics.setState(ParticipantState.PASSIVE); + participantStatistics.setHealthStatus(ParticipantHealthStatus.HEALTHY); + + return participantStatistics; + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantTest.java new file mode 100644 index 000000000..5c96df6f1 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantTest.java @@ -0,0 +1,253 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.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.clamp.controlloop.models.controlloop.concepts.Participant; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the {@link JpaParticiant} class. + */ +public class JpaParticipantTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + public void testJpaParticipantConstructor() { + assertThatThrownBy(() -> { + new JpaParticipant((JpaParticipant) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant((PfConceptKey) null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, null, null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, null, null, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, null, ParticipantState.ACTIVE, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, null, ParticipantState.ACTIVE, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, new PfConceptKey(), null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, new PfConceptKey(), null, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, new PfConceptKey(), ParticipantState.ACTIVE, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, new PfConceptKey(), ParticipantState.ACTIVE, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), null, null, null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), null, null, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), null, ParticipantState.ACTIVE, null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), null, ParticipantState.ACTIVE, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), new PfConceptKey(), null, null); + }).hasMessageMatching("participantState is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), new PfConceptKey(), null, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching("participantState is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), new PfConceptKey(), ParticipantState.ACTIVE, null); + }).hasMessageMatching("healthStatus is marked .*ull but is null"); + + assertNotNull(new JpaParticipant()); + assertNotNull(new JpaParticipant((new PfConceptKey()))); + assertNotNull(new JpaParticipant(new PfConceptKey(), new PfConceptKey(), ParticipantState.ACTIVE, + ParticipantHealthStatus.HEALTHY)); + } + + @Test + public void testJpaParticipant() { + JpaParticipant testJpaParticipant = createJpaParticipantInstance(); + + Participant participant = createParticipantInstance(); + assertEquals(participant, testJpaParticipant.toAuthorative()); + + assertThatThrownBy(() -> { + testJpaParticipant.fromAuthorative(null); + }).hasMessageMatching("participant is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaParticipant((JpaParticipant) null)).isInstanceOf(NullPointerException.class); + + JpaParticipant testJpaParticipantFa = new JpaParticipant(); + testJpaParticipantFa.setKey(null); + testJpaParticipantFa.fromAuthorative(participant); + assertEquals(testJpaParticipant, testJpaParticipantFa); + testJpaParticipantFa.setKey(PfConceptKey.getNullKey()); + testJpaParticipantFa.fromAuthorative(participant); + assertEquals(testJpaParticipant, testJpaParticipantFa); + testJpaParticipantFa.setKey(new PfConceptKey("participant", "0.0.1")); + testJpaParticipantFa.fromAuthorative(participant); + assertEquals(testJpaParticipant, testJpaParticipantFa); + + assertEquals("participant", testJpaParticipant.getKey().getName()); + assertEquals("participant", new JpaParticipant(createParticipantInstance()).getKey().getName()); + assertEquals("participant", + ((PfConceptKey) new JpaParticipant(createParticipantInstance()).getKeys().get(0)).getName()); + + testJpaParticipant.clean(); + assertEquals("participant", testJpaParticipant.getKey().getName()); + + testJpaParticipant.setDescription(" A Message "); + testJpaParticipant.clean(); + assertEquals("A Message", testJpaParticipant.getDescription()); + + JpaParticipant testJpaParticipant2 = new JpaParticipant(testJpaParticipant); + assertEquals(testJpaParticipant, testJpaParticipant2); + } + + @Test + public void testJpaParticipantValidation() { + JpaParticipant testJpaParticipant = createJpaParticipantInstance(); + + assertThatThrownBy(() -> { + testJpaParticipant.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + assertTrue(testJpaParticipant.validate("").isValid()); + } + + @Test + public void testJpaParticipantCompareTo() { + JpaParticipant testJpaParticipant = createJpaParticipantInstance(); + + JpaParticipant otherJpaParticipant = new JpaParticipant(testJpaParticipant); + assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + assertEquals(-1, testJpaParticipant.compareTo(null)); + assertEquals(0, testJpaParticipant.compareTo(testJpaParticipant)); + assertNotEquals(0, testJpaParticipant.compareTo(new DummyJpaParticipantChild())); + + testJpaParticipant.setKey(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + testJpaParticipant.setKey(new PfConceptKey("participant", "0.0.1")); + assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + + testJpaParticipant.setDefinition(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + testJpaParticipant.setDefinition(new PfConceptKey("participantDefinitionName", "0.0.1")); + assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + + testJpaParticipant.setParticipantState(ParticipantState.PASSIVE); + assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + testJpaParticipant.setParticipantState(ParticipantState.UNKNOWN); + assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + + testJpaParticipant.setHealthStatus(ParticipantHealthStatus.NOT_HEALTHY); + assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + testJpaParticipant.setHealthStatus(ParticipantHealthStatus.UNKNOWN); + assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + + assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant)); + } + + @Test + public void testJpaParticipantLombok() { + assertNotNull(new Participant()); + JpaParticipant p0 = new JpaParticipant(); + + assertThat(p0.toString()).contains("JpaParticipant("); + assertThat(p0.hashCode()).isNotZero(); + assertEquals(true, p0.equals(p0)); + assertEquals(false, p0.equals(null)); + + + JpaParticipant p1 = new JpaParticipant(); + + p1.setDefinition(new PfConceptKey("defName", "0.0.1")); + p1.setDescription("Description"); + p1.setHealthStatus(ParticipantHealthStatus.HEALTHY); + p1.setKey(new PfConceptKey("participant", "0.0.1")); + p1.setParticipantState(ParticipantState.ACTIVE); + + assertThat(p1.toString()).contains("Participant("); + assertEquals(false, p1.hashCode() == 0); + assertEquals(false, p1.equals(p0)); + assertEquals(false, p1.equals(null)); + + assertNotEquals(p1, p0); + + JpaParticipant p2 = new JpaParticipant(); + assertEquals(p2, p0); + } + + private JpaParticipant createJpaParticipantInstance() { + Participant testParticipant = createParticipantInstance(); + JpaParticipant testJpaParticipant = new JpaParticipant(); + testJpaParticipant.setKey(null); + testJpaParticipant.fromAuthorative(testParticipant); + testJpaParticipant.setKey(PfConceptKey.getNullKey()); + testJpaParticipant.fromAuthorative(testParticipant); + + return testJpaParticipant; + } + + private Participant createParticipantInstance() { + Participant testParticipant = new Participant(); + testParticipant.setName("participant"); + testParticipant.setVersion("0.0.1"); + testParticipant.setDefinition(new ToscaConceptIdentifier("participantDefinitionName", "0.0.1")); + + return testParticipant; + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/PojosTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/PojosTest.java new file mode 100644 index 000000000..9e21b216b --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/PojosTest.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.EqualsAndHashCodeMatchRule; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.NoPublicFieldsExceptStaticFinalRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import java.util.List; +import org.junit.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +public class PojosTest { + + @Test + public void testPojos() { + List<PojoClass> pojoClasses = + PojoClassFactory.getPojoClasses(PojosTest.class.getPackageName()); + + // @formatter:off + final Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new EqualsAndHashCodeMatchRule()) + .with(new NoPublicFieldsExceptStaticFinalRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .with(new ToStringTester()) + .build(); + + validator.validate(pojoClasses); + // @formatter:on + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java new file mode 100644 index 000000000..c6304a030 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java @@ -0,0 +1,113 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import java.util.Date; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public class ClElementStatisticsProviderTest { + private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; + private static final Coder CODER = new StandardCoder(); + private static final String CL_ELEMENT_STATS_JSON = + "src/test/resources/providers/TestClElementStatistics.json"; + + private static AtomicInteger dbNameCounter = new AtomicInteger(); + + private PolicyModelsProviderParameters parameters; + private ClElementStatisticsProvider clElementStatisticsProvider; + private ClElementStatisticsList inputClElementStats; + private String originalJson = ResourceUtils.getResourceAsString(CL_ELEMENT_STATS_JSON); + + /** + * Set up test ClElement statistics provider. + */ + @Before + public void setupDao() throws Exception { + + parameters = new PolicyModelsProviderParameters(); + parameters.setDatabaseDriver("org.h2.Driver"); + parameters.setName("PolicyProviderParameterGroup"); + parameters.setImplementation("org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl"); + parameters.setDatabaseUrl("jdbc:h2:mem:clElementTestDb" + dbNameCounter.getAndIncrement()); + parameters.setDatabaseUser("policy"); + parameters.setDatabasePassword("P01icY"); + parameters.setPersistenceUnit("ToscaConceptTest"); + + clElementStatisticsProvider = new ClElementStatisticsProvider(parameters); + inputClElementStats = CODER.decode(originalJson, ClElementStatisticsList.class); + } + + @After + public void teardown() { + clElementStatisticsProvider.close(); + } + + @Test + public void testClElementStatisticsCreate() throws Exception { + assertThatThrownBy(() -> { + clElementStatisticsProvider.createClElementStatistics(null); + }).hasMessageMatching(LIST_IS_NULL); + + ClElementStatisticsList createdClElementStats = new ClElementStatisticsList(); + createdClElementStats.setClElementStatistics(clElementStatisticsProvider + .createClElementStatistics(inputClElementStats.getClElementStatistics())); + + assertEquals(inputClElementStats.toString().replaceAll("\\s+", ""), + createdClElementStats.toString().replaceAll("\\s+", "")); + } + + @Test + public void testGetClElementStatistics() throws Exception { + + List<ClElementStatistics> getResponse; + + //Return empty list when no data present in db + getResponse = clElementStatisticsProvider.getClElementStatistics(null, null, null); + assertThat(getResponse).isEmpty(); + + clElementStatisticsProvider.createClElementStatistics(inputClElementStats + .getClElementStatistics()); + ToscaConceptIdentifier identifier = inputClElementStats.getClElementStatistics().get(0) + .getControlLoopElementId(); + Date date = inputClElementStats.getClElementStatistics().get(0).getTimeStamp(); + assertEquals(1, clElementStatisticsProvider.getClElementStatistics(identifier.getName(), + identifier.getVersion(), date).size()); + + assertEquals(1, clElementStatisticsProvider.getFilteredClElementStatistics("name2", + "1.0.1", null, null, null, + "DESC", 1).size()); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java new file mode 100644 index 000000000..fb443c82e --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java @@ -0,0 +1,163 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider; + +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.assertNull; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; + +public class ControlLoopProviderTest { + + private static final String LIST_IS_NULL = "controlLoops is marked .*ull but is null"; + private static final Coder CODER = new StandardCoder(); + private static final String CONTROL_LOOP_JSON = "src/test/resources/providers/TestControlLoops.json"; + private static final String UPDATE_CL_JSON = "src/test/resources/providers/UpdateControlLoops.json"; + + private static AtomicInteger dbNameCounter = new AtomicInteger(); + + private PolicyModelsProviderParameters parameters; + private ControlLoopProvider controlLoopProvider; + private ControlLoops inputControlLoops; + private ControlLoops updateControlLoops; + private String originalJson = ResourceUtils.getResourceAsString(CONTROL_LOOP_JSON); + private String updateClJson = ResourceUtils.getResourceAsString(UPDATE_CL_JSON); + + /** + * Set up test control loop provider. + */ + @Before + public void setupDao() throws Exception { + + parameters = new PolicyModelsProviderParameters(); + parameters.setDatabaseDriver("org.h2.Driver"); + parameters.setName("PolicyProviderParameterGroup"); + parameters.setImplementation("org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl"); + parameters.setDatabaseUrl("jdbc:h2:mem:controlLoopProviderTestDb" + dbNameCounter.getAndDecrement()); + parameters.setDatabaseUser("policy"); + parameters.setDatabasePassword("P01icY"); + parameters.setPersistenceUnit("ToscaConceptTest"); + + controlLoopProvider = new ControlLoopProvider(parameters); + + inputControlLoops = CODER.decode(originalJson, ControlLoops.class); + updateControlLoops = CODER.decode(updateClJson, ControlLoops.class); + } + + @After + public void teardown() { + controlLoopProvider.close(); + } + + @Test + public void testControlLoopCreate() throws Exception { + assertThatThrownBy(() -> { + controlLoopProvider.createControlLoops(null); + }).hasMessageMatching(LIST_IS_NULL); + + ControlLoops createdControlLoops = new ControlLoops(); + createdControlLoops + .setControlLoopList(controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList())); + String createdJson = CODER.encode(createdControlLoops, true); + + System.err.println(originalJson); + System.out.println(createdJson); + assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", "")); + } + + @Test + public void testGetControlLoops() throws Exception { + + List<ControlLoop> getResponse; + + // Return empty list when no data present in db + getResponse = controlLoopProvider.getControlLoops(null, null); + assertThat(getResponse).isEmpty(); + + controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList()); + String name = inputControlLoops.getControlLoopList().get(0).getName(); + String version = inputControlLoops.getControlLoopList().get(0).getVersion(); + assertEquals(1, controlLoopProvider.getControlLoops(name, version).size()); + + ControlLoop cl = new ControlLoop(); + cl = controlLoopProvider.getControlLoop(new ToscaConceptIdentifier("PMSHInstance1", "1.0.1")); + assertEquals(inputControlLoops.getControlLoopList().get(1), cl); + + assertNull(controlLoopProvider.getControlLoop(new ToscaConceptIdentifier("invalid_name", "1.0.1"))); + + assertThatThrownBy(() -> { + controlLoopProvider.getFilteredControlLoops(null); + }).hasMessageMatching("filter is marked .*ull but is null"); + + final ToscaTypedEntityFilter<ControlLoop> filter = ToscaTypedEntityFilter.<ControlLoop>builder() + .type("org.onap.domain.pmsh.PMSHControlLoopDefinition").build(); + assertEquals(2, controlLoopProvider.getFilteredControlLoops(filter).size()); + } + + + @Test + public void testUpdateControlLoops() throws Exception { + assertThatThrownBy(() -> { + controlLoopProvider.updateControlLoops(null); + }).hasMessageMatching("controlLoops is marked .*ull but is null"); + + ControlLoops existingControlLoops = new ControlLoops(); + existingControlLoops + .setControlLoopList(controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList())); + ControlLoop updateResponse = new ControlLoop(); + updateResponse = controlLoopProvider.updateControlLoop(updateControlLoops.getControlLoopList().get(0)); + + assertEquals(ControlLoopOrderedState.RUNNING, updateResponse.getOrderedState()); + } + + @Test + public void testDeleteControlLoop() throws Exception { + assertThatThrownBy(() -> { + controlLoopProvider.deleteControlLoop("Invalid_name", "1.0.1"); + }).hasMessageMatching(".*.failed, control loop does not exist"); + + ControlLoop deletedCl; + List<ControlLoop> clList = controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList()); + String name = inputControlLoops.getControlLoopList().get(0).getName(); + String version = inputControlLoops.getControlLoopList().get(0).getVersion(); + + deletedCl = controlLoopProvider.deleteControlLoop(name, version); + assertEquals(clList.get(0), deletedCl); + + } +} + + diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProviderTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProviderTest.java new file mode 100644 index 000000000..7a86a49dc --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProviderTest.java @@ -0,0 +1,154 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; + +public class ParticipantProviderTest { + + private static final Coder CODER = new StandardCoder(); + private static final String PARTICIPANT_JSON = + "src/test/resources/providers/TestParticipant.json"; + private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; + + private static AtomicInteger dbNameCounter = new AtomicInteger(); + + private PolicyModelsProviderParameters parameters; + private ParticipantProvider participantProvider; + private List<Participant> inputParticipants = new ArrayList<>(); + private Participant updateParticipants; + private String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON); + + /** + * Set up test Participant provider. + */ + @Before + public void setupDao() throws Exception { + + parameters = new PolicyModelsProviderParameters(); + parameters.setDatabaseDriver("org.h2.Driver"); + parameters.setName("PolicyProviderParameterGroup"); + parameters.setImplementation("org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl"); + parameters.setDatabaseUrl("jdbc:h2:mem:participantProviderTestDb" + dbNameCounter.getAndIncrement()); + parameters.setDatabaseUser("policy"); + parameters.setDatabasePassword("P01icY"); + parameters.setPersistenceUnit("ToscaConceptTest"); + + participantProvider = new ParticipantProvider(parameters); + inputParticipants.add(CODER.decode(originalJson, Participant.class)); + + } + + @After + public void teardown() { + participantProvider.close(); + } + + @Test + public void testParticipantCreate() throws Exception { + assertThatThrownBy(() -> { + participantProvider.createParticipants(null); + }).hasMessageMatching(LIST_IS_NULL); + + List<Participant> createdParticipants = new ArrayList<>(); + createdParticipants.addAll(participantProvider + .createParticipants(inputParticipants)); + + assertEquals(createdParticipants.get(0), + inputParticipants.get(0)); + } + + + @Test + public void testGetControlLoops() throws Exception { + + List<Participant> getResponse; + + //Return empty list when no data present in db + getResponse = participantProvider.getParticipants(null, null); + assertThat(getResponse).isEmpty(); + + participantProvider.createParticipants(inputParticipants); + String name = inputParticipants.get(0).getName(); + String version = inputParticipants.get(0).getVersion(); + assertEquals(1, participantProvider.getParticipants(name, version).size()); + + assertThat(participantProvider.getParticipants("invalid_name", + "1.0.1")).isEmpty(); + + assertThatThrownBy(() -> { + participantProvider.getFilteredParticipants(null); + }).hasMessageMatching("filter is marked .*ull but is null"); + + final ToscaTypedEntityFilter<Participant> filter = ToscaTypedEntityFilter.<Participant>builder() + .type("org.onap.domain.pmsh.PMSHControlLoopDefinition").build(); + assertEquals(1, participantProvider.getFilteredParticipants(filter).size()); + } + + @Test + public void testUpdateParticipant() throws Exception { + assertThatThrownBy(() -> { + participantProvider.updateParticipants(null); + }).hasMessageMatching("participants is marked .*ull but is null"); + + participantProvider.createParticipants(inputParticipants); + updateParticipants = inputParticipants.get(0); + updateParticipants.setParticipantState(ParticipantState.ACTIVE); + List<Participant> participantList = new ArrayList<>(); + participantList.add(updateParticipants); + List<Participant> updateResponse = new ArrayList<>(); + updateResponse = participantProvider.updateParticipants(participantList); + + assertEquals(ParticipantState.ACTIVE, updateResponse.get(0).getParticipantState()); + } + + @Test + public void testDeleteParticipant() throws Exception { + assertThatThrownBy(() -> { + participantProvider.deleteParticipant("Invalid_name", "1.0.1"); + }).hasMessageMatching(".*.failed, participant does not exist"); + + Participant deletedParticipant; + List<Participant> participantList = participantProvider.createParticipants(inputParticipants); + String name = inputParticipants.get(0).getName(); + String version = inputParticipants.get(0).getVersion(); + + deletedParticipant = participantProvider.deleteParticipant(name, version); + assertEquals(participantList.get(0), deletedParticipant); + + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java new file mode 100644 index 000000000..3a4905b3e --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import java.util.Date; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatisticsList; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public class ParticipantStatisticsProviderTest { + + private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; + private static final Coder CODER = new StandardCoder(); + private static final String PARTICIPANT_STATS_JSON = "src/test/resources/providers/TestParticipantStatistics.json"; + + private static AtomicInteger dbNameCounter = new AtomicInteger(); + + private PolicyModelsProviderParameters parameters; + private ParticipantStatisticsProvider participantStatisticsProvider; + private ParticipantStatisticsList inputParticipantStatistics; + private String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_STATS_JSON); + + /** + * Set up test Participant statistics provider. + */ + @Before + public void setupDao() throws Exception { + + parameters = new PolicyModelsProviderParameters(); + parameters.setDatabaseDriver("org.h2.Driver"); + parameters.setName("PolicyProviderParameterGroup"); + parameters.setImplementation("org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl"); + parameters.setDatabaseUrl("jdbc:h2:mem:participantStatisticsProviderTestDb" + dbNameCounter.getAndIncrement()); + parameters.setDatabaseUser("policy"); + parameters.setDatabasePassword("P01icY"); + parameters.setPersistenceUnit("ToscaConceptTest"); + + participantStatisticsProvider = new ParticipantStatisticsProvider(parameters); + inputParticipantStatistics = CODER.decode(originalJson, ParticipantStatisticsList.class); + } + + @After + public void teardown() { + participantStatisticsProvider.close(); + } + + @Test + public void testParticipantStatisticsCreate() throws Exception { + assertThatThrownBy(() -> { + participantStatisticsProvider.createParticipantStatistics(null); + }).hasMessageMatching(LIST_IS_NULL); + + ParticipantStatisticsList createdStatsList = new ParticipantStatisticsList(); + createdStatsList.setStatisticsList(participantStatisticsProvider + .createParticipantStatistics(inputParticipantStatistics.getStatisticsList())); + + assertEquals(inputParticipantStatistics.toString().replaceAll("\\s+", ""), + createdStatsList.toString().replaceAll("\\s+", "")); + } + + @Test + public void testGetControlLoops() throws Exception { + List<ParticipantStatistics> getResponse; + + // Return empty list when no data present in db + getResponse = participantStatisticsProvider.getParticipantStatistics(null, null, null); + assertThat(getResponse).isEmpty(); + + participantStatisticsProvider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList()); + ToscaConceptIdentifier identifier = inputParticipantStatistics.getStatisticsList().get(0).getParticipantId(); + Date date = inputParticipantStatistics.getStatisticsList().get(0).getTimeStamp(); + assertEquals(1, participantStatisticsProvider + .getParticipantStatistics(identifier.getName(), identifier.getVersion(), date).size()); + + assertEquals(1, participantStatisticsProvider + .getFilteredParticipantStatistics("name2", "1.0.1", null, null, null, "DESC", 1).size()); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotificationTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotificationTest.java new file mode 100644 index 000000000..d1e3dcfcc --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotificationTest.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.notification; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; + +public class ControlLoopNotificationTest { + + @Test + public void testControlLoopNotification() { + ControlLoopNotification cln0 = new ControlLoopNotification(); + + List<ControlLoopStatus> addedList = new ArrayList<>(); + addedList.add(new ControlLoopStatus()); + + List<ControlLoopStatus> deletedList = new ArrayList<>(); + deletedList.add(new ControlLoopStatus()); + + assertEquals(true, cln0.isEmpty()); + + cln0.setAdded(addedList); + assertEquals(false, cln0.isEmpty()); + cln0.setAdded(null); + assertEquals(true, cln0.isEmpty()); + + cln0.setDeleted(deletedList); + assertEquals(false, cln0.isEmpty()); + cln0.setDeleted(null); + assertEquals(true, cln0.isEmpty()); + + cln0.setAdded(addedList); + cln0.setDeleted(deletedList); + assertEquals(false, cln0.isEmpty()); + cln0.setAdded(null); + cln0.setDeleted(null); + assertEquals(true, cln0.isEmpty()); + } + + @Test + public void testControlLoopNotificationLombok() { + assertNotNull(new ControlLoopNotification()); + assertNotNull(new ControlLoopNotification(new ArrayList<>(), new ArrayList<>())); + + ControlLoopNotification cln0 = new ControlLoopNotification(); + + assertThat(cln0.toString()).contains("ControlLoopNotification("); + assertEquals(false, cln0.hashCode() == 0); + assertEquals(true, cln0.equals(cln0)); + assertEquals(false, cln0.equals(null)); + + + ControlLoopNotification cln1 = new ControlLoopNotification(); + + assertThat(cln1.toString()).contains("ControlLoopNotification("); + assertEquals(false, cln1.hashCode() == 0); + assertEquals(true, cln1.equals(cln0)); + assertEquals(false, cln1.equals(null)); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatusTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatusTest.java new file mode 100644 index 000000000..d1ddbf4e6 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatusTest.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.notification; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.UUID; +import org.junit.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public class ControlLoopStatusTest { + + @Test + public void testControlLoopStatusLombok() { + assertNotNull(new ControlLoopStatus()); + assertNotNull(new ControlLoopStatus(UUID.randomUUID(), new ToscaConceptIdentifier())); + + ControlLoopStatus cln0 = new ControlLoopStatus(); + + assertThat(cln0.toString()).contains("ControlLoopStatus("); + assertEquals(false, cln0.hashCode() == 0); + assertEquals(true, cln0.equals(cln0)); + assertEquals(false, cln0.equals(null)); + + ControlLoopStatus cln1 = new ControlLoopStatus(); + assertEquals(true, cln1.equals(cln0)); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/NotificationPojosTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/NotificationPojosTest.java new file mode 100644 index 000000000..6ea07be76 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/NotificationPojosTest.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.notification; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import java.util.List; +import org.junit.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +public class NotificationPojosTest { + + @Test + public void testPojos() { + List<PojoClass> pojoClasses = + PojoClassFactory.getPojoClasses(NotificationPojosTest.class.getPackageName()); + + // @formatter:off + final Validator validator = ValidatorBuilder + .create() + .with(new ToStringTester()) + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + + validator.validate(pojoClasses); + // @formatter:on + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChangeTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChangeTest.java new file mode 100644 index 000000000..3250ce713 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChangeTest.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.UUID; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the copy constructor and other methods. + */ +public class ParticipantControlLoopStateChangeTest { + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new ParticipantStateChange(null)).isInstanceOf(NullPointerException.class); + + ParticipantControlLoopStateChange orig = new ParticipantControlLoopStateChange(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantControlLoopStateChange(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setControlLoopId(id); + orig.setParticipantId(id); + orig.setRequestId(UUID.randomUUID()); + orig.setOrderedState(ControlLoopOrderedState.RUNNING); + orig.setTimestampMs(Long.valueOf(3000)); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantControlLoopStateChange(orig).toString())); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdateTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdateTest.java new file mode 100644 index 000000000..6be84ca8b --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdateTest.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.UUID; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; + +/** + * Test the copy constructor. + */ +public class ParticipantControlLoopUpdateTest { + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new ParticipantControlLoopUpdate(null)).isInstanceOf(NullPointerException.class); + + ParticipantControlLoopUpdate orig = new ParticipantControlLoopUpdate(); + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setControlLoopId(id); + orig.setParticipantId(id); + orig.setRequestId(UUID.randomUUID()); + orig.setTimestampMs(Long.valueOf(3000)); + + ControlLoop controlLoop = new ControlLoop(); + controlLoop.setName("controlLoop"); + ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate(); + toscaServiceTemplate.setName("serviceTemplate"); + toscaServiceTemplate.setDerivedFrom("parentServiceTemplate"); + toscaServiceTemplate.setDescription("Description of serviceTemplate"); + toscaServiceTemplate.setVersion("1.2.3"); + orig.setControlLoopDefinition(toscaServiceTemplate); + orig.setControlLoop(controlLoop); + + ParticipantControlLoopUpdate other = new ParticipantControlLoopUpdate(orig); + + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); + + // ensure list and items are not the same object + assertNotSame(other.getControlLoop(), controlLoop); + assertNotSame(other.getControlLoopDefinition(), toscaServiceTemplate); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheckTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheckTest.java new file mode 100644 index 000000000..f78365c00 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheckTest.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.UUID; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the copy constructor and other methods. + */ +public class ParticipantHealthCheckTest { + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new ParticipantStateChange(null)).isInstanceOf(NullPointerException.class); + + ParticipantHealthCheck orig = new ParticipantHealthCheck(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantHealthCheck(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setControlLoopId(id); + orig.setParticipantId(id); + orig.setRequestId(UUID.randomUUID()); + orig.setState(ParticipantState.ACTIVE); + orig.setTimestampMs(Long.valueOf(3000)); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantHealthCheck(orig).toString())); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java new file mode 100644 index 000000000..a17b0f873 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.UUID; +import org.junit.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public class ParticipantMessageTest { + private ParticipantMessage message; + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new ParticipantMessage((ParticipantMessage) null)) + .isInstanceOf(NullPointerException.class); + + // verify with null values + message = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE); + ParticipantMessage newmsg = new ParticipantMessage(message); + newmsg.setRequestId(message.getRequestId()); + newmsg.setTimestampMs(message.getTimestampMs()); + assertEquals(message.toString(), newmsg.toString()); + + // verify with all values + message = makeMessage(); + newmsg = new ParticipantMessage(message); + newmsg.setRequestId(message.getRequestId()); + newmsg.setTimestampMs(message.getTimestampMs()); + assertEquals(message.toString(), newmsg.toString()); + } + + @Test + public void testAppliesTo_NullParticipantId() { + message = makeMessage(); + + assertThatThrownBy(() -> message.appliesTo(null)) + .isInstanceOf(NullPointerException.class); + + } + + @Test + public void testAppliesTo_ParticipantIdMatches() { + message = makeMessage(); + + // ParticipantId matches + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + assertTrue(message.appliesTo(id)); + } + + @Test + public void testAppliesTo_ParticipantIdNoMatch() { + message = makeMessage(); + + // ParticipantId doesnot match + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id1111"); + id.setVersion("3.2.1"); + assertFalse(message.appliesTo(id)); + message.setParticipantId(null); + assertTrue(message.appliesTo(id)); + } + + private ParticipantMessage makeMessage() { + ParticipantMessage msg = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE); + + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + msg.setControlLoopId(id); + msg.setParticipantId(id); + msg.setRequestId(UUID.randomUUID()); + msg.setTimestampMs(Long.valueOf(3000)); + + return msg; + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java new file mode 100644 index 000000000..a7a76c05b --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +/** + * Utility class for tests of ParticipantMessage subclasses. + */ +public class ParticipantMessageUtils { + + private ParticipantMessageUtils() { + + } + + public static String removeVariableFields(String text) { + return text.replaceAll("requestId=[^,]*", "requestId=xxx").replaceAll("timestampMs=[^,]*", "timestampMs=nnn"); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java new file mode 100644 index 000000000..301f9acc0 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import java.util.List; +import org.junit.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +public class ParticipantPojosTest { + + @Test + public void testPojos() { + List<PojoClass> pojoClasses = + PojoClassFactory.getPojoClasses(ParticipantPojosTest.class.getPackageName()); + + pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessage.class)); + pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessageTest.class)); + + // @formatter:off + final Validator validator = ValidatorBuilder + .create() + .with(new ToStringTester()) + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + + validator.validate(pojoClasses); + // @formatter:on + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChangeTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChangeTest.java new file mode 100644 index 000000000..192f36342 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChangeTest.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.UUID; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the copy constructor and the other methods. + */ +public class ParticipantStateChangeTest { + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new ParticipantStateChange(null)).isInstanceOf(NullPointerException.class); + + ParticipantStateChange orig = new ParticipantStateChange(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantStateChange(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setControlLoopId(id); + orig.setParticipantId(id); + orig.setRequestId(UUID.randomUUID()); + orig.setState(ParticipantState.ACTIVE); + orig.setTimestampMs(Long.valueOf(3000)); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantStateChange(orig).toString())); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java new file mode 100644 index 000000000..62b3d9d02 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.UUID; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public class ParticipantStatusTest { + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new ParticipantStatus(null)).isInstanceOf(NullPointerException.class); + + final ParticipantStatus orig = new ParticipantStatus(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantStatus(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setControlLoopId(id); + orig.setParticipantId(id); + orig.setRequestId(UUID.randomUUID()); + orig.setState(ParticipantState.ACTIVE); + orig.setTimestampMs(Long.valueOf(3000)); + + final ParticipantResponseDetails resp = new ParticipantResponseDetails(); + resp.setResponseMessage("my-response"); + orig.setResponse(resp); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantStatus(orig).toString())); + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/MessagesRestPojosTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/MessagesRestPojosTest.java new file mode 100644 index 000000000..299a580d3 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/MessagesRestPojosTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.rest; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import java.util.List; +import org.junit.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +public class MessagesRestPojosTest { + + @Test + public void testPojos() { + List<PojoClass> pojoClasses = + PojoClassFactory.getPojoClassesRecursively(MessagesRestPojosTest.class.getPackageName(), null); + + + // @formatter:off + final Validator validator = ValidatorBuilder + .create() + .with(new ToStringTester()) + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + + validator.validate(pojoClasses); + // @formatter:on + } +} diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommandTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommandTest.java new file mode 100644 index 000000000..6bda3b736 --- /dev/null +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommandTest.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.models.messages.rest.instantiation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import org.junit.Test; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; + +public class InstantiationCommandTest { + @Test + public void testInstantiationCommandLombok() { + assertNotNull(new InstantiationCommand()); + InstantiationCommand ic0 = new InstantiationCommand(); + + assertThat(ic0.toString()).contains("InstantiationCommand("); + assertEquals(false, ic0.hashCode() == 0); + assertEquals(true, ic0.equals(ic0)); + assertEquals(false, ic0.equals(null)); + + + InstantiationCommand ic1 = new InstantiationCommand(); + + ic1.setControlLoopIdentifierList(new ArrayList<>()); + ic1.setOrderedState(ControlLoopOrderedState.UNINITIALISED); + + assertThat(ic1.toString()).contains("InstantiationCommand("); + assertEquals(false, ic1.hashCode() == 0); + assertEquals(false, ic1.equals(ic0)); + assertEquals(false, ic1.equals(null)); + + assertNotEquals(ic1, ic0); + + InstantiationCommand ic2 = new InstantiationCommand(); + + assertEquals(ic2, ic0); + } +} diff --git a/tosca-controlloop/models/src/test/resources/META-INF/persistence.xml b/tosca-controlloop/models/src/test/resources/META-INF/persistence.xml new file mode 100644 index 000000000..8f0e0648b --- /dev/null +++ b/tosca-controlloop/models/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,138 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + Copyright (C) 2019-2020 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========================================================= +--> +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"> + <persistence-unit name="CommissioningMariaDb" transaction-type="RESOURCE_LOCAL"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + + <class>org.onap.policy.models.base.PfConceptKey</class> + <class>org.onap.policy.models.dao.converters.CDataConditioner</class> + <class>org.onap.policy.models.dao.converters.Uuid2String</class> + <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class> + <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class> + <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics</class> + <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignment</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignments</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityType</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityTypes</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeType</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTypes</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaParameter</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRelationshipType</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRelationshipTypes</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRequirement</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRequirements</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger</class> + <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoop</class> + <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoopElement</class> + <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipant</class> + <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipantStatistics</class> + <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaClElementStatistics</class> + + <properties> + <property name="eclipselink.ddl-generation" value="create-or-extend-tables" /> + <property name="eclipselink.ddl-generation.output-mode" value="database" /> + <property name="eclipselink.logging.level" value="INFO" /> + + <!-- property name="eclipselink.logging.level" value="ALL" /> + <property name="eclipselink.logging.level.jpa" value="ALL" /> + <property name="eclipselink.logging.level.ddl" value="ALL" /> + <property name="eclipselink.logging.level.connection" value="ALL" /> + <property name="eclipselink.logging.level.sql" value="ALL" /> + <property name="eclipselink.logging.level.transaction" value="ALL" /> + <property name="eclipselink.logging.level.sequencing" value="ALL" /> + <property name="eclipselink.logging.level.server" value="ALL" /> + <property name="eclipselink.logging.level.query" value="ALL" /> + <property name="eclipselink.logging.level.properties" value="ALL" /--> + </properties> + <shared-cache-mode>NONE</shared-cache-mode> + </persistence-unit> + + <persistence-unit name="ToscaConceptTest" transaction-type="RESOURCE_LOCAL"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + + <class>org.onap.policy.models.base.PfConceptKey</class> + <class>org.onap.policy.models.dao.converters.CDataConditioner</class> + <class>org.onap.policy.models.dao.converters.Uuid2String</class> + <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class> + <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class> + <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics</class> + <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignment</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignments</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityType</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityTypes</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeType</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTypes</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaParameter</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRelationshipType</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRelationshipTypes</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRequirement</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRequirements</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate</class> + <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger</class> + <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoop</class> + <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoopElement</class> + <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipant</class> + <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipantStatistics</class> + <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaClElementStatistics</class> + + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> + <property name="eclipselink.ddl-generation.output-mode" value="database" /> + <property name="eclipselink.logging.level" value="INFO" /> + + <!-- <property name="eclipselink.logging.level" value="ALL" /> + <property name="eclipselink.logging.level.jpa" value="ALL" /> + <property name="eclipselink.logging.level.ddl" value="ALL" /> + <property name="eclipselink.logging.level.connection" value="ALL" /> + <property name="eclipselink.logging.level.sql" value="ALL" /> + <property name="eclipselink.logging.level.transaction" value="ALL" /> + <property name="eclipselink.logging.level.sequencing" value="ALL" /> + <property name="eclipselink.logging.level.server" value="ALL" /> + <property name="eclipselink.logging.level.query" value="ALL" /> + <property name="eclipselink.logging.level.properties" value="ALL"/> --> + </properties> + <shared-cache-mode>NONE</shared-cache-mode> + </persistence-unit> +</persistence> + diff --git a/tosca-controlloop/models/src/test/resources/json/ControlLoopElementNoOrderedState.json b/tosca-controlloop/models/src/test/resources/json/ControlLoopElementNoOrderedState.json new file mode 100644 index 000000000..e9da16aad --- /dev/null +++ b/tosca-controlloop/models/src/test/resources/json/ControlLoopElementNoOrderedState.json @@ -0,0 +1,13 @@ +{ + "id": "a95757ba-b34a-4049-a2a8-46773abcbe5e", + "definition": { + "name": "cleDef", + "version": "0.0.1" + }, + "participantId": { + "name": "participant", + "version": "0.0.1" + }, + "state": "UNINITIALISED", + "orderedState": null +} diff --git a/tosca-controlloop/models/src/test/resources/json/ControlLoopNoOrderedState.json b/tosca-controlloop/models/src/test/resources/json/ControlLoopNoOrderedState.json new file mode 100644 index 000000000..6bff97580 --- /dev/null +++ b/tosca-controlloop/models/src/test/resources/json/ControlLoopNoOrderedState.json @@ -0,0 +1,12 @@ +{ + "definition": { + "name": "controlLoopDefinitionName", + "version": "0.0.1" + }, + "state": "UNINITIALISED", + "orderedState": null, + "elements": [ + ], + "name": "control-loop", + "version": "0.0.1" +} diff --git a/tosca-controlloop/models/src/test/resources/providers/TestClElementStatistics.json b/tosca-controlloop/models/src/test/resources/providers/TestClElementStatistics.json new file mode 100644 index 000000000..78aeb3a6e --- /dev/null +++ b/tosca-controlloop/models/src/test/resources/providers/TestClElementStatistics.json @@ -0,0 +1,22 @@ +{ + "clElementStatistics":[ + { + "controlLoopElementId":{ + "name":"name1", + "version":"1.001" + }, + "timeStamp": "2021-01-10T13:45:00.000Z", + "controlLoopState": "UNINITIALISED", + "clElementUptime":250 + }, + { + "controlLoopElementId":{ + "name":"name2", + "version":"1.001" + }, + "timeStamp": "2021-01-10T14:25:00.000Z", + "controlLoopState": "UNINITIALISED", + "clElementUptime":330 + } + ] +} diff --git a/tosca-controlloop/models/src/test/resources/providers/TestControlLoops.json b/tosca-controlloop/models/src/test/resources/providers/TestControlLoops.json new file mode 100644 index 000000000..25e36458c --- /dev/null +++ b/tosca-controlloop/models/src/test/resources/providers/TestControlLoops.json @@ -0,0 +1,142 @@ +{ + "controlLoopList": [ + { + "definition": { + "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition", + "version": "1.0.0" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "elements": [ + { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", + "version": "1.2.3" + }, + "participantId": { + "name": "DCAEParticipant0", + "version": "1.0.0" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "DCAE Control Loop Element for the PMSH instance 0 control loop" + }, + { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c21", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement", + "version": "1.2.3" + }, + "participantId": { + "name": "PolicyParticipant0", + "version": "1.0.0" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "Monitoring Policy Control Loop Element for the PMSH instance 0 control loop" + }, + { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c22", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement", + "version": "1.2.3" + }, + "participantId": { + "name": "PolicyParticipant0", + "version": "1.0.0" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "Operational Policy Control Loop Element for the PMSH instance 0 control loop" + }, + { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c23", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement", + "version": "1.2.3" + }, + "participantId": { + "name": "CDSParticipant0", + "version": "1.0.0" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "CDS Control Loop Element for the PMSH instance 0 control loop" + } + ], + "name": "PMSHInstance0", + "version": "1.0.1", + "description": "PMSH control loop instance 0" + }, + { + "definition": { + "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition", + "version": "1.0.0" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "elements": [ + { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c24", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", + "version": "1.2.3" + }, + "participantId": { + "name": "DCAEParticipant0", + "version": "1.0.0" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "DCAE Control Loop Element for the PMSH instance 1 control loop" + }, + { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c25", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement", + "version": "1.2.3" + }, + "participantId": { + "name": "PolicyParticipant0", + "version": "1.0.0" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "Monitoring Policy Control Loop Element for the PMSH instance 1 control loop" + }, + { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c26", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement", + "version": "1.2.3" + }, + "participantId": { + "name": "PolicyParticipant0", + "version": "1.0.0" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "Operational Policy Control Loop Element for the PMSH instance 1 control loop" + }, + { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c27", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement", + "version": "1.2.3" + }, + "participantId": { + "name": "CDSParticipant0", + "version": "1.0.0" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "CDS Control Loop Element for the PMSH instance 1 control loop" + } + ], + "name": "PMSHInstance1", + "version": "1.0.1", + "description": "PMSH control loop instance 1" + } + ] +} diff --git a/tosca-controlloop/models/src/test/resources/providers/TestParticipant.json b/tosca-controlloop/models/src/test/resources/providers/TestParticipant.json new file mode 100644 index 000000000..c6965ce62 --- /dev/null +++ b/tosca-controlloop/models/src/test/resources/providers/TestParticipant.json @@ -0,0 +1,11 @@ +{ + "name": "dummy_participant1", + "version": "1.0.1", + "definition":{ + "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition", + "version": "1.0.0" + }, + "participantState": "PASSIVE", + "healthStatus": "HEALTHY", + "description": "A dummy PMSH participant1" +} diff --git a/tosca-controlloop/models/src/test/resources/providers/TestParticipantStatistics.json b/tosca-controlloop/models/src/test/resources/providers/TestParticipantStatistics.json new file mode 100644 index 000000000..5cf626816 --- /dev/null +++ b/tosca-controlloop/models/src/test/resources/providers/TestParticipantStatistics.json @@ -0,0 +1,32 @@ +{ + "statisticsList":[ + { + "participantId":{ + "name":"name1", + "version":"1.001" + }, + "timeStamp": "2021-01-10T13:45:00.000Z", + "state": "PASSIVE", + "healthStatus": "HEALTHY", + "eventCount":250, + "lastExecutionTime":100, + "averageExecutionTime":90, + "upTime":1000, + "lastStart":3000 + }, + { + "participantId":{ + "name":"name2", + "version":"1.001" + }, + "timeStamp": "2021-01-27T14:25:00.000Z", + "state": "PASSIVE", + "healthStatus": "HEALTHY", + "eventCount":245, + "lastExecutionTime":1020, + "averageExecutionTime":85, + "upTime":1050, + "lastStart":3100 + } + ] +} diff --git a/tosca-controlloop/models/src/test/resources/providers/UpdateControlLoops.json b/tosca-controlloop/models/src/test/resources/providers/UpdateControlLoops.json new file mode 100644 index 000000000..0ae402629 --- /dev/null +++ b/tosca-controlloop/models/src/test/resources/providers/UpdateControlLoops.json @@ -0,0 +1,73 @@ +{ + "controlLoopList": [ + { + "name": "PMSHInstance0", + "version": "1.0.1", + "definition": { + "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition", + "version": "1.0.0" + }, + "state": "RUNNING", + "orderedState": "RUNNING", + "description": "PMSH control loop instance 0", + "elements": [ + { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", + "version": "1.2.3" + }, + "participantId": { + "name": "DCAEParticipant0", + "version": "1.0.0" + }, + "state": "RUNNING", + "orderedState": "RUNNING", + "description": "DCAE Control Loop Element for the PMSH instance 0 control loop" + }, + { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c21", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement", + "version": "1.2.3" + }, + "participantId": { + "name": "PolicyParticipant0", + "version": "1.0.0" + }, + "state": "RUNNING", + "orderedState": "RUNNING", + "description": "Monitoring Policy Control Loop Element for the PMSH instance 0 control loop" + }, + { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c22", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement", + "version": "1.2.3" + }, + "participantId": { + "name": "PolicyParticipant0", + "version": "1.0.0" + }, + "state": "RUNNING", + "orderedState": "RUNNING", + "description": "Operational Policy Control Loop Element for the PMSH instance 0 control loop" + }, + { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c23", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement", + "version": "1.2.3" + }, + "participantId": { + "name": "CDSParticipant0", + "version": "1.0.0" + }, + "state": "RUNNING", + "orderedState": "RUNNING", + "description": "CDS Control Loop Element for the PMSH instance 0 control loop" + } + ] + } + ] +} diff --git a/tosca-controlloop/pom.xml b/tosca-controlloop/pom.xml index 008f45e36..c5c5ebc57 100755 --- a/tosca-controlloop/pom.xml +++ b/tosca-controlloop/pom.xml @@ -27,7 +27,7 @@ <groupId>org.onap.policy.parent</groupId> <artifactId>integration</artifactId> <version>3.3.0-SNAPSHOT</version> - <relativePath/> + <relativePath>../../parent/integration</relativePath> </parent> <groupId>org.onap.policy.clamp.controlloop</groupId> @@ -144,6 +144,20 @@ </excludes> </resource> </resources> + + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <forkCount>1C</forkCount> + <reuseForks>true</reuseForks> + <useSystemClassLoader>false</useSystemClassLoader> + <parallel>methods</parallel> + <useUnlimitedThreads>true</useUnlimitedThreads> + </configuration> + </plugin> + </plugins> </build> </project> |