Summary: Explains how to deploy your processing unit onto the GigaSpaces
Service Grid to get automated SLA management and self-healing capabilities
OverviewDeploying your processing unit to the service grid is the preferred way to run your it in your production environment. The service grid provides the following main benefits to the processing unit deployed onto it:
The Deployment ProcessOnce built according to the processing unit directory structure, the processing unit can be deployed via the various deployment tools available in GigaSpaces XAP (UI, CLI, Ant, Maven or the Admin API). After you package the processing unit and deploy it via one of the deployment tools, the deployment tool uploads it to all the running GSMs, where it is extracted and provisioned to the GSCs.
Distribution of Processing Unit Binaries to the Running GSCsBy default, when a processing unit instance is provisioned to run on a certain GSC, the GSC downloads the processing unit archive from the GSM into the <GigaSpaces Root>/work/deployed-processing-units directory (The location of this directory can be overridden via the com.gs.work system property). Downloading the processing unit archive to the GSC is the recommended option, but it can be disabled. In order to disable it, the pu.download deployment property should be set to false. This will not download the entire archive to the GSC, but will force the GSC to load the processing unit classes one at a time from the GSM via a URLClassLoader. Deploying the Processing Unit Using the Various Deployment ToolsGigaSpaces provides several options to deploy a processing unit onto the Service Grid. Below you can find a simple deployment example with the various deployment tools for deploying a processing unit archive called myPU.jar located in the usr/gigaspaces directory:
Admin API
Deploying via code is done using the GigaSpaces Admin API. The following example shows how to deploy the myPU.jar processing unit using one of the available GSMs. For more details please consult the documentation and javadoc of the Admin API. Admin admin = new AdminFactory().addGroup("myGroup").createAdmin(); File puArchive = new File("/opt/gigaspaces/myPU.jar"); ProcessingUnit myPU = admin.getGridServiceManagers().deploy(new ProcessingUnitDeployment(puArchive)); Ant Deploying with Ant is based on the org.openspaces.pu.container.servicegrid.deploy.Deploy class (in fact, all of the deployment tools use this class although it is not exposed directly to the end user). In the below example we create an Ant macro using this class and use it to deploy our processing unit. The deploy class is executable via its main() method, and can accept various parameters to control the deployment process. These parameters are identical to these of the deploy CLI command, for a complete list of the available parameters please consult the deploy CLI reference documentation.. <deploy file="/opt/gigaspaces/myPU.jar" /> <macrodef name="deploy"> <attribute name="file"/> <sequential> <java classname="org.openspaces.pu.container.servicegrid.deploy.Deploy" fork="false"> <classpath refid="all-libs"/> <arg value="-groups" /> <arg value="mygroup" /> <arg value="@{file}"/> </java> </sequential> </macrodef> GigaSpaces CLI Deploying via the CLI is based on the deploy command. This command accepts various parameters to control the deployment process. These parameters are documented in full in the deploy CLI reference documentation.. > <gigaspaces root>/bin/gs.sh(bat) deploy myPU.jar GigaSpaces UI
Hot DeployTo enable business continuity in a better manner, having system upgrade without any downtime, here is a simple procedure you should follow when you would like to perform a hot deploy, upgrading a PU that includes both a business logic and a collocated embedded space: You can script the above procedure via the Administration and Monitoring API, allowing you to perform system upgrade without downtime. Restart a running PU via the GS-UITo restart a running PU (all instances) via the GS-UI you should: Restart a running PU via the Admin APIThe ProcessingUnitInstance includes few restart methods you may use to restart a PU instance: restart()
restartAndWait()
restartAndWait(long timeout, TimeUnit timeUnit)
Here is an example code that is using the ProcessingUnitInstance.restart to restart the entire PU instances in an automatic manner: import java.util.concurrent.TimeUnit; import java.util.logging.Logger; import org.openspaces.admin.Admin; import org.openspaces.admin.AdminFactory; import org.openspaces.admin.pu.ProcessingUnit; import org.openspaces.admin.pu.ProcessingUnitInstance; import com.gigaspaces.cluster.activeelection.SpaceMode; public class PUReatartMain { static Logger logger = Logger.getLogger("PUReatart"); public static void main(String[] args) { String puToReatart = "myPU"; Admin admin = new AdminFactory().createAdmin(); ProcessingUnit processingUnit = admin.getProcessingUnits().waitFor( puToReatart, 10, TimeUnit.SECONDS); if (processingUnit == null) { logger.info("can't get PU instances for "+puToReatart ); admin.close(); System.exit(0); } // Wait for all the members to be discovered processingUnit.waitFor(processingUnit.getTotalNumberOfInstances()); ProcessingUnitInstance[] puInstances = processingUnit.getInstances(); // restart all backups for (int i = 0; i < puInstances.length; i++) { if (getSpaceMode(puInstances[i]) == SpaceMode.BACKUP) { restartPUInstance(puInstances[i]); } } // restart all primaries for (int i = 0; i < puInstances.length; i++) { if (getSpaceMode(puInstances[i]) == SpaceMode.PRIMARY) { restartPUInstance(puInstances[i]); } } admin.close(); System.exit(0); } private static void restartPUInstance( ProcessingUnitInstance pi) { final String instStr = getSpaceMode(pi) != SpaceMode.PRIMARY?"backup" : "primary"; logger.info("restarting instance " + pi.getInstanceId() + " on " + pi.getMachine().getHostName() + "[" + pi.getMachine().getHostAddress() + "] GSC PID:" + pi.getVirtualMachine().getDetails().getPid() + " mode:" + instStr + "..."); pi = pi.restartAndWait(); logger.info("done"); } private static SpaceMode getSpaceMode(ProcessingUnitInstance pi){ while (pi.getSpaceInstance().getMode() == SpaceMode.NONE){ try { Thread.sleep(1000); } catch(Exception e){} } return pi.getSpaceInstance().getMode(); } } |
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |