com.lightdev.app.trec.server
Class ServerAdministrator

java.lang.Object
  extended by com.lightdev.app.trec.server.Agent
      extended by com.lightdev.app.trec.server.ServerAdministrator
All Implemented Interfaces:
SAMApplication

public class ServerAdministrator
extends Agent

An agent that is used by the Light Development Transparent Remote Computing (TREC) platform to enable users to do administration of a TREC server.

The agent makes available methods to upload agents and libraries as well as to add and remove agents as running services. It can be used to make backups of the SAM user and role database too.

Version:
2, 31.12.2005
Author:
Ulrich Hilger, Light Development, http://www.lightdev.com, info@lightdev.com, published under the terms and conditions of the BSD License, for details see file license.txt in the distribution package of this software

Field Summary
static String DEFAULT_NAME
          name of agent this class is addressed under on a TREC server by default
 
Fields inherited from class com.lightdev.app.trec.server.Agent
communicator
 
Constructor Summary
ServerAdministrator()
          create a new instance of a ServerAdministrator object
 
Method Summary
 boolean addAgent(String agentName, String className)
          add an agent existing on the server to the group of running agents on this server
 boolean deleteAgent(String fileName)
          delete an agent archive file and its extracted contents When the agent creates files on the server, it has to remove these itself using its destroy method.
 boolean deleteBackup(String backupDir)
           
 boolean deleteLibrary(String libName)
           
 void destroy()
          required by abstract Agent class but unsused here
 byte[] downloadBackup(String backupDirectory)
          download a SAM backup file This method assumes all backups in directory WEB-INF/sambackup
 Vector getAgentArchives()
          get the names of all archive files on the server
 Vector getAgentNames()
          get the names of all agents running on this server
 Vector getLibraries()
           
 String[] getRequiredRoleIds()
          get id of all roles required by this agent
 byte[] getRolesForAgent(String agentName)
          get all roles required by the agent with a given name
 Vector getUserDataStoreSettings()
           
 void init()
          required by abstract Agent class but unsused here
protected  void initMethodRoleMappings()
          initialize the mapping between method names, that require a role and respective role id This method is called automatically upon construction but the developer must implement it individually for all methods that are to be guarded by SAM.
protected  void initRoleNames()
          initialize names of the roles required by this agent This method is called automatically upon construction but the developer must implement it individually for roles that are required by this agent.
 boolean removeAgent(String agentName)
          remove an agent from the group of running agents on this server
 void setServer(Server server)
          set the TREC server this ServerAdministrator should use
 boolean setUserDataStore(int storeType, String driverName, String connectString)
          set the user data store the TREC server should use
 boolean uploadAgent(String fileName, byte[] agentArchive)
          load an agent up to the server Contents of the uploaded archive will be extracted as found in the archive to the WEB-INF/classes directory of the TREC server.
 boolean uploadBackup(String fileName, byte[] file)
          upload a backup file This method assumes to receive a ZIP file with a backup directory.
 boolean uploadLibrary(String fileName, byte[] library)
          load a library up to the server The uploaded library will be saved to the WEB-INF/lib directory of the TREC server.
 
Methods inherited from class com.lightdev.app.trec.server.Agent
getNameForRole, getRoleForMethod, mapRoleToMethod, setCommunicator, setNameForRoleId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NAME

public static final String DEFAULT_NAME
name of agent this class is addressed under on a TREC server by default

See Also:
Constant Field Values
Constructor Detail

ServerAdministrator

public ServerAdministrator()
create a new instance of a ServerAdministrator object

Method Detail

setUserDataStore

public boolean setUserDataStore(int storeType,
                                String driverName,
                                String connectString)
set the user data store the TREC server should use

Parameters:
storeType - the type of data store, one of STORE_TYPE_ROOT, STORE_TYPE_EMBEDDED or STORE_TYPE_SHARED_JDBC
driverName - full name of database driver class, e.g. com.mysql.jdbc.Driver
connectString - the connect string, e.g. jdbc:mysql://server/database?user=name&password=pw
Returns:
true, when store was set successfully, false otherwise

getUserDataStoreSettings

public Vector getUserDataStoreSettings()
                                throws IOException
Throws:
IOException

setServer

public void setServer(Server server)
set the TREC server this ServerAdministrator should use

Parameters:
server - the TREC server

downloadBackup

public byte[] downloadBackup(String backupDirectory)
                      throws Exception

download a SAM backup file

This method assumes all backups in directory WEB-INF/sambackup

Parameters:
backupDirectory - the backup directory
Returns:
the ZIP file with the backup as a byte array
Throws:
Exception

deleteBackup

public boolean deleteBackup(String backupDir)
                     throws Exception
Throws:
Exception

uploadBackup

public boolean uploadBackup(String fileName,
                            byte[] file)
                     throws Exception
upload a backup file

This method assumes to receive a ZIP file with a backup directory. The ZIP file will be extracted to directory WEB-INF/sambackup/[zip file name].

Parameters:
fileName - name of ZIP file
file - ZIP file contents
Returns:
true, when upload was successful
Throws:
Exception

init

public void init()
required by abstract Agent class but unsused here

Specified by:
init in class Agent

destroy

public void destroy()
required by abstract Agent class but unsused here

Specified by:
destroy in class Agent

uploadAgent

public boolean uploadAgent(String fileName,
                           byte[] agentArchive)
                    throws Exception
load an agent up to the server

Contents of the uploaded archive will be extracted as found in the archive to the WEB-INF/classes directory of the TREC server. Files with the same name are overwritten.

Parameters:
fileName - name of file for agent archive
agentArchive - content of agent archive as byte array
Returns:
true, when upload finished successful
Throws:
Exception

getAgentArchives

public Vector getAgentArchives()
                        throws Exception
get the names of all archive files on the server

Returns:
a Vector with names of agent archive files
Throws:
Exception

getLibraries

public Vector getLibraries()
                    throws Exception
Throws:
Exception

deleteLibrary

public boolean deleteLibrary(String libName)
                      throws Exception
Throws:
Exception

deleteAgent

public boolean deleteAgent(String fileName)
                    throws Exception
delete an agent archive file and its extracted contents

When the agent creates files on the server, it has to remove these itself using its destroy method. Method destroy is called when the agent is stopped thus removing all files created by the agent before the agent itself is removed.

Parameters:
fileName - agent archive file name, e.g. my_agent.zip
Returns:
true, when operation was successful
Throws:
Exception

uploadLibrary

public boolean uploadLibrary(String fileName,
                             byte[] library)
                      throws Exception
load a library up to the server

The uploaded library will be saved to the WEB-INF/lib directory of the TREC server. A file with the same name is overwritten.

Parameters:
fileName - name of library file
library - contents of library as byte array
Returns:
true, when upload finished successfully
Throws:
Exception

addAgent

public boolean addAgent(String agentName,
                        String className)
                 throws InstantiationException,
                        IllegalAccessException,
                        ClassNotFoundException,
                        IOException
add an agent existing on the server to the group of running agents on this server

Parameters:
agentName - name under which agent should be addressed
className - class name of agent, e.g. com.lightdev.app.trec.sample.SampleSAMApplication
Returns:
true, when successfully added agent
Throws:
InstantiationException
IllegalAccessException
ClassNotFoundException
IOException

removeAgent

public boolean removeAgent(String agentName)
                    throws IOException
remove an agent from the group of running agents on this server

Parameters:
agentName - name of agent to remove
Returns:
true, when agent was removed successful
Throws:
IOException

getAgentNames

public Vector getAgentNames()
get the names of all agents running on this server

Returns:
a Vector of Strings with agent names

getRolesForAgent

public byte[] getRolesForAgent(String agentName)
get all roles required by the agent with a given name

Parameters:
agentName - name of agent to get all requred roles for
Returns:
an array of roles as a byte array

getRequiredRoleIds

public String[] getRequiredRoleIds()
get id of all roles required by this agent

Specified by:
getRequiredRoleIds in interface SAMApplication
Specified by:
getRequiredRoleIds in class Agent
Returns:
an array for id strings

initMethodRoleMappings

protected void initMethodRoleMappings()
initialize the mapping between method names, that require a role and respective role id

This method is called automatically upon construction but the developer must implement it individually for all methods that are to be guarded by SAM.

Specified by:
initMethodRoleMappings in class Agent

initRoleNames

protected void initRoleNames()
initialize names of the roles required by this agent

This method is called automatically upon construction but the developer must implement it individually for roles that are required by this agent.

Specified by:
initRoleNames in class Agent