Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added a hackey login command

  • Loading branch information...
commit 837cfa1cd3325e58bf4cdf75eb77e661c09d13fa 1 parent 84fe9eb
@carlosdotdanger authored
View
9 bin/pooper.sh
@@ -46,10 +46,17 @@ 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"
+
+if [ "$1" == "login" ] ; then
+ COMMAND=`$JAVA $JAVA_OPTS -jar $POOPER_JAR get-login-command $2 | tail -n1`
+else
+ COMMAND="$JAVA $JAVA_OPTS -jar $POOPER_JAR $1 $2 $3 $4 $5 $6"
+fi
exec $COMMAND
View
1  src/com/lunabeat/dooper/ClusterConfig.java
@@ -34,6 +34,7 @@
public static final String MASTER_HOST_KEY = "Master.Host";
public static final String WEB_PORTS_KEY = "EC2.WebPorts";
public static final String USERNAME_KEY = "EC2.Username";
+ public static final String EC2_INSTANCE_PREFIX = "i-";
public static final List<String> INSTANCE_TYPES = initInstanceTypes();
private static List<String> initInstanceTypes(){
ArrayList<String> tmpList = new ArrayList<String>();
View
8 src/com/lunabeat/dooper/HadoopCluster.java
@@ -477,4 +477,12 @@ public String getUserData() throws IOException {
}
return userData.toString();
}
+
+ /**
+ * convenience method for getting instance info.
+ * @return
+ */
+ public DescribeInstancesResult getInstanceForId(String instanceId) {
+ return _ec2.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceId));
+ }
}
View
37 src/com/lunabeat/pooper/commands/AppCommand.java
@@ -4,6 +4,7 @@
*/
package com.lunabeat.pooper.commands;
+import com.amazonaws.services.ec2.model.DescribeInstancesResult;
import com.amazonaws.services.ec2.model.Instance;
import com.amazonaws.services.ec2.model.InstanceStateChange;
import com.amazonaws.services.ec2.model.Reservation;
@@ -50,7 +51,9 @@ public AppCommand(ClusterConfig config) {
tmpMap.put("terminate-slaves", new CommandInfo(6, new String[]{"name:string", "nodes:int"}, "Terminate slaves in a cluster."));
tmpMap.put("describe-cluster", new CommandInfo(7, new String[]{"name:string"}, "Get instance info for a cluster."));
tmpMap.put("push-file", new CommandInfo(8, new String[]{"clusterName:string", "instances:instances", "srcPath:string", "destPath:string"}, "Copy file to cluster machines."));
- tmpMap.put("create-groups", new CommandInfo(9, new String[]{"clusterName:string"}, "Copy file to cluster machines."));
+ tmpMap.put("create-groups", new CommandInfo(9, new String[]{"clusterName:string"}, "Create security groups for cluster"));
+ tmpMap.put("get-login-command", new CommandInfo(10, new String[]{"target:string"}, "Get remote login command for master or specified instance id. This command is for external scripts."));
+ tmpMap.put("login", new CommandInfo(11, new String[]{"target:string"}, "Launch remote login for master or specific instance."));
return Collections.unmodifiableMap(tmpMap);
}
@@ -108,6 +111,13 @@ public void runCommand(String commandName, String[] args) {
case 9:
createGroups(args[0]);
break;
+ case 10:
+ getLoginCommand(args[0]);
+ break;
+ case 11:
+ LOG.fatal("Direct call to login.");
+ System.out.println("COMMAND 'login' needs to be handled by external script for now.\nUse 'get-login-command' to retrieve command and exec in shell.");
+ break;
default:
throw new RuntimeException("Bad AppInfo index for '" + commandName + "' :" + cInfo.getIndex());
}
@@ -470,6 +480,31 @@ private void createGroups(String clusterName) {
System.out.println("Created groups for " + clusterName + ".");
}
+ private void getLoginCommand(String target) {
+ String host = null;
+ HadoopCluster cluster = new HadoopCluster(target, _config);
+ if(cluster.groupsExist())
+ if(cluster.getMaster() != null)
+ host = cluster.getMaster().getInstance().getPublicDnsName();
+ else if(target.startsWith(ClusterConfig.EC2_INSTANCE_PREFIX)){
+ DescribeInstancesResult ir = cluster.getInstanceForId(target);
+ if(ir.getReservations().size() > 0)
+ if(ir.getReservations().get(0).getInstances().size() > 0)
+ host = ir.getReservations().get(0).getInstances().get(0).getPublicDnsName();
+ }
+ if(host == null){
+ System.out.println("'" + target + "' is not a valid cluster name or instance id.\nexiting.");
+ System.exit(0);
+ }
+ StringBuilder sb = new StringBuilder("ssh -i")
+ .append(_config.get(ClusterConfig.KEYPAIR_FILE_KEY))
+ .append(" ")
+ .append(_config.get(ClusterConfig.USERNAME_KEY))
+ .append("@")
+ .append(host);
+ System.out.println(sb.toString());
+ }
+
public static class CommandInfo {
private String[] _requiredArgNames;
Please sign in to comment.
Something went wrong with that request. Please try again.