Deploy

Deploying Applications Using Java (JMX)

Hi,

Jay SenSharma

Jay SenSharma

Here is a Simple JMX code to deploy our applications on WebLogic Server. This JMX Code uses some very important WLS Deployment API like:

WebLogicDeploymentManager, SesionHelper, DeploymentOptions,  TargetModuleID, ProgressObject etc…

When u will try the following program to deploy your applications then please  replace “ModuleType.WAR” to ModuleType.EAR -> If u want to deploy EAR Application And Similarly  replace “ModuleType.WAR” to ModuleType.JAR -> If u want to deploy JAR (EJB)Application

import java.io.*;
import weblogic.deploy.api.tools.*;  //SesionHelper
import weblogic.deploy.api.spi .*;  //WebLogicDeploymentManager
import weblogic.deploy.api.spi.DeploymentOptions;
import javax.enterprise.deploy.spi.TargetModuleID;
import javax.enterprise.deploy.spi.status.ProgressObject;
import javax.enterprise.deploy.spi.status.DeploymentStatus;
import javax.enterprise.deploy.shared.ModuleType;
import javax.enterprise.deploy.spi.Target;

import javax.enterprise.deploy.shared.*;

public class ApplicationDeployment
{
     public static void main(String ar[]) throws Exception
		{
			ApplicationDeployment appDeploy=new ApplicationDeployment();
			String protocol="t3";
			String hostName="localhost";
			String portString="7001";
			String adminUser="weblogic";
			String adminPassword="weblogic";

			WebLogicDeploymentManager deployManager=SessionHelper.getRemoteDeploymentManager( protocol,hostName,portString,adminUser,adminPassword);
			System.out.println("nt WebLogicDeploymentManager: "+deployManager);
			DeploymentOptions options = new DeploymentOptions();
			System.out.println("nt DeploymentOptions: "+options);

			Target targets[]=deployManager.getTargets();
			System.out.println("------------------------------------------------------------");
			System.out.println("t Application Can be Deployed in the Following targets:");
			int i=0;
			for (i=0;i<targets.length;i++)
					{
					   System.out.println("nt "+targets[i]);
				    }
			System.out.println("-----------Above We need to write our Logic to Choose the Deploy target---------nn");
			Target deployTargets[]=new Target[1];
			//SUPPOSE WE WAANT TO DEPLOY IT ON AdminServer ...
			deployTargets[0]=targets[0];

            //-------------DEPLOYING FIRST APPLICATION-------------//
			String applicationDisplayName="FirstEARApplication";
			options.setName(applicationDisplayName);
			ProgressObject processStatus=deployManager.distribute(deployTargets, new File("FirstEAR.ear"), null,options);
			processStatus=deployManager.deploy(deployTargets, new File("FirstEAR.ear"), null,options);
			DeploymentStatus deploymentStatus=processStatus.getDeploymentStatus() ;
			System.out.println("nnt For FirstEAR.ear DeploymentStayus.getState(): "+deploymentStatus.getState() +"nn");

			System.out.println("Sleeping for atleast 5-Seconds. Sothat the Deployment Activation gets Completed Successfully.");
			Thread.sleep(5000);

            //-------------DEPLOYING SECOND APPLICATION-------------//
			deployManager=null;
			deployManager=SessionHelper.getRemoteDeploymentManager( protocol,hostName,portString,adminUser,adminPassword);
			applicationDisplayName="SecondEARApplication";
			options.setName(applicationDisplayName);
			processStatus=deployManager.distribute(deployTargets, new File("SecondEAR.ear"), null,options);
			Thread.sleep(5000);
			processStatus=deployManager.deploy(deployTargets, new File("SecondEAR.ear"), null,options);
			deploymentStatus=processStatus.getDeploymentStatus() ;
			System.out.println("nnt For SecondEAR.ear DeploymentStayus.getState(): "+deploymentStatus.getState() +"nn");

		}
}

(Based on the comment http://middlewaremagic.com/weblogic/?p=483#comment-4189 we have updated the JMX Deployment Code)

In the above Updated JMX Code You will get following kind of Output:

C:JMX_Notification>javac ApplicationDeployment.java
Note: ApplicationDeployment.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

C:JMX_Notification>java ApplicationDeployment

         WebLogicDeploymentManager: weblogic.deploy.api.spi.deploy.WebLogicDeploymentManagerImpl@1dd7ed

         DeploymentOptions: {isRetireGracefully=true,isGracefulProductionToAdmin=false,isGracefulIgnoreSessions=false,rmiGracePeriod=-1,reti
reTimeoutSecs=-1,undeployAllVersions=false,archiveVersion=null,planVersion=null,isLibrary=false,libSpecVersion=null,libImplVersion=null,stag
eMode=null,clusterTimeout=3600000,altDD=null,altWlsDD=null,name=null,securityModel=null,securityValidationEnabled=false,versionIdentifier=nu
ll,isTestMode=false,forceUndeployTimeout=0,defaultSubmoduleTargets=true,timeout=0deploymentPrincipalName=null}
------------------------------------------------------------
         Application Can be Deployed in the Following targets:

         AdminServer/server

         MyJMSServer/JMS server
-----------Above We need to write our Logic to Choose the Deploy target---------

<Jun 4, 2011 6:37:17 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating distribute operation for application, FirstEARApplication
 [archive: C:JMX_NotificationFirstEAR.ear], to AdminServer .>
<Jun 4, 2011 6:37:41 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, FirstEARApplication [ar
chive: C:JMX_NotificationFirstEAR.ear], to AdminServer .>

         For FirstEAR.ear DeploymentStayus.getState(): running

Sleeping for atleast 5-Seconds. Sothat the Deployment Activation gets Completed Successfully.
<Jun 4, 2011 6:38:14 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating distribute operation for application, SecondEARApplicatio
n [archive: C:JMX_NotificationSecondEAR.ear], to AdminServer .>
<Jun 4, 2011 6:38:19 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, SecondEARApplication [a
rchive: C:JMX_NotificationSecondEAR.ear], to AdminServer .>

         For SecondEAR.ear DeploymentStayus.getState(): running

<Jun 4, 2011 6:38:21 PM IST> <Warning> <JNDI> <BEA-050001> <WLContext.close() was called in a different thread than the one in which it was
created.>
<Jun 4, 2011 6:38:21 PM IST> <Warning> <JNDI> <BEA-050001> <WLContext.close() was called in a different thread than the one in which it was
created.>

.
.
Thanks

Jay SenSharma


Undeploying Application Using Java Method (JMX)

Hi,

Jay SenSharma

Jay SenSharma

Here is a Simple JMX code to deploy our applications on WebLogic Server. This JMX Code uses some very important WLS Deployment API like: WebLogicDeploymentManager, SesionHelper, DeploymentOptions,  TargetModuleID, ProgressObject etc…

Note: To deploy Applications using JMX u can refer to: http://middlewaremagic.com/weblogic/?p=483

Here is a Simple Code which demeontrate ..How we can Undeploy an Application Deployed on WebLogic Server using Java Methods…We Need to Use JMX Api to do this using Java…

ApplicationUndeployment.java

import java.io.*;
import weblogic.deploy.api.tools.*;  //SesionHelper
import weblogic.deploy.api.spi .*;  //WebLogicDeploymentManager
import weblogic.deploy.api.spi.DeploymentOptions;
import javax.enterprise.deploy.spi.TargetModuleID;
import javax.enterprise.deploy.spi.status.ProgressObject;
import javax.enterprise.deploy.spi.status.DeploymentStatus;
import javax.enterprise.deploy.shared.ModuleType;
import javax.enterprise.deploy.spi.Target;

public class ApplicationUndeployment
{
public static void main(String ar[]) throws Exception
{
ApplicationUndeployment appDeploy=new ApplicationUndeployment();
String protocol="t3";
String hostName="localhost";
String portString="7001";
String adminUser="weblogic";
String adminPassword="weblogic";

WebLogicDeploymentManager deployManager=SessionHelper.getRemoteDeploymentManager( protocol,hostName,portString,adminUser,adminPassword);
System.out.println("nt WebLogicDeploymentManager: "+deployManager);
DeploymentOptions options = new DeploymentOptions();
System.out.println("nt DeploymentOptions: "+options);

TargetModuleID[] targetModuleIDs=deployManager.getAvailableModules(ModuleType.EAR, deployManager.getTargets());
System.out.println("targetModuleIDs length: "+targetModuleIDs.length);
for(int i=0;i<targetModuleIDs.length;i++)
{
System.out.println("nntUNDEPLOYING------- targetModuleIDs["+i+"]: "+targetModuleIDs[i]);
ProgressObject processStatus=deployManager.undeploy(new TargetModuleID[]{targetModuleIDs[i]});
DeploymentStatus deploymentStatus=processStatus.getDeploymentStatus() ;
System.out.println("UnDeploymentStayus.getMessage(): "+deploymentStatus.getMessage() );
}
}

OUTPUT:
C:DELETEJMX_Deploy>java ApplicationUndeployment

WebLogicDeploymentManager: weblogic.deploy.api.spi.deploy.WebLogicDeploymentManagerImpl@35e6e3

DeploymentOptions: {isRetireGracefully=true,isGracefulProductionToAdmin=false,isGracefulIgnoreSessions=false,rmiGracePeriod=-1,retireTimeoutSecs=-1,undeployAllVersions=false,archiveVersion=null,planVersion=null,isLibrary=false,libSpecVersion=null,libImplVersion=null,stageMode=null,clusterTimeout=3600000,altDD=null,altWlsDD=null,name=null,securityModel=null,securityValidationEnabled=false,versionIdentifier=null,isTestMode=false,forceUndeployTimeout=0,defaultSubmoduleTargets=true,timeout=0deploymentPrincipalName=null}         targetModuleIDs length: 2
UNDEPLOYINF------- targetModuleIDs[0]: {Target=AdminServer, WebLogicTargetType=server, Name=SecondWebAppEar}
<Jan 15, 2010 12:25:25 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating undeploy operation for application,
SecondWebAppEar [archive: null], to AdminServer .>
UnDeploymentStayus.getMessage(): null

UNDEPLOYING------- targetModuleIDs[1]: {Target=AdminServer, WebLogicTargetType=server, Name=wls-commonslogging-b
ridge#1.0@1.1}
<Jan 15, 2010 12:25:26 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating undeploy operation for application,
wls-commonslogging-bridge#1.0@1.1 [archive: null], to AdminServer .>
UnDeploymentStayus.getMessage(): weblogic.management.ManagementException: [Deployer:149164]The domain edit lock is owned
by another session in exclusive mode - hence this deployment operation cannot proceed.
<Jan 15, 2010 12:25:27 PM IST>

<Warning> <JNDI> <BEA-050001> <WLContext.close() was called in a different thread than th
e one in which it was created.>

.
.
Thanks
Jay SenSharma


Ant to Deploy Applications

Hi,

Jay SenSharma

Jay SenSharma

Form WLS 9.x onwards in Admin Console we have a Feature called as “Lock & Edit”. It has many advantages but Some Adminstrators always complaint that because of this feature they need to keep on click on this button before deploying Any Application on WLS Server ..then there are several pages in the process of Deployment through Admin Console…for testing when we want to keep on deploying Applications /redeploy and undeploy them. Like in Dev Environments..This Simple ANT script will save our lots of time.

I have a very simple ANT Script which i use most of the time for quick deployment/redeployment/undeployment.

Just have a look … it is  good.

Step1). WhereEver you have placed your Jar/WAR/EAR file to be deployed on the Server Just Paste this “build.xml” file. Just change the Property values according to your requirement in the below file…
“build.xml”

<project name="webservices-hello_world" default="deploy">
<property name="wls.username" value="weblogic" />
<property name="wls.password" value="weblogic" />
<property name="wls.hostname" value="localhost" />
<property name="wls.port" value="7001" />
<property name="admin.server.name" value="AdminServer" />
<property name="deploy.target" value="ClusterNameABC" />
<!-- Here you can specify Either ClusterName, IndividualServerName Like "ManagedOne" or comma Seperated List of Managed/AdminServer -->
<property name="deploy.name" value="TestApp" />
<property name="deploy.source" value="TestApp.ear" />

<!-- Setting TaskDefinition -->
<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy">
<classpath>
<pathelement location="C:/bea103/wlserver_10.3/server/lib/weblogic.jar"/>
</classpath>
</taskdef>

<!-- Deploying Applications  -->
<target name="deploy">
<wldeploy action="deploy"
          name="${deploy.name}"
          source="${deploy.source}"
          user="${wls.username}"
          nostage="true"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>

<!-- Redeploying Applications  -->
<target name="redeploy">
<wldeploy action="redeploy"
          name="${deploy.name}"
          user="${wls.username}"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>

<!-- Uneploying Applications  -->
<target name="undeploy">
<wldeploy action="undeploy"
          name="${deploy.name}"
          failonerror="false"
          user="${wls.username}"
          password="${wls.password}"
          verbose="true"
          adminurl="t3://${wls.hostname}:${wls.port}" targets="${deploy.target}" />
</target>
</project>

Step2). Whenever you want to deploy the Application Just Change the Properties according to your requirement.

Step3). Open a command Window and then run (setWLSenv.cmd or setWLSEnv.sh or setDomainEnv.sh or setDomainEnv.cmd)

Step4). To Deploy the Application move to the current directory where ever you have placed “build.xml” and “TestApp.ear” (Your Application) and then run

ant deploy

Step5). To Redeploy the Application

ant redeploy

Step6). To Undeploy the Application

ant undeploy

.

.

Thanks
Jay SenSharma


Copyright © 2010-2012 Middleware Magic. All rights reserved. |