We have deployed an ear file to our WebSphere instance. By default, all *.jar & *.war modules are mapped to the jvm.
We would like to map all the *.war modules also to the web server.
I have created the below jython script to map the additional modules to the web server:
modules = AdminApp.listModules('${p:appName}', '-server')
splitted = modules.splitlines()
for moduleLine in splitted:
print "Mapping module: " + moduleLine
appName, moduleUri, target = moduleLine.split("#")
print appName
print moduleUri
print target
if moduleUri.find('.war') >= 0:
print "It's a war: " + moduleUri
module, webXml = moduleUri.split("+")
print module
print webXml
AdminApp.edit('${p:appName}', ['-MapModulesToServers', [[module, module + ',' + webXml, target]]])
The above script works when the name of the module is the same name as referenced in the uri. However, in some cases, the web.xml contains another name as 'display name'. When we do a -MapModulesToServers, it seems to look at the display name of the module, not the uri.
For example:
In the WebSphere console, we would have the following line:
Module URI Module type
Demo be.fictive.company.demo.war,WEB-INF/web.xml Web Module
The 'AdminApp.listModules' method is returning the uri name (be.fictive.company.demo.war), whereas I need the name of the module (Demo).
Am I missing something or is there another way to retrieve the module name, so I can use the AdminApp.edit('${p:appName}', ['-MapModulesToServers', [[module, module + ',' + webXml, target]]]) to update the targets?
The administrative scripting console is not available, so I don't see a way to retrieve the commands that have been issued.
You can use the wildcat to match the name of the module. Replace
AdminApp.edit('${p:appName}', ['-MapModulesToServers', [[module, module + ',' + webXml, target]]])
with
AdminApp.edit('${p:appName}', ['-MapModulesToServers', [['.*', module + ',' + webXml, target]]])
Related
I need to generate the dynamic file path in the setup thread group like below.
def result_file = new File(org.apache.jmeter.services.FileServer.getFileServer().getBaseDir() + File.separator + 'transactions_passed_' + new Date().format('MM_dd_yyyy_HH_mm_ss') + '.csv');
props.put("result_file", result_file);
Now I want to pass that file path as a filename value of Flexible File Writer plugin of jmeter so that variables are stored inside it.
Not able to make it work. Kindly help. Thanks
I have tried below options:
Filename: ${__groovy(props.get("result_file").text)}
tried to use preprocessor and set the value:
vars.put("result_file", '${__FileToString(props.get("result_file"),,)}');
Also tried to use below groovy script in the FileName field of Flexible File Writer, however it throws an exception of FileNotFound exception:
${__groovy(new File(org.apache.jmeter.services.FileServer.getFileServer().getBaseDir() + System.getProperty('file.separator') + 'transactions_passed_' + new Date().format('MM_dd_yyyy_HH_mm_ss') + '.csv').text)}
I want to use DYNAMIC FILE PATH (which I am setting as property in setup thread group) in the FILENAME field of FLEXIBLE FILE WRITER
The approach with __groovy() function should work however you need to remove this .text bit from there
${__groovy(new File(org.apache.jmeter.services.FileServer.getFileServer().getBaseDir() + System.getProperty('file.separator') + 'transactions_passed_' + new Date().format('MM_dd_yyyy_HH_mm_ss') + '.csv'))}
because .text returns you the file contents and as the file doesn't exist - you're getting this FileNotFound error. More information on Groovy scripting in JMeter - Apache Groovy: What Is Groovy Used For?
I am trying to package multiple modules in one manifest module with PowerShell 4.0. Basically, I have 3 Setup Modules that do some stuff. I package these three using my manifest module. I then export only some functions and variables from all three modules. However, only my functions are callable from outside, my variables are nowhere to be seen. Can anyone help me out here? I basically followed this guide.
Here is my code:
Setup.ps1 (Startup-Script):
$currentDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition
$setupScriptPath = $currentDirectory + "\Setup.psd1"
Import-module $setupScriptPath
# This has to be set for every environment
$firstVariable # Not defined?
# $secondVariable= "http://url/"
# $thirdVariable= "http://url/"
Start-FirstSetup
Remove-Module -Name Setup
Setup.psd1 (Manifest module):
#
# Module manifest for module 'Setup'
#
# Generated by: Name
#
# Generated on: 1/7/2017
#
#{
# Script module or binary module file associated with this manifest.
# RootModule = ''
# Version number of this module.
ModuleVersion = '1.0'
# ID used to uniquely identify this module
GUID = 'guid'
# Author of this module
Author = 'Author name'
# Company or vendor of this module
CompanyName = 'Company'
# Copyright statement for this module
Copyright = '(c) 2017 Company'
# Description of the functionality provided by this module
Description = 'Starts three setups.'
# Minimum version of the Windows PowerShell engine required by this module
# PowerShellVersion = ''
# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''
# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''
# Minimum version of Microsoft .NET Framework required by this module
# DotNetFrameworkVersion = ''
# Minimum version of the common language runtime (CLR) required by this module
# CLRVersion = ''
# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''
# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = #()
# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = #()
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = #()
# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = #()
# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = #()
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
NestedModules = #('FirstSetup.psm1', 'SecondSetup.psm1', 'ThirdSetup.psm1')
# Functions to export from this module
FunctionsToExport = #('Start-FirstSetup', 'Start-SecondSetup', 'Start-ThirdSetup')
# Cmdlets to export from this module
CmdletsToExport = '*'
# Variables to export from this module
VariablesToExport = #('firstVariable', 'secondVariable', 'thirdVariable')
# Aliases to export from this module
AliasesToExport = '*'
# List of all modules packaged with this module
ModuleList = #('FirstSetup.psm1', 'SecondSetup.psm1', 'ThirdSetup.psm1')
# List of all files packaged with this module
# FileList = #()
# Private data to pass to the module specified in RootModule/ModuleToProcess
# PrivateData = ''
# HelpInfo URI of this module
# HelpInfoURI = ''
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''
}
FirstSetup.psm1 (First Module):
$firstVariable # This is not getting exported. Why?
function Start-FirstSetup{
Register-FirstVariables
echo "First setup started..."
}
Second and third setups: Same as first, only varables and functions are named firstVariable, thirdVariable, Start-SecondSetup, etc.
So my specific problem is, when I try to access $firstVariable from Setup.psm1, I get an error that it's not defined. But I marked it for export in my manifest module. So what did I miss here? When Start-FirstSetup is called, it goes through without any problem and I can even debug my module, but even then my $firstVariable is undefined.
You need to do 3 things to get a variable exported from a module:
Define the variable explicitly:
New-Variable -Name firstvariable
An implicit definition ($firstvariable) does not suffice.
Export the variable in the module (the .psm1 file):
Export-ModuleMember -Variable firstvariable
Define the exported variables in the manifest (the .psd1 file). A wildcard should normally suffice here:
VariablesToExport = '*'
but you can also provide a list:
VariablesToExport = #('firstvariable', 'secondvariable', 'thirdvariable')
This setting is basically a filter for defining which of the exported variables will actually be exposed. If a variable does not have a match here it will not be exported from the module, even if it's exported in a .psm1 file.
Can you please look into the below issue?
import time
node = AdminConfig.getid('/Node:node111/')
print node
print "sss" +AdminControl.queryNames('WebSphere:type=Server,*')
cell = AdminControl.getCell()
print " Cell name is --> "+ cell
warLoc='/home/test/PA_Test.war'
appName='PA_Test'
cellName=AdminControl.getCell()
print cellName
nodeName=AdminControl.getNode()
print "hello"
print " nodeName is --> "+ nodeName
appManager=AdminControl.queryNames('cell='+cellName+',node=node111,type=ApplicationManager,process=WebSphere_Portal,*')
print appManager
application = AdminConfig.getid("/Deployment:"+appName+"/")
print 'printing application name in next line'
print application
len(application)
print application
len(application)
var1 = len(application)
if var1:
print "Application exists"
print "before uninstall"
AdminApp.uninstall('PA_Test')
print "after uninstall"
AdminConfig.save()
else:
print "Application doesnot exist"
print "Before install"
print AdminApp.install(warLoc,'[-target default -usedefaultbindings -defaultbinding.virtual.host default_host]')
print "Done from My Side"
print "After install"
AdminConfig.save()
time.sleep(30)
AdminControl.invoke(appManager , 'startApplication',appName)
print "The script is completed."
Below is the successful message:
ADMA5016I: Installation of PA_Test.war154ed2178ed started.
ADMA5058I: Application and module versions are validated with versions of deployment targets.
ADMA5005I: The application PA_Test.war154ed2178ed is configured in the WebSphere Application Server repository.
ADMA5005I: The application PA_Test.war154ed2178ed is configured in the WebSphere Application Server repository.
ADMA5081I: The bootstrap address for client module is configured in the WebSphere Application Server repository.
ADMA5053I: The library references for the installed optional package are created.
ADMA5001I: The application binaries are saved in /opt/IBM/WebSphere/wp_profile/wstemp/Script154ed215c59/workspace/cells/inpudingpwmtst1Cell/applications/PA_Test.war154ed2178ed.ear/PA_Test.war154ed2178ed.ear
Now I am able to deploy the war but the file name is getting change to PA_Test.war154ed2178ed.ear but its should actually be PA_Test.ear. Can you please help how to change the current script?
Short answer:
print AdminApp.install(warLoc, [
'-appname', 'PA_Test.ear',
'-target', 'default',
'-usedefaultbindings',
'-defaultbinding.virtual.host', 'default_host'
])
Even shorter one: use WDR.
You'll need an application manifest file PA_Test.wdra:
PA_Test.ear pa.war
target default
usedefaultbindings
defaultbinding.virtual.host default_host
... and Jython script to import this manifest:
alreadyInstalled = 'PA_Test.ear' in AdminApp.list().splitlines()
importApplicationManifest('PA_Test.wdra')
save()
sync()
while AdminApp.isAppReady('PA_Test.ear') != 'true':
time.sleep(10)
if not alreadyInstalled:
for appMgr in queryMBeans(type='ApplicationManager', process='WebSphere_Portal'):
appMgr.startApplication('PA_Test.ear')
Disclosure: I'm a contributor and maintainer of WDR
Title says it all.
Is it possible to reverse-engineer pom.xml dependencies given a lib folder full of jars?
i.e. Discover the publicly available Maven artifacts given a jar name and/or SHA1 checksum.
Here's a naive attempt which didn't work very well, because the search often returns too many matches:
#!/usr/bin/python
# Mavenize a lib folder, converting jars into dependencies
import os
import sys
import urllib2
import json
for file in os.listdir(sys.argv[1]):
url = "http://search.maven.org/solrsearch/select?rows=1&wt=json&q=" + file
response = urllib2.urlopen(url)
jsonStr = response.read()
jsonObj = json.loads(jsonStr)
if(jsonObj["response"]["numFound"] > 0):
print "<dependency><!-- for " + file + "-->"
print " <groupId>" + jsonObj["response"]["docs"][0]["g"] + "</groupId>"
print " <artifactId>" + jsonObj["response"]["docs"][0]["a"] + "</artifactId>"
print " <version>" + jsonObj["response"]["docs"][0]["latestVersion"] + "</version>"
print "</dependency>"
If those jar files produced by maven then yes it is possible. In other case it is not possible without extra step like trying to find group id and version from mvnrepository etc.
With $AdminApp view <applicationName> -MapResRefToEJB it is possible to list the resource references defined for a deployed EJB module. However, the result of that command is plain text (that in addition may be localized). To extract that information one would have to parse this text, which is not very convenient. Is there a way to get the same information (i.e. the resources references of an application) in a structured form using $AdminConfig?
The AppManagement MBean provides this data in a structured format (Vector of AppDeploymentTasks). To obtain this data using wsadmin scripting (jython):
import javax.management as mgmt
appName = sys.argv[0]
appMgmt = mgmt.ObjectName(AdminControl.completeObjectName("WebSphere:*,type=AppManagement"))
appInfo = AdminControl.invoke_jmx(appMgmt, "getApplicationInfo", [appName, java.util.Hashtable(), None], ["java.lang.String", "java.util.Hashtable", "java.lang.String"])
for task in appInfo :
if (task.getName() == "MapResRefToEJB") :
resRefs = task.getTaskData()
# skip the first row since it contains the headers
for i in range(1, len(resRefs)) :
resRef = resRefs[i]
print
print "URI:", resRef[4]
print "EJB:", resRef[3]
print "Name:", resRef[5]
print "Type:", resRef[6]
print "JNDI:", resRef[8]