Permalink
Browse files

Addition of ability to shutdown vms added to nimbus-admin

  • Loading branch information...
rrusnak1 authored and oldpatricka committed Jun 21, 2011
1 parent 9f5a2fa commit 112fe1a257754f68bae1d3dc988889775ffc1fb8
@@ -22,6 +22,7 @@
private static final String FIND_OBJECT_BY_NAME = "Select id from objects where name = ? and parent_id = ? and object_type = ?";
private static final String FIND_OBJECT_BY_DATA_KEY = "Select id from objects where data_key = ?";
private static final String FIND_USER_BY_ALIAS = "Select user_id from user_alias where alias_name = ? and alias_type = ?";
+ private static final String FIND_USER_BY_FRIENDLY = "Select user_id from user_alias where friendly_name = ? and alias_type = ?";
private static final String CHECK_PERMISSIONS = "Select access_type_id from object_acl where object_id = ? and user_id = ?";
private static final String GET_DATA_KEY = "select data_key from objects where id = ?";
private static final String GET_CKSUM = "select md5sum from objects where id = ?";
@@ -63,6 +64,7 @@ public String getCumulusPublicUser()
return cumulusPublicUser;
}
+
public void setCumulusPublicUser(
String pubUser)
{
@@ -84,6 +86,10 @@ public String getCanonicalUserIdFromDn(
return getCanonicalUserIdFromAlias(name, ALIAS_TYPE_DN);
}
+ public String getCanonicalUserIdFromFriendlyName(String name) throws AuthzDBException {
+ return getCanonicalUserIdFromFriendly(name, ALIAS_TYPE_DN);
+ }
+
public List<UserAlias> getUserAliases(String userId)
throws AuthzDBException
{
@@ -886,6 +892,53 @@ public String getCanonicalUserIdFromAlias(
}
}
+ public String getCanonicalUserIdFromFriendly(String name, int type) throws AuthzDBException {
+ Connection c = null;
+ PreparedStatement pstmt = null;
+
+ try
+ {
+ c = getConnection();
+ pstmt = c.prepareStatement(FIND_USER_BY_FRIENDLY);
+ pstmt.setString(1, name);
+ pstmt.setInt(2, type);
+ logger.debug("getting user " + pstmt.toString());
+ ResultSet rs = pstmt.executeQuery();
+
+ if(!rs.next())
+ {
+ throw new AuthzDBException("no such user found " + name);
+ }
+ String canUserId = rs.getString(1);
+
+ return canUserId;
+
+ }
+ catch(SQLException e)
+ {
+ logger.error("",e);
+ throw new AuthzDBException(e);
+ }
+ finally
+ {
+ try
+ {
+ if (pstmt != null)
+ {
+ pstmt.close();
+ }
+ if (c != null)
+ {
+ returnConnection(c);
+ }
+ }
+ catch (SQLException sql)
+ {
+ logger.error("SQLException in finally cleanup", sql);
+ }
+ }
+ }
+
private Connection getConnection() throws SQLException
{
return this.dataSource.getConnection();
@@ -25,5 +25,8 @@
public interface RemoteAdminToolsManagement extends Remote {
public Hashtable getAllRunningVMs() throws RemoteException;
-
+ public Hashtable getVMsByUser(String user) throws RemoteException;
+ public String shutdownVM(String id, String seconds) throws RemoteException;
+ public String shutdownAllVMs(String seconds) throws RemoteException;
+ public String test(String user) throws RemoteException;
}
@@ -21,24 +21,19 @@
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.*;
import org.apache.log4j.varia.NullAppender;
-import org.globus.workspace.remoting.RemotingClient;
import org.globus.workspace.remoting.admin.NodeReport;
import org.globus.workspace.remoting.admin.VmmNode;
import org.nimbustools.api.services.admin.RemoteNodeManagement;
-import org.nimbustools.api.brain.NimbusHomePathResolver;
import java.io.*;
-import java.rmi.NotBoundException;
-import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.*;
-import java.util.concurrent.ExecutionException;
public class AdminClient extends RMIConfig {
private static final Log logger =
- LogFactory.getLog(AdminClient.class.getName());
+ LogFactory.getLog(RMIConfig.class.getName());
public static final int EXIT_OK = 0;
public static final int EXIT_PARAMETER_PROBLEM = 1;
@@ -91,7 +86,6 @@
public static void main(String args[]) {
- // early check for debug options
boolean isDebug = false;
final String debugFlag = "--" + Opts.DEBUG_LONG;
for (String arg : args) {
@@ -108,7 +102,8 @@ public static void main(String args[]) {
BasicConfigurator.configure(consoleAppender);
logger.info("Debug mode enabled");
- } else {
+ }
+ else {
BasicConfigurator.configure(new NullAppender());
}
@@ -407,7 +402,7 @@ private void loadArgs(String[] args) throws ParameterProblem {
if (config == null || config.trim().length() == 0) {
throw new ParameterProblem("Config file path is invalid");
}
- this.configPath = config.trim();
+ super.configPath = config.trim();
final boolean batchMode = line.hasOption(Opts.BATCH);
final boolean json = line.hasOption(Opts.JSON);
@@ -133,11 +133,46 @@ public Options getOptions() {
OptionBuilder.withLongOpt(POOL_LONG).hasArg().create(POOL);
+ //*************************************************************************
+ // NIMBUS-ADMIN
+ //*************************************************************************
+
+ public static final String LIST_VMS = "l";
+ public static final String LIST_VMS_LONG = "list";
+ public final Option LIST_VMS_OPT =
+ OptionBuilder.withLongOpt(LIST_VMS_LONG).hasOptionalArg().create(LIST_VMS);
+
+ public static final String SHUTDOWN_VMS = "s";
+ public static final String SHUTDOWN_VMS_LONG = "shutdown";
+ public final Option SHUTDOWN_VMS_OPT =
+ OptionBuilder.withLongOpt(SHUTDOWN_VMS_LONG).hasOptionalArg().create(SHUTDOWN_VMS);
+
+ public static final String ALL_VMS = "a";
+ public static final String ALL_VMS_LONG = "all";
+ public final Option ALL_VMS_OPT =
+ OptionBuilder.withLongOpt(ALL_VMS_LONG).hasOptionalArg().create(ALL_VMS);
+
+ public static final String USER = "u";
+ public static final String USER_LONG = "user";
+ public final Option USER_OPT =
+ OptionBuilder.withLongOpt(USER_LONG).hasOptionalArg().create(USER);
+
+ public static final String ID = "i";
+ public static final String ID_LONG = "id";
+ public final Option ID_OPT =
+ OptionBuilder.withLongOpt(ID_LONG).hasOptionalArg().create(ID);
+
+ public static final String SECONDS = "n";
+ public static final String SECONDS_LONG = "seconds";
+ public final Option SECONDS_OPT =
+ OptionBuilder.withLongOpt(SECONDS_LONG).hasOptionalArg().create(SECONDS);
+
public final Option[] ALL_ENABLED_OPTIONS = {
HELP_OPT, DEBUG_OPT, CONFIG_OPT, BATCH_OPT, DELIMITER_OPT,
REPORT_OPT, JSON_OPT, OUTPUT_OPT, ADD_NODES_OPT, LIST_NODES_OPT,
REMOVE_NODES_OPT, UPDATE_NODES_OPT, NETWORKS_OPT, MEMORY_OPT, POOL_OPT,
- ACTIVE_OPT, INACTIVE_OPT,
+ ACTIVE_OPT, INACTIVE_OPT, LIST_VMS_OPT, SHUTDOWN_VMS_OPT, USER_OPT, ID_OPT,
+ SECONDS_OPT, ALL_VMS_OPT
};
}
@@ -2,6 +2,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.PatternLayout;
+import org.apache.log4j.varia.NullAppender;
import org.globus.workspace.remoting.RemotingClient;
import org.nimbustools.api.brain.NimbusHomePathResolver;
Oops, something went wrong.

0 comments on commit 112fe1a

Please sign in to comment.