Skip to content

Commit

Permalink
added launcher script and logging config.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdotdanger committed Mar 6, 2011
1 parent e26df10 commit 45d4602
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 16 deletions.
53 changes: 53 additions & 0 deletions bin/pooper.sh
@@ -0,0 +1,53 @@
#!/bin/bash
# resolve links - $0 may be a softlink
this="${BASH_SOURCE-$0}"
while [ -h "$this" ]; do
ls=`ls -ld "$this"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '.*/.*' > /dev/null; then
this="$link"
else
this=`dirname "$this"`/"$link"
fi
done

# convert relative path to absolute path
bin=`dirname "$this"`
script=`basename "$this"`
bin=`unset CDPATH; cd "$bin"; pwd`
this="$bin/$script"
POOPER_HOME=`cd $bin/..;pwd`
POOPER_JAR="$POOPER_HOME/HadooperPooper.jar"
unset CDPATH
cd $bin

JAVA="java"

if [ -z "$POOPER_CONFIG" ] ; then
if [ -f ~/.ec2/pooper.properties ] ; then
POOPER_CONFIG=~/.ec2/pooper.properties
else
if [ -f "$POOPER_HOME/config/pooper.properties" ] ; then
POOPER_CONFIG="$POOPER_HOME/config/pooper.properties"
fi
fi
fi

POOPER_LIB="$POOPER_HOME/lib"
#theincessant aws log messages will make you mental if you don't have this.

if [ -z $CLASSPATH ] ; then
CLASSPATH="."
fi

for jar in $POOPER_LIB/*.jar ; do
CLASSPATH=$CLASSPATH:$jar
done

JAVA_OPTS="-Dlogging.config=$POOPER_HOME/config/log4j.properties"
JAVA_OPTS="$JAVA_OPTS -Dclasspath=$CLASSPATH"
JAVA_OPTS="$JAVA_OPTS -Dpooper.config=$POOPER_CONFIG"

COMMAND="$JAVA $JAVA_OPTS -jar $POOPER_JAR $1 $2 $3 $4 $5 $6"

exec $COMMAND
11 changes: 11 additions & 0 deletions build.xml
Expand Up @@ -71,5 +71,16 @@
nbproject/build-impl.xml file.
-->
<target name="-post-jar">
<copy todir="${dist.dir}/bin">
<fileset dir="bin">
</fileset>
</copy>
<copy todir="${dist.dir}/config">
<fileset dir="config">
</fileset>
</copy>
<chmod file="${dist.dir}/bin/pooper.sh" perm="755"/>
</target>

</project>
4 changes: 4 additions & 0 deletions config/log4j.properties
@@ -0,0 +1,4 @@
log4j.rootLogger=WARN, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
9 changes: 4 additions & 5 deletions nbproject/project.properties
Expand Up @@ -30,7 +30,8 @@ includes=**
jar.compress=false
javac.classpath=\
${libs.aws.classpath}:\
${libs.commons-codec.classpath}
${libs.commons-codec.classpath}:\
${libs.log4j.classpath}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
Expand Down Expand Up @@ -61,16 +62,14 @@ meta.inf.dir=${src.dir}/META-INF
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
${build.classes.dir}/data
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=-Dpooper.config=/Users/cory/.ec2/pooper.properties
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}:\
${build.classes.dir}/data
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
5 changes: 4 additions & 1 deletion src/com/lunabeat/pooper/Main.java
Expand Up @@ -9,7 +9,7 @@
import com.lunabeat.dooper.ClusterConfig.ConfigException;
import com.lunabeat.pooper.commands.AppCommand;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.log4j.PropertyConfigurator;

/**
*
Expand All @@ -26,6 +26,9 @@ public static void main(String[] args) {
}
System.exit(1);
}
if(System.getProperty("logging.config") != null){
PropertyConfigurator.configure(System.getProperty("logging.config"));
}

String configPath = System.getProperty("pooper.config",DEFAULT_CONFIG_PATH);
try{
Expand Down
34 changes: 24 additions & 10 deletions src/com/lunabeat/pooper/commands/AppCommand.java
Expand Up @@ -16,15 +16,19 @@
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
*
* @author cory
*/
public class AppCommand {
private static final Log LOG = LogFactory.getLog(AppCommand.class.getName());
private static final Map<String, CommandInfo> COMMANDS = initCommands();
private ClusterConfig _config;

Expand Down Expand Up @@ -146,28 +150,38 @@ private void checkCommandArgs(String commandName ,CommandInfo cInfo, String[] ar

private void listClusters() {
Map<String,Map<String,List<Instance>>> out = ClusterList.getClusterMap(_config);
System.out.println("found clusters:");
System.out.println("found running clusters:");
HashSet<String> emptyClusters = new HashSet<String>();
for(String clustername:out.keySet()){
System.out.println(clustername);
//System.out.println(clustername);
boolean empty = true;
for(String group: out.get(clustername).keySet()){
if(out.get(clustername).get(group).size() < 1)
System.out.println("\t"+group+" (empty)");
else
System.out.println("\t"+group);
emptyClusters.add(group.replace(HadoopCluster.MASTER_SUFFIX, ""));
else{
System.out.println(group+" ("+out.get(clustername).get(group).size()+")");
empty = false;
}
for(Instance i: out.get(clustername).get(group)){
StringBuilder sb = new StringBuilder("\t");
sb.append(i.getInstanceId());
sb.append("\t");
sb.append(i.getPublicDnsName());
sb.append("\t");
sb.append(i.getState().getName());
sb.append("\t");
sb.append(i.getInstanceType());
sb.append("\t");
sb.append(i.getLaunchTime().toString());
sb.append(i.getState().getName());
//sb.append("\t");
//sb.append(i.getPublicDnsName());
System.out.println(sb.toString());
}
if(!empty)
System.out.println();
}
if(!empty)
System.out.println("-----------");
}
System.out.println("Found empty cluster security groups:");
for(String s:emptyClusters){
System.out.println("\t"+s);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/log4j.properties
@@ -0,0 +1,4 @@
log4j.rootLogger=WARN, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

0 comments on commit 45d4602

Please sign in to comment.