Skip to content

Commit

Permalink
Fix #790, Add org.smartdata.server.utils.tools.GetConf (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
littlezhou authored Jul 27, 2017
1 parent 4faa162 commit ba93f07
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bin/format-database.sh → bin/smart-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ if [ x"$?" = x"0" ]; then
echo "[Success]"
else
echo "[Failed]"
fi
fi
28 changes: 13 additions & 15 deletions bin/start-smart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,18 @@ done
SMARTSERVERS=$("${SMART_HOME}/bin/smart" getconf SmartServers 2>/dev/null)

if [ "$?" != "0" ]; then
echo "${SMARTSERVERS}"
exit 1
echo "${SMARTSERVERS}"
exit 1
fi

#if [[ -z "${SMARTSERVERS}" ]]; then
#SMARTSERVERS=$HOSTNAME
#fi

echo "Starting SmartServers on [${SMARTSERVERS}]"

. "${SMART_HOME}/bin/smart" \
--remote \
--config "${SMART_CONF_DIR}" \
--hosts "${SMARTSERVERS}" --hostsend \
--daemon start ${DEBUG_OPT} \
smartserver

if [ x"${SMARTSERVERS}" != x"" ]; then
echo "Starting SmartServers on [${SMARTSERVERS}]"
. "${SMART_HOME}/bin/smart" \
--remote \
--config "${SMART_CONF_DIR}" \
--hosts "${SMARTSERVERS}" --hostsend \
--daemon start ${DEBUG_OPT} \
smartserver
else
echo "No SmartServers configured in 'hazelcast.xml'."
fi
24 changes: 11 additions & 13 deletions bin/stop-smart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,14 @@ if [ "$?" != "0" ]; then
exit 1
fi

#if [[ -z "${SMARTSERVERS}" ]]; then
#SMARTSERVERS=$HOSTNAME
#fi

echo "Stopping SmartServers on [${SMARTSERVERS}]"

. "${SMART_HOME}/bin/smart" \
--remote \
--config "${SMART_CONF_DIR}" \
--hosts "${SMARTSERVERS}" --hostsend \
--daemon stop ${DEBUG_OPT} \
smartserver

if [ x"${SMARTSERVERS}" != x"" ]; then
echo "Stopping SmartServers on [${SMARTSERVERS}]"
. "${SMART_HOME}/bin/smart" \
--remote \
--config "${SMART_CONF_DIR}" \
--hosts "${SMARTSERVERS}" --hostsend \
--daemon stop ${DEBUG_OPT} \
smartserver
else
echo "No SmartServers configured in 'hazelcast.xml'."
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.smartdata.server.utils.tools;

import com.hazelcast.config.ClasspathXmlConfig;

import java.io.PrintStream;
import java.util.List;

public class GetConf {
public static final String USAGE="USAGE: GetConf <Option>\n"
+ "\t'Option' can be:\n"
+ "\t\tHelp Show this help message\n"
+ "\t\tSmartServers List SmartServers for the cluster(defined in hazelcast.xml)\n";

public static int getSmartServers(PrintStream p) {
ClasspathXmlConfig conf = new ClasspathXmlConfig("hazelcast.xml");
List<String> ret = conf.getNetworkConfig().getJoin().getTcpIpConfig().getMembers();
for (String s : ret) {
p.println(s);
}
return 0;
}

public static void main(String[] args) {
int exitCode = 0;
if (args == null || args.length == 0) {
System.err.println(USAGE);
System.exit(1);
}

try {
if (args[0].equalsIgnoreCase("SmartServers")) {
exitCode = getSmartServers(System.out);
} else if (args[0].equalsIgnoreCase("Help")) {
System.out.println(USAGE);
}
} catch (Throwable t) {
System.out.println(t.getMessage());
exitCode = 1;
}
System.exit(exitCode);
}
}

0 comments on commit ba93f07

Please sign in to comment.