Tag: Plan.xml

Tuning EJB3 Application using Plan.xml

Hi,

Jay SenSharma

Jay SenSharma

In response to comment posted regarding tunning of EJB3 app:   http://middlewaremagic.com/weblogic/?p=1696#comment-1356

Here is a Simple Demonstration of Changing the Tunable Parameters of an EJB3.0 application using “Plan.xml”. As we have many annotations available as part of EJB3.0 Specifications But we dont have the Annotations available for many Tunable parameters like “max-beans-in-free-pool”, “initial-beans-in-free-pool”…etc. If we want to change/add these values for our EJB3.0/EJB2.x Application then we have have to change provide our own “weblogic-ejb-jar.xml” file.

But In Most of the production scenarios The WebLogic Administrator doesnt have priviledge to change any thing inside the EJB jar module. So in that case A WebLogic AdminiStartor can use the “Plan.xml” file to change these Tunable Parameters Settings…

Step1). Create a Directory somewhere in your file system.
Example: C:EJB3_Plan_XML_Demo

Step2). Create a Directory “EJB3App” inside Directory “C:EJB3_Plan_XML_Demo”

Step3). Provide the EJB3 Business Interface “CalculatorRemote.java” inside “C:EJB3_Plan_XML_DemoEJB3App”

package calculator;
import javax.ejb.*;
@Remote
public interface CalculatorRemote
{
public int add(int x,int y);
public int sub(int x,int y);
public int mult(int x,int y);
public int div(int x,int y);
}

Step4). Provide the EJB3 Stateless Bean Implementation class “CalculatorBean.java” inside “C:EJB3_Plan_XML_DemoEJB3App”

package calculator;
import javax.ejb.*;
@Stateless
public class CalculatorBean implements CalculatorRemote
{
public int add(int x,int y)
{
return (x+y);
}
public int sub(int x,int y)
{
return(x-y);
}
public int mult(int x,int y)
{
return (x*y);
}
public int div(int x,int y)
{
return (x/y);
}
}

Step5). Now Create a directory “META-INF” inside “C:EJB3_Plan_XML_DemoEJB3App” and then provide an Empty “weblogic-ejb-jar.xml” file as following:

<weblogic-ejb-jar xmlns="http://www.bea.com/ns/weblogic/weblogic-ejb-jar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd">
</weblogic-ejb-jar>

NOTE: Step5 is the Most important Step because if we want to override setting of any descriptor then at least that file must exist inside our application….doesn’t matter if it is Empty or having some contents inside it.

Step6). Now a command prompt and the run the “setWLSEnv.cmd” and then Compile the above two ejb stuffs.

Compiling_EJB3_App

Compiling_EJB3_Ap

Step7). Write the “build.xml” file to deploy your Application…inside “C:EJB3_Plan_XML_Demo” like following:

<project name="webservices-hello_world" default="deploy">
<!-- set global properties for this build -->
<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="wls.server.name" value="AdminServer" />

<target name="deploy">
<wldeploy action="deploy" name="EJB3App" source="EJB3App"
user="${wls.username}" password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}" targets="${wls.server.name}" />
</target>

<target name="undeploy">
<wldeploy action="undeploy" name="EJB3App" failonerror="false"
user="${wls.username}" password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}" targets="${wls.server.name}" />
</target>

</project>

Step8). Now open a Command prompt and then run “setWLSEnv.cmd” then run the above ant “build.xml” file to deploy your application:

Deploying_EJB3_App_using_Ant

Deploying_EJB3_App_Using_Ant

Step9). Now Login to Admin Consoel to see how many initial beans have been created for our EJB3App.

Step10). Now Provide the “plan.xml” file inside “C:EJB3_Plan_XML_Demo” location as following to change the “initial-bean-in-free-pool” setting for our EJB3App…

<?xml version=’1.0' encoding=’UTF-8'?>
<deployment-plan xmlns="http://www.bea.com/ns/weblogic/deployment-plan" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/deployment-plan http://www.bea.com/ns/weblogic/deployment-plan/1.0/deployment-plan.xsd" global-variables="false">
<application-name>EJB3App</application-name>

<variable-definition>
<variable>
<name>initialPoolVariable</name>
<value>15</value>
</variable>
</variable-definition>

<module-override>
<module-name>EJB3App</module-name>
<module-type>ejb</module-type>
<module-descriptor external="true">
<root-element>weblogic-ejb-jar</root-element>
<uri>META-INF/weblogic-ejb-jar.xml</uri>
<variable-assignment>
<name>initialPoolVariable</name>
<xpath>/weblogic-ejb-jar/weblogic-enterprise-bean/[ejb-name="CalculatorBean"]/stateless-session-descriptor/pool/initial-beans-in-free-pool</xpath>
</variable-assignment>
</module-descriptor>
</module-override>

<config-root>C:EJB3_Plan_XML_Demo</config-root>
</deployment-plan>

Step11). provide the “build_with_plan.xml” file inside “C:EJB3_Plan_XML_Demo” to redepoy the application with the settings provided as part of our “plan.xml” file. Like following :

Redeploying_EJB_Using_Pla

Redeploying_EJB_Using_Pla

Step12). Now again Login to AdminConsole and then see the Monitoring Tab of your EJB3App … like following:

AfterRedeploying_UsingPlan

AfterRedeploying_UsingPlan

.

.

Thanks

Jay SenSharma


Adding WorkManager Using Plan.xml to a WAR file

Hi,

Jay SenSharma

Jay SenSharma

Suppose if you already have deployed your WebApplication (WAR) file on the Server …this time if you hit your Application then in AdminConsole you will see that the requests are being processed by the “default” workManager.

To see this you can login to your applications workmanager status ….
AdminConsole—>Deployments—.YourWebApplication—>Monitoring (TAB)—>workload (Sub tab)
.
Here you will see that as soon as you hit your webapplication it’s request is being served by the “default” work manager. You don’t want to Change your WebApplication by adding <wl-dispatch-policy> tag inside your “weblogic.xml”. So this can be done by using “Plan.xml”…using this file we will assign WorkManager Dynamically to an existing application without physically touching the actual application.
.
NOTE: Please make sure that atleast on “weblogic.xml” is already available inside your WebApplication which uses WLS9.x onwards schema defination…like following… If you already have weblogic.xml inside your WAR then it’s good…or else please add the following empty “weblogic.xml” inside your WebApp…
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<weblogic-web-app xmlns=”http://www.bea.com/ns/weblogic/90″>
</weblogic-web-app>

.
Step1). Create a WorkManager through AdminConsole with the following configuration:
with the following Configuration: in your “config.xml”…or define your Workmanager according to your requirement
<self-tuning>
<context-request-class>
<name>ContextReqClass-0</name>
<target>AdminServer</target>
</context-request-class>
<min-threads-constraint>
<name>MyMaxConstraint</name>
<target>AdminServer</target>
<count>1</count>
</min-threads-constraint>
<capacity>
<name>CapacityConstraint-0</name>
<target>AdminServer</target>
<count>1</count>
</capacity>
<work-manager>
<name>myConsoleWorkManager</name>
<target>AdminServer</target>
<context-request-class>ContextReqClass-0</context-request-class>
<min-threads-constraint>MyMaxConstraint</min-threads-constraint>
<capacity>CapacityConstraint-0</capacity>
</work-manager>
</self-tuning>
Note: After configuring the above workManager we need to restart the Server…As a Best practice.
.
.
Step2). Open a Command window or a Shell prompt and then run “. ./setWLSEnv.sh” or “setDomainEnv.sh” to set the environment in that shell.
.
.
Step3). In the Shell prompt Move till the your WAR file…Lets say your WAR filename is “MyWorkManagerDemo.war”. which is placed inside
“/opt/apps” directory then first do
cd /opt/apps
.
.
Step4). Now run the “weblogic.PlanGenerator” utility to generate the Plan.xml file in the current Directory. Like following:
java weblogic.PlanGenerator -all MyWorkManagerDemo.war
OUTPUT:
Generating plan for application MyWorkManagerDemo.war
Export option is: all
Exporting properties…
Saving plan to /opt/apps/plan.xml…
<Mar 14, 2010 2:57:00 PM IST> <Info> <J2EE Deployment SPI> <BEA-260072> <Saved configuration for application, MyWorkManagerDemo>
.
.
Step5). Now the generated “plan.xml” file will be bit large …we need to edit it…
.
.
Step6). Edit it like:
You will find <variable-definition> with many sub tags like <variable>   Just edit one of them and delete rest of the <variable> Tags
you can give any name to the variable like “firstVariableName”.
Now edit the next line <value xsi:nil=”true”></value>  by removing the  xsi:nil=”true” from this Tag….means you need to change it to and then add your WorkManager name there like:
<value>myConsoleWorkManager</value>
Now edit the Module which you want to override: <module-override> and then assign the Variable there and <config-root> tag pointing to the Plan.xml directory…Finally you will get a “plan.xml” file like following:
<?xml version='1.0' encoding='UTF-8'?>
<deployment-plan xmlns="http://www.bea.com/ns/weblogic/deployment-plan" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/deployment-plan http://www.bea.com/ns/weblogic/deployment-plan/1.0/deployment-plan.xsd" global-variables="false">
<application-name>MyWorkManagerDemo.war</application-name>
<variable-definition>
<variable>
<name>firstVariableName</name>
<value>myConsoleWorkManager</value>
</variable>
</variable-definition>
<module-override>
<module-name>MyWorkManagerDemo</module-name>
<module-type>war</module-type>
<module-descriptor external="true">
<root-element>weblogic-web-app</root-element>
<uri>WEB-INF/weblogic.xml</uri>
<variable-assignment>
<name>firstVariableName</name>
<xpath>/weblogic-web-app/wl-dispatch-policy</xpath>
</variable-assignment>
</module-descriptor>
</module-override>
<config-root>/opt/apps/</config-root>
</deployment-plan>
.
.
Step7). Now Login to AdminConsole then Update your Application …while updating your Application it will ask for the “plan.xml” file Location…just browse for this file… While updating your WebApplication with “plan.xml” file please choose the following radio button in the AdminConsole:
“Redeploy this application using the following deployment files” FINISH
.
.
Step8). Now hit your application …you will see in the “workload” Subtab of your application then it is being processed by the “myConsoleWorkManager” which is created by us.
.
.
.
Thanks
Jay SenSharma

Updating CookieName Using Plan.xml

Hi,

Jay SenSharma

Jay SenSharma

We will see a Demonstration of How we can change the HttpSession Cookie Name of a Web Application from (example: XSESSIONID) to something else like (XYZSESSIONID) using Plan.xml Dynamically…without directly modifying the Deployment Descriptors placed inseide the Archived application Which is already deployed and Running on the Server. It’s called as Hot Updation….It’s Really HOT.

Step1). We will develope a Simple Enterprse Application with a WAR file inside it. In order to do that Just create a Directory where we can place all our Application Files:

Example:  C:JavaTestPlanDemo

Step2). Create a Directory “PlanDemoEAR” inside “C:JavaTestPlanDemo”.

Step3). Inside “C:JavaTestPlanDemoPlanDemoEAR” Create two more Directories “META-INF” and “PlanDemoWEB”.

—————–
Step4). Create web.xml file inside: “C:JavaTestPlanDemoPlanDemoEARPlanDemoWEBWEB-INF” like following

<web-app xmlns=”http://java.sun.com/xml/ns/j2ee“>
</web-app>
—————–

Step5). Create weblogic.xml file inside: “C:JavaTestPlanDemoPlanDemoEARPlanDemoWEBWEB-INF” like following

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<weblogic-web-app xmlns=”http://www.bea.com/ns/weblogic/90“>
<session-descriptor>
<cookie-name>XSESSIONID</cookie-name>
<timeout-secs>900</timeout-secs>
<invalidation-interval-secs>30</invalidation-interval-secs>
</session-descriptor>
</weblogic-web-app>

—————–
Step 6). Provide the Default “index.jsp” welcome page for our WebApplication: in the location: C:JavaTestPlanDemoPlanDemoEARPlanDemoWEBindex.jsp

<center>
<TABLE Border=10%>
<TR><TH>CookieName</TH><TH>CookieValue</TH></TR>
<%
Cookie cookies[]=request.getCookies();
if(cookies!=null)
{
for(int i=0;i<cookies.length;i++)
{
out.println(“<TR><TD>”+cookies[i].getName()+” </TD><TD>”+cookies[i].getValue()+”</TD></TR>”);
}
}
else
out.println(“<h3>Please Refresh The page…”);
%>
</TABLE>
————–
Step 7). Provide “application.xml” file in the location: “C:JavaTestPlanDemoPlanDemoEARMETA-INF” like:

<?xml version=”1.0″ encoding=”UTF-8″?>
<application xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” version=”1.4″>
<description>Plan Example</description>
<module>
<web>
<web-uri>PlanDemoWEB</web-uri>
<context-root>PlanDemoWEB</context-root>
</web>
</module>
</application>
————–
Step8). Deploy the EAR file “PlanDemoEAR” in Exploded format or you can even create an EAR from it… “C:JavaTestPlanDemoPlanDemoEAR” to the Desired WebLogic Server.

Step 9). Now access the “index.jsp” Page of your Application. Note: First time this page will display an empty table in the WebPage…You need to referesh the Page sothat it will display the Table like below:

Step10). Now We want to Update the HttpSession Cookie Name from “XSESSIONID” to “XYZSESSIONID” …in order to do that we need to Provide the “plan.xml” file…

Step 11). open a comand window and then run the “setDomainEnv.cmd” or “setWLSEnv.cmd” in it.

Step 12). Now move to “C:JavaTestPlanDemo”  in the Command Window and then run
C:JavaTestPlanDemo>java weblogic.PlanGenerator -all PlanDemoEAR
You will see the Similar Following Output:—->
Generating plan for application PlanDemoEAR
Export option is: all
Exporting properties…
Saving plan to C:JavaTestPlanDemoplan.xml…
<Dec 16, 2009 11:51:24 AM IST> <Info> <J2EE Deployment SPI> <BEA-260072> <Saved configuration for application, PlanDemoEAR>
————————

Step 13). Modify this Plan.xml file like following sothat we can change only the “Session-Descriptor/Cookie-name” element

<?xml version=’1.0′ encoding=’UTF-8′?>
<deployment-plan xmlns=”http://www.bea.com/ns/weblogic/deployment-plan” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://www.bea.com/ns/weblogic/deployment-plan http://www.bea.com/ns/weblogic/deployment-plan/1.0/deployment-plan.xsd” global-variables=”false”>
<application-name>PlanDemoEAR</application-name>

<variable-definition>
<variable>
<name>NewCookieName</name>
<value>XYZSESSIONID</value>
</variable>
</variable-definition>

<module-override>
<module-name>PlanDemoWEB</module-name>
<module-type>war</module-type>
<module-descriptor external=”false”>
<root-element>weblogic-web-app</root-element>
<uri>WEB-INF/weblogic.xml</uri>
<variable-assignment>
<name>NewCookieName</name>
<xpath>/weblogic-web-app/session-descriptor/cookie-name</xpath>
</variable-assignment>
</module-descriptor>
</module-override>

<config-root>C:DOCUME~1JAYKUM~1LOCALS~1Tempjaykumars.configdeploymentsPlanDemoEARplan</config-root>
</deployment-plan>
—————-
Step 14). Now Login to admin Console and then Click on “Lock and edit” Button From Deployment Platte select(Check) your Desired Application “PlanDemoEAR” and then Clieck on “Update” Button…While Updating the Application it will ask for the New “Plan.xml” file Location Just browse to “C:JavaTestPlanDemoplan.xml” and then click on “Next”—>”Finish”. Save the Changes.

Step 15). Now once again Access the “index.jsp” page…Now you will see that the Cookie Name is Changed to “XYZSESSIONID”

.

.

Thanks
Jay SenSharma


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