Java 类com.vmware.vim25.ScheduledTaskSpec 实例源码

项目:vijava    文件:CreateScheduledTasks.java   
static ScheduledTaskSpec createOneTimeSchedulerSpec(
    String taskName, Calendar runTime)
{
  // specify the action
  MethodAction action = new MethodAction();
  action.setName("PowerOffVM_Task");
  action.setArgument(new MethodActionArgument[] { });

  // specify the schedule
  runTime.add(Calendar.MINUTE, 01);
  OnceTaskScheduler scheduler = new OnceTaskScheduler();
  scheduler.setRunAt(runTime);

  // create a spec for the scheduled task
  ScheduledTaskSpec scheduleSpec = new ScheduledTaskSpec();
  scheduleSpec.setName(taskName);
  scheduleSpec.setDescription("PowerOff VM in 1 minutes");
  scheduleSpec.setEnabled(true);
  scheduleSpec.setAction(action);
  scheduleSpec.setScheduler(scheduler);

  return scheduleSpec;
}
项目:vijava    文件:CreateScheduledTasks.java   
static ScheduledTaskSpec createWeeklySchedulerSpec(
  String taskName)
{
  // create an action to take snapshot
  MethodAction action = new MethodAction();
  action.setName("CreateSnapshot_Task");
  MethodActionArgument nameArg = new MethodActionArgument();
  nameArg.setValue("My Snapshot");
  MethodActionArgument descArg = new MethodActionArgument();
  descArg.setValue("My Description");
  MethodActionArgument memArg = new MethodActionArgument();
  memArg.setValue(true);
  MethodActionArgument quieArg = new MethodActionArgument();
  quieArg.setValue(true);
  action.setArgument(new MethodActionArgument[] 
    {nameArg, descArg, memArg, quieArg });

  // run the task only once every week at Saturday midnight
  WeeklyTaskScheduler scheduler = new WeeklyTaskScheduler();
  scheduler.setSaturday(true);
  scheduler.setHour(23);
  scheduler.setMinute(59);
  scheduler.setInterval(1); 

  ScheduledTaskSpec scheduleSpec = new ScheduledTaskSpec();
  scheduleSpec.setName(taskName);
  scheduleSpec.setDescription(
    "Run a command at 23:59PM every other Saturday.");
  scheduleSpec.setEnabled(true);
  scheduleSpec.setAction(action);
  scheduleSpec.setScheduler(scheduler);

  return scheduleSpec;
}
项目:vijava    文件:CreateScheduledTasks.java   
public static void main(String [] args) throws Exception
 {
   if(args.length != 4)
   {
     System.out.println("Usage: java CreateScheduledTasks " 
    + "<url> <username> <password> <vmname>");
  return;
   }

   ServiceInstance si = new ServiceInstance(
              new URL(args[0]), args[1], args[2], true);
   Folder rootFolder = si.getRootFolder();

   InventoryNavigator inv = new InventoryNavigator(rootFolder);
   String vmname = args[3];
   VirtualMachine vm = (VirtualMachine)inv.searchManagedEntity(
           "VirtualMachine", vmname);
if(vm==null)
{
  System.out.println("Cannot find the VM " + vmname 
    + "\nExisting...");
  si.getServerConnection().logout();
  return;
}

   ScheduledTaskManager stm = si.getScheduledTaskManager();
   if(stm!=null)
   {
     //to save space, we just check one name here
     if(taskNameExists(stm, "ViMaster_OneTime"))
     {
       si.getServerConnection().logout();
       return;
     }

     // Note: the time should be fetched from server,
     // just to make sure it's synchronized.
     ScheduledTaskSpec oneSpec = createOneTimeSchedulerSpec(
         "ViMaster_OneTime", si.currentTime());

     ScheduledTaskSpec weekSpec = createWeeklySchedulerSpec(
         "ViMaster_Weekly");

     ScheduledTask st = stm.createScheduledTask(vm, oneSpec);
     ScheduledTask st1 = stm.createScheduledTask(vm, weekSpec);
  // sleep two minutes before deleting 
  // the one time scheduled task.
     // An one time scheduled task has not to be deleted after
     // it's run. It can be run any time again by calling the 
     // runScheduledTask() method.
     Thread.sleep(2*60*1000);
     st.removeScheduledTask();
   }
   else
   {
     System.out.println("SchduledTaskManager is not "
       + "available on this target.");
   }

si.getServerConnection().logout();
  }
项目:jcloud-vsphere    文件:ScheduledTaskManagerApi.java   
/**
 * @since SDK4.0
 */
ScheduledTask createObjectScheduledTask(ManagedObject obj, ScheduledTaskSpec spec) throws InvalidName, DuplicateName, RuntimeFault, RemoteException;
项目:jcloud-vsphere    文件:ScheduledTaskManagerApi.java   
ScheduledTask createScheduledTask(ManagedEntity entity, ScheduledTaskSpec spec) throws InvalidName, DuplicateName, RuntimeFault, RemoteException;