/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.service.parameters.engineservice;
import jakarta.validation.Valid;
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.apex.core.engine.EngineParameters;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
import org.onap.policy.apex.service.parameters.ApexParameterConstants;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.BeanValidator;
import org.onap.policy.common.parameters.ParameterGroup;
import org.onap.policy.common.parameters.annotations.Max;
import org.onap.policy.common.parameters.annotations.Min;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.common.parameters.annotations.Pattern;
// @formatter:off
/**
* This class holds the parameters for an Apex Engine Service with multiple engine threads running multiple engines.
*
*
The following parameters are defined:
*
* - name: The name of the Apex engine service, which can be set to any value that matches the regular expression
* {@link org.onap.policy.apex.model.basicmodel.concepts.AxKey#NAME_REGEXP}.
*
- version: The name of the Apex engine service, which can be set to any value that matches the regular expression
* {@link org.onap.policy.apex.model.basicmodel.concepts.AxKey#VERSION_REGEXP}.
*
- id: The ID of the Apex engine service, which can be set to any integer value by a user.
*
- instanceCount: The number of Apex engines to spawn in this engine service. Each engine executes in its own
* thread.
*
- deploymentPort: The port that the Apex Engine Service will open so that it can be managed using the EngDep
* protocol. The EngDep protocol allows the engine service to be monitored, to start and stop engines in the engine
* service, and to update the policy model of the engine service.
*
- engineParameters: Parameters (a {@link EngineParameters} instance) that all of the engines in the engine service
* will use. All engine threads use the same parameters and act as a pool of engines. Engine parameters specify the
* executors and context management for the engines.
*
- periodicEventPeriod: The period in milliseconds at which the periodic event PERIOIC_EVENT will be generated by
* APEX, 0 means no periodic event generation, negative values are illegal.
*
*/
// @formatter:on
@Getter
@Setter
@NotNull
public class EngineServiceParameters implements ParameterGroup {
private static final int MAX_PORT = 65535;
// @formatter:off
/** The default name of the Apex engine service. */
public static final String DEFAULT_NAME = "ApexEngineService";
/** The default version of the Apex engine service. */
public static final String DEFAULT_VERSION = "1.0.0";
/** The default ID of the Apex engine service. */
public static final int DEFAULT_ID = -1;
/** The default instance count for the Apex engine service. */
public static final int DEFAULT_INSTANCE_COUNT = 1;
/** The default EngDep deployment port of the Apex engine service. */
public static final int DEFAULT_DEPLOYMENT_PORT = 34421;
// Constants for repeated strings
// Apex engine service parameters
@Pattern(regexp = AxKey.NAME_REGEXP)
private String name = DEFAULT_NAME;
@Pattern(regexp = AxKey.VERSION_REGEXP)
private String version = DEFAULT_VERSION;
@Min(0)
private int id = DEFAULT_ID;
@Min(1)
private int instanceCount = DEFAULT_INSTANCE_COUNT;
@Min(1)
@Max(MAX_PORT)
private int deploymentPort = DEFAULT_DEPLOYMENT_PORT;
@NotBlank
private String policyModel = null;
@Min(0)
private long periodicEventPeriod = 0;
// @formatter:on
// Apex engine internal parameters
private @Valid EngineParameters engineParameters = new EngineParameters();
/**
* Constructor to create an apex engine service parameters instance and register the instance with the parameter
* service.
*/
public EngineServiceParameters() {
super();
// Set the name for the parameters
this.name = ApexParameterConstants.ENGINE_SERVICE_GROUP_NAME;
}
/**
* Gets the key of the Apex engine service.
*
* @return the Apex engine service key
*/
public AxArtifactKey getEngineKey() {
return new AxArtifactKey(name, version);
}
/**
* Sets the key of the Apex engine service.
*
* @param key the the Apex engine service key
*/
public void setEngineKey(final AxArtifactKey key) {
this.setName(key.getName());
this.setVersion(key.getVersion());
}
/**
* {@inheritDoc}.
*/
@Override
public BeanValidationResult validate() {
return new BeanValidator().validateTop(getClass().getSimpleName(), this);
}
}