Java 类com.vmware.vim25.mo.EventHistoryCollector 实例源码

项目:contrail-vcenter-plugin    文件:VCenterNotify.java   
private EventHistoryCollector createEventHistoryCollector(ManagedObject mo,
        String[] events) throws InvalidState, RuntimeFault, RemoteException
{
    if (eventManager == null) {
        s_logger.error("Cannot create EventHistoryCollector, eventManager is null");
        return null;
    }
    EventFilterSpec eventFilterSpec = new EventFilterSpec();
    eventFilterSpec.setType(events);

    // Create an Entity Event Filter Spec to
    // specify the MoRef of the MO to be get events filtered for
    EventFilterSpecByEntity entitySpec = new EventFilterSpecByEntity();
    entitySpec.setEntity(mo.getMOR());
    entitySpec.setRecursion(EventFilterSpecRecursionOption.children);
    // set the entity spec in the EventFilter
    eventFilterSpec.setEntity(entitySpec);

    if (vcenterConnectedTime != null) {
        EventFilterSpecByTime timeSpec = new EventFilterSpecByTime();
        timeSpec.setBeginTime(vcenterConnectedTime);
        // set the time spec in the EventFilter
        eventFilterSpec.setTime(timeSpec);
    }

    // create the EventHistoryCollector to monitor events for a VM
    // and get the ManagedObjectReference of the EventHistoryCollector
    // returned

    EventHistoryCollector collector = eventManager.createCollectorForEvents(eventFilterSpec);
    collector.setCollectorPageSize(1000);
    collectors.add(collector);

    return collector;
}
项目:contrail-vcenter-plugin    文件:VCenterNotify.java   
private PropertyFilterSpec createEventFilterSpec(EventHistoryCollector collector)
        throws Exception
{
    // Set up a PropertySpec to use the latestPage attribute
    // of the EventHistoryCollector
    PropertySpec propSpec = new PropertySpec();
    propSpec.setAll(new Boolean(false));
    propSpec.setPathSet(new String[] { "latestPage" });
    propSpec.setType(collector.getMOR().getType());

    // PropertySpecs are wrapped in a PropertySpec array
    PropertySpec[] propSpecAry = new PropertySpec[] { propSpec };

    // Set up an ObjectSpec with the above PropertySpec for the
    // EventHistoryCollector we just created
    // as the Root or Starting Object to get Attributes for.
    ObjectSpec objSpec = new ObjectSpec();
    objSpec.setObj(collector.getMOR());
    objSpec.setSkip(new Boolean(false));

    // Get Event objects in "latestPage" from "EventHistoryCollector"
    // and no "traversal" further, so, no SelectionSpec is specified
    objSpec.setSelectSet(new SelectionSpec[] {});

    // ObjectSpecs are wrapped in an ObjectSpec array
    ObjectSpec[] objSpecAry = new ObjectSpec[] { objSpec };

    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.setPropSet(propSpecAry);
    spec.setObjectSet(objSpecAry);
    return spec;
}
项目:contrail-vcenter-plugin    文件:VCenterNotify.java   
private void watchManagedObjectEvents(ManagedObject mos, String[] events)
{
    if (mos == null || events == null) {
        s_logger.error("Null arguments in watchManagedObjectEvents");
        return;
    }
    try
    {
        EventHistoryCollector collector =
                createEventHistoryCollector(mos, events);

        if (collector == null) {
            s_logger.error("Cannot create EventHistoryCollector for events" + events);
            return;
        }
        PropertyFilterSpec eventFilterSpec = createEventFilterSpec(collector);

        if (eventFilterSpec == null) {
            s_logger.error("Cannot create PropertyFilterSpec for EventHistoryCollector for events"
                        + events);
            return;
        }

        PropertyFilter propFilter = propColl.createFilter(eventFilterSpec, true);

        if (propFilter != null) {
            watchedFilters.put(mos, propFilter);
        } else {
            s_logger.error("Cannot create event filter for managed object ");
        }
    } catch(Exception e)
    {
        s_logger.error("Cannot watchManagedObjectEvents for " + mos + ", exception " + e);
        s_logger.error(Throwables.getStackTraceAsString(e));
        throw new RuntimeException(e);
    }
}
项目:vijava    文件:QueryEvent.java   
public static void main(String[] args) throws Exception 
{

    if (args.length != 3) 
    {
        usage();
        return;
    }

    String urlStr = args[0];
    String username = args[1];
    String password = args[2];

    System.out.println("Connecting to " + urlStr + " as " + username);

    ServiceInstance si = new ServiceInstance(new URL(urlStr), username,
            password, true);

    System.out.println("info---" + si.getAboutInfo().getFullName());

    // Displays all the Events with Full Formatted message
    try 
    {
        EventManager _eventManager = si.getEventManager();
        EventFilterSpec eventFilter = new EventFilterSpec();

        EventHistoryCollector history = _eventManager
                .createCollectorForEvents(eventFilter);
        Event[] events = history.getLatestPage();

        System.out.println("Events In the latestPage are : ");
        for (int i = 0; i < events.length; i++) 
        {
            Event anEvent = events[i];
            System.out.println("Event: " + anEvent.getClass().getName()
                    + "  FullFormattedMessage: "
                    + anEvent.getFullFormattedMessage());
        }
    } catch (Exception e)
    {
        System.out.println("Caught Exception : " + " Name : "
                + e.getClass().getName() + " Message : " + e.getMessage()
                + " Trace : ");
        e.printStackTrace();
    }

    si.getServerConnection().logout();

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

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

  EventManager evtMgr = si.getEventManager();

  if(evtMgr!=null)
  {
    EventFilterSpec eventFilter = new EventFilterSpec();
    EventHistoryCollector ehc = 
      evtMgr.createCollectorForEvents(eventFilter);

    int total = 0;

    Event[] latestEvts = ehc.getLatestPage();
    printEvents(latestEvts, 0);
    total += latestEvts==null? 0 : latestEvts.length;

    System.out.println("\nBefore Latest Page:");
    ehc.resetCollector();
    while(true)
    {
      Event[] events = ehc.readPreviousEvents(50);
      if(events==null)
      {
        break;
      }
      printEvents(events, total);
      total += events.length;
    }
  }
  si.getServerConnection().logout();
}
项目:jcloud-vsphere    文件:EventManagerApi.java   
EventHistoryCollector createCollectorForEvents(EventFilterSpec filter) throws InvalidState, RuntimeFault, RemoteException;