Tag: Deploy

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


_wls_cls_gen.jar Issue

Hi,

Jay SenSharma

Jay SenSharma

WebLogic 10 And WebLogic 10.3 creates a Jar file (_wls_cls_gen.jar)while deploying our Archieved Applications (WAR files). Which includes all the contains available inside the WEB-INF/classes directory inside this jar file(_wls_cls_gen.jar). I didnot find a way to tell WebLogic Server to not to create this JAR file, because it creates many issues.

Example: if we have placed a Property file or Some XML files  inside the “WEB-INF/classes” directory with the name “test.properties” or “test.xml” then WebLogic Server will place this Property file as well inside the (_Wls_cls_gen.jar) file while deployment…

zip:C:/bea103/user_projects/domains/Test_Domain/servers/AdminServer/tmp/_WL_user/testWebApp/8j5e1y/war/WEB-INF/lib/_wl_cls_gen.jar!/test.properties

Now if we write the following code inside out application like Servlet then it won’t work and will fail while reading the Properties file:

Note: Many frameworks uses the Following techinques and Sometimes WebLogic Code causes this issue..(http://forums.oracle.com/forums/thread.jspa?messageID=4217650#4217650 AND   http://forums.oracle.com/forums/thread.jspa?threadID=2223518&tstart=105 )…which may cause our applications to fail while reading jar Archieved resources. because they uses the following techinque to read the resources available inside a JAR file:

——————————————-WRONG – APPROACH – BELOW———————

InputStream stream = null;
try {
Properties p = new Properties();
String path=Thread.currentThread().getContextClassLoader().getResource("Info.properties").getPath();
System.out.println("----------------PATH: "+path);
p.load(new java.io.FileInputStream(path));
Host = p.getProperty("Host");
Pot = p.getProperty("Port");
User = p.getProperty("User");
Passwd = p.getProperty("Passwd");
System.out.println("Property Key-Values:" +"n"+ Host +"n"+ Pot + "n"+User+ "n"+Passwd);
} catch (Exception e) {
e.printStackTrace();
}

To avoid the above issue…we need to change our code like following: most of the Frameworks also need to change their implementations…

———————— CORRECT – APPROACH – BELOW ——————-

InputStream stream = null;
System.out.println("------------------------------------");
try {
Properties p = new Properties();
stream=this.getClass().getClassLoader().getResourceAsStream("Info.properties");
p.load(stream);
Host = p.getProperty("Host");
Pot = p.getProperty("Port");
User = p.getProperty("User");
Passwd = p.getProperty("Passwd");
System.out.println("Property Key-Values:" +"n"+ Host +"n"+ Pot + "n"+User+ "n"+Passwd);
} catch (Exception e) {
e.printStackTrace();
}

The above piece of code can be used whenever we want to read a Non-Class/Class resource from inside a JAR file.

Thanks

Jay SenSharma


Production Redeployment , WebLogic Versioning

Hi,

Jay SenSharma

Jay SenSharma

In a production environment, deployed applications frequently require 24×7 availability in order to provide uninterrupted services to customers and internal clients.

Production Redeployment (Hot Deployment)

Production redeployment strategy involves deploying a new version of an updated application alongside an older version of the same application. WebLogic Server automatically manages client connections so that only new client requests are directed to the new version. Clients already connected to the application during the redeployment continue to use the older version of the application until they complete their work, at which point WebLogic Server automatically retires the older application.

Production redeployment enables you to update and redeploy an application in a production environment without stopping the application or otherwise interrupting the application’s availability to clients. Production redeployment saves you the trouble of scheduling application downtime, setting up redundant servers to host new application versions, manually managing client access to multiple application versions, and manually retiring older versions of an application.

Here is a Simple Demo of it:

Step1). Use the Following command to Deploy a Fresh Application with the -appversion flag using weblogic.Deployer utility:

Deploy the Application Like following: (VersionA)

java weblogic.Deployer -adminurl t3://localhost:7001 -username weblogic -password weblogic -deploy -name complexServiceEar -appversion VesionA -targets AdminServer -source /apps/Original/complexServiceEar.ear

Step2). See the Admin Console …you will find in the Deployment page that the Application is deployed with the Version in for as “VersionA”.

Step3). Now If you Deploy the Application Like following: (VersionB)

java weblogic.Deployer -adminurl t3://localhost:7001 -username weblogic -password weblogic -deploy -name complexServiceEar -appversion VesionB -retiretimeout 30 -targets AdminServer -source /apps/NewVersion/complexServiceEar.ear

Then you will find in the Admin Console that Another Version (VersionB) is deployed in the AdminServer of the Same application…As in the above deployment command we have specified that “-retiretimeout 30” means after within 30 Seconds you will find that the Old Version of Application (VersionA) will be declared as “Retired” in Admin Console. And will not be used by WebLogic any more.

The “retiretimeout” is just to specify when the Current Active Application will become Retired…WebLogic Will never try to Undeploy the Retired application automatically. retiretimeout is an attribute just to make sure that the Users Sessions from the exesting versions should not be lost immediately…WLS will wait at least for the time specified in this attribute …before making the application to Retired…In the mean time All new request will be passed to the new Application Version.

Step 4). Now we need to manually Undeploy the Old version of Application using the following command.

java weblogic.Deployer -adminurl t3://localhost:7001 -username weblogic -password weblogic -undeploy -name complexServiceEar -appversion VesionA -targets AdminServer.

Always keep in mind the following RESTRICTIONS/LIMITATIONS of Production redeployment (Versioning):

http://download.oracle.com/docs/cd/E11035_01/wls100/deployment/redeploy.html#wp1023028

————————

Thanks

Jay senSharma


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