Class ServiceTask
java.lang.Object
eu.cloudnetservice.driver.service.ServiceConfigurationBase
eu.cloudnetservice.driver.service.ServiceTask
- All Implemented Interfaces:
Named,DefaultedDocPropertyHolder,DocPropertyHolder,Cloneable
The main base configuration for all services within the CloudNet cluster. A task is normally permanent stored
somewhere to allow loads after a node restart. Therefore, service tasks are the main configuration point for everyone
who needs either permanent storing of a service configuration or who doesn't work with the CloudNet api to start a
service.
- Since:
- 4.0
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface eu.cloudnetservice.driver.document.property.DefaultedDocPropertyHolder
DefaultedDocPropertyHolder.Mutable<S extends DocPropertyHolder.Mutable<S>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanprivate final booleanprivate final Stringprivate final Stringprivate final booleanprivate final intprivate final Stringprivate final Stringstatic final Patternstatic final StringThe jvm static pattern which validate that a task or service name is acceptable.private final ProcessConfigurationprivate final Stringprivate final intprivate final booleanFields inherited from class eu.cloudnetservice.driver.service.ServiceConfigurationBase
deployments, includes, properties, templates -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedServiceTask(@NonNull String name, @NonNull String runtime, @Nullable String hostAddress, @Nullable String javaCommand, @NonNull String nameSplitter, boolean disableIpRewrite, boolean maintenance, boolean autoDeleteOnStop, boolean staticServices, @NonNull Set<String> groups, @NonNull Set<String> associatedNodes, @NonNull Set<String> deletedFilesAfterStop, @NonNull ProcessConfiguration processConfiguration, int startPort, int minServiceCount, @NonNull Set<ServiceTemplate> templates, @NonNull Set<ServiceDeployment> deployments, @NonNull Set<ServiceRemoteInclusion> includes, @NonNull Document properties) Constructs a new service task instance. -
Method Summary
Modifier and TypeMethodDescriptionGet the unique ids of all nodes which are allowed to pick up and manage the underlying service.booleanGet if services should be deleted when stopping the service.static ServiceTask.Builderbuilder()Constructs a new builder for a service task.static ServiceTask.Builderbuilder(@NonNull ServiceTask serviceTask) Constructs a new builder for a service task which has the same properties set than the given service task.clone()Get the files (or directories) which should get deleted when stopping the service (before deployments are executed).booleanGet if rewriting the ip set in the service configuration file (for example the server.properties file) should be disabled and the set ip should be used.Get the environment variables which should get appended to all environments of services which are created based on this configuration.groups()Get the names of the groups whose configuration should get included when starting a service based on this configuration.Get the host address that all services of this task are bound to.Get the java command to use when starting a service.Get the jvm options which should get applied to the service command line.booleanGet if this service task is in maintenance.Get the amount of services which should be always online if this task is not in maintenance.name()Get the unique name identifier of this object in the related scope.Get the splitter to put between the name of the task and the numeric id of it when creating a full display name variant of the underlying service.Get the process configuration to apply to all services which get created based on this configuration.Get the process parameters which should get appended to the command line.runtime()Get the runtime to use when services gets created based on this configuration.The port of the service to start on.booleanGet if services which get created based on this configuration are static.Methods inherited from class eu.cloudnetservice.driver.service.ServiceConfigurationBase
deployments, inclusions, propertyHolder, templatesMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.document.property.DefaultedDocPropertyHolder
propertyAbsent, propertyPresent, readProperty, readPropertyOrDefault, readPropertyOrGet, readPropertyOrThrow, readPropertyOrThrow
-
Field Details
-
NAMING_REGEX
The jvm static pattern which validate that a task or service name is acceptable. It for example doesn't allow slashes to prevent navigation out of the service directory itself (path traversal).- See Also:
-
NAMING_PATTERN
-
name
-
runtime
-
hostAddress
-
javaCommand
-
nameSplitter
-
disableIpRewrite
private final boolean disableIpRewrite -
maintenance
private final boolean maintenance -
autoDeleteOnStop
private final boolean autoDeleteOnStop -
staticServices
private final boolean staticServices -
groups
-
associatedNodes
-
deletedFilesAfterStop
-
processConfiguration
-
startPort
private final int startPort -
minServiceCount
private final int minServiceCount
-
-
Constructor Details
-
ServiceTask
protected ServiceTask(@NonNull @NonNull String name, @NonNull @NonNull String runtime, @Nullable @Nullable String hostAddress, @Nullable @Nullable String javaCommand, @NonNull @NonNull String nameSplitter, boolean disableIpRewrite, boolean maintenance, boolean autoDeleteOnStop, boolean staticServices, @NonNull @NonNull Set<String> groups, @NonNull @NonNull Set<String> associatedNodes, @NonNull @NonNull Set<String> deletedFilesAfterStop, @NonNull @NonNull ProcessConfiguration processConfiguration, int startPort, int minServiceCount, @NonNull @NonNull Set<ServiceTemplate> templates, @NonNull @NonNull Set<ServiceDeployment> deployments, @NonNull @NonNull Set<ServiceRemoteInclusion> includes, @NonNull @NonNull Document properties) Constructs a new service task instance.- Parameters:
name- the name of the service task.runtime- the runtime, used to determine the service factory for services of the task.hostAddress- the host address all services of this task are bound to.javaCommand- the overridden java command to use, if null the node specific one will be used.nameSplitter- the splitter to put into the service name, between the task name and service id.disableIpRewrite- true if the ip set in a service configuration file should not get touched.maintenance- true if the task should be in maintenance.autoDeleteOnStop- true if services based on the task should get deleted when stopping them.staticServices- true if services created based on the task should be static.groups- the groups to automatically include to all services started based on the task.associatedNodes- the nodes which are allowed to pickup services based on the task.deletedFilesAfterStop- the files which should automatically get deleted when stopping a service.processConfiguration- the process configuration of the task.startPort- the start port of the task.minServiceCount- the amount of services which should be online by default.templates- the templates to include on each service created based on the task.deployments- the deployments which should be added initially to each service.includes- the includes which should be added initially to each service.properties- the properties of the task.- Throws:
NullPointerException- if one of the parameters (except the java command) is null.
-
-
Method Details
-
builder
Constructs a new builder for a service task.- Returns:
- a new service task builder.
-
builder
Constructs a new builder for a service task which has the same properties set than the given service task.When calling build directly after constructing a builder using this method, it will result in a service task which is equal but not the same as the given one.
- Parameters:
serviceTask- the service task to copy the properties of.- Returns:
- a builder for a service task with the properties of the given one already set.
- Throws:
NullPointerException- if the given service task is null.
-
name
-
runtime
Get the runtime to use when services gets created based on this configuration. Runtimes are there to allow different types of configuration for running in different environments, for example inside a docker container. The given runtime must be registered on the node which picks up the service, if not it will result in an error.- Returns:
- the runtime to use when creating a service based on this configuration.
-
hostAddress
Get the host address that all services of this task are bound to. The host address is not required to be an ip address, it is possible that the host address is just an ip alias which needs to be resolved using the configuration of the node. The host address might be null, in that case the fallback host of the node is used.- Returns:
- the host address all services of this task are bound to.
-
javaCommand
Get the java command to use when starting a service. This can for example be used to use different java distros or versions on services. If no java command is set the java command configured in the node that is picking up the service will be used.- Returns:
- the java command to use when starting services based on this configuration.
-
nameSplitter
-
disableIpRewrite
public boolean disableIpRewrite()Get if rewriting the ip set in the service configuration file (for example the server.properties file) should be disabled and the set ip should be used. Note that if disabled the node starting the service will not read the ip from the configuration, therefore the configured ip of the node is still used as the service address.- Returns:
- true if the node starting a service based on the task should not change the ip in the service config.
-
maintenance
public boolean maintenance()Get if this service task is in maintenance. This option is used to restrict for example who is able to join on a service. On the other hand, CloudNet will not try to start any service of tasks which are in maintenance even if the configured minimum service count is more than 0.- Returns:
- true if this task is in maintenance, false otherwise.
-
autoDeleteOnStop
public boolean autoDeleteOnStop()Get if services should be deleted when stopping the service. This does only mean that the service gets unregistered and is no longer available for starting, but does not mean that all service files get deleted when the service is static.If this option is false the service will be stopped and then go back to the prepared state, ready to get started again.
- Returns:
- if the service should get unregistered when stopping it.
-
staticServices
public boolean staticServices()Get if services which get created based on this configuration are static. Files of static services will not get deleted when deleting the service. That means that starting the exact service after it was deleted, will result in the same service files to be present.NOTE: static services are not automatically synced between nodes, therefore a specific node to start the service on should be present, else it might result in a different configuration (or world) than expected.
- Returns:
- if services created based on this configuration should be static.
-
jvmOptions
Get the jvm options which should get applied to the service command line. JVM options are there to configure the behaviour of the jvm, for example the garbage collector.- Specified by:
jvmOptionsin classServiceConfigurationBase- Returns:
- the jvm options to set for services created based on this configuration.
-
processParameters
Get the process parameters which should get appended to the command line. Process parameters are there to configure the application, for example setting an option like --online-mode=true.- Specified by:
processParametersin classServiceConfigurationBase- Returns:
- the process parameters to set for services created based on this configuration.
-
environmentVariables
Get the environment variables which should get appended to all environments of services which are created based on this configuration.- Specified by:
environmentVariablesin classServiceConfigurationBase- Returns:
- the environment variables to set for services created based on this configuration.
-
groups
Get the names of the groups whose configuration should get included when starting a service based on this configuration. Each configuration is only included when it is present on the node starting the service, if not it will silently be ignored. Note that groups targeting the same environment as this configuration will get included automatically.- Returns:
- the names of the group configurations to include their configurations before starting.
-
associatedNodes
Get the unique ids of all nodes which are allowed to pick up and manage the underlying service. This method returns an empty collection if all nodes are allowed to pick up the service, but never null.Note: this method might return an empty collection if a specific node was already chosen, you might need to check that too.
- Returns:
- the unique ids of the nodes which are allowed to pick up and manage the underlying service.
-
deletedFilesAfterStop
Get the files (or directories) which should get deleted when stopping the service (before deployments are executed). Trying to delete files outside the service directory will result in an exception.- Returns:
- a set of path to files/directories which should get deleted when stopping a service based on this config.
-
processConfiguration
Get the process configuration to apply to all services which get created based on this configuration.- Returns:
- the process configuration to apply to all services.
-
startPort
The port of the service to start on. If the given port is already taken it will be counted up until it reaches the port limit (65535) or one of the ports in between is free to be taken. Port changes because of counting up will not be reflected into this configuration and vice-versa.- Returns:
- the port number to start the service on, might be counted up when the port is already taken.
-
minServiceCount
Get the amount of services which should be always online if this task is not in maintenance. CloudNet tries to start services until the minimum amount of them is online if possible, if for example no nodes are online which are able to pick up the service, the minimum service count might not get reached.- Returns:
- the minimum amount of services which CloudNet should try to keep online.
-
clone
-