diff options
Diffstat (limited to 'services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java')
-rw-r--r-- | services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java | 329 |
1 files changed, 329 insertions, 0 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java new file mode 100644 index 000000000..6b60732c3 --- /dev/null +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java @@ -0,0 +1,329 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.service.parameters.engineservice; + +import java.io.File; +import java.net.URL; + +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.service.AbstractParameters; +import org.onap.policy.apex.model.basicmodel.service.ParameterService; +import org.onap.policy.apex.model.utilities.ResourceUtils; +import org.onap.policy.apex.service.parameters.ApexParameterValidator; + +import org.onap.policy.apex.core.engine.EngineParameters; + +/** + * This class holds the parameters for an Apex Engine Service with multiple engine threads running + * multiple engines. + * + * <p> + * The following parameters are defined: + * <ol> + * <li>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}. + * <li>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}. + * <li>id: The ID of the Apex engine service, which can be set to any integer value by a user. + * <li>instanceCount: The number of Apex engines to spawn in this engine service. Each engine + * executes in its own thread. + * <li>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. + * <li>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. + * <li>policyModelFileName: The full path to the policy model file name to deploy on the engine + * service. + * <li>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. + * </ol> + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class EngineServiceParameters extends AbstractParameters implements ApexParameterValidator { + 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; + + // Apex engine service parameters + private String name = DEFAULT_NAME; + private String version = DEFAULT_VERSION; + private int id = DEFAULT_ID; + private int instanceCount = DEFAULT_INSTANCE_COUNT; + private int deploymentPort = DEFAULT_DEPLOYMENT_PORT; + private String policyModelFileName = null; + private long periodicEventPeriod = 0; + // @formatter:on + + // Apex engine internal parameters + private EngineParameters engineParameters = new EngineParameters(); + + /** + * Constructor to create an apex engine service parameters instance and register the instance + * with the parameter service. + */ + public EngineServiceParameters() { + super(EngineServiceParameters.class.getCanonicalName()); + ParameterService.registerParameters(EngineServiceParameters.class, this); + } + + /** + * 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()); + } + + /** + * Gets the name of the engine service. + * + * @return the name of the engine service + */ + public String getName() { + return name; + } + + /** + * Sets the name of the engine service. + * + * @param name the name of the engine service + */ + public void setName(final String name) { + this.name = name; + } + + /** + * Gets the version of the engine service. + * + * @return the version of the engine service + */ + public String getVersion() { + return version; + } + + /** + * Sets the version of the engine service. + * + * @param version the version of the engine service + */ + public void setVersion(final String version) { + this.version = version; + } + + /** + * Gets the id of the engine service. + * + * @return the id of the engine service + */ + public int getId() { + return id; + } + + /** + * Sets the id of the engine service. + * + * @param id the id of the engine service + */ + public void setId(final int id) { + this.id = id; + } + + /** + * Gets the instance count of the engine service. + * + * @return the instance count of the engine service + */ + public int getInstanceCount() { + return instanceCount; + } + + /** + * Sets the instance count of the engine service. + * + * @param instanceCount the instance count of the engine service + */ + public void setInstanceCount(final int instanceCount) { + this.instanceCount = instanceCount; + } + + /** + * Gets the deployment port of the engine service. + * + * @return the deployment port of the engine service + */ + public int getDeploymentPort() { + return deploymentPort; + } + + /** + * Sets the deployment port of the engine service. + * + * @param deploymentPort the deployment port of the engine service + */ + public void setDeploymentPort(final int deploymentPort) { + this.deploymentPort = deploymentPort; + } + + /** + * Gets the file name of the policy engine for deployment on the engine service. + * + * @return the file name of the policy engine for deployment on the engine service + */ + public String getPolicyModelFileName() { + return ResourceUtils.getFilePath4Resource(policyModelFileName); + } + + /** + * Sets the file name of the policy engine for deployment on the engine service. + * + * @param policyModelFileName the file name of the policy engine for deployment on the engine + * service + */ + public void setPolicyModelFileName(final String policyModelFileName) { + this.policyModelFileName = policyModelFileName; + } + + /** + * Get the period in milliseconds at which periodic events are sent, zero means no periodic + * events are being sent. + * + * @return the periodic period + */ + public long getPeriodicEventPeriod() { + return periodicEventPeriod; + } + + /** + * Set the period in milliseconds at which periodic events are sent, zero means no periodic + * events are to be sent, negative values are illegal. + * + * @param periodicEventPeriod the periodic period + */ + public void setPeriodicEventPeriod(final long periodicEventPeriod) { + this.periodicEventPeriod = periodicEventPeriod; + } + + /** + * Gets the engine parameters for engines in the engine service. + * + * @return the engine parameters for engines in the engine service + */ + public EngineParameters getEngineParameters() { + return engineParameters; + } + + /** + * Sets the engine parameters for engines in the engine service. + * + * @param engineParameters the engine parameters for engines in the engine service + */ + public void setEngineParameters(final EngineParameters engineParameters) { + this.engineParameters = engineParameters; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate() + */ + @Override + public String validate() { + final StringBuilder errorMessageBuilder = new StringBuilder(); + + try { + new AxArtifactKey(name, version); + } catch (final Exception e) { + errorMessageBuilder.append(" name [" + name + "] and/or version [" + version + "] invalid\n"); + errorMessageBuilder.append(" " + e.getMessage() + "\n"); + } + + if (id < 0) { + errorMessageBuilder.append( + " id not specified or specified value [" + id + "] invalid, must be specified as id >= 0\n"); + } + + if (instanceCount < 1) { + errorMessageBuilder.append( + " instanceCount [" + instanceCount + "] invalid, must be specified as instanceCount >= 1\n"); + } + + if (deploymentPort < 1 || deploymentPort > MAX_PORT) { + errorMessageBuilder.append( + " deploymentPort [" + deploymentPort + "] invalid, must be specified as 1024 <= port <= 65535\n"); + } + + if (policyModelFileName != null) { + if (policyModelFileName.trim().length() == 0) { + errorMessageBuilder.append(" policyModelFileName [" + policyModelFileName + + "] invalid, must be specified as a non-empty string\n"); + } else { + // The file name can refer to a resource on the local file system or on the class + // path + final URL fileURL = ResourceUtils.getURL4Resource(policyModelFileName); + if (fileURL == null) { + errorMessageBuilder.append( + " policyModelFileName [" + policyModelFileName + "] not found or is not a plain file\n"); + } else { + final File policyModelFile = new File(fileURL.getPath()); + if (!policyModelFile.isFile()) { + errorMessageBuilder.append(" policyModelFileName [" + policyModelFileName + + "] not found or is not a plain file\n"); + } + } + } + } + + if (periodicEventPeriod < 0) { + errorMessageBuilder.append(" periodicEventPeriod [" + periodicEventPeriod + + "] invalid, must be specified in milliseconds as >=0\n"); + } + + return errorMessageBuilder.toString(); + } +} |