#!/bin/sh +x
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
#
# The contents of this file are subject to the terms of either the GNU
# General Public License Version 2 only ("GPL") or the Common Development
# and Distribution License("CDDL") (collectively, the "License").  You
# may not use this file except in compliance with the License.  You can
# obtain a copy of the License at
# https://oss.oracle.com/licenses/CDDL+GPL-1.1
# or LICENSE.txt.  See the License for the specific
# language governing permissions and limitations under the License.
#
# When distributing the software, include this License Header Notice in each
# file and include the License file at LICENSE.txt.
#
# GPL Classpath Exception:
# Oracle designates this particular file as subject to the "Classpath"
# exception as provided by Oracle in the GPL Version 2 section of the License
# file that accompanied this code.
#
# Modifications:
# If applicable, add the following below the License Header, with the fields
# enclosed by brackets [] replaced by your own identifying information:
# "Portions Copyright [year] [name of copyright owner]"
#
# Contributor(s):
# If you wish your version of this file to be governed by only the CDDL or
# only the GPL Version 2, indicate your decision by adding "[Contributor]
# elects to include this software in this distribution under the [CDDL or GPL
# Version 2] license."  If you don't indicate a single choice of license, a
# recipient has the option to distribute your version of this file under
# either the CDDL, the GPL Version 2 or to extend the choice of license to
# its licensees as provided above.  However, if you add GPL Version 2 code
# and therefore, elected the GPL Version 2 license, then the option applies
# only if the new code is made subject to such option by the copyright
# holder.
#


GF_HOME=${S1AS_HOME}

# production systems will not take generation of multicastport and multicastaddress to chance,
# they will explicitly set these values.  Recommend setting these values for our testing.  (not necessarily to the values listed below)
# Valid multicastport is between 2048 and 32000
# Generated multicast address is 228.9.X.Y  where X and Y are between 0 to 255.

$GF_HOME/bin/asadmin start-domain
echo "domain started"

GF_CLUSTER_NAME=`uname -n`-cluster
$GF_HOME/bin/asadmin create-cluster --multicastport 2231 --multicastaddress 228.9.1.3 ${GF_CLUSTER_NAME}

# how to turn on ShoalLogger to FINE logging using CLI.  The names below are subject to change in future but what will work now.
#$GF_HOME/bin/asadmin set-log-level ShoalLogger=FINE:javax.org.glassfish.gms.org.glassfish.gms=FINE:

# need to set unique GMS_LISTENER_PORT when running multiple instances on same machine.
# no need to set GMS_LISTENER_PORT when running one instance on each machine (includes DAS running on its own machine)

GF_DAS_HOST=localhost
GF_DAS_PORT=4848

for GF_INSTANCE_ID in 1 2 3 4 5
do 
$GF_HOME/bin/asadmin --host ${GF_DAS_HOST} --port ${GF_DAS_PORT} create-local-instance --cluster ${GF_CLUSTER_NAME} --systemproperties ASADMIN_LISTENER_PORT=${GF_INSTANCE_ID}4848:HTTP_LISTENER_PORT=${GF_INSTANCE_ID}8080:HTTP_SSL_LISTENER_PORT=${GF_INSTANCE_ID}8181:JMS_PROVIDER_PORT=${GF_INSTANCE_ID}7676:IIOP_LISTENER_PORT=${GF_INSTANCE_ID}3700:IIOP_SSL_LISTENER_PORT=${GF_INSTANCE_ID}3820:IIOP_SSL_MUTUALAUTH_PORT=${GF_INSTANCE_ID}3920:JMX_SYSTEM_CONNECTOR_PORT=${GF_INSTANCE_ID}8686:BIND_INTERFACE_ADDRESS=10.132.108.74:GMS_LISTENER_PORT-${GF_CLUSTER_NAME}=${GF_INSTANCE_ID}9490 inst${GF_INSTANCE_ID}
done

$GF_HOME/bin/asadmin start-cluster ${GF_CLUSTER_NAME}

echo Clustered created and started.
$GF_HOME/bin/asadmin list-instances


