How to read MQ base queue name using wsadmin script? - websphere

I want to read bas queue names inside the queues, have written code but which only able to read the last queue name instead of all.
Below is a code
queueList = AdminConfig.list('MQQueue', AdminConfig.getid('/Cell:' + AdminControl.getCell() + '/')).splitlines()
for queue in queueList:
print "\t" + queue +"in QueueList"
queueName = AdminConfig.showAttribute(queue, 'baseQueueName')
print queueName
The queue is reading only the last queue name from queueList, I want it to read all the base queue names present inside queues.

Your script as currently written will only execute the following line for each queue in the queueList:
print "\t" + queue +"in QueueList"
You need to indent the last 2 lines to make them part of the for loop, otherwise they are only executed once after the loop is finished, at that point queue will have the value of the last queue.
queueList = AdminConfig.list('MQQueue', AdminConfig.getid('/Cell:' + AdminControl.getCell() + '/')).splitlines()
for queue in queueList:
print "\t" + queue +"in QueueList"
queueName = AdminConfig.showAttribute(queue, 'baseQueueName')
print queueName

Related

Set heartbeat via command line in hadoop

It is possible to set the heartbeat of the nodemanager parameter via command line in hadoop ?
How ?
In alternative is possible to modify such parameter without restart the cluster ?
The parameter I am interested in manage is yarn.resourcemanager.nodemanagers.heartbeat-interval-ms under yarn-default.xml
You cannot set this parameter yarn.resourcemanager.nodemanagers.heartbeat-interval-ms (indicates The heart-beat interval in milliseconds for every NodeManager in the cluster.) using command line.
You can change this parameter in yarn-site.xml and then you need to re-start the services.
The reason being, this parameter is read once, when the Resource Tracker Service is started in the Resource Manager. The heart beat interval is returned to the Node Manager, as part of NodeHeartbeatResponse.
// Heartbeat response
NodeHeartbeatResponse nodeHeartBeatResponse = YarnServerBuilderUtils
.newNodeHeartbeatResponse(lastNodeHeartbeatResponse.
getResponseId() + 1, NodeAction.NORMAL, null, null, null, null,
nextHeartBeatInterval);
The parameter nextHeartBeatInterval in the call above, is read in serviceInit() method of Resource Tracker Service:
nextHeartBeatInterval =
conf.getLong(YarnConfiguration.RM_NM_HEARTBEAT_INTERVAL_MS,
YarnConfiguration.DEFAULT_RM_NM_HEARTBEAT_INTERVAL_MS);
if (nextHeartBeatInterval <= 0) {
throw new YarnRuntimeException("Invalid Configuration. "
+ YarnConfiguration.RM_NM_HEARTBEAT_INTERVAL_MS
+ " should be larger than 0.");
}
Also, the value of yarn.resourcemanager.nodemanagers.heartbeat-interval-ms (default 1000) should be less than value of yarn.nm.liveness-monitor.expiry-interval-ms (default 600000). yarn.nm.liveness-monitor.expiry-interval-ms indicates How long to wait until a node manager is considered dead..
The check for this is in validateConfigs() method of the Resource Manager:
// validate expireIntvl >= heartbeatIntvl
long expireIntvl = conf.getLong(YarnConfiguration.RM_NM_EXPIRY_INTERVAL_MS,
YarnConfiguration.DEFAULT_RM_NM_EXPIRY_INTERVAL_MS);
long heartbeatIntvl =
conf.getLong(YarnConfiguration.RM_NM_HEARTBEAT_INTERVAL_MS,
YarnConfiguration.DEFAULT_RM_NM_HEARTBEAT_INTERVAL_MS);
if (expireIntvl < heartbeatIntvl) {
throw new YarnRuntimeException("Nodemanager expiry interval should be no"
+ " less than heartbeat interval, "
+ YarnConfiguration.RM_NM_EXPIRY_INTERVAL_MS + "=" + expireIntvl
+ ", " + YarnConfiguration.RM_NM_HEARTBEAT_INTERVAL_MS + "="
+ heartbeatIntvl);
}

How to change the SDR channel definition of IBM MQ

I need to change the CONNAME('xx.xx.xxx.xx(1414) to CONNAME('yy.yy.yyy.yy(1414) for IBM MQ. I searched through the internet I did not found any command. My object definition code is given below.
DEFINE CHANNEL(CHANNELNAME) +
CHLTYPE(SDR) +
TRPTYPE(TCP) +
MAXMSGL(30000000) +
DESCR('Channel to REPLY TO sender') +
XMITQ('Sender.XMITQ') +
CONNAME('xx.xx.xxx.xx(1414)') +
BATCHSZ(50) +
DISCINT(6000) +
SHORTRTY(10) +
SHORTTMR(60) +
LONGRTY(999999999) +
KAINT(AUTO) +
LONGTMR(1200) +
SEQWRAP(999999999) +
CONVERT(YES) +
MCATYPE(PROCESS) +
HBINT(300) +
BATCHINT(0) +
NPMSPEED(FAST)
Can I use the ALTER command? if I delete the channel and redefine it will it cause any problem to existing channels and queues?
You can use the ALTER CHANNEL command like this:-
ALTER CHANNEL(CHANNELNAME) CHLTYPE(SDR) CONNAME('yy.yy.yyy.yy(1414)')
You only need to supply the attributes that you need to change, plus always the CHLTYPE.
You don't need to DELETE and re-DEFINE the channel object, and doing so would cause the run-time state such as channel sequence numbers to get out of step.
Additional Reading
ALTER CHANNEL reference documentation

Read both header and body in one call using java

I have a mail reader class which sets the FetchProfile and later does a msg.getContent.
I want to do both reading of header and content in one call, basically download the full mail in one call. Because I have observed msg.getcontent makes a call to the server to get the body/content , if we can download the full mail in one call, a call to the server can be saved.
Is this possible?
The code is similar to this
inbox.open(Folder.READ_ONLY);
/* Get the messages which is unread in the Inbox */
Message messages[] = inbox.search(new FlagTerm(
new Flags(Flag.SEEN), false));
/* Use a suitable FetchProfile */
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.CONTENT_INFO);
inbox.fetch(messages, fp);
for (int i = 0; i < messages.length; i++) {
System.out.println("MESSAGE #" + (i + 1) + ":");
Message message = messages[i];
**String content = message.getContent();**
System.out.println("Content : " + content);
}
Appreciate any help.
Thanks and Regards
Raaghu.K
If you want the entire message in one call, and don't need to use any of the features of the IMAP protocol, you have two choices:
Use POP3 instead of IMAP.
Use the Message.writeTo method to write the message content to a file or byte array and process it from there, e.g., using the MimeMessage constructor that takes an InputStream. (This makes a local copy of the entire message.)

Browse All Messages from WebSphere MQ at a single time using Java

How can we browse all the messages in a WebSphere MQ queue in one API call using java?
Here is the code which I'm using. Here I'm using this code a for loop until q depth is reached.
MQGetMessageOptions gmo=new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_NEXT ;
//System.out.println("Status: "+i);
MQMessage out=new MQMessage();
out.format =MQC.MQFMT_XMIT_Q_HEADER;//MQC.MQFMT_REF_MSG_HEADER;
mqCon.getQue().get(out,gmo);
System.out.print(i);
How can I get all messages without using for loop? It's taking a long time to browse 10,000 messages.
How can I get all messages without using for loop?
Use a while loop. Sorry, could not resist a slightly snarky answer on that one. WMQ does not have an API call analogous to the SQL select statement. Messaging and databases share some traits but address fundamentally different requirements.
It's taking a long time to browse 10,000 messages.
Take a look at the Performance SupportPacs. These are published on the SupportPacs main page and have names beginning with MP. Find the one for your platform and MQ version and it will list different scenarios for putting and getting messages as well as performance tuning recommendations.
I would also ask why a normal app needs to browse 10,000 messages. The QMgr will select messages for you based on MsgID, Correlation ID or property and this is much faster than browsing all the messages in order for the application to find the ones of interest. Occasionally people need to browse all messages on a queue to archive the queue or to debug a problem, but this is the exception rather than the rule. If a Production app regularly browses all messages on a queue, then the queues may have been inappropriately used as a database.
How can I get all messages without using for loop?
MQGetMessageOptions getOptions = new MQGetMessageOptions();
getOptions.options = MQC.MQGMO_BROWSE_NEXT + MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING;
MQMessage message = new MQMessage();
byte[] b = null;
while(true)
{
try
{
queue.get(message, getOptions);
b = new byte[message.getMessageLength()];
message.readFully(b);
System.out.println(new String(b));
message.clearMessage();
}
catch (IOException e)
{
System.out.println("IOException: " + e.getMessage());
break;
}
catch (MQException e)
{
if (e.completionCode == 2 && e.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE)
System.out.println("All messages read.");
else
System.out.println("MQException: Completion Code = " + e.completionCode + " : Reason Code = " + e.reasonCode);
break;
}
}
I have posted many Java/MQ samples here:
http://www.capitalware.biz/mq_code_java.html
If you want just browse messeges (not retrive them), you can use javax.jms.QueueBrowser.
Is pretty fast...
import javax.jms.*
...
public ArrayList<Message> browse() {
...
QueueBrowser queueBrowser = queueSession.createBrowser((javax.jms.Queue) lookupQueue());
Enumeration enums = queueBrowser.getEnumeration();
while (enums.hasMoreElements()) {
Object objMsg = enums.nextElement();
if (objMsg instanceof TextMessage) {
TextMessage message = (TextMessage) objMsg;
Log4j.trace("Text message: " + i + ". MSG:" + message.getText() + " MSG id:"
+ message.getJMSMessageID() + " MSG dest:" + message.getJMSDestination());
} else if (objMsg instanceof ObjectMessage) {
ObjectMessage message = (ObjectMessage) objMsg;
Log4j.trace("Object Message: " + i + ". MSG" + " MSG id:" + message.getJMSMessageID()
+ " MSG dest:" + message.getJMSDestination());
}
}
}
...
Just noticed the message format (out.Format) you are using. MQFMT_XMIT_Q_HEADER is used for messages that are sent to a transmit queue. Messages in transmit queue are not generally read by applications. MQ uses a transmit queue to send messages from one queue manager to another queue manager in a MQ network. I hope you are not browsing messages in a transmission queue.
For applications, message format would typically depend on the receiving application. For example if the receiving application is CICS based, then format would be MQFMT_CICS, for IMS it would be MQFMT_IMS. If text/string type of data is expected then you could use MQFMT_STRING. For administering MQ using PCF messages, then format can be MQFMT_PCF.

JMeter, threads using dynamic incremented value

I have created a JMeter functional test that essentially:
creates a user;
logs in with the user;
deletes the user.
Now, I need to be able to thread this, and dynamically generate a username with a default prefix and a numerically incremented suffix (ie TestUser_1, TestUser_2, ... etc).
I used the counter, and things were working fine until I really punched up the number of threads/loops. When I did this, I was getting a conflict with the counter. Some threads were trying to read the counter, but the counter had already been incremented by another thread. This resulted in trying to delete a thread that was just created, then trying to log in with a thread that was just deleted.
The project is set up like this:
Test Plan
Thread group
Counter
User Defined Variables
Samplers
I was hoping to solve this problem by using the counter to append a number to the user defined variables upon thread execution, but the counter cannot be accessed in the user defined variables.
Any ideas on how I can solve this problem?
Thank you in advance.
I've used the following scheme successfully with any amount of test users:
1. Generate using beanshell-script (in BeanShell Sampler e.g.) csv-file with test-user details, for example:
testUserName001,testPwd001
testUserName002,testPwd002
. . .
testUserName00N,testPwd00N
with the amount of entries you need for the test-run.
This is done once per "N users test-run", in separate Thread Group, in setUp Thread Group or maybe even in separate jmx-script... makes no difference.
You can please find working beanshell-code below.
2. Create your test users IN TEST APPLICATION using previously created users-list.
If you don't need create in application you may skip this.
Thread Group
Number of Threads = 1
Loop Count = 1
. . .
While Controller
Condition = ${__javaScript("${newUserName}"!="",)} // this will repeat until EOF
CSV Data Set Config
Filename = ${__property(user.dir)}${__BeanShell(File.separator,)}${__P(users-list,)} // path to generated users-list
Variable Names = newUserName,newUserPwd // these are test-users details read from file into pointed variables
Delimiter = '
Recycle on EOF? = False
Stop thread on EOF? = True
Sharing Mode = Current thread group
[CREATE TEST USERS LOGIC HERE] // here are actions to create separate user in application
. . .
3. Perform multi-user logic.
Schema like the given above one but Thread Group executed not for 1 but for N threads.
Thread Group
Number of Threads = ${__P(usersCount,)} // set number of users you need to test
Ramp-Up Period = ${__P(rampUpPeriod,)}
Loop Count = X
. . .
While Controller
Condition = ${__javaScript("${newUserName}"!="",)} // this will repeat until EOF
CSV Data Set Config
Filename = ${__property(user.dir)}${__BeanShell(File.separator,)}${__P(users-list,)} // path to generated users-list
Variable Names = newUserName,newUserPwd // these are test-users details read from file into pointed variables
Delimiter = '
Recycle on EOF? = False
Stop thread on EOF? = True
Sharing Mode = Current thread group
[TEST LOGIC HERE] // here are test actions
. . .
The key idea is in using Thread Group + While Controller + CSV Data Set Config combination:
3.1. CSV Data Set Config reads details for each the test users from generated file:
. . . a. only once - because of "Stop thread on EOF? = True";
. . . b. doesn't block file for further access (in another thread groups, e.g., if there are any) - because of "Sharing Mode = Current thread group";
. . . c. pointed variables - "Variable Names = newUserName,newUserPwd" - you will use in further test-actions;
3.2. While Controller forces CSV Data Set Config to read all the entries from generated file - because of defined condition (until the EOF).
3.3. Thread Group will start all the threads with defined ramp-up - or simultaneously if ramp-up = 0.
You can take here template script for described schema: multiuser.jmx.
Beanshell script to generate test-users details looks like below and takes the following args:
- test-users count
- test-user name template ("TestUser_" in your case)
- test-user name format (e.g. 0 - to get TestUser_1, 00 - to get TestUser_01, 000- for TestUser_001, etc... you can simply hardcode this orexclude at all)
- name of generated file.
import java.text.*;
import java.io.*;
import java.util.*;
String [] params = Parameters.split(",");
int count = Integer.valueOf(params[0]);
String testName = params[1];
String nameFormat = params[2];
String usersList = params[3];
StringBuilder contents = new StringBuilder();
try {
DecimalFormat formatter = new DecimalFormat(nameFormat);
FileOutputStream fos = new FileOutputStream(System.getProperty("user.dir") + File.separator + usersList);
for (int i = 1; i <= count; i++) {
String s = formatter.format(i);
String testUser = testName + s;
contents.append(testUser).append(",").append(testUser);
if (i < count) {
contents.append("\n");
}
}
byte [] buffer = contents.toString().getBytes();
fos.write(buffer);
fos.close();
}
catch (Exception ex) {
IsSuccess = false;
log.error(ex.getMessage());
System.err.println(ex.getMessage());
}
catch (Throwable thex) {
System.err.println(thex.getMessage());
}
All together it will look like:
Sorry if answer is too overloaded.
Hope this helps.
The "User Defined Variables" config element does not pick up the reference variable from the "Counter" config element. I think this is a bug in JMeter. I have verified this behavior in version 3.2.
I added a "BeanShell Sampler" element to work around the issue.
Notice that the reference name of the "Counter" element is INDEX
The RUN_FOLDER variable gets set to a combination of the TESTS_FOLDER variable and the INDEX variable in the "BeanShell Sampler"
The "Debug Sampler" simply gathers a snapshot of the variables so I can see them in the "View Results Tree" listener element. Notice how the RUN_FOLDER variable has the INDEX variable value (5 in this case) appended.

Resources