Class UriDeploymentSpi
- java.lang.Object
-
- org.apache.ignite.spi.IgniteSpiAdapter
-
- org.apache.ignite.spi.deployment.uri.UriDeploymentSpi
-
- All Implemented Interfaces:
DeploymentSpi,IgniteSpi
@IgniteSpiMultipleInstancesSupport(true) @IgniteSpiConsistencyChecked(optional=false) public class UriDeploymentSpi extends IgniteSpiAdapter implements DeploymentSpi
Implementation ofDeploymentSpiwhich can deploy tasks from different sources like file system folders, email and HTTP. There are different ways to deploy tasks in grid and every deploy method depends on selected source protocol. This SPI is configured to work with a list of URI's. Every URI contains all data about protocol/transport plus configuration parameters like credentials, scan frequency, and others.When SPI establishes a connection with an URI, it downloads deployable units to the temporary directory in order to prevent it from any changes while scanning. Use method
setTemporaryDirectoryPath(String)) to set custom temporary folder for downloaded deployment units. SPI will create folder under the path with name identical to local node ID.SPI tracks all changes of every given URI. This means that if any file is changed or deleted, SPI will re-deploy or delete corresponding tasks. Note that the very first apply to
findResource(String)is blocked until SPI finishes scanning all URI's at least once.There are several deployable unit types supported:
- JAR file.
- GAR file.
- Local disk folder with structure of an unpacked deployment archive.
- Local disk folder containing only compiled Java classes.
Deployment package
Deployment package can be represented as a regular JAR file with a specific structure similar to WAR format. Package files can have'.jar'or'.gar'extension.Package structure:
META-INF/ | - ignite.xml - ... lib/ | -some-lib.jar - ... xyz.class ...-
META-INF/entry may containignite.xmlfile which is a task descriptor file. The purpose of task descriptor XML file is to specify all tasks to be deployed. This file is a regular Spring XML definition file.META-INF/entry may also contain any other file specified by JAR format. -
lib/entry contains all library dependencies. - Compiled Java classes must be placed in the root of a package file.
ComputeTaskinterface. In that case, all grid task classes must have a public no-argument constructor. UseComputeTaskAdapteradapter for convenience when creating grid tasks.By default, all downloaded packages that have digital signature in
META-INFfolder will be verified and deployed only if signature is valid.URI
This SPI uses a hierarchical URI definition. For more information about standard URI syntax refer tojava.net.URIdocumentation.[scheme:][//authority][path][?query] [#fragment]
Every URI defines its own deployment repository which will be scanned for any changes. URI itself has all information about protocol, connectivity, scan intervals and other parameters.
URI's may contain special characters, like spaces. If
encodeUriflag is set totrue(seesetEncodeUri(boolean)), then URI 'path' field will be automatically encoded. By default this flag is set totrue.Code Example
The following example demonstrates how the deployment SPI can be used. It expects that you have a package file in 'home/username/ignite/work/my_deployment/file' folder which contains 'myproject.HelloWorldTask' class.IgniteConfiguration cfg = new IgniteConfiguration(); DeploymentSpi deploymentSpi = new UriDeploymentSpi(); deploymentSpi.setUriList(Arrays.asList("file:///home/username/ignite/work/my_deployment/file")); cfg.setDeploymentSpi(deploymentSpi); try (Ignite ignite = Ignition.start(cfg)) { ignite.compute().execute("myproject.HelloWorldTask", "my args"); }Configuration
UriDeploymentSpihas the following optional configuration parameters (there are no mandatory parameters):-
Array of
UriDeploymentScanner-s which will be used to deploy resources (seesetScanners(UriDeploymentScanner...)). If not specified, preconfiguredUriDeploymentFileScannerandUriDeploymentHttpScannerare used. You can implement your own scanner by implementingUriDeploymentScannerinterface. -
Temporary directory path where scanned packages are
copied to (see
setTemporaryDirectoryPath(String)). -
List of URIs to scan (see
setUriList(List)). If not specified, then URI specified byDFLT_DEPLOY_DIRis used. -
Flag to control encoding of the
'path'portion of URI (seesetEncodeUri(boolean)).
Protocols
Following protocols are supported by this SPI out of the box: Custom Protocols.You can add support for additional protocols if needed. To do this implement UriDeploymentScanner interface and plug your implementation into the SPI via
setScanners(UriDeploymentScanner...)method.In addition to SPI configuration parameters, all necessary configuration parameters for selected URI should be defined in URI. Different protocols have different configuration parameters described below. Parameters are separated by '
;' character.File
For this protocol SPI will scan folder specified by URI on file system and download any deplloyment files or directories that end with .jar or .gar from source directory defined in URI. For file system URI must have scheme equal tofile.Following parameters are supported:
Parameter Description Optional Default freq Scanning frequency in milliseconds. Yes 5000ms specified inUriDeploymentFileScanner.DFLT_SCAN_FREQ.File URI Example
The following example will scan'c:/Program files/ignite/deployment'folder on local box every'1000'milliseconds. Note that since path has spaces,setEncodeUri(boolean)parameter must be set totrue(which is default behavior).file://freq=2000@localhost/c:/Program files/ignite/deploymentHTTP/HTTPS
URI deployment scanner tries to read DOM of the html it points to and parses out href attributes of all <a> tags - this becomes the collection of URLs to deployment package files that should be deployed. It's important that HTTP scanner usesURLConnection.getLastModified()method to check if there were any changes since last iteration for each deployment file before redeploying.Following parameters are supported:
Parameter Description Optional Default freq Scanning frequency in milliseconds. Yes 300000ms specified inUriDeploymentHttpScanner.DFLT_SCAN_FREQ.HTTP URI Example
The following example will download the page `www.mysite.com/ignite/deployment`, parse it and download and deploy all deployment packages specified by href attributes of <a> elements on the page using authentication'username:password'every '10000' milliseconds (only new/updated packages).http://username:password;freq=10000@www.mysite.com:110/ignite/deploymentJava Example
UriDeploymentSpi needs to be explicitly configured to override default local deployment SPI.UriDeploymentSpi deploySpi = new UriDeploymentSpi(); IgniteConfiguration cfg = new IgniteConfiguration(); // Set URIs. deploySpi.setUriList(Arrays.asList("http://www.site.com/tasks", "file://freq=20000@localhost/c:/Program files/gg-deployment")); // Override temporary directory path. deploySpi.setTemporaryDirectoryPath("c:/tmp/grid"); // Override default deployment SPI. cfg.setDeploymentSpi(deploySpi); // Start grid. Ignition.start(cfg);Spring Example
UriDeploymentSpi can be configured from Spring XML configuration file:<bean id="grid.custom.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" singleton="true"> ... <property name="deploymentSpi"> <bean class="org.apache.ignite.grid.spi.deployment.uri.UriDeploymentSpi"> <property name="temporaryDirectoryPath" value="c:/tmp/grid"/> <property name="uriList"> <list> <value>http://www.site.com/tasks</value> <value>file://freq=20000@localhost/c:/Program files/gg-deployment</value> </list> </property> </bean> </property> ... </bean>
For information about Spring framework visit www.springframework.org- See Also:
DeploymentSpi
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEPLOY_TMP_ROOT_NAMEDefault temporary directory name relative to file pathsetTemporaryDirectoryPath(String)} (value isgg.uri.deployment.tmp).static StringDFLT_DEPLOY_DIRDefault deployment directory where SPI will pick up packages.static StringXML_DESCRIPTOR_PATHDefault task description file path and name (value isMETA-INF/ignite.xml).-
Fields inherited from class org.apache.ignite.spi.IgniteSpiAdapter
ignite, igniteInstanceName
-
-
Constructor Summary
Constructors Constructor Description UriDeploymentSpi()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @Nullable DeploymentResourcefindResource(String rsrcName)Finds class loader for the given class.org.apache.ignite.spi.deployment.uri.scanners.UriDeploymentScanner[]getScanners()Gets scanners.StringgetTemporaryDirectoryPath()Gets temporary directory path.List<String>getUriList()Gets list of URIs that are processed by SPI.booleanisCheckMd5()GetscheckMd5property.booleanregister(ClassLoader ldr, Class<?> rsrc)Registers a class loader with this SPI.UriDeploymentSpisetCheckMd5(boolean checkMd5)If set totruethen SPI should exclude files with same md5s from deployment.UriDeploymentSpisetEncodeUri(boolean encodeUri)Indicates that URI must be encoded before usage.voidsetListener(@Nullable DeploymentListener lsnr)Sets or unsets deployment event listener.IgniteSpiAdaptersetName(String name)Sets SPI name.UriDeploymentSpisetScanners(org.apache.ignite.spi.deployment.uri.scanners.UriDeploymentScanner... scanners)Sets scanners.UriDeploymentSpisetTemporaryDirectoryPath(String tmpDirPath)Sets absolute path to temporary directory which will be used by deployment SPI to keep all deployed classes in.UriDeploymentSpisetUriList(List<String> uriList)Sets list of URI which point to a directory with packages and which should be scanned by SPI for the new tasks.voidspiStart(String igniteInstanceName)This method is called to start SPI.voidspiStop()This method is called to stop SPI.StringtoString()booleanunregister(String rsrcName)Unregisters all class loaders that have a class with given name or have a class with giveComputeTaskNamevalue.-
Methods inherited from class org.apache.ignite.spi.IgniteSpiAdapter
addTimeoutObject, assertParameter, checkConfigurationConsistency0, clientFailureDetectionTimeout, configInfo, createSpiAttributeName, failureDetectionTimeout, failureDetectionTimeoutEnabled, failureDetectionTimeoutEnabled, getConsistentAttributeNames, getExceptionRegistry, getLocalNode, getName, getNodeAttributes, getSpiContext, ignite, initFailureDetectionTimeout, injectables, injectResources, isNodeStopping, onBeforeStart, onClientDisconnected, onClientReconnected, onContextDestroyed, onContextDestroyed0, onContextInitialized, onContextInitialized0, registerMBean, removeTimeoutObject, started, startInfo, startStopwatch, stopInfo, unregisterMBean
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.ignite.spi.IgniteSpi
getName, getNodeAttributes, onClientDisconnected, onClientReconnected, onContextDestroyed, onContextInitialized
-
-
-
-
Field Detail
-
DFLT_DEPLOY_DIR
public static final String DFLT_DEPLOY_DIR
Default deployment directory where SPI will pick up packages. Note that this path is relative toIGNITE_HOME/workfolder ifIGNITE_HOMEsystem or environment variable specified, otherwise it is relative toworkfolder under systemjava.io.tmpdirfolder.
-
XML_DESCRIPTOR_PATH
public static final String XML_DESCRIPTOR_PATH
Default task description file path and name (value isMETA-INF/ignite.xml).- See Also:
- Constant Field Values
-
DEPLOY_TMP_ROOT_NAME
public static final String DEPLOY_TMP_ROOT_NAME
Default temporary directory name relative to file pathsetTemporaryDirectoryPath(String)} (value isgg.uri.deployment.tmp).- See Also:
- Constant Field Values
-
-
Method Detail
-
setTemporaryDirectoryPath
@IgniteSpiConfiguration(optional=true) public UriDeploymentSpi setTemporaryDirectoryPath(String tmpDirPath)
Sets absolute path to temporary directory which will be used by deployment SPI to keep all deployed classes in.If not provided, default value is
java.io.tmpdirsystem property value.- Parameters:
tmpDirPath- Temporary directory path.- Returns:
thisfor chaining.
-
setUriList
@IgniteSpiConfiguration(optional=true) public UriDeploymentSpi setUriList(List<String> uriList)
Sets list of URI which point to a directory with packages and which should be scanned by SPI for the new tasks.If not provided, default value is list with
file://${IGNITE_HOME}/work/deployment/fileelement. Note that system propertyIGNITE_HOMEmust be set. For unknownIGNITE_HOMElist of URI must be provided explicitly.- Parameters:
uriList- Package file URIs.- Returns:
thisfor chaining.
-
setCheckMd5
@IgniteSpiConfiguration(optional=true) public UriDeploymentSpi setCheckMd5(boolean checkMd5)
If set totruethen SPI should exclude files with same md5s from deployment. Otherwise it should try to load new unit regardless to possible file duplication.- Parameters:
checkMd5- new value for the property- Returns:
thisfor chaining.
-
isCheckMd5
public boolean isCheckMd5()
GetscheckMd5property.- Returns:
- value of the
checkMd5property.
-
setEncodeUri
@IgniteSpiConfiguration(optional=true) public UriDeploymentSpi setEncodeUri(boolean encodeUri)
Indicates that URI must be encoded before usage. Encoding means replacing all occurrences of space with '%20', percent sign with '%25' and semicolon with '%3B'.If not provided, default value is
true.- Parameters:
encodeUri-trueif every URI should be encoded andfalseotherwise.- Returns:
thisfor chaining.
-
getTemporaryDirectoryPath
public String getTemporaryDirectoryPath()
Gets temporary directory path.- Returns:
- Temporary directory path.
-
getUriList
public List<String> getUriList()
Gets list of URIs that are processed by SPI.- Returns:
- List of URIs.
-
setListener
public void setListener(@Nullable @Nullable DeploymentListener lsnr)Sets or unsets deployment event listener. Grid implementation will use this listener to properly add and remove various deployments.- Specified by:
setListenerin interfaceDeploymentSpi- Parameters:
lsnr- Listener for deployment events.nullto unset the listener.
-
getScanners
public org.apache.ignite.spi.deployment.uri.scanners.UriDeploymentScanner[] getScanners()
Gets scanners.- Returns:
- Scanners.
-
setScanners
@IgniteSpiConfiguration(optional=true) public UriDeploymentSpi setScanners(org.apache.ignite.spi.deployment.uri.scanners.UriDeploymentScanner... scanners)
Sets scanners.- Parameters:
scanners- Scanners.- Returns:
thisfor chaining.
-
spiStop
public void spiStop() throws IgniteSpiExceptionThis method is called to stop SPI. After this method returns kernel assumes that this SPI is finished and all resources acquired by it are released.Note that this method can be called at any point including during recovery of failed start. It should make no assumptions on what state SPI will be in when this method is called.
- Specified by:
spiStopin interfaceIgniteSpi- Throws:
IgniteSpiException- Thrown in case of any error during SPI stop.
-
spiStart
public void spiStart(String igniteInstanceName) throws IgniteSpiException
This method is called to start SPI. After this method returns successfully kernel assumes that SPI is fully operational.- Specified by:
spiStartin interfaceIgniteSpi- Parameters:
igniteInstanceName- Name of Ignite instance this SPI is being started for (nullfor default Ignite instance).- Throws:
IgniteSpiException- Throws in case of any error during SPI start.
-
findResource
@Nullable public @Nullable DeploymentResource findResource(String rsrcName)
Finds class loader for the given class.- Specified by:
findResourcein interfaceDeploymentSpi- Parameters:
rsrcName- Class name or class alias to find class loader for.- Returns:
- Deployed class loader, or
nullif not deployed.
-
register
public boolean register(ClassLoader ldr, Class<?> rsrc) throws IgniteSpiException
Registers a class loader with this SPI. This method exists to be able to add external class loaders to deployment SPI. Deployment SPI may also have its own class loaders. For example, in case of GAR deployment, every GAR file is loaded and deployed with a separate class loader maintained internally by the SPI.The array of classes passed in should be checked for presence of
ComputeTaskNameannotations. The classes that have this annotation should be accessible by this name fromDeploymentSpi.findResource(String)method.- Specified by:
registerin interfaceDeploymentSpi- Parameters:
ldr- Class loader to register.rsrc- Class that should be checked for aliases. Currently the only alias in the system isComputeTaskNamefor task classes; in future, there may be others.- Returns:
Trueif resource was registered.- Throws:
IgniteSpiException- If registration failed.
-
unregister
public boolean unregister(String rsrcName)
Unregisters all class loaders that have a class with given name or have a class with giveComputeTaskNamevalue.- Specified by:
unregisterin interfaceDeploymentSpi- Parameters:
rsrcName- Either class name orComputeTaskNamevalue for a class whose class loader needs to be unregistered.- Returns:
Trueif resource was unregistered.
-
setName
public IgniteSpiAdapter setName(String name)
Sets SPI name.- Overrides:
setNamein classIgniteSpiAdapter- Parameters:
name- SPI name.- Returns:
thisfor chaining.
-
-