Showing posts with label WLST. Show all posts
Showing posts with label WLST. Show all posts

Saturday, June 23, 2012

Weblogic Fusion Middleware 10.3.5 WLST Script for Creation of the Database Resource and Redeployment of the Database Adapter

On steps to executing the script, please click here
 
import os
connect(userName,passWord,'t3://'+wlsHost+':'+adminServerListenPort)
edit()
startEdit()

soaJDBCSystemResource1 = create('DBAdapterTestDataSource',"JDBCSystemResource")
soaJDBCResource1 = soaJDBCSystemResource1.getJDBCResource()
soaJDBCResource1.setName('DBAdapterDataSource')

soaConnectionPoolParams1 = soaJDBCResource1.getJDBCConnectionPoolParams()
soaConnectionPoolParams1.setTestTableName("SQL SELECT 1 FROM DUAL")

soaConnectionPoolParams1.setInitialCapacity(10)
soaConnectionPoolParams1.setMaxCapacity(100)

soaDataSourceParams1 = soaJDBCResource1.getJDBCDataSourceParams()
soaDataSourceParams1.addJNDIName('jdbc/dbSample')
soaDriverParams1 = soaJDBCResource1.getJDBCDriverParams()
soaDriverParams1.setUrl('jdbc:oracle:thin:@'+db_host_name+':'+db_port+':'+db_sid)
soaDriverParams1.setDriverName('oracle.jdbc.xa.client.OracleXADataSource')
soaDriverParams1.setPassword('my_password')

soaDriverProperties1 = soaDriverParams1.getProperties()
soaProperty1 = soaDriverProperties1.createProperty("user")
soaProperty1.setValue('scott')

varSOAServerTarget = '/Servers/'+serverName
soaServerTarget = getMBean(varSOAServerTarget)

soaJDBCSystemResource1.addTarget(soaServerTarget)

dumpStack()

try : 

save()

activate(block="true")

except:
    print "Error while trying to save and/or activate!!!"
    dumpStack()

print "Creating DB adapter resource  information"
try:
     redeploy('DBAdapter', '@deployment.plan@', upload='true', stageMode='stage') 
    
except:
    print "Error while modifying db adapter connection factory" 

########

WLST Script for Creation of JMS Resource and Redeployment of JMS Adapter

This script can be used for creation of JMS Resource and Redeployment of JMS Adapter
On steps to executing the script, please click here. 
# lookup the JMSModule 
    jmsSOASystemResource = lookup("SOAJMSModule","JMSSystemResource")
        
    jmsResource = jmsSOASystemResource.getJMSResource()
    
    cfbean = jmsResource.lookupConnectionFactory('DemoSupplierTopicCF')
    if cfbean is None:
        print "Creating DemoSupplierTopicCF connection factory"
        demoConnectionFactory =
 jmsResource.createConnectionFactory('DemoSupplierTopicCF')
        demoConnectionFactory.setJNDIName('jms/DemoSupplierTopicCF')
        demoConnectionFactory.setSubDeploymentName('SOASubDeployment')

    topicbean = jmsResource.lookupTopic('DemoSupplierTopic')
    if topicbean is None:
        print "Creating DemoSupplierTopic jms topic"
        demoJMSTopic = jmsResource.createTopic("DemoSupplierTopic")
        demoJMSTopic.setJNDIName('jms/DemoSupplierTopic')
        demoJMSTopic.setSubDeploymentName('SOASubDeployment')
        
try:
    save()
    # activate the changes
    activate(block="true")
    print "jms topic and factory for SOA Fusion Order Demo successfully created"
except:
    print "Error while trying to save and/or activate!!!"
    dumpStack()
    
print "Creating jms adapter connection factory information"
try:
     redeploy('JmsAdapter', '@deployment.plan@', upload='true', stageMode='stage') 
    
except:
    print "Error while modifying jms adapter connection factory"

########

Weblogic 10.3.5: Enable Debugging Using the WebLogic Scripting Tool WLST Scripts and WLST from Java

Weblogic 10.3.5: Enable Debugging Using the WebLogic Scripting Tool  WLST Scripts and WLST from Java
WebLogic Scripting Tool (WLST) can be used to set the debugging values. For example, the following command runs a program for setting debugging values called debug.py:
java weblogic.WLST debug.py
The main scope, weblogic, does not appear in the graphic; jms is a sub-scope within weblogic. Note that the fully-qualified DebugScope for DebugJMSBackEnd is weblogic.jms.backend.
The debug.py program contains the following code:
user='user1'
password='password'
url='t3://localhost:7001'
connect(user, password, url)
edit()
cd('Servers/myserver/ServerDebug/myserver')
startEdit()
set('DebugJMSBackEnd','true')
save()
activate()
Note that you can also use WLST from Java. The following example shows a Java file used to set debugging values:
import weblogic.management.scripting.utils.WLSTInterpreter;
import java.io.*;
import weblogic.jndi.Environment;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class test {
  public static void main(String args[]) {
 try {
  WLSTInterpreter interpreter = null;
  String user="user1";
  String pass="pw12ab";
  String url ="t3://localhost:7001";
  Environment env = new Environment();
  env.setProviderUrl(url);
  env.setSecurityPrincipal(user);
  env.setSecurityCredentials(pass);
  Context ctx = env.getInitialContext();

  interpreter = new WLSTInterpreter();
  interpreter.exec
   ("connect('"+user+"','"+pass+"','"+url+"')");
  interpreter.exec("edit()");
  interpreter.exec("startEdit()");
  interpreter.exec
   ("cd('Servers/myserver/ServerDebug/myserver')");
  interpreter.exec("set('DebugJMSBackEnd','true')"); 
  interpreter.exec("save()");
  interpreter.exec("activate()");

 } catch (Exception e) {
 System.out.println("Exception "+e);
 }
 }
}
Using the WLST is a dynamic method and can be used to enable debugging while the server is running.

########

Oracle Fusion Middleware Security for Web Services 11g Release 1 (11.1.1.6) Policy Sets using WLST

Policy sets provide a means to attach policies globally to a range of endpoints of the same type. 



  • In addition to attaching policies directly to endpoints, you can create policy sets that allow you to attach policies globally to a range of endpoints of the same type, regardless of the deployment state. You can create and manage policy sets using both Fusion Middleware Control and the WebLogic Scripting Tool, WLST. 
  • Attaching policies globally using policy sets allows an administrator to ensure that all subjects are secured in situations where the developer, assembler, or deployer did not explicitly specify the policies to be attached.
  • Policies attached globally using policy sets also provide the following:
    • Override the policies
    • Specify run time constraint
  • Policy subjects to which policy sets can be attached include SOA components, SOA service endpoints, SOA references, Web services endpoints, Web service clients, Web service connections, and asynchronous callback clients. Policy sets can be attached at the following scopes:
    • Domain — all policy subjects of the specified type in a domain
    • Server instance—all policy subjects of the specified type in a server instance
    • Application or Partition—all policy subjects of the specified type in an application or SOA partition
    • Application module or SOA composite—all policy subjects of the specified type in an application module or SOA composite
    • Service or reference—all policy subjects of the specified type in a SOA service or reference
    • Port or component—all policy subjects of the specified type in a port or SOA component

CREATING A POLICY SET USINg  WLST

CreatePolicySet.py
import os
propInputStream = FileInputStream("PolicySets.properties")
configProps = Properties()
configProps.load(propInputStream)
connect(configProps.get("userName"),configProps.get("passWord"),'t3://'+configProps.get("wlsHost")+':'+configProps.get("adminServerListenPort"))
splits=String(configProps.get("policysets_to_be_created")).split(",")
for dsIndex in splits:
    beginRepositorySession()
    #Variable Definitions
    policySetName=configProps.get("policySetName_"+ str(dsIndex))
    policySetType=configProps.get("policySetType_"+ str(dsIndex))
    policySetAttachTo=configProps.get("policySetAttachTo_"+ str(dsIndex))
    policySetDescription=configProps.get("policySetDescription_"+ str(dsIndex))
    policySetEnabled=configProps.get("policySetEnabled_"+ str(dsIndex))
    policySetUrl=configProps.get("policySetUrl_"+ str(dsIndex))
    print "Creating Policy Sets for System Resource Name:"+policySetName + ", Policy Set Type:" + policySetType +" Attached To: "+ policySetAttachTo + " , Description:" + policySetDescription + ", Enabled true or false: "+ policySetEnabled 
    createPolicySet(policySetName,policySetType,policySetAttachTo,description=policySetDescription,enable=policySetEnabled)
    print "Attaching Policy Sets"
    attachPolicySetPolicy(policySetUrl)
    print "Commiting Session"
    commitRepositorySession() 
PolicySets.properties
userName=username
passWord=password
wlsHost=localhost
domainDir=domainDir
adminServerListenPort=7001
#Total Number of Data Sources 
policysets_to_be_created=1
#Properties for the first PolicySets
policySetName_1=TestWSClientPolicySet
policySetType_1=sca-reference
policySetAttachTo_1=Domain("domain") and Server("server1") and Composite("*CBP*")
policySetDescription_1=Global policy attachments for SOA Reference resources.
policySetEnabled_1=true
policySetUrl_1=oracle/wss10_saml_token_client_policy_OPT_ON

########