forked from mithun008/amazonmq-rabbitmq-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·77 lines (69 loc) · 4.08 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
cd ~/environment
echo "Installing jq..."
sudo yum install -y jq > /dev/null 2>&1
java_version=`java -version |& awk -F '"' '/version/ {print $2}'`
if [[ "$java_version" =~ .*1\.8.* ]]; then
echo "Java is up to date"
else
echo "Updating java to 1.8..."
wget https://d3pxv6yz143wms.cloudfront.net/8.222.10.1/java-1.8.0-amazon-corretto-devel-1.8.0_222.b10-1.x86_64.rpm > /dev/null 2>&1
sudo yum localinstall -y java-1.8.0-amazon-corretto-devel-1.8.0_222.b10-1.x86_64.rpm > /dev/null 2>&1
fi
echo "export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac))))" >> ~/.bashrc
source ~/.bashrc
mvn_version=`mvn -version |& awk '/Apache Maven/ {print $3 }'`
if [[ "$mvn_version" =~ .*3\.6.* ]]; then
echo "Maven is up to date"
else
echo "Updating maven to 3.6..."
wget http://mirror.cc.columbia.edu/pub/software/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz > /dev/null 2>&1
tar zxvf apache-maven-3.6.1-bin.tar.gz > /dev/null 2>&1
echo "export PATH=~/environment/apache-maven-3.6.1/bin:$PATH" >> ~/.bashrc
fi
if [[ -d ~/environment/activemq-perftest ]];
then
echo "Maven performance tool kit exists"
else
echo "Installing maven performance plugin..."
svn checkout http://svn.apache.org/repos/asf/activemq/sandbox/activemq-perftest/ activemq-perftest > /dev/null 2>&1
sed -i 's/5.8-SNAPSHOT/5.15.9/g' ~/environment/activemq-perftest/pom.xml
mkdir ~/environment/activemq-perftest/reports
fi
echo "Getting broker urls..."
brokerId=`aws mq list-brokers | jq '.BrokerSummaries[] | select(.BrokerName=="Broker") | {id:.BrokerId}' | grep "id" | cut -d '"' -f4`
nob1Id=`aws mq list-brokers | jq '.BrokerSummaries[] | select(.BrokerName=="NoB1") | {id:.BrokerId}' | grep "id" | cut -d '"' -f4`
nob2Id=`aws mq list-brokers | jq '.BrokerSummaries[] | select(.BrokerName=="NoB2") | {id:.BrokerId}' | grep "id" | cut -d '"' -f4`
nob3Id=`aws mq list-brokers | jq '.BrokerSummaries[] | select(.BrokerName=="NoB3") | {id:.BrokerId}' | grep "id" | cut -d '"' -f4`
url=`aws mq describe-broker --broker-id=$brokerId | jq '.BrokerInstances[].Endpoints[0]' | xargs -n 2 | awk '{ print "failover:("$1","$2")" }'`
mesh1url=`aws mq describe-broker --broker-id=$nob1Id | jq '.BrokerInstances[].Endpoints[0]' | xargs -n 2 | awk '{ print "failover:("$1","$2")" }'`
mesh2url=`aws mq describe-broker --broker-id=$nob2Id | jq '.BrokerInstances[].Endpoints[0]' | xargs -n 2 | awk '{ print "failover:("$1","$2")" }'`
mesh3url=`aws mq describe-broker --broker-id=$nob3Id | jq '.BrokerInstances[].Endpoints[0]' | xargs -n 2 | awk '{ print "failover:("$1","$2")" }'`
echo "Saving broker urls..."
echo "perfurl=\"$url\"" >> ~/.bashrc;
echo "url=\"$url\"" >> ~/.bashrc;
echo "mesh1url=\"$mesh1url\"" >> ~/.bashrc;
echo "mesh2url=\"$mesh2url\"" >> ~/.bashrc;
echo "mesh3url=\"$mesh3url\"" >> ~/.bashrc;
echo "Accessing parameter store..."
userPassword=`aws ssm get-parameter --name "MQBrokerUserPassword" |& grep "Value\|ParameterNotFound"`
if [[ $userPassword =~ .*ParameterNotFound.* ]];
then
echo "Unable to obtain parameters from SSM. Most likely you are running this script outside of workshop."
else
brokerUser=`echo $userPassword | sed 's/"//g' | sed 's/Value://g' | cut -d',' -f1 | sed 's/ //g'`
brokerPassword=`echo $userPassword | sed 's/"//g' | sed 's/Value://g' | cut -d',' -f2`
fi
echo "brokerUser=\"$brokerUser\"" >> ~/.bashrc;
echo "brokerPassword=\"$brokerPassword\"" >> ~/.bashrc;
source ~/.bashrc
if [[ ! -z $perfurl ]];
then
printf "\nfactory.brokerURL=$perfurl\n" >> ~/environment/amazon-mq-workshop/openwire-producer.properties
printf "factory.userName=$brokerUser\n" >> ~/environment/amazon-mq-workshop/openwire-producer.properties
printf "factory.password=$brokerPassword\n" >> ~/environment/amazon-mq-workshop/openwire-producer.properties
printf "\nfactory.brokerURL=$perfurl\n" >> ~/environment/amazon-mq-workshop/openwire-consumer.properties
printf "factory.userName=$brokerUser\n" >> ~/environment/amazon-mq-workshop/openwire-consumer.properties
printf "factory.password=$brokerPassword\n" >> ~/environment/amazon-mq-workshop/openwire-consumer.properties
fi
echo "Done."