Integration Toolbox
for IBM® TIVOLI® Storage Manager

package event_retention; import hu.user.toolbox.tsm.IArchiveObject; import hu.user.toolbox.tsm.IArchiveObjectList; import hu.user.toolbox.tsm.IFilespace; import hu.user.toolbox.tsm.IResultSet; import hu.user.toolbox.tsm.ITSMSession; import hu.user.toolbox.tsm.ManagementClass; import hu.user.toolbox.tsm.Toolbox; import hu.user.toolbox.tsm.exception.ToolboxErrorCodes; import hu.user.toolbox.tsm.exception.ToolboxException; import hu.user.toolbox.tsm.internal.structures.DsUint160_t; import hu.user.toolbox.tsm.query.IArchiveQuery; import java.io.File; import java.io.FileInputStream; import java.io.IOException; /** * <b>Function:</b><br> * Demonstrates the usage of retention events. * <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 parameters: * high-level name "/ARCHIVE", low-level name "/OBJECT1", and the owner name "Owner".</li> * <li>Binding the management class "TOOLBOX_MGMT_RET".</li> * <li>Sending the content of the file to the server.</li> * <li>Querying the sent object and printing the details.</li> * <li>Issuing the HOLD event to the queried object.</li> * <li>Querying the object and showing the modified held state and * the retention state.</li> * <li>Issuing the RELEASE event to the queried object.</li> * <li>Querying the object and showing the modified held state and * the retention state.</li> * <li>Issuing the ACTIVATE event to the queried object.</li> * <li>Querying the object and showing the modified held state and * the retention state.</li> * <li>Disconnecting from the server and cleaning up the resources.</li> * </ol> * <p> * <b>Compile:</b></br> * <pre> * javac -d bin -cp ../lib/toolboxfortsm.jar event_retention/EventRetention.java * </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> * To set up archive data retention protection on a new server installation (no * previous data), issue * <p> * <pre> * SET ARCHIVERETENTIONPROTECTION ON * </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 event_retention.EventRetention * </pre> */ public class EventRetention { private static final String NODE_NAME = "TOOLBOX"; private static final String PASSWORD = "PASSWORD"; private static final String INPUT_FILE_NAME = "inputs/archive.txt"; private static final String OWNER = "Owner"; private static final String LOW_LEVEL_NAME = "/OBJECT_EVENT"; private static final String HIGH_LEVEL_NAME = "/ARCHIVE"; private static final String FILESPACE_NAME = "/ARCHIVEFS"; private static final String MANAGEMENT_CLASS_NAME = "TOOLBOX_MGMT_RET"; private static final String DESCRIPTION = "sample descripiton"; 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); // Retrieving the existing filespace from server 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, OWNER); archive.setDescription(DESCRIPTION); try { ManagementClass managementClass = session.retrieveManagementClass(MANAGEMENT_CLASS_NAME); // Binding the management class archive.bindManagementClass(managementClass); } catch (ToolboxException e) { // Checking for archive copy group if (e.getReturnCode() == ToolboxErrorCodes.TSM_EXCEPTION) { System.out.println(e.getCause().getMessage()); } return; } File file = new File(INPUT_FILE_NAME); FileInputStream in = new FileInputStream(file); // Setting object size archive.setEstimatedSize(file.length()); // Beginning a transaction session.beginTransaction(); try { // Sending the object to the server archive.send(in); session.commit(); } catch(ToolboxException e) { // Rolling back the current transaction session.rollback(); } IArchiveObjectList archivesList = session.createArchiveObjectList(); IArchiveQuery archiveQuery = filespace.createArchiveQuery(); IResultSet archiveObjects = null; try { // Querying all archive objects of the filespace matching the specified criteria archiveObjects = archiveQuery .highLevelNameMatches(HIGH_LEVEL_NAME) .lowLevelNameMatches(LOW_LEVEL_NAME) .ownerMatchesAny() // Matches any owner name .descriptionMatchesAny() // Matches any description .files() // Query files .execute(); // Execute the query archivesList.clear(); // Iterating over the returned result set while (archiveObjects.next()) { IArchiveObject archiveObject = (IArchiveObject) archiveObjects.get(); printDetails(archiveObject); archivesList.add(archiveObject); } } catch (Exception e) { e.printStackTrace(); }finally{ // The result set must be closed. archiveObjects.close(); } // Issuing hold on archive object System.out.println("Issuing HOLD on archive objects."); archivesList.holdObjects(); try{ // Querying all archive objects of the filespace matching the specified criteria archiveObjects = archiveQuery .highLevelNameMatches(HIGH_LEVEL_NAME) .lowLevelNameMatches(LOW_LEVEL_NAME) .ownerMatchesAny() // Matches any owner name .descriptionMatchesAny() // Matches any description .files() // Query files .execute(); archivesList.clear(); // Iterating over the returned result set while (archiveObjects.next()) { IArchiveObject archiveObject = (IArchiveObject) archiveObjects.get(); printDetails(archiveObject); archivesList.add(archiveObject); } }catch (Exception e) { e.printStackTrace(); }finally{ // The result set must be closed. archiveObjects.close(); } // Releasing archive object System.out.println("Issuing RELEASE on archive objects."); archivesList.releaseObjects(); try{ // Querying all archive objects of the filespace matching the specified criteria archiveObjects = archiveQuery .highLevelNameMatches(HIGH_LEVEL_NAME) .lowLevelNameMatches(LOW_LEVEL_NAME) .ownerMatchesAny() // Matches any owner name .descriptionMatchesAny() // Matches any description .files() // Query files .execute(); archivesList.clear(); // Iterating over the returned result set while (archiveObjects.next()) { IArchiveObject archiveObject = (IArchiveObject) archiveObjects.get(); printDetails(archiveObject); archivesList.add(archiveObject); } }catch (Exception e) { e.printStackTrace(); }finally{ // The result set must be closed. archiveObjects.close(); } // Activating archive object retention System.out.println("Issuing ACTIVATE on archive objects."); archivesList.activateRetention(); try{ // Querying all archive objects of the filespace matching the specified criteria archiveObjects = archiveQuery .highLevelNameMatches(HIGH_LEVEL_NAME) .lowLevelNameMatches(LOW_LEVEL_NAME) .ownerMatchesAny() // Matches any owner name .descriptionMatchesAny() // Matches any description .files() // Query files .execute(); // Iterating over the returned result set while (archiveObjects.next()) { IArchiveObject archiveObject = (IArchiveObject) archiveObjects.get(); printDetails(archiveObject); } }catch (Exception e) { e.printStackTrace(); }finally{ // The result set must be closed. archiveObjects.close(); } } catch (ToolboxException e) { e.printStackTrace(); } finally { // Disconnecting session.disconnect(); // Cleaning up the environment Toolbox.cleanUp(); } } /** * Prints the details of a archive object. */ private static void printDetails(IArchiveObject o){ DsUint160_t restOrder = o.getRestoreOrderExt(); System.out.printf(" Name: %s%s%s\n", o.getFilespaceName(), o.getHighLevelName(), o.getLowLevelName()); System.out.printf(" Object type: %s\n", o.getType()); System.out.printf(" Description: %s\n", o.getDescription()); System.out.printf(" Insert date: %s\n", o.getInsertionDate()); System.out.printf(" Expiration date: %s\n", o.getExpirationDate()); System.out.printf(" Owner: %s\n", o.getOwner()); System.out.printf(" Restore order: %d-%d-%d-%d-%d\n", restOrder.getTop(), restOrder.getHi_hi(), restOrder.getHi_lo(), restOrder.getLo_hi(), restOrder.getLo_lo()); System.out.printf(" Object ID: %d\n", o.getId()); System.out.printf(" Copy group: %d\n", o.getCopyGroup()); System.out.printf(" Media class: %s\n", o.getMediaClass()); System.out.printf(" Management class: %s\n", o.getManagementClass().getName()); System.out.printf(" Object information: %s\n", o.getInformation()); System.out.printf("Estimated size (byte): %d\n", o.getEstimatedSize()); System.out.printf(" Retention initated: %s\n", o.getRetentionInitiated()); System.out.printf(" Object held?: %s\n", o.getHeld()); System.out.printf(" Compression: %s\n", o.getCompressionType()); System.out.printf(" Encryption: %s\n", o.getEncryptionType()); System.out.printf(" Client deduplicated: %s\n", o.isClientDeduplicated() ? "YES" : "NO"); System.out.println(); } }