|
BEA Systems, Inc. | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
This MBean is the user API for initiating deployment requests and exists only on an Admin Server.
To access this MBean use DeployerRuntime.getDeployerRuntime()
.
The deployment methods in this MBean provide access to the 2 phase deployment protocol. This protocol is only supported on WLS 7.x servers and later. If no target servers in an activate request are known to be pre-release 7 servers, then the 2 phase protocol is used. Otherwise the deployment will use the WLS 6.x deployment protocol, even if some target servers are at release 7.
The deployment process involves a number of state changes: start<-->staged<-->prepared<-->active. The methods in this MBean provide the means for changing the state of an application, as follows:
activate: places application in active state from any other state
deactivate: places application in prepared state from active state
unprepare: places application in staged state from active and prepared state
remove: places application in start state from any other state
Activating An Application
The basic process of deploying an application is shown in the following example:
DeployerRuntimeMBean deployer = getDeployerRuntime(userName, password, adminURL); try { DeploymentTaskRuntimeMBean task = deployer.activate(sourceFile, appName, staging, info, id); } catch (ManagementException me) { System.out.println("Deployment failed: "+me.getMessage()); }
In this example, sourceFile is the path to the application. If the application is an EAR, then sourceFile would name the EAR archive or the root directory if it is not archived. Similarly, if the application is not an EAR, but a standalone module (web app or EJB), the sourceFile argument would be the path to the module archive or directory.
The sourceFile argument can be null, indicating that this is a redeployment and that the source is unchanged from a previous deployment.
The appName argument is the name to be given to the application. If this is a new
deployment, an ApplicationMBean
is created. For redeployments,
an existing ApplicationMBean with appName is used as the application's configured state.
The info argument is a DeploymentData
object which is used to
qualify the deployment in terms of targets of the deployment and an optional list of files which
are to be refreshed during a redeploy.
The staging argument is used to specify whether the application is to be staged to the target servers. This
argument may be null (use ServerMBean.getStagingMode()
), "stage", or "nostage".
Staging is the process of uploading the application file to the target servers' staging area, defined in
ServerMBean.getStagingDirectoryName()
.
The id argument allows the caller to name the deployment task. Care should be taken here as the tag must be unique. The recommendation is to generally use null for this argument, allowing the system to generate a unique tag.
The deployment process runs asynchronously to the invoker; it will initiate the task then return the
DeploymentTaskRuntimeMBean
object representing the task to the client.
This object may be used to track status of the task. If the client wants to wait until the task completes then
the following is a basic method for doing this.
while (task.isRunning()) { try { Thread.sleep(oneSecond); } catch (InterruptedException ie) {} }
Cancelling A Deployment
Note that a task will not complete until all targets have either completed the deployment or failed. If one of the targets is inactive, the task will remain active until the server starts or the task is cancelled. Cancelling a deployment task is accomplished as follows:
if (task.isRunning()) { try { task.cancel(); } catch (Exception e) {} }
Targeting Specific Servers
The folowing examples show how to be more specific when targeting a deployment.
DeploymentData info = new DeploymentData(); info.addTarget(server1,null); // adds server1 as target for all modules in app String[] mods = { "web-module","ejb" }; info.addTarget(server2,mods); //adds server2 as target for modules web-module and ejb deployer.activate(sourceFile, appName, info, null, null); // refreshes the hello.jsp file on all currently targeted servers. The "jsps" directory is // relative to the root of the application. String[] files = { "jsps/hello.jsp" }; DeploymentData info = new DeploymentData(files); deployer.activate(null, appName, null, info, null);
Deactivating An Application
To deactivate an application is to suspend it. The application files remain staged on the target servers, and can be reactivated without restaging. It should be noted that deactivating an application does not unload any of its classes. To do so requires an unprepare operation (see below). The following example show appName being deactivated, then subsequently reactivated on all configured servers.
deployer.deactivate(appName, null, null); . . . deployer.activate(null, appName, null, null, null);
Unpreparing An Application
To unprepare an application is to suspend and unload it. The application files remain staged on the target servers, and any relevant classes are unloaded. If the application is to be reactivated with new class files, unprepare is the correct approach, rather than deactivate. The following example show appName being unprepared, then subsequently reactivated on all configured servers.
deployer.unprepare(appName, null, null); . . . deployer.activate(sourceFile, appName, null, null, null);
Removing An Application
Removing an application involves deactivation, unstaging and possible removal of the application. After removing an application from a managed server it is deconfigured from that server. If no servers remain targeted by the application, the entire configuration of the application is removed. Removal does not touch the application source, but will remove staged copies of the application.
// this completely removes an application from the domain configuration deployer.remove(appName, null, null);
Tracking Deployment Status
Once initiated, a deployment task can be monitored via notifications or polling. Use of notifications relies on JMX Notifications on the relevant ApplicationMBean and is accomplished as follows:
package examples.deploy; import java.io.Serializable; import javax.management.MBeanServer; import javax.management.Notification; import javax.management.NotificationFilter; import weblogic.management.DeploymentNotification; import weblogic.management.Helper; import weblogic.management.MBeanHome; import weblogic.management.RemoteNotificationListener; import weblogic.management.configuration.ApplicationMBean; import weblogic.management.deploy.DeploymentData; import weblogic.management.deploy.DeployerRuntime; import weblogic.management.runtime.DeployerRuntimeMBean; import weblogic.management.runtime.DeploymentTaskRuntimeMBean; // // // This example activates and application and prints the resulting notifications // generated during the processing of the deployment. The args passed to this // program are: // arg1: userid // arg2: password // arg3: admin URL // arg4: app name // arg5: app source // arg6: target server // // public class Activater implements Serializable { private static String userid; private static String password; private static String url; private static String name; private static String source; private static String server; void deploy() { try { // Get access to MBeanHome MBeanHome home = Helper.getAdminMBeanHome(userid, password, url); // Get the deployer DeployerRuntimeMBean deployer = DeployerRuntime.getDeployerRuntime(home); // Build the DeploymentData object DeploymentData info = new DeploymentData(); info.addTarget(server, null); // Create the deployment task. Last arg indicates to just create the task, but not initiate it DeploymentTaskRuntimeMBean task = deployer.activate(source,name,null,info,null,false); // Register for notifications ApplicationMBean app = task.getDeploymentObject(); MBeanServer mBeanServer = home.getMBeanServer(); mBeanServer.addNotificationListener( app.getObjectName(), new DeployListener(), new DeployFilter(), null ); // Start the task task.start(); System.out.println(task.getDescription()); // wait until finished while (task.isRunning()) { try { Thread.sleep(1000); } catch (InterruptedException ie) { System.out.println(task.getStatus()); } } } catch (Exception e) { System.out.println(e.getMessage()); } } public static void main(String[] argv) throws Exception { if (argv.length == 6) { userid = argv[0]; password = argv[1]; url = argv[2]; name = argv[3]; source = argv[4]; server = argv[5]; Activater activater = new Activater(); activater.deploy(); System.exit(0); } } // Inner classes for handling notifications class DeployListener implements RemoteNotificationListener { public void handleNotification(Notification notification, java.lang.Object handback) { System.out.println( notification.getMessage() ); } }; // inner class for filtering notifications class DeployFilter implements NotificationFilter, Serializable { public boolean isNotificationEnabled( Notification n ) { return ( n instanceof DeploymentNotification ); } } }
Field Summary | |
static java.lang.String |
DEPLOYER_NAME
Name of this singleton mbean |
Method Summary | |
DeploymentTaskRuntimeMBean |
activate(java.lang.String source,
java.lang.String name,
java.lang.String stagingMode,
DeploymentData info,
java.lang.String id)
Activate a deployment. |
DeploymentTaskRuntimeMBean |
activate(java.lang.String source,
java.lang.String name,
java.lang.String stagingMode,
DeploymentData info,
java.lang.String id,
boolean startTask)
Same functionality as activate(String, String, String, DeploymentData, String) except that control
is given back to caller without actually initiating the task, when startTask is false. |
DeploymentTaskRuntimeMBean |
deactivate(java.lang.String name,
DeploymentData info,
java.lang.String id)
Deactivate a deployment. |
DeploymentTaskRuntimeMBean |
deactivate(java.lang.String name,
DeploymentData info,
java.lang.String id,
boolean startTask)
Same functionality as deactivate(String, DeploymentData, String) except that control
is given back to caller without actually initiating the task, when startTask is false. |
java.util.Map |
getAvailabilityStatusForApplication(java.lang.String appName,
boolean refreshCache)
Provides a map consisting of Component names of the application and map of availability status for each target of that component including any virtual host. |
java.util.Map |
getAvailabilityStatusForComponent(ComponentMBean compMBean,
boolean refreshCache)
Provides a map of availability status for each target of that component including any virtual host. |
DeploymentTaskRuntimeMBean[] |
list()
Return array of all known deployment tasks |
TargetMBean[] |
lookupActiveTargetsForComponent(ComponentMBean comp)
Provides list of targets where a module/component is currently active. |
VirtualHostMBean[] |
lookupActiveVirtualHostsFor(WebDeploymentMBean comp)
Provides list of virtual hosts where a WebDeployment is currently active. |
DeploymentTaskRuntimeMBean |
query(java.lang.String id)
locates a deployment task based on the deployment id. |
DeploymentTaskRuntimeMBean |
remove(java.lang.String name,
DeploymentData info,
java.lang.String id)
Removes a deployment. |
DeploymentTaskRuntimeMBean |
remove(java.lang.String name,
DeploymentData info,
java.lang.String id,
boolean startTask)
Same functionality as remove(String, DeploymentData, String) except that control
is given back to caller without actually initiating the task, when startTask is false. |
DeploymentTaskRuntimeMBean |
unprepare(java.lang.String name,
DeploymentData info,
java.lang.String id)
Deactivate and unload a deployment. |
DeploymentTaskRuntimeMBean |
unprepare(java.lang.String name,
DeploymentData info,
java.lang.String id,
boolean startTask)
Same functionality as unprepare(String, DeploymentData, String) except that control
is given back to caller without actually initiating the task, when startTask is false. |
Methods inherited from interface weblogic.management.WebLogicMBean |
getMBeanInfo,
getName,
getObjectName,
getParent,
getType,
isCachingDisabled,
isRegistered,
setName,
setParent |
Methods inherited from interface javax.management.DynamicMBean |
getAttribute,
getAttributes,
invoke,
setAttribute,
setAttributes |
Methods inherited from interface javax.management.MBeanRegistration |
postDeregister,
postRegister,
preDeregister,
preRegister |
Methods inherited from interface javax.management.NotificationBroadcaster |
addNotificationListener,
getNotificationInfo,
removeNotificationListener |
Field Detail |
public static final java.lang.String DEPLOYER_NAME
Method Detail |
public DeploymentTaskRuntimeMBean activate(java.lang.String source, java.lang.String name, java.lang.String stagingMode, DeploymentData info, java.lang.String id) throws ManagementException
If the source argument is a valid path to an EAR or module, the application files will be distributed, as necessary, to the target servers. If the source argument is null, then the application must already be configured with a valid path.
The name argument must always be specified (not null). If there is already an application configured with this name, then the deployment will be based on that application. Otherwise, this is a new deployment and an ApplicationMBean will be created and fully configured based on the application descriptors found in the archive or directory named by the source argument. If this is a new deployment, the source argument cannot be null.
The stagingMode argument can be used to override the staging attribute of the targeted servers. If this argument is null, the application will be staged to each server if that server is configured to be staged. If stagingMode is "stage" or "nostage" then the application will be staged or not staged, respectively, to each server, regardless of the server's configuration. If the staging mode is "external_stage", the application files are not staged by the server, rather the user is expected to place them in the staging area.
The info argument is used to qualify the deployment. If null, the deployment will apply to the application's configured target servers. If info is not null, then it names a list of servers, each of which can be further qualified by module names. If a named target is not already configured for this application, it will be added as a target to the appropriate components.
The info argument can also specify a list of files and directories. This supports application refreshes. When a file list is defined in the info object, the deployment will cause those files to be redistributed to the target servers. The file paths must be relative to the application source. If the application is an archive, the entire archive is redistributed, otherwise only the named files are distributed. Note that if the application targets release 6.x servers, there is no guarantee that only the files listed are redeployed.
The id argument is used to specify the identifier for the resulting task. If null, the system will generate the id. If not null, then the value must be unique across all existing deployment tasks.
source
- is the path to the application. If null, the configured path is used.name
- is the configured name of the application.stagingMode
- the value that will be set on the ApplicationMBean for this deployment "stage", "external_stage", "nostage", or null which implies use the servers stagingMode value.info
- describes the details of the deployment.id
- to use for tracking. Use null to allow system to generate.public DeploymentTaskRuntimeMBean activate(java.lang.String source, java.lang.String name, java.lang.String stagingMode, DeploymentData info, java.lang.String id, boolean startTask) throws ManagementException
activate(String, String, String, DeploymentData, String)
except that control
is given back to caller without actually initiating the task, when startTask is false. The client must then invoke
the DeploymentTaskRuntimeMBean.start()
method to complete the activation process. This is most useful when
the client is interested in receiving notifications of the task's progress.
source
- is the path to the application. If null, the configured path is used.name
- is the configured name of the application.stagingMode
- the value that will be set on the ApplicationMBean for this deployment "stage", "external_stage", "nostage", or null which implies use the servers stagingMode value.info
- describes the details of the deployment.id
- to use for tracking. Use null to allow system to generate.startTask
- indicates whether to initiate the activation (true) or allow the client to initiate it.public DeploymentTaskRuntimeMBean deactivate(java.lang.String name, DeploymentData info, java.lang.String id) throws ManagementException
The info parameter is used to define the specific targets the deactivation applies to. If any targets are specified in the info object, they will be removed from the application configuration. If info object does not specify any targets then the deactivation will apply to all targets configured for the application. In this scenario the configured targets are not removed from the configuration. Rather, the application is configured as undeployed.
name
- is the configured name of the application.info
- describes the details of the deployment. Null interpreted to deactivate the application on all servers, retaining targets.id
- to use for tracking. If null, a system generated id is used.public DeploymentTaskRuntimeMBean deactivate(java.lang.String name, DeploymentData info, java.lang.String id, boolean startTask) throws ManagementException
deactivate(String, DeploymentData, String)
except that control
is given back to caller without actually initiating the task, when startTask is false. The client must invoke
the DeploymentTaskRuntimeMBean.start()
method to complete the deactivation process. This is most useful when
the client is interested in receiving notifications of the task's progress.
name
- is the configured name of the application.info
- describes the details of the deployment. Null interpreted to deactivate the application on all servers, retaining targets.id
- to use for tracking. If null, a system generated id is used.startTask
- specifies whether to start the task or allow client to start it themselves.public DeploymentTaskRuntimeMBean remove(java.lang.String name, DeploymentData info, java.lang.String id) throws ManagementException
name
- is the configured name of the application to removeinfo
- describes the details of the deployment.id
- to use for tracking. If null, a system generated id is used.public DeploymentTaskRuntimeMBean remove(java.lang.String name, DeploymentData info, java.lang.String id, boolean startTask) throws ManagementException
remove(String, DeploymentData, String)
except that control
is given back to caller without actually initiating the task, when startTask is false. The client must invoke
the DeploymentTaskRuntimeMBean.start()
method to complete the remove process. This is most useful when
the client is interested in receiving notifications of the task's progress.
name
- is the configured name of the application to removeinfo
- describes the details of the deployment.id
- to use for tracking. If null, a system generated id is used.startTask,
- when false, delays actual starting of the task until explicitly requested by client via
DeploymentTaskRuntimeMBean.start()
call.public DeploymentTaskRuntimeMBean unprepare(java.lang.String name, DeploymentData info, java.lang.String id) throws ManagementException
name
- is the configured name of the application to unprepareinfo
- describes the details of the deployment.id
- to use for tracking. If null, a system generated id is used.public DeploymentTaskRuntimeMBean unprepare(java.lang.String name, DeploymentData info, java.lang.String id, boolean startTask) throws ManagementException
unprepare(String, DeploymentData, String)
except that control
is given back to caller without actually initiating the task, when startTask is false. The client must invoke
the DeploymentTaskRuntimeMBean.start()
method to complete the process. This is most useful when
the client is interested in receiving notifications of the task's progress.
name
- is the configured name of the application to unprepareinfo
- describes the details of the deployment.id
- to use for tracking. If null, a system generated id is used.startTask,
- when false, delays actual starting of the task until explicitly requested by client via
DeploymentTaskRuntimeMBean.start()
call.public DeploymentTaskRuntimeMBean query(java.lang.String id)
id
- is the id to querypublic DeploymentTaskRuntimeMBean[] list()
public TargetMBean[] lookupActiveTargetsForComponent(ComponentMBean comp)
public VirtualHostMBean[] lookupActiveVirtualHostsFor(WebDeploymentMBean comp)
public java.util.Map getAvailabilityStatusForApplication(java.lang.String appName, boolean refreshCache) throws javax.management.InstanceNotFoundException
ComponentName - Map | ComponentTargetName - TargetAvailabilityStatus
appName
- - Application NamerefreshCache
- - This basically pings all the underlying servers that
are present in the activatedComponentTargets list for each component. This
allows to remove any stale componentTarget object for a server that are
unavailable because of server process is killed or there is a network
partition.public java.util.Map getAvailabilityStatusForComponent(ComponentMBean compMBean, boolean refreshCache) throws javax.management.InstanceNotFoundException
|
Documentation is available at http://download.oracle.com/docs/cd/E13222_01/wls/docs70 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |