Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Addition of ability to shutdown vms added to nimbus-admin
Browse files Browse the repository at this point in the history
  • Loading branch information
rrusnak1 authored and oldpatricka committed Oct 4, 2011
1 parent 9f5a2fa commit 112fe1a
Show file tree
Hide file tree
Showing 7 changed files with 474 additions and 62 deletions.
53 changes: 53 additions & 0 deletions authzdb/src/org/nimbus/authz/AuthzDBAdapter.java
Expand Up @@ -22,6 +22,7 @@ public class AuthzDBAdapter
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_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_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_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 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_DATA_KEY = "select data_key from objects where id = ?";
private static final String GET_CKSUM = "select md5sum from objects where id = ?"; private static final String GET_CKSUM = "select md5sum from objects where id = ?";
Expand Down Expand Up @@ -63,6 +64,7 @@ public String getCumulusPublicUser()
return cumulusPublicUser; return cumulusPublicUser;
} }



public void setCumulusPublicUser( public void setCumulusPublicUser(
String pubUser) String pubUser)
{ {
Expand All @@ -84,6 +86,10 @@ public String getCanonicalUserIdFromDn(
return getCanonicalUserIdFromAlias(name, ALIAS_TYPE_DN); 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) public List<UserAlias> getUserAliases(String userId)
throws AuthzDBException throws AuthzDBException
{ {
Expand Down Expand Up @@ -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 private Connection getConnection() throws SQLException
{ {
return this.dataSource.getConnection(); return this.dataSource.getConnection();
Expand Down
Expand Up @@ -25,5 +25,8 @@
public interface RemoteAdminToolsManagement extends Remote { public interface RemoteAdminToolsManagement extends Remote {


public Hashtable getAllRunningVMs() throws RemoteException; 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;
} }
Expand Up @@ -21,24 +21,19 @@
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.log4j.*; import org.apache.log4j.*;
import org.apache.log4j.varia.NullAppender; 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.NodeReport;
import org.globus.workspace.remoting.admin.VmmNode; import org.globus.workspace.remoting.admin.VmmNode;
import org.nimbustools.api.services.admin.RemoteNodeManagement; import org.nimbustools.api.services.admin.RemoteNodeManagement;
import org.nimbustools.api.brain.NimbusHomePathResolver;


import java.io.*; import java.io.*;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutionException;




public class AdminClient extends RMIConfig { public class AdminClient extends RMIConfig {


private static final Log logger = 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_OK = 0;
public static final int EXIT_PARAMETER_PROBLEM = 1; public static final int EXIT_PARAMETER_PROBLEM = 1;
Expand Down Expand Up @@ -91,7 +86,6 @@ public class AdminClient extends RMIConfig {


public static void main(String args[]) { public static void main(String args[]) {


// early check for debug options
boolean isDebug = false; boolean isDebug = false;
final String debugFlag = "--" + Opts.DEBUG_LONG; final String debugFlag = "--" + Opts.DEBUG_LONG;
for (String arg : args) { for (String arg : args) {
Expand All @@ -108,7 +102,8 @@ public static void main(String args[]) {
BasicConfigurator.configure(consoleAppender); BasicConfigurator.configure(consoleAppender);


logger.info("Debug mode enabled"); logger.info("Debug mode enabled");
} else { }
else {
BasicConfigurator.configure(new NullAppender()); BasicConfigurator.configure(new NullAppender());
} }


Expand Down Expand Up @@ -407,7 +402,7 @@ private void loadArgs(String[] args) throws ParameterProblem {
if (config == null || config.trim().length() == 0) { if (config == null || config.trim().length() == 0) {
throw new ParameterProblem("Config file path is invalid"); 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 batchMode = line.hasOption(Opts.BATCH);
final boolean json = line.hasOption(Opts.JSON); final boolean json = line.hasOption(Opts.JSON);
Expand Down
Expand Up @@ -133,11 +133,46 @@ public Options getOptions() {
OptionBuilder.withLongOpt(POOL_LONG).hasArg().create(POOL); 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 = { public final Option[] ALL_ENABLED_OPTIONS = {
HELP_OPT, DEBUG_OPT, CONFIG_OPT, BATCH_OPT, DELIMITER_OPT, HELP_OPT, DEBUG_OPT, CONFIG_OPT, BATCH_OPT, DELIMITER_OPT,
REPORT_OPT, JSON_OPT, OUTPUT_OPT, ADD_NODES_OPT, LIST_NODES_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, 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
}; };


} }
Expand Up @@ -2,6 +2,10 @@


import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.globus.workspace.remoting.RemotingClient;
import org.nimbustools.api.brain.NimbusHomePathResolver; import org.nimbustools.api.brain.NimbusHomePathResolver;


Expand Down

0 comments on commit 112fe1a

Please sign in to comment.