def getServerState(serverName):
	"""
	Returns the state of the server with the specified name.

	Following server states exist:
		SHUTDOWN
		STARTING
		RUNNING
		FORCE_SUSPENDING
		FAILED_NOT_RESTARTABLE

	@type  serverName: String
	@param serverName: the name of a managed server

	@rtype:            String
	@return:           the managed server's current state
	"""

	currentPath = wl.pwd()

	wl.domainRuntime()
	bean = wl.cmo.lookupServerLifeCycleRuntime(serverName)
	status = bean.getState()

	wl.cd(currentPath)

	return status
def importSecuritySettings():
    global domain
    try:
        wl.serverConfig()
        # wl.setEditMBeanServerEnabled(1)
        # wl.edit()
        # wl.startEdit()
        wl.cd("SecurityConfiguration/" + domain.strip() + "/DefaultRealm/myrealm/Authorizers/XACMLAuthorizer")
        # wl.serverRuntime()
        # wl.cmo.exportData('XACML','exportPolicies.xml',wl.Properties())
        wl.cmo.importData("XACML", "OSBSecurityExportESBDEV/XACMLAuthorizer.dat", wl.Properties())
        # wl.save()
        # wl.activate(block="true")
    except:
        print "Error while trying to save and/or activate!!!"
        dumpStack()
def createJMS():

    # Switch to the server runtime tree
    # wl.serverRuntime()
    # Navigate to the JMS Destination Runtime MBean
    # wl.cd('JMSRuntime/' + adminServer + '.jms/JMSServers/' + jmsServer)
    # wl.cd('Destinations/' + jmsmodulename + '!' +  jmsdestname)

    jms_module_path = getJMSModulePath(jmsModule)
    wl.cd(jms_module_path)
    theJMSResource = wl.cmo
    # print "Creating OSBSamplesJMSServer..."
    # jmsserver1mb = wl.create('OSBSamplesJMSServer','JMSServer')
    # jmsserver1mb.addTarget(servermb)
    # jmsserver1mb.setNotes("This JMS server is used by the osb-109-JMS sample project.")

    # print "Creating the OSBSamplesJMSResources JMS Module..."
    # jmsMySystemResource = wl.create("OSBSamplesJMSResources","JMSSystemResource")
    # jmsMySystemResource.addTarget(servermb)
    # jmsMySystemResource.setNotes("A JMS system module to contain the connection factory and the JMS queue")

    # print "Creating subdeployment..."
    # subDep1mb = jmsMySystemResource.createSubDeployment('OSBSamplesJMSSubdeploy')
    # subDep1mb.addTarget(jmsserver1mb)

    # theJMSResource = jmsMySystemResource.getJMSResource()

    # print "Creating connection factory..."
    # connfact1 = theJMSResource.createConnectionFactory('OSBSamplesJMSConnectionFactory')
    # connfact1.setJNDIName('jms.OSBSamplesJMSConnectionFactory')
    # connfact1.setLocalJNDIName('local.jms.OSBSamplesConnectionFactory')
    # connfact1.setSubDeploymentName('OSBSamplesJMSSubdeploy')
    # connfact1.setNotes("Use the JNDI name to connect to the JMS queue")

    print "Creating Queues..."
    queueList = queues.split(",")
    for q in queueList:
        createQueue(theJMSResource, q, jms_module_path)

    print "Creating Topics..."
    topicList = topics.split(",")
    for t in topicList:
        createTopic(theJMSResource, t, jms_module_path)
def getWebServiceState(serviceName):
	"""
	Returns the state of the server with the specified name.

	Following service states exist:
		STATE_ACTIVE
		STATE_PREPARED
		STATE_FAILED

	@type  serviceName: String
	@param serviceName: the name of a web service

	@rtype:             String
	@return:            the service's current state
	"""

	currentPath = wl.pwd()


	wl.domainConfig()

	try:
		wl.cd ('/AppDeployments/' + serviceName + '/Targets')
	except:
		wl.cd(currentPath)
		raise NameError('No web service with the name \'' + serviceName + '\' exists!')

	mytargets = wl.ls(returnMap='true')


	wl.domainRuntime()
	wl.cd('/AppRuntimeStateRuntime/AppRuntimeStateRuntime')

	for targetinst in mytargets:
		status = wl.cmo.getCurrentState(serviceName,targetinst)
		wl.cd(currentPath)
		return status

	wl.cd(currentPath)

	raise AttributeError('No status could be determined for the service \'' + serviceName + '\'!')
def getWebService(serviceName):
	"""
	Returns the server with the specified name.

	@type  serviceName: String
	@param serviceName: the name of a web service

	@rtype:             javax.management.MBeanServerInvocationHandler
	@return:            a service
	"""

	currentPath = wl.pwd()

	wl.serverConfig()
	wl.cd('/AppDeployments')

	servicesList = wl.cmo.getAppDeployments()
	for service in servicesList:

		actualName = service.getName()
		if actualName==serviceName:
			wl.cd(currentPath)
			return service

	wl.cd(currentPath)

	raise NameError('The service \'' + serviceName + '\' doesn\'t exist!')
def getServer(serverName):
	"""
	Returns the server with the specified name.

	@type  serverName: String
	@param serverName: the name of a managed server

	@rtype:            javax.management.MBeanServerInvocationHandler
	@return:           a managed server
	"""

	previousPath = wl.pwd()

	wl.serverConfig()
	wl.cd('/Servers')

	serverList = wl.cmo.getServers()
	for server in serverList:

		actualName = server.getName()

		if actualName==serverName:
			wl.cd(previousPath)
			return server

	wl.cd(previousPath)

	raise NameError('The server \'' + serverName + '\' doesn\'t exist!')
import wl

print "Connecting to the server ..."
wl.connect('weblogic','welcome1','t3://localhost:7021')
wl.serverConfig()
#wl.serverRuntime()
#wl.edit()
#wl.startEdit()
#wl.cd('/')
currentDomainName=wl.cmo.getName()
print "currentDomainName = " + currentDomainName
currentDir = wl.pwd()
print "we are in directory = " + currentDir 
# wl.cd("/servicebus/serverConfig/SecurityConfiguration/servicebus/DefaultRealm/myrealm/Authorizers/XACMLAuthorizer")
wl.cd("SecurityConfiguration/servicebus/DefaultRealm/myrealm/Authorizers/XACMLAuthorizer")
#wl.serverRuntime()
wl.cmo.exportData('XACML','exportPolicies.xml',wl.Properties())
#wl.cd('serverConfig:/SecurityConfiguration/' + currentDomainName + '/Realms/myrealm/CredentialMappers/DefaultCredentialMapper')
#prop=wl.Properties()
# wl.cmo.exportData('DefaultCreds','credentialmapper_properties.txt',prop)
#wl.cmo.exportData('XACML','exportPolicies.xml',Properties())
# wl.save()
#wl.activate(block="true")
#wl.disconnect()
print "script returns SUCCESS" 
Beispiel #8
0
def main():

  print ' Copyright 2012 Oracle Corporation. '
  print ' All Rights Reserved. '
  print ''
  print ' Provided on an ''as is'' basis, without warranties or conditions of any kind, '
  print ' either express or implied, including, without limitation, any warranties or '
  print ' conditions of title, non-infringement, merchantability, or fitness for a '
  print ' particular purpose. You are solely responsible for determining the '
  print ' appropriateness of using and assume any risks. You may not redistribute.'
  print ''
  print ' Please refer to http://redstack.wordpress.com/continous-integration for details.'
  print ''
  print ' This WLST script can be used as part of a continuous integration build process'
  print ' before deploying a SCA composite, to create any necessary JMS queues'
  print ' on the WebLogic Server.'
  print ''
  print ' In addition to creating the queue, this script will also update the '
  print ' resource adapter and redeploy it.'
  print ''
  print ' !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!'
  print ''
  print ' This script will make changes to your WebLogic domain.  Make sure you know '
  print ' what you are doing.  There is no support for this script.  If something bad '
  print ' happens, you are on your own!  You have been warned.'

  #
  # generate a unique string to use in the names
  # 

  uniqueString = str(int(time.time()))

  #
  # Create a JDBC Data Source.
  # 

  try:
    print('--> about to connect to weblogic')
    wl.connect(username, password, url)  
    print('--> about to create a queue ' + qName)
    wl.edit()
    wl.startEdit()
    wl.cd('/JMSSystemResources/' + jmsModule + '/JMSResource/' + jmsModule)
    wl.cmo.createQueue(qName)
    wl.cd('/JMSSystemResources/' + jmsModule + '/JMSResource/' + jmsModule + '/Queues/' + qName)
    wl.set('JNDIName', jndiName)
    wl.set('SubDeploymentName', jmsSubDeployment)
    wl.save()
    print('--> activating changes')
    wl.activate()
    print('--> done')

#
# update the deployment plan
#
    print('--> about to update the deployment plan for the DbAdapter')
    wl.startEdit()
    planPath = wl.get('/AppDeployments/JmsAdapter/PlanPath')
    appPath = wl.get('/AppDeployments/JmsAdapter/SourcePath')
    print('--> Using plan ' + planPath)
    plan = wl.loadApplication(appPath, planPath)
    print('--> adding variables to plan')

    makeDeploymentPlanVariable(plan, 'ConnectionInstance_eis/wls/' + qName + '_JNDIName_' + uniqueString, eisName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.tip.adapter.jms.IJmsConnectionFactory"]/connection-instance/[jndi-name="' + eisName + '"]/jndi-name')
    makeDeploymentPlanVariable(plan, 'ConfigProperty_ConnectionFactoryLocation' + uniqueString, eisName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.tip.adapter.jms.IJmsConnectionFactory"]/connection-instance/[jndi-name="' + eisName + '"]/connection-properties/properties/property/[name="ConnectionFactoryLocation"]/value')
    print('--> saving plan')
    makeDeploymentPlanVariableplan.save();
    makeDeploymentPlanVariablesave();
    print('--> activating changes')
    activate(block='true');
    wl.cd('/AppDeployments/JmsAdapter/Targets');
    print('--> redeploying the JmsAdapter')
    print(appName, planPath)
    wl.redeploy(appName, planPath, targets=cmo.getTargets())
    print('--> done')
  
  except Exception, inst :
	print('--> something went wrong, bailing out')
	print type(inst)     # the exception instance
	print inst.args      # arguments stored in .args
	print inst           # __str__ allows args to be printed directly
	# x, y = inst.args
	# print 'x =', x
	# print 'y =', y    
	stopEdit('y')
	raise SystemExit
Beispiel #9
0
def getServerStatus():
    import time;
    stoppedSvrCnt=0;
    runningSvrCnt=0;
    startingSvrCnt=0;
    otherSvrCnt=0;
    wl.cd('/')
    wl.domainConfig()
    serverNames = wl.cmo.getServers()
    wl.domainRuntime()
 
    results=[]

    for name in serverNames:
        try:
            wl.cd("/ServerLifeCycleRuntimes/" + name.getName())
            serverState = wl.cmo.getState()
            actTime='';

            if serverState == "RUNNING":
                wl.cd('../../ServerRuntimes/'+name.getName())
                actTime=wl.cmo.getActivationTime()
                x = time.gmtime(actTime/1000)
                timestr=" " + str(x[0]) + "/" + str(x[1]).zfill(2) + "/" + str(x[2]).zfill(2) + "," + str(x[3]).zfill(2) + ":" + str(x[4]).zfill(2)+':'+str(x[5]).zfill(2)
                wl.cd('JVMRuntime/'+name.getName())
                heapfree=wl.cmo.getHeapFreeCurrent();
                heapfreeperc=wl.cmo.getHeapFreePercent()
                heapmax=wl.cmo.getHeapSizeMax()
                heapused=100-heapfreeperc
                wl.cd('../..')
                serverHealth = str(wl.cmo.getOverallHealthState())
                healthok='State:HEALTH_OK'
                for serverComp in serverHealth.split(','):
                    if serverComp.find('State:')>-1:
                       healthok=serverComp
                runningSvrCnt=runningSvrCnt+1
                linestring=str(datetime.datetime.now().strftime('%Y-%m-%d,%H:%M:%S'))+',' + name.getName() + ',\033[1;32m' + serverState + '\033[0m'
                if healthok=='State:HEALTH_OK':
                      linestring=linestring+',\033[1;32mHEALTHY\033[0m,'+timestr+','+str(heapfree)+','+str(heapmax)+','+str(heapused)
                else:
                      linestring=linestring+',\033[1;33m  WARNING \033[0m,'+timestr+','+str(heapfree)+','+str(heapmax)+','+str(heapused)
                      for serverComp in serverHealth.split(','):
                          holdvalue=serverComp.split(':')
                          if holdvalue[0]=='ReasonCode':
                             linestring=linestring+'\n'
                          if holdvalue[0]!='MBean':
                             linestring=linestring+',\033[0;33m '+holdvalue[1].upper()+ '\033[0m'
                results.append(linestring);
            elif serverState == "STARTING":
                startingSvrCnt=startingSvrCnt+1;
                results.append(str(datetime.datetime.now().strftime('%Y-%m-%d,%H:%M:%S'))+',' + name.getName() + ',\033[1;33m' + serverState + '\033[0m,,,,,,');
            elif serverState == "SHUTDOWN":
                otherSvrCnt=otherSvrCnt+1;
                results.append(str(datetime.datetime.now().strftime('%Y-%m-%d,%H:%M:%S'))+',' + name.getName() + ',\033[1;31m' + serverState + '\033[0m,,,,,,');
            else:
                stoppedSvrCnt=stoppedSvrCnt+1
                results.append(str(datetime.datetime.now().strftime('%Y-%m-%d,%H:%M:%S'))+',' + name.getName() + ',\033[1;34m' + serverState + '\033[0m,,,,,,');
            wl.cd('../..')
        except:
            pass;

    return results;