Skip to content
This repository was archived by the owner on May 5, 2020. It is now read-only.

Commit cdbbc9a

Browse files
authored
Merge pull request #72 from parrobe/v3
Removed requirement for `MQ_QMGR_NAME` environment variable
2 parents 3128d3c + cf8b2d2 commit cdbbc9a

File tree

6 files changed

+87
-20
lines changed

6 files changed

+87
-20
lines changed

mq-create-qmgr.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@
1616

1717
set -e
1818

19+
if [ -z ${MQ_QMGR_NAME+x} ]; then
20+
# no ${MQ_QMGR_NAME} supplied so set Queue Manager name as the hostname
21+
# However make sure we remove any characters that are not valid.
22+
echo "Hostname is: $(hostname)"
23+
MQ_QMGR_NAME=`echo $(hostname) | sed 's/[^a-zA-Z0-9._%/]//g'`
24+
fi
25+
echo "Setting Queue Manager name to ${MQ_QMGR_NAME}"
26+
1927
QMGR_EXISTS=`dspmq | grep ${MQ_QMGR_NAME} > /dev/null ; echo $?`
28+
2029
if [ ${QMGR_EXISTS} -ne 0 ]; then
2130
MQ_DEV=${MQ_DEV:-"true"}
2231
if [ "${MQ_DEV}" == "true" ]; then

mq-monitor-qmgr.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616

1717
set -e
1818

19+
MQ_QMGR_NAME=$1
20+
1921
state()
2022
{
2123
dspmq -n -m ${MQ_QMGR_NAME} | awk -F '[()]' '{ print $4 }'
2224
}
2325

24-
trap mq-stop-container.sh SIGTERM SIGINT
26+
trap "source mq-stop-container.sh" SIGTERM SIGINT
27+
28+
echo "Monitoring Queue Manager ${MQ_QMGR_NAME}"
2529

2630
# Loop until "dspmq" says the queue manager is running
2731
until [ "`state`" == "RUNNING" ]; do

mq-parameter-check.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
set -e
1818

19-
: ${MQ_QMGR_NAME?"ERROR: You need to set the MQ_QMGR_NAME environment variable"}
20-
2119
# We want to do parameter checking early as then we can stop and error early before it looks
2220
# like everything is going to be ok (when it won't)
2321
if [ ! -z ${MQ_TLS_KEYSTORE+x} ]; then

mq-stop-container.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616

1717
set -e
1818

19-
endmqm $MQ_QMGR_NAME
20-
which endmqweb && endmqweb
19+
endmqm ${MQ_QMGR_NAME}
20+
which endmqweb && su -c "endmqweb" -l mqm

mq.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ which strmqweb && setup-mqm-web.sh
2525
echo "----------------------------------------"
2626
mq-pre-create-setup.sh
2727
echo "----------------------------------------"
28-
mq-create-qmgr.sh
28+
source mq-create-qmgr.sh
2929
echo "----------------------------------------"
30-
mq-start-qmgr.sh
30+
source mq-start-qmgr.sh
3131
echo "----------------------------------------"
32-
mq-configure-qmgr.sh
32+
source mq-configure-qmgr.sh
3333
echo "----------------------------------------"
34-
mq-dev-config.sh
34+
source mq-dev-config.sh
3535
echo "----------------------------------------"
36-
exec mq-monitor-qmgr.sh
36+
exec mq-monitor-qmgr.sh ${MQ_QMGR_NAME}

test/test.js

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,24 @@ describe('MQ Docker sample', function() {
4646
done();
4747
});
4848
});
49-
it('should fail if MQ_QMGR_NAME is not set', function (done) {
50-
exec(`docker run --rm --env LICENSE=accept ${DOCKER_IMAGE}`, function (err, stdout, stderr) {
51-
assert.equal(err.code, 1);
52-
assert.isTrue(stderr.includes("ERROR"));
53-
done();
54-
});
55-
});
5649
});
5750

5851
// Utility function to run a container and wait until MQ starts
59-
let runContainer = function(options) {
52+
let runContainer = function(options, unsetQMName, hostname) {
6053
return new Promise((resolve, reject) => {
61-
let cmd = `docker run -d --env LICENSE=accept --env MQ_QMGR_NAME=${QMGR_NAME} --net ${DOCKER_NETWORK} ${options} ${DOCKER_IMAGE}`;
54+
let cmd = "";
55+
let qmName = "";
56+
if(!unsetQMName){
57+
cmd = `docker run -d --env LICENSE=accept --env MQ_QMGR_NAME=${QMGR_NAME} --net ${DOCKER_NETWORK} ${options} ${DOCKER_IMAGE}`;
58+
qmName=QMGR_NAME
59+
} else{
60+
cmd = `docker run -d --env LICENSE=accept --net ${DOCKER_NETWORK} ${options} ${DOCKER_IMAGE}`;
61+
qmName=hostname
62+
}
6263
exec(cmd, function (err, stdout, stderr) {
6364
if (err) reject(err);
6465
let containerId = stdout.trim();
65-
let startStr = `IBM MQ Queue Manager ${QMGR_NAME} is now fully running`;
66+
let startStr = `IBM MQ Queue Manager ${qmName} is now fully running`;
6667
// Run dspmq every second, until the queue manager comes up
6768
let timer = setInterval(function() {
6869
exec(`docker logs ${containerId}`, function (err, stdout, stderr) {
@@ -118,6 +119,61 @@ describe('MQ Docker sample', function() {
118119
let container = null;
119120
this.timeout(10000);
120121

122+
describe('and no queue manager variable supplied', function(){
123+
let containerName="MQTestQM"
124+
125+
before(function() {
126+
this.timeout(20000);
127+
return runContainer("-h " + containerName, true, containerName)
128+
.then((details) => {
129+
container = details;
130+
});
131+
});
132+
after(function() {
133+
return deleteContainer(container.id);
134+
});
135+
it('should be using the hostname as the queue manager name', function (done) {
136+
exec(`docker exec ${container.id} dspmq`, function (err, stdout, stderr) {
137+
if (err) throw(err);
138+
if (stdout && stdout.includes(containerName)) {
139+
// Queue manager is up, so clear the timer
140+
done();
141+
}
142+
});
143+
});
144+
});
145+
146+
describe('with running container', function() {
147+
let container = null;
148+
this.timeout(10000);
149+
150+
describe('and no queue manager variable supplied but the hostname has invalid characters', function(){
151+
let containerName="MQ-Test-QM"
152+
let containerValidName="MQTestQM"
153+
154+
before(function() {
155+
this.timeout(20000);
156+
return runContainer("-h " + containerName, true, containerValidName)
157+
.then((details) => {
158+
container = details;
159+
});
160+
});
161+
after(function() {
162+
return deleteContainer(container.id);
163+
});
164+
it('should be using the hostname as the queue manager name without the invalid characters', function (done) {
165+
exec(`docker exec ${container.id} dspmq`, function (err, stdout, stderr) {
166+
if (err) throw(err);
167+
if (stdout && stdout.includes(containerValidName)) {
168+
// Queue manager is up, so clear the timer
169+
done();
170+
}
171+
});
172+
});
173+
});
174+
});
175+
176+
121177
describe('and implicit volume', function() {
122178
before(function() {
123179
this.timeout(20000);

0 commit comments

Comments
 (0)