Class RunnablePlugin<T extends org.gcube.vremanagement.executor.plugin.Plugin>
java.lang.Object
org.gcube.vremanagement.executor.pluginmanager.RunnablePlugin<T>
- All Implemented Interfaces:
Runnable
public class RunnablePlugin<T extends org.gcube.vremanagement.executor.plugin.Plugin>
extends Object
implements Runnable
- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.gcube.vremanagement.executor.plugin.PluginStateEvolutionstatic final StringThe key, in the configuration of a plugin, of the identifier of its client.static final StringThe key, in the configuration of a plugin, of the secret of its client.protected final StringThe Context the task runs in.static final StringThe metric of the executions, by plugin, Context and final state, in the metrics of the node.protected final intprotected final org.gcube.common.security.secrets.SecretThe secret of the node in the Context of the task: the service does its own work with it.protected final Stringprotected final Tprotected org.gcube.common.security.secrets.SecretThe secret the plugin runs with, seeobtainPluginSecret(Map); set when the execution starts.protected final List<org.gcube.vremanagement.executor.plugin.PluginStateNotification>protected final UUID -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidRuns code of the plugin with the secret of the plugin.protected voidcountExecution(org.gcube.vremanagement.executor.plugin.PluginState pluginState) Counts the execution in the metrics of the node (/smartgears/metrics, not public): "smartexecutor.executions" by plugin, Context and final state.protected org.gcube.common.security.secrets.SecretobtainPluginSecret(Map<String, Object> configuration) Returns the secret the plugin runs with: a token of its client, given by "client_id" and "client_secret" in its configuration, in the Context of the task.Returns the configuration of the plugin: the content of<plugin>.yamlin the directory of the plugin (WEB-INF/lib/plugins/<plugin>/), written by the provisioning and read by SmartGears when the service starts.voidrun()protected voidsetPercentage(Integer percentage) voidsetState(org.gcube.vremanagement.executor.plugin.PluginState pluginState) voidprotected voidsetState(org.gcube.vremanagement.executor.plugin.PluginState pluginState, Integer percentage, Exception exception) It is up to the plugin to update the State of the Running Plugin using this facilities function.voidstop()Stop the Plugin setting state toPluginState.STOPPEDtoString()
-
Field Details
-
CLIENT_ID
The key, in the configuration of a plugin, of the identifier of its client.- See Also:
-
CLIENT_SECRET
The key, in the configuration of a plugin, of the secret of its client.- See Also:
-
plugin
-
inputs
-
uuid
-
iterationNumber
protected final int iterationNumber -
pluginStateNotifications
protected final List<org.gcube.vremanagement.executor.plugin.PluginStateNotification> pluginStateNotifications -
ownerId
-
context
The Context the task runs in. -
nodeSecret
protected final org.gcube.common.security.secrets.Secret nodeSecretThe secret of the node in the Context of the task: the service does its own work with it. -
pluginSecret
protected volatile org.gcube.common.security.secrets.Secret pluginSecretThe secret the plugin runs with, seeobtainPluginSecret(Map); set when the execution starts. -
actualStateEvolution
protected org.gcube.vremanagement.executor.plugin.PluginStateEvolution actualStateEvolution -
EXECUTIONS_METRIC
The metric of the executions, by plugin, Context and final state, in the metrics of the node.- See Also:
-
-
Constructor Details
-
RunnablePlugin
-
-
Method Details
-
run
public void run() -
asPlugin
Runs code of the plugin with the secret of the plugin.- Parameters:
task- the code of the plugin- Throws:
Exception- if the code fails
-
readConfiguration
Returns the configuration of the plugin: the content of<plugin>.yamlin the directory of the plugin (WEB-INF/lib/plugins/<plugin>/), written by the provisioning and read by SmartGears when the service starts. Every plugin has one, with at least its client; a missing, unreadable or wrong file is an error, never an empty configuration.- Returns:
- the configuration
- Throws:
Exception- if SmartGears does not know the plugin or has no configuration for it
-
countExecution
protected void countExecution(org.gcube.vremanagement.executor.plugin.PluginState pluginState) Counts the execution in the metrics of the node (/smartgears/metrics, not public): "smartexecutor.executions" by plugin, Context and final state.- Parameters:
pluginState- the final state of the execution
-
obtainPluginSecret
protected org.gcube.common.security.secrets.Secret obtainPluginSecret(Map<String, Object> configuration) throws ExceptionReturns the secret the plugin runs with: a token of its client, given by "client_id" and "client_secret" in its configuration, in the Context of the task.- Parameters:
configuration- the configuration of the plugin- Returns:
- the secret
- Throws:
Exception- if the configuration has no client or its token cannot be obtained
-
getPlugin
- Returns:
- the plugin
-
getInputs
- Returns:
- the launchInputs
-
setPercentage
protected void setPercentage(Integer percentage) throws AlreadyInFinalStateException, InvalidPluginStateEvolutionException -
setState
public void setState(org.gcube.vremanagement.executor.plugin.PluginState pluginState) throws AlreadyInFinalStateException, InvalidPluginStateEvolutionException -
setState
public void setState(org.gcube.vremanagement.executor.plugin.PluginState pluginState, Exception e) throws AlreadyInFinalStateException, InvalidPluginStateEvolutionException -
setState
protected void setState(org.gcube.vremanagement.executor.plugin.PluginState pluginState, Integer percentage, Exception exception) throws AlreadyInFinalStateException, InvalidPluginStateEvolutionException It is up to the plugin to update the State of the Running Plugin using this facilities function.- Parameters:
pluginState- the new plugin state to setpercentage- the completion percentage (can be null)exception- the exception that caused the state change (can be null)- Throws:
AlreadyInFinalStateException- if the plugin is already in a final stateInvalidPluginStateEvolutionException- if the state transition is invalid
-
toString
-
stop
Stop the Plugin setting state toPluginState.STOPPED- Throws:
Exception
-