AWS Community Day CPH - Three problems of Terraform
Deployment Best Practices on WebLogic Server (DOAG IMC Summit 2013)
1. DOAG 2013 IMC,Mainz, 06. Juni 2013
Andreas Koop
CEO & Consultant
Oracle Technologies
DEPLOYMENT BEST PRACTICES
ON WEBLOGIC SERVER
Challenges
Strategies
Plan
Best Practices
2. Andreas Koop
CEO & Consultant
Oracle TechnologiesABOUT
Consulting, Training Oracle Fusion Middleware
ADF Certified Implementation Specialist
Community
DOAG, ADF EMG, ADF German Community, Twitter @multikoop
Blog
Technical http://multikoop.blogspot.com
Sonstiges http://www.enpit.de/blog
2
5. Andreas Koop
DEPLOYMENT CHALLENGES
‣ Multiple Apps, multiple versions, instant releases..
‣ Application development becomes easy,
Middleware becomes complex:
DataSources, WebServices, Processes, JMS, MDS,
App Roles, Permissions, custom configuration,
What else?
‣ Who can handle this?
5
6. Andreas Koop
APPLICATION DEPLOYMENT
OVERVIEW
‣ Prepare
‣ Copy deployment units to
target servers if needed
‣ Deploy
‣ Shared Libraries
‣ Applications
DataSources
JMS Topics/Queues
EJBs
..
6
AS App1 App2
App / Lib
deploy
Cluster
(sample topology)
7. Andreas Koop
WEBLOGIC DEPLOYMENT
TOOLS
‣ java weblogic.Deployer (. ./setWLSEnv.sh)
‣ Ant Task / Maven / Autodeploy
=> Development / Test
‣ WLST Commands
=> Development / Test / Production
‣ Admin Console / EM
=> Development / AdHoc Cases / Support
7
! Do not use in
Production
My Favorit! Gives a
lot of predictability and
safety!
8. Andreas Koop
STAGING MODE: STAGE FOR
SMALL APPLICATIONS
‣ Admin Server copies
deployment unit to
servers/<name>/
stage
‣ Managed Servers deploy
using their local copy
‣ => Use for small
applications !
8
AS App1 App2
App
deploy
ear
earcopy
earcopy
(sample topology)
9. Andreas Koop
‣ Admin Server does not
copy deployment units
‣ shared, directly
accessibly by AS and MS
‣ => Use for large
applications or exploded
-->Reload of JSP/Servlet
‣ => Saves time!
AS App1 App2
STAGING MODE: NO STAGE
FOR LARGE APPLICATIONS
9
/shared/apps/myapp1.ear
App
deploy
(sample topology)
10. Andreas Koop
‣ Admin Server does not
copy deployment units
‣ Manuel copy to AS and
MS needed
‣ => Use if no shared fs
available
‣ => Use if scripts for
manual distrib. exists
STAGING MODE: EXTERNAL
STAGE FOR...
10
AS App1 App2
App
deploy
earcopy
earcopy
earcopy
Admin
Guy
(sample topology)
11. Andreas Koop
WHERE TO LOCATE
DEPLOYMENT UNITS
‣ ! Prerequisite: Do not use default for domain home:
$MW_HOME/user_projects/domains
‣ Locate domain outside $MW_HOME
‣ Locate App artefacts outside $MW_HOME
11
/domains/mydomain/
/applications/mydomain/myapp1/1.0/app/myapp1.ear
/applications/mydomain/myapp1/1.0/plan/plan.xml
12. Andreas Koop
QUIZ: WHAT DO THAT OPTIONS
MEAN? (FROM ADMIN CONSOLE)
12
AS uses nostage by
default
MS uses stage by
default
depends
stage
nostage
15. Andreas Koop
DEPLOY WITH MAVEN
PREPARE
‣ Need to generate maven plugin with the WebLogic
JarBuilder Tool (at least in 11g)
‣ Install into Maven Repository(see documentation)
‣ Use in your projects pom.xml (see next slide)
15
$ java -jar wljarbuilder.jar -profile weblogic-maven-plugin
..
..
Created new jar file: ../wlserver_10.3/server/lib/weblogic-maven-plugin.jar
16. Andreas Koop
DEPLOY WITH MAVEN
USE
‣ Directly
‣ In ,install‘ Maven Lifecycle of your pom.xml
16
$ mvn weblogic:deploy
<plugin>
<groupId>com.oracle.weblogic</groupId>
<artifactId>weblogic-maven-plugin</artifactId>
<version>10.3.6</version>
<configuration>
<adminurl>t3://localhost:7001</adminurl>
<user>weblogic</user>
<password>password</password>
<name>myapp</name>
<upload>true</upload>
<targets>AdminServer</targets>
</configuration>
17. Andreas Koop
DEPLOY WITH MAVEN
USE
‣ In ,install‘ Maven Lifecycle of your pom.xml
17
...
<executions>
<execution>
<id>deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<source>deploy/myapp.war</source>
</configuration>
</execution>
</executions>
</plugin>
18. Andreas Koop
DEPLOYMENT WITH ANT / MVN
CONCLUSION
‣ „Pure Ant“ WebLogic Deployment Tasks are not
powerful enough.
‣ Extend where needed with custom WLST scripts
‣ Fits typically well in existing CI Build Environment
‣ Extended Maven Features in WLS 12c : create-
domain, start-server .... !
18
19. Andreas Koop
DEPLOY WITH WLST
HOW TO
19
connect('weblogic', 'welcome1', ADMIN_URL)
deploy('myApp', '/path/to/myApp.ear', targets='Cluster1')
# targets='Server1'
startApplication('myApp')
disconnect()
exit()
20. Andreas Koop
UNDEPLOY WITH WLST
HOW TO
20
connect('weblogic', 'welcome1', ADMIN_URL)
stopApplication('myApp')
undeploy('myApp')
# default: from all targets
disconnect()
exit()
22. Andreas Koop
‣ Always start with a cluster - even if only a single
MS is needed at the beginning
‣ => Easily to scale afterwards
‣ => No changes to deployment
strategy needed
DEPLOY TO A CLUSTER FROM
THE BEGINNING
22
App1 / Lib
deploy
App1
Cluster
App1
Cluster
App1
...
25. Andreas Koop
WHAT IS A DEPLOYMENT PLAN
‣ Plan (plan.xml) used with deployment artefact
‣ Replacing values by XPath / Variables
‣ Useful for
‣ Changes to web.xml / weblogic.xml / Other XML
‣ ! No changes to .properties possible
‣ „Deploy myapp.ear -plan /path/to/plan.xml ...“
25
26. Andreas Koop
DEPLOYMENT PLAN
CREATION / EDITING
‣ Working with plan.xml and plain text editor is
difficult! Best Practice: OEPE plan.xml Editor!
26
Or use
,java weblogic.PlanGenerator‘
27. Andreas Koop
EDIT DEPLOYMENT PLAN
WITH OEPE
‣ Nice XPath Editor included! easy selection of
assignable elements and selection on variable!
27
28. Andreas Koop
HOW TO DEPLOY WITH PLAN
‣ weblogic.Deployer
‣ Or with WLST
‣ Or Admin Console / EM
28
deploy('myApp', '/path/to/1.0/app/myApp.ear', plan='/path/to/1.0/plan/
plan.xml' ..)
java weblogic.Deployer .... -plan /path/to/1.0/plan/plan.xml ...
29. Andreas Koop
USE SHARED LIBRARIES
‣ Static content: js, css, images
‣ Common Functionality, Modules
29
31. Andreas Koop
HOW TO DEPLOY
SHARED LIBRARIES
‣ weblogic.Deployer
‣ Or WLST
31
#!/bin/sh
. $WL_HOME/server/bin/setWLSEnv.sh
java weblogic.Deployer -adminurl t3://eden.local:7001 -username weblogic -
password welcome1 -upload -library -targets Cluster1 -deploy -source enpit-
shared-lib.war
...
deploy('enpit-shared-lib', '/path/to/enpit-shared-lib.war',
targets='Cluster1',libraryModule='true'[, upload='true'])
32. Andreas Koop
HOW TO CONSUME
SHARED LIBRARIES
‣ Configure references in weblogic.xml or weblogic-
application.xml
32
<?xml version='1.0' encoding='UTF-8'?>
<weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app.xsd"
xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
...
<library-ref>
<library-name>enpit-common-lib</library-name>
<!--specification-version>1.0</specification-version>
<implementation-version>1.0.6</implementation-version>
<exact-match>true</exact-match-->
</library-ref>
</weblogic-web-app>
33. Andreas Koop
SHARED LIBRARIES -
POSSIBLE ERRORS
‣ Precondition: Shared Library is referenced. App is
running
‣ Solution
‣ Deploy Library as new version
‣ „Production redeploy“ dependent application
33
Cannot undeploy library Extension-Name: enpit-common-war-lib, Specification-Version: 1,
Implementation-Version: 1.0.4 from server AdminServer, because the following deployed applications
reference it: enpittestcommons-reflib.war
35. Andreas Koop
SECURITY DEPLOYMENT
CONSIDERATIONS
‣ Deployment Descriptor (DD only, Java EE Standard)
‣
‣ Custom Roles Model
=> Any DD Role-Mapping is ignored
‣ Custom Roles and Policy Model
=> Not recommended for fine-grained control
35
<security-role-assignment>
<role-name>admin-users</role-name>
<principal-name>Administrator</principal-name>
</security-role-assignment>
weblogic.xml
37. Andreas Koop
PRODUCTION REDEPLOYMENT
37
app v1.0 app v1.0.1
Existing client
connections
New Client
Connections
deploy('myApp', '/path/to/myApp.ear', ..,appVersion = '1.0')
deploy('myApp', '/path/to/myApp.ear', ..,appVersion = '1.0.1')
38. Andreas Koop
PRODUCTION REDEPLOYMENT
BEST PRACTICE
38
‣ Provide Version information inside
MANIFEST.MF
‣ Set version during CI build process!
‣ Specify retire grace period on redeploy
‣ Retire immediately
... -redeploy -source ...myapp.ear -retiretimeout 300
... -undeploy -name myapp -appversion 1.0
Arggh. Need the
lower version no. Not
easy to automate...
39. Andreas Koop
SOLUTION FOR
UNDEPLOY RETIRED APPS
39
def undeploy_retired_apps(l_appName):
cd ('AppDeployments')
l_apps=cmo.getAppDeployments()
for app in l_apps:
domainConfig()
cd ('/AppDeployments/'+app.getName()+'/Targets')
l_targets = ls(returnMap='true')
domainRuntime()
cd('AppRuntimeStateRuntime/AppRuntimeStateRuntime')
for target in l_targets:
l_state=cmo.getCurrentState(app.getName(),target)
if app.getName().find(l_appName) != -1:
if l_state == 'STOP_RUNNING':
log_info ('Found:'+ app.getName()+' - '+str(l_state))
stopApplication(app.getName())
l_state=cmo.getCurrentState(app.getName(),target)
if l_state == 'STATE_RETIRED':
log_info ('Found:'+ app.getName()+' - '+str(l_state))
undeploy_app(app.getName())
undeploy_retired_apps()
40. Andreas Koop
PRODUCTION REDEPLOYMENT
BEST PRACTICE
40
‣ Rollback deployment to previous
version is an easy task
‣ Keep in mind: In-Place redeployment destroys
existing sessions! To keep the session state:
... -redeploy -source .../1.0/app/myapp.ear
weblogic.xml
..
<container-descriptor>
<save-sessions-enabled>true</save-sessions-enabled>
</container-descriptor>
..
!Hower, the
application will not be
available at redeploy!
41. Andreas Koop
PAIN POINTS AND POSSIBLE
SOLUTIONS
‣ Custom configuration data
Suggestion: Properties accessible by JNDI (See GlassFish)
‣ Single Security Policy Store for all applications
(system-jazn-data.xml)
Recommendation: OID or DB based Policy-Store
Suggestion: Policy-Store bundled with app deployment
41
App1
Domain
App 2
system-jazn-data.xml
- Role-Mapping App1
- Role-Mapping App2
- Permissions App1
- Permissions App2
42. Andreas Koop
CONCLUSION
‣ Automate from the beginning
‣ Stage mode depends on app size, existing
infrastructure
‣ Use deployment plans & „production
redeployment“
‣ Use shared libs where applicable
42
43. Andreas Koop
FURTHER READING
‣ Oracle FMW Admin Guide
http://docs.oracle.com/cd/E23943_01/core.1111/e10105/deployer_role.htm
‣ Oracle FMW Deploying Applications to WLS
http://docs.oracle.com/cd/E23943_01/web.1111/e13702/toc.htm
‣ Community / Blogs
http://middlewaremagic.com
http://weblogic-wonders.com
http://weblogic-tips.com
...
43