@GridSpiMultipleInstancesSupport(value=true) @GridSpiConsistencyChecked(optional=false) public class GridUriDeploymentSpi extends org.gridgain.grid.spi.GridSpiAdapter implements org.gridgain.grid.spi.deployment.GridDeploymentSpi, GridUriDeploymentSpiMBean
GridDeploymentSpi which can deploy tasks from
different sources like file system folders, FTP, 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) findClassLoader(String)}
is blocked until SPI finishes scanning all URI's at least once.
There are several deployable unit types supported:
'.gar' extension.
GAR file structure (file or directory ending with '.gar'):
META-INF/
|
- gridgain.xml
- ...
lib/
|
-some-lib.jar
- ...
xyz.class
...
META-INF/ entry may contain gridgain.xml file 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.
GridComputeTask interface. In that case, all grid task classes must have a
public no-argument constructor. Use GridComputeTaskAdapter adapter for
convenience when creating grid tasks.
By default, all downloaded GAR files that have digital signature in META-INF
folder will be verified and deployed only if signature is valid.
java.net.URI documentation.
[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 encodeUri
flag is set to true (see setEncodeUri(boolean)), then
URI 'path' field will be automatically encoded. By default this flag is
set to true.
GridUriDeploymentSpi has the following optional configuration
parameters (there are no mandatory parameters):
setTemporaryDirectoryPath(String)).
setUriList(List)). If not
specified, then URI specified by DFLT_DEPLOY_DIR is used.
'path' portion of URI
(see setEncodeUri(boolean)).
;' character.
file.
Following parameters are supported for FILE protocol:
| Parameter | Description | Optional | Default |
|---|---|---|---|
| freq | File directory scan frequency in milliseconds. | Yes | 5000 ms specified in DFLT_DISK_SCAN_FREQUENCY. |
'c:/Program files/gridgain/deployment'
folder on local box every '5000' milliseconds. Note that since path
has spaces, setEncodeUri(boolean) parameter must
be set to true (which is default behavior).
file://freq=5000@localhost/c:/Program files/gridgain/deployment
GridComputeTask interface.
This protocol comes very handy during development, as it allows developer
to specify IDE compilation output folder as URI and all task classes
in that folder will be deployed automatically.
Following parameters are supported for CLASSES protocol:
| Parameter | Description | Optional | Default |
|---|---|---|---|
| freq | File directory scan frequency in milliseconds. | Yes | 5000 ms specified in DFLT_DISK_SCAN_FREQUENCY. |
'c:/Program files/gridgain/deployment'
folder on local box every '5000' milliseconds. Note that since path
has spaces, setEncodeUri(boolean) parameter must
be set to true (which is default behavior).
classes://freq=5000@localhost/c:/Program files/gridgain/deployment
| Parameter | Description | Optional | Default |
|---|---|---|---|
| freq | FTP location scan frequency in milliseconds. | Yes | 300000 ms specified in DFLT_FTP_SCAN_FREQUENCY. |
| username:password | FTP username and password specified in standard URI server-based authority format. | No | --- |
username:password to 'localhost' on port '21',
with initial path set to 'gridgain/deployment'
ftp://username:password;freq=10000@localhost:21/gridgain/deployment
'gridgain/deployment' folder with
on site 'www.mysite.com' using authentication
'username:password' every '10000' milliseconds.
http://username:password;freq=10000@www.mysite.com:110/gridgain/deployment
GridUriDeploymentSpi deploySpi = new GridUriDeploymentSpi();
GridConfiguration cfg = new GridConfiguration();
List<String> uris = new ArrayList<String>(5);
uris.add("http://www.site.com/tasks");
uris.add("ftp://ftpuser:password;freq=10000@localhost:21/gg-test/deployment");
uris.add("file://freq=20000@localhost/c:/Program files/gg-deployment");
uris.add("classes:///c:/Java_Projects/myproject/out");
// Set URIs.
deploySpi.setUriList(uris);
// Override temporary directory path.
deploySpi.setTemporaryDirectoryPath("c:/tmp/grid");
// Override default deployment SPI.
cfg.setDeploymentSpi(deploySpi);
// Start grid.
G.start(cfg);
<bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfiguration" singleton="true">
...
<property name="deploymentSpi">
<bean class="org.gridgain.grid.spi.deployment.uri.GridUriDeploymentSpi">
<property name="temporaryDirectoryPath" value="c:/tmp/grid"/>
<property name="uriList">
<list>
<value>http://www.site.com/tasks</value>
<value>ftp://ftpuser:password;freq=10000@localhost:21/gg-test/deployment</value>
<value>file://freq=20000@localhost/c:/Program files/gg-deployment</value>
<value>classes:///c:/Java_Projects/myproject/out</value>
</list>
</property>
</bean>
</property>
...
</bean>
For information about Spring framework visit www.springframework.org
GridDeploymentSpi| Modifier and Type | Field and Description |
|---|---|
static String |
DEPLOY_TMP_ROOT_NAME
Default temporary directory name relative to file path
setTemporaryDirectoryPath(String)} (value is gg.uri.deployment.tmp). |
static String |
DFLT_DEPLOY_DIR
Default deployment directory where SPI will pick up GAR files.
|
static int |
DFLT_DISK_SCAN_FREQUENCY
Default scan frequency for
file:// and classes:// protocols (value is 5000). |
static int |
DFLT_FTP_SCAN_FREQUENCY
Default scan frequency for
ftp:// protocol (value is 300000). |
static int |
DFLT_HTTP_SCAN_FREQUENCY
Default scan frequency for
http:// protocol (value is 300000). |
static String |
XML_DESCRIPTOR_PATH
Default task description file path and name (value is
META-INF/gridgain.xml). |
| Constructor and Description |
|---|
GridUriDeploymentSpi() |
| Modifier and Type | Method and Description |
|---|---|
org.gridgain.grid.spi.deployment.GridDeploymentResource |
findResource(String rsrcName) |
String |
getTemporaryDirectoryPath()
Gets temporary directory path.
|
List<String> |
getUriList()
Gets list of URIs that are processed by SPI.
|
boolean |
isCheckMd5()
Gets
checkMd5 property. |
boolean |
register(ClassLoader ldr,
Class<?> rsrc) |
void |
setCheckMd5(boolean checkMd5)
If set to
true then SPI should exclude files with same md5s from deployment. |
void |
setEncodeUri(boolean encodeUri)
Indicates that URI must be encoded before usage.
|
void |
setListener(org.gridgain.grid.spi.deployment.GridDeploymentListener lsnr) |
void |
setTemporaryDirectoryPath(String tmpDirPath)
Sets absolute path to temporary directory which will be used by
deployment SPI to keep all deployed classes in.
|
void |
setUriList(List<String> uriList)
Sets list of URI which point to GAR file and which should be
scanned by SPI for the new tasks.
|
void |
spiStart(String gridName) |
void |
spiStop() |
String |
toString() |
boolean |
unregister(String rsrcName) |
assertParameter, checkConfigurationConsistency0, configInfo, createSpiAttributeName, getConsistentAttributeNames, getGridGainHome, getLocalNodeId, getName, getNodeAttributes, getSpiContext, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, injectables, onContextDestroyed, onContextDestroyed0, onContextInitialized, onContextInitialized0, registerMBean, setName, startInfo, startStopwatch, stopInfo, unregisterMBeanclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitpublic static final String DFLT_DEPLOY_DIR
GRIDGAIN_HOME/work folder if GRIDGAIN_HOME system or environment variable specified,
otherwise it is relative to work folder under system java.io.tmpdir folder.GridConfiguration.getWorkDirectory(),
Constant Field Valuespublic static final int DFLT_DISK_SCAN_FREQUENCY
file:// and classes:// protocols (value is 5000).public static final int DFLT_FTP_SCAN_FREQUENCY
ftp:// protocol (value is 300000).public static final int DFLT_HTTP_SCAN_FREQUENCY
http:// protocol (value is 300000).public static final String XML_DESCRIPTOR_PATH
META-INF/gridgain.xml).public static final String DEPLOY_TMP_ROOT_NAME
setTemporaryDirectoryPath(String)} (value is gg.uri.deployment.tmp).@GridSpiConfiguration(optional=true) public void setTemporaryDirectoryPath(String tmpDirPath)
If not provided, default value is java.io.tmpdir system property value.
tmpDirPath - Temporary directory path.@GridSpiConfiguration(optional=true) public void setUriList(List<String> uriList)
If not provided, default value is list with
file://${GRIDGAIN_HOME}/work/deployment/file element.
Note that system property GRIDGAIN_HOME must be set.
For unknown GRIDGAIN_HOME list of URI must be provided explicitly.
uriList - GAR file URIs.@GridSpiConfiguration(optional=true) public void setCheckMd5(boolean checkMd5)
true then SPI should exclude files with same md5s from deployment.
Otherwise it should try to load new unit regardless to possible file duplication.checkMd5 - new value for the propertypublic boolean isCheckMd5()
checkMd5 property.isCheckMd5 in interface GridUriDeploymentSpiMBeancheckMd5 property.@GridSpiConfiguration(optional=true) public void setEncodeUri(boolean encodeUri)
If not provided, default value is true.
encodeUri - true if every URI should be encoded and
false otherwise.public String getTemporaryDirectoryPath()
getTemporaryDirectoryPath in interface GridUriDeploymentSpiMBeanpublic List<String> getUriList()
getUriList in interface GridUriDeploymentSpiMBeanpublic void setListener(@Nullable
org.gridgain.grid.spi.deployment.GridDeploymentListener lsnr)
setListener in interface org.gridgain.grid.spi.deployment.GridDeploymentSpipublic void spiStop()
throws org.gridgain.grid.spi.GridSpiException
spiStop in interface org.gridgain.grid.spi.GridSpiorg.gridgain.grid.spi.GridSpiExceptionpublic void spiStart(String gridName) throws org.gridgain.grid.spi.GridSpiException
spiStart in interface org.gridgain.grid.spi.GridSpiorg.gridgain.grid.spi.GridSpiException@Nullable public org.gridgain.grid.spi.deployment.GridDeploymentResource findResource(String rsrcName)
findResource in interface org.gridgain.grid.spi.deployment.GridDeploymentSpipublic boolean register(ClassLoader ldr, Class<?> rsrc) throws org.gridgain.grid.spi.GridSpiException
register in interface org.gridgain.grid.spi.deployment.GridDeploymentSpiorg.gridgain.grid.spi.GridSpiExceptionpublic boolean unregister(String rsrcName)
unregister in interface org.gridgain.grid.spi.deployment.GridDeploymentSpiCopyright © 2014. All rights reserved.