Integration Toolbox
for IBM® TIVOLI® Storage Manager

package archive_retrieve; import hu.user.toolbox.tsm.IArchiveObject; import hu.user.toolbox.tsm.IFilespace; import hu.user.toolbox.tsm.ITSMSession; import hu.user.toolbox.tsm.ManagementClass; import hu.user.toolbox.tsm.Toolbox; import hu.user.toolbox.tsm.exception.TSMException; import hu.user.toolbox.tsm.exception.ToolboxErrorCodes; import hu.user.toolbox.tsm.exception.ToolboxException; import hu.user.toolbox.tsm.internal.structures.TsmReturnCodes; import; import; import; /** * <b>Function:</b><br> * Creates and sends an archive object with contents of "inputs/archive.txt" as * data and sets the management class different from default. * <p> * Before executing this program register a filespace named "/ARCHIVEFS" * using the RegisterFilespace sample. * <p> * The following operations are performed: * <ol> * <li>Initializing a single-threaded TSM API environment.</li> * <li>Creating a new TSMSession instance. Setting default connection options. * Connecting to the server using the node name "TOOLBOX" and password * "PASSWORD".</li> * <li>Retrieving the filespace named "/ARCHIVEFS"</li> * <li>Creating a new archive object with the following parameters: * high-level name "/ARCHIVE", low-level name "/OBJECT1", and the owner name "Owner".</li> * <li>Binding the default management class.</li> * <li>Getting a different management class from the one returned by the binding. * Setting it to the backup object.</li> * <li>Sending the content of the file to the server.</li> * <li>Disconnecting from the server and cleaning up the resources.</li> * </ol> * <p> * <b>Compile:</b> * * <pre> * javac -d bin -cp ../lib/toolboxfortsm.jar * archive_retrieve/ * </pre> * <p> * <b>Execute:</b><br> * You should first set the environment variables to point to the correct * files/directories. * * <pre> * set DSMI_CONFIG={Full path of your dsm.opt} * set DSMI_DIR={Tivoli Storage Manager API installation directory} * set DSMI_LOG={Any arbitrary directory} * </pre> * * Then use the java command to execute the program: * <p> * * <pre> * java -cp bin:../lib/toolboxfortsm.jar:../lib/ext/log4j-1.2.17.jar:../config * -Djava.library.path=../lib archive_retrieve.ArchiveSingleObjectManagementClassOverride * </pre> */ public class ArchiveSingleObjectManagementClassOverride { private static final String NODE_NAME = "TOOLBOX"; private static final String PASSWORD = "PASSWORD"; private static final String MANAGEMENT_CLASS = "TOOLBOX_MGMT_ACG"; private static final String INPUT_FILE_NAME = "inputs/archive.txt"; private static final String LOW_LEVEL_NAME = "/OBJECT1"; private static final String HIGH_LEVEL_NAME = "/ARCHIVE"; private static final String FILESPACE_NAME = "/ARCHIVEFS"; public static void main(final String args[]) throws IOException, ToolboxException { ITSMSession session = null; try { // Initializing a single-threaded environment Toolbox.initSingleThreading(); // Connecting to the server with the default connection options session = Toolbox.createSession(NODE_NAME, PASSWORD); // Registering the filespace IFilespace filespace = session.retrieveFilespace(FILESPACE_NAME); // Checking if filespace exists if (filespace == null) { System.out.printf("Warning: '%s' does not exists.\n", FILESPACE_NAME); return; } // Creating a new archive object IArchiveObject archive = filespace.createArchiveFile( HIGH_LEVEL_NAME, LOW_LEVEL_NAME); try { // Binding the management class archive.bindManagementClass(); } catch (ToolboxException e) { // Checking if archive copy group exists in the bound management // class if (e.getReturnCode() == ToolboxErrorCodes.TSM_EXCEPTION) { TSMException ex = (TSMException) e.getCause(); if (ex.getReturnCode() == TsmReturnCodes.DSM_RC_TL_NOACG) { System.out.println(ex.getMessage()); return; } } return; } File file = new File(INPUT_FILE_NAME); FileInputStream in = new FileInputStream(file); // Setting object size archive.setEstimatedSize(file.length()); // Getting and setting a different management class from the // default. ManagementClass managementClass = session .getManagementClass(MANAGEMENT_CLASS); archive.setManagementClass(managementClass); // Beginning a transaction session.beginTransaction(); try { // Sending the object to the server archive.send(in); session.commit(); System.out.printf("Archive object '%s%s%S' has been sent.\n", FILESPACE_NAME, HIGH_LEVEL_NAME, LOW_LEVEL_NAME); } catch (ToolboxException e) { // Rolling back the current transaction session.rollback(); } } catch (ToolboxException e) { e.printStackTrace(); } finally { // Disconnecting session.disconnect(); // Cleaning up the environment Toolbox.cleanUp(); } } }