Get Task Status (Java code sample)

Problem this snippet solves:

This Java client code sample uses Enterprise Manager's device inventory to get the status for a specific task executed by the referenced Enterprise Manager.

Code :

/**
 * A class for testing the Management::EM::get_task_status iControl interface.
 */

public class ManagementEMGetTaskStatus {
    
    private static int MIN_ARGS = 3;
    private static String USAGE = 
        "ManagementEMGetTaskStatus    " +
        "[] ...";
    private static int EM_PORT = 443;


    /**
     * The main method.
     *
     * @param args command line arguments
     */

    public static void main(String[] args) {

        if (args.length < MIN_ARGS) {
            System.err.println("Usage: " + USAGE);
            System.exit(1);
        }

        String emAddress = args[0];
        String emUsername = args[1];
        String emPassword = args[2];

        String[] taskIds = new String[args.length - MIN_ARGS];

        for (int i = 0; i < taskIds.length; i++) {
            taskIds[i] = args[i + MIN_ARGS];
        }

        iControl.ManagementEMTaskStatus[] statuses = null;

        try {
            iControl.Interfaces ic = new iControl.Interfaces();
            ic.initialize(emAddress, EM_PORT, emUsername, emPassword);

             statuses = ic.getManagementEM().get_task_status(taskIds);

             if (statuses.length != taskIds.length) {
                 throw new Exception("wrong number of status values returned");
             }
        }
        catch (Exception e) {
            System.err.println("Failed to get task status: " + e.getMessage());
            System.exit(1);
        }

        for (int i = 0; i < taskIds.length; i++) {
            System.out.print("Task ");
            System.out.print(taskIds[i]);
            System.out.print(": ");
            System.out.println(statuses[i]);
        }

     } // public static void main

} // public class ManagementEMGetTaskStatus
Published Mar 09, 2015
Version 1.0
No CommentsBe the first to comment