#!/bin/bash
#Date:8/2/2019

if [ "$1" != "" ]
then

cd /home/glassfishv3/payara41/glassfish/bin

./asadmin create-domain --user glassfish --passwordfile /home/glassfishv3/AS_ADMIN_PASSWORD/normal.txt --domaindir ../domains --adminport $1 $2

./asadmin start-domain $2

./asadmin --user glassfish --passwordfile /home/glassfishv3/AS_ADMIN_PASSWORD/normal.txt --port $1 enable-secure-admin

./asadmin restart-domain $2

./asadmin --user glassfish --passwordfile /home/glassfishv3/AS_ADMIN_PASSWORD/normal.txt --host host1 --port $1 create-node-ssh --nodehost host1
--nodedir /home/glassfishv3/payara41/glassfish/nodes $3-g01

./asadmin --user glassfish --passwordfile /home/glassfishv3/AS_ADMIN_PASSWORD/normal.txt --host host1 --port $1 create-node-ssh --nodehost host2
--nodedir /home/glassfishv3/payara41/glassfish/nodes $3-g02

./asadmin --user glassfish --passwordfile /home/glassfishv3/AS_ADMIN_PASSWORD/normal.txt --host host1 --port $1 create-cluster cluster
sleep 5

./asadmin --user glassfish --passwordfile /home/glassfishv3/AS_ADMIN_PASSWORD/normal.txt --host host1 --port $1 create-instance --node $3-g01 --cluster clus
ter $3-g1
sleep 5

ssh host2 /home/glassfishv3/payara41/glassfish/bin/asadmin --user glassfish --passwordfile /home/glassfishv3/AS_ADMIN_PASSWORD/normal.txt --host listix0rdwe
ba03 --port $1 create-instance --node $3-g02 --cluster cluster $3-g2
sleep 5

./asadmin --user glassfish --passwordfile /home/glassfishv3/AS_ADMIN_PASSWORD/normal.txt --host host1 --port $1 set configs.config.cluster-config.network-co
nfig.network-listeners.network-listener.http-listener-1.port=9500
sleep 5

./asadmin --passwordfile /home/glassfishv3/AS_ADMIN_PASSWORD/normal.txt --host host1 --port $1 start-cluster cluster

elif [ "$1" == "delete" ]
then
./asadmin stop-domain domain2
./asadmin delete-domain --domaindir ../domains domain2
else
echo "Please set adminport domain# appname appport"
fi