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

项目:contrail-vcenter-plugin    文件:VCenterEventHandler.java   
private void handleVmDeleteEvent(Event event) throws Exception {
    if (event.getHost() != null) {
        String hostName = event.getHost().getName();
        if (!vcenterDB.esxiToVRouterIpMap.containsKey(hostName)) {
            s_logger.info("Skipping event for unmanaged host " + hostName);
            return;
        }
    }

    VirtualMachineInfo vmInfo = MainDB.getVmByName(event.getVm().getName());

    if (vmInfo == null) {
        return;
    }

    vmInfo.delete(vncDB);
}
项目:contrail-vcenter-plugin    文件:VCenterEventHandler.java   
private void handleNetworkDeleteEvent(Event event) throws Exception {
String net_name = event.getNet().getName();
/*
From Mitaka nova driver will append cluster_id to port group
therefore need to extract the appended cluster id
*/
if (vcenterDB.mode == Mode.VCENTER_AS_COMPUTE) {
           net_name = net_name.substring(Math.max(0, net_name.length() - 36));
}
       VirtualNetworkInfo vnInfo = MainDB.getVnByName(net_name);

       if (vnInfo == null) {
           return;
       }
       VCenterNotify.unwatchVn(vnInfo);
       vnInfo.delete(vncDB);
   }
项目:contrail-vcenter-plugin    文件:VCenterEventHandler.java   
public void handle(Event event) throws Exception {
    s_logger.info("Process event " + event.getFullFormattedMessage());
    if (event instanceof VmCreatedEvent
        || event instanceof VmClonedEvent
        || event instanceof VmDeployedEvent
        || event instanceof VmReconfiguredEvent
        || event instanceof  VmRenamedEvent
        || event instanceof VmMacChangedEvent
        || event instanceof VmMacAssignedEvent
        || event instanceof DrsVmMigratedEvent
        || event instanceof DrsVmPoweredOnEvent
        || event instanceof VmMigratedEvent
        || event instanceof VmPoweredOnEvent
        || event instanceof VmPoweredOffEvent
        || event instanceof VmSuspendedEvent) {
        handleVmUpdateEvent(event);
    } else if (event instanceof VmRemovedEvent) {
        handleVmDeleteEvent(event);
    } else if (event instanceof DVPortgroupCreatedEvent
            || event instanceof DVPortgroupReconfiguredEvent
            || event instanceof DVPortgroupRenamedEvent) {
        handleNetworkUpdateEvent(event);
    } else if (event instanceof DVPortgroupDestroyedEvent) {
        handleNetworkDeleteEvent(event);
    } else {
        handleEvent(event);
    }
    s_logger.info("Done processing event " + event.getFullFormattedMessage());
}
项目:contrail-vcenter-plugin    文件:VCenterEventHandler.java   
private void handleVmUpdateEvent(Event event) throws Exception {
    VirtualMachineInfo newVmInfo = null;
    if (event.getHost() != null) {
        String hostName = event.getHost().getName();
        if (!vcenterDB.esxiToVRouterIpMap.containsKey(hostName)) {
            s_logger.info("Skipping event for unmanaged host " + hostName);
            return;
        }
        if (!vcenterDB.isVmEventOnMonitoredCluster(event, hostName)) {
            s_logger.info("Skipping vm event from host " + hostName);
            return;
        }
    }

    try {
        newVmInfo = new VirtualMachineInfo(event, vcenterDB, vncDB);
    } catch (RuntimeException e) {
        s_logger.error(e.getMessage());
        return;
    }

    VirtualMachineInfo oldVmInfo = MainDB.getVmById(newVmInfo.getUuid());

    if (oldVmInfo != null) {
        oldVmInfo.update(newVmInfo, vncDB);
    } else {
        newVmInfo.create(vncDB);
    }
}
项目:contrail-vcenter-plugin    文件:VCenterEventHandler.java   
private void handleNetworkUpdateEvent(Event event) throws Exception {
    VirtualNetworkInfo newVnInfo = new VirtualNetworkInfo(event, vcenterDB, vncDB);

    VirtualNetworkInfo oldVnInfo = MainDB.getVnByName(newVnInfo.getName());

    if (oldVnInfo != null) {
        oldVnInfo.update(newVnInfo, vncDB);
    } else {
        newVnInfo.create(vncDB);
        VCenterNotify.watchVn(newVnInfo);
    }
}
项目:contrail-vcenter-plugin    文件:VCenterDB.java   
public boolean isVmEventOnMonitoredCluster(Event event, String hostName)
    throws RemoteException {
    String dcName;
    Datacenter dc;

    // If contrailClusterName is null, all clusters under datacenter 
    // are monitored by vcenter plugin.
    if (contrailClusterName == null)
        return true;

    if (event.getHost() != null) {
        hostName = event.getHost().getName();
        HostSystem host = getVmwareHost(hostName, contrailDC, contrailDataCenterName);

        if (host != null) {
            ClusterComputeResource cluster = (ClusterComputeResource) host.getParent();
            if (cluster != null) {
                String clstrName = cluster.getName();
                if (clstrName != null && clstrName.equals(contrailClusterName)) {
                    return true;
                }
            }
        }
    }

    return false;
}
项目:contrail-vcenter-plugin    文件:VCenterNotify.java   
public static void printEvent(Event event) {
    s_logger.info("\n----------" + "\n Event ID: "
          + event.getKey() + "\n Event: "
          + event.getClass().getName()
          + ", happened on: "
          + event.getCreatedTime().getTime()
          + "\n FullFormattedMessage: "
          + event.getFullFormattedMessage()
          + "\n----------\n");
}
项目:vijava    文件:QueryEvents.java   
/**
 * Only print an event as Event type.
 * More info can be printed if casted to a sub type. 
 */
static void printEvent(Event evt)
{
  String typeName = evt.getClass().getName();
  int lastDot = typeName.lastIndexOf('.');
  if(lastDot != -1) 
  {
    typeName = typeName.substring(lastDot+1);
  }
  System.out.println("Type:" + typeName);
  System.out.println("Key:" + evt.getKey());
  System.out.println("ChainId:" + evt.getChainId());
  System.out.println("User:" + evt.getUserName());
  System.out.println("Time:" + evt.getCreatedTime().getTime());
  System.out.println("FormattedMessage:" 
      + evt.getFullFormattedMessage());
  if(evt.getDatacenter()!= null)
  {
    System.out.println("Datacenter:" 
        + evt.getDatacenter().getDatacenter());
  }
  if(evt.getComputeResource()!=null)
  {
    System.out.println("ComputeResource:" 
        + evt.getComputeResource().getComputeResource());
  }
  if(evt.getHost()!=null)
  {
    System.out.println("Host:" + evt.getHost().getHost());
  }
  if(evt.getVm()!=null)
  {
    System.out.println("VM:" + evt.getVm().getVm());
  }
}
项目:vijava    文件:QueryHistoricalEvents.java   
static void printEvents(Event[] events, int total)
{
  for(int i=0; i<events.length; i++)
  {
    System.out.println("Event[" + (total+i) + "]=" + events[i].getClass().getName());
    System.out.println("Event: " + events[i].getCreatedTime().getTime());
  }
}
项目:vijava    文件:EventHistoryCollectorMonitor.java   
public static void main(String[] args) throws Exception
{
  CommandLineParser clp = new CommandLineParser(
      new OptionSpec[]{}, args);
  String urlStr = clp.get_option("url");
  String username = clp.get_option("username");
  String password = clp.get_option("password");

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

  EventManager evtMgr = si.getEventManager();

  if(evtMgr!=null)
  {
    EventFilterSpec eventFilter = new EventFilterSpec();
    EventHistoryCollector ehc = 
      evtMgr.createCollectorForEvents(eventFilter);
    Event[] events = ehc.getLatestPage();

    for (int i = 0; i < events.length; i++)
    {
      Event anEvent = events[i];
      System.out.println("Event: " + 
          anEvent.getClass().getName());
    }
  }
  si.getServerConnection().logout();
}
项目:contrail-vcenter-plugin    文件:VCenterEventHandler.java   
private void handleEvent(Event event) {
    s_logger.error("Event "+ event.getClass().getName() + " received, but not handled.");
}
项目:contrail-vcenter-plugin    文件:VCenterNotify.java   
@Override
protected boolean removeEldestEntry(Map.Entry<Integer, Event> eldest) {
   return size() > MAX_CACHED_EVENTS;
}
项目:contrail-vcenter-plugin    文件:VirtualNetworkInfo.java   
@SuppressWarnings("rawtypes")
public VirtualNetworkInfo(Event event,  VCenterDB vcenterDB, VncDB vncDB) throws Exception {
    vmiInfoMap = new ConcurrentSkipListMap<String, VirtualMachineInterfaceInfo>();

    if (event.getDatacenter() != null) {
        dcName = event.getDatacenter().getName();
        dc = vcenterDB.getVmwareDatacenter(dcName);
    }

    if (event.getDvs() != null) {
        dvsName = event.getDvs().getName();
        dvs = vcenterDB.getVmwareDvs(dvsName, dc, dcName);
    } else {
        dvsName = vcenterDB.contrailDvSwitchName;
        dvs = vcenterDB.getVmwareDvs(dvsName, dc, dcName);
    }

    if (event.getNet() != null) {
        name = event.getNet().getName();
        net = vcenterDB.getVmwareNetwork(name, dvs, dvsName, dcName);
    }

    dpg = vcenterDB.getVmwareDpg(name, dvs, dvsName, dcName);
    ManagedObject mo[] = new ManagedObject[1];
    mo[0] = dpg;

    Hashtable[] pTables = PropertyCollectorUtil.retrieveProperties(mo,
                            "DistributedVirtualPortgroup",
            new String[] {"name",
            "config.key",
            "config.defaultPortConfig",
            "config.vendorSpecificConfig",
            "summary.ipPoolId",
            "summary.ipPoolName",
            });

    if (pTables == null || pTables[0] == null) {
        throw new RemoteException("Could not read properties for network " + name);
    }

    populateInfo(vcenterDB, pTables[0]);

    if (vcenterDB.mode == Mode.VCENTER_AS_COMPUTE) {
       apiVn = vncDB.findVirtualNetwork(uuid);
       readIpAm();
    }
}
项目:vijava    文件:ManagedEntity.java   
public Event[] getConfigIssue()
{
    return (Event[]) getCurrentProperty("configIssue");
}
项目: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    文件:QueryEvents.java   
public static void main(String[] args) throws Exception
{
  if(args.length != 3)
  {
    System.out.println("Usage: java QueryEvents " 
        + "<url> <username> <password>");
    return;
  }

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

  // get the latest event and print it out
  EventManager evtMgr = si.getEventManager();
  Event latestEvent = evtMgr.getLatestEvent();
  printEvent(latestEvent);

  // create a filter spec for querying events
  EventFilterSpec efs = new EventFilterSpec();
  // limit to only error and warning
  efs.setType(new String[] {"VmFailedToPowerOnEvent", 
      "HostConnectionLostEvent"});
  // limit to error and warning only
  efs.setCategory(new String[] {"error", "warning"});

  // limit to the children of root folder
  EventFilterSpecByEntity eFilter = 
    new EventFilterSpecByEntity();
  eFilter.setEntity(si.getRootFolder().getMOR());
  eFilter.setRecursion(
      EventFilterSpecRecursionOption.children);

  // limit to the events happened since a month ago
  EventFilterSpecByTime tFilter = new EventFilterSpecByTime();
  Calendar startTime = si.currentTime();
  startTime.roll(Calendar.MONTH, false);
  tFilter.setBeginTime(startTime);
  efs.setTime(tFilter);
  // limit to the user of "administrator"
  EventFilterSpecByUsername uFilter = 
      new EventFilterSpecByUsername();
  uFilter.setSystemUser(false);
  uFilter.setUserList(new String[] {"administrator"});

  Event[] events = evtMgr.queryEvents(efs);

  // print each of the events
  for(int i=0; events!=null && i<events.length; i++) 
  {
    System.out.println("\nEvent #" + i);
    printEvent(events[i]);
  }

  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   
Event getLatestEvent();
项目:jcloud-vsphere    文件:EventManagerApi.java   
void postEvent(Event eventToPost, TaskInfo taskInfo) throws InvalidEvent, RuntimeFault, RemoteException;
项目:jcloud-vsphere    文件:EventManagerApi.java   
List<Event> queryEvents(EventFilterSpec filter) throws RuntimeFault, RemoteException;