private static void watchManagedObject(ManagedObject mos, String[] propNames) { PropertyFilterSpec pfs = new PropertyFilterSpec(); ObjectSpec[] oss = new ObjectSpec[1]; oss[0] = new ObjectSpec(); oss[0].setObj(mos.getMOR()); pfs.setObjectSet(oss); PropertySpec ps = new PropertySpec(); ps.setType(mos.getMOR().getType()); ps.setPathSet(propNames); pfs.setPropSet(new PropertySpec[] { ps }); try { PropertyFilter pf = propColl.createFilter(pfs, true); //report only nesting properties, not enclosing ones. if (pf != null) { watchedFilters.put(mos, pf); } } catch(RemoteException re) { throw new RuntimeException(re); } }
@SuppressWarnings("unused") private void unwatchManagedObjectEvents(ManagedObject mos) { if (mos == null) { s_logger.error("Null arguments in unwatchManagedObjectEvents"); return; } if (watchedFilters.containsKey(mos)) { try { PropertyFilter pf = watchedFilters.remove(mos); if (pf != null) { pf.destroyPropertyFilter(); } } catch (RemoteException e) { s_logger.error("Cannot unwatchManagedObjectEvents for " + mos + ", exception " + e); s_logger.error(Throwables.getStackTraceAsString(e)); } } }
public void watch(ManagedObject[] mos, String[] propNames) { PropertyFilterSpec pfs = new PropertyFilterSpec(); ObjectSpec[] oss = new ObjectSpec[mos.length]; for(int i=0; i<oss.length; i++) { oss[i] = new ObjectSpec(); oss[i].setObj(mos[i].getMOR()); } pfs.setObjectSet(oss); PropertySpec ps = new PropertySpec(); ps.setType(mos[0].getMOR().getType()); ps.setPathSet(propNames); pfs.setPropSet(new PropertySpec[] { ps }); watch(pfs); }
private static void unwatchManagedObject(ManagedObject mos) { if (watchedFilters.containsKey(mos)) { try { PropertyFilter pf = watchedFilters.remove(mos); pf.destroyPropertyFilter(); } catch (RemoteException e) { s_logger.error("Cannot unwatchManagedObject " + mos + " due to exception " + e); s_logger.error(Throwables.getStackTraceAsString(e)); } } }
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; }
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); } }
/** * Get a copy of the cached property. You can change the returned * object as you like * @param mo Managed object * @param propName property name * @return the data object identified by the propName. * NullObject.NULL if the data object is really null */ public Object getCopy(ManagedObject mo, String propName) { Object obj = get(mo.getMOR(), propName); try { obj = DeepCopier.deepCopy(obj); } catch(Exception e) { throw new RuntimeException(e); } return obj; }
@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(); } }
public void update(Observable obj, Object arg) { if (arg instanceof PropertyFilterUpdate[]) { PropertyFilterUpdate[] pfus = (PropertyFilterUpdate[]) arg; for(int i=0; pfus!=null && i< pfus.length; i++) { ObjectUpdate[] ous = pfus[i].getObjectSet(); for(int j=0; ous!=null && j < ous.length; j++) { ManagedObjectReference mor = ous[j].getObj(); if(! items.containsKey(mor)) { items.put(mor, new ConcurrentHashMap<String, Object>()); } Map<String, Object> moMap = items.get(mor); PropertyChange[] pcs = ous[j].getChangeSet(); if(pcs==null) { continue; } for(int k=0; k < pcs.length; k++) { Object value = pcs[k].getVal(); value = value == null ? NULL : value; //null is not allowed as value in CHM String propName = pcs[k].getName(); if(moMap.containsKey(propName)) { moMap.put(propName, value); } else { String parentPropName = getExistingParentPropName(moMap, propName); if(parentPropName != null) { ManagedObject mo = MorUtil.createExactManagedObject(si.getServerConnection(), mor); moMap.put(parentPropName, mo.getPropertyByPath(parentPropName)); } else { //almost impossible to be here. moMap.put(propName, value); } } } } } } isReady = true; }
static String createMobUrl(String serviceUrl, ManagedObject mo) { int sdkLoc = serviceUrl.indexOf("/sdk"); String baseUrl = serviceUrl.substring(0, sdkLoc); return baseUrl + "/mob/?moid=" + mo.getMOR().get_value(); }
/** * @since SDK4.0 */ ScheduledTask createObjectScheduledTask(ManagedObject obj, ScheduledTaskSpec spec) throws InvalidName, DuplicateName, RuntimeFault, RemoteException;
/** * @since SDK4.0 */ List<ScheduledTask> retrieveObjectScheduledTask(ManagedObject obj) throws RuntimeFault, RemoteException;
/** * SDK2.5 signature for back compatibility */ TaskInfo createTask(ManagedObject obj, String taskTypeId, String initiatedBy, boolean cancelable) throws RuntimeFault, RemoteException;
/** * SDK4.0 signature */ TaskInfo createTask(ManagedObject obj, String taskTypeId, String initiatedBy, boolean cancelable, String parentTaskKey) throws RuntimeFault, RemoteException;
/** * Add the managed objects and their properties to be watched. * @param mos array of managed objects. * @param props array of properties to watch */ public void watch(ManagedObject[] mos, String[] props) { mom.watch(mos, props); }
/** * Get the value of cached property whose name is propName. * You should NEVER change the returned data object. * @param mo Managed object on which the cached property is requested * @param propName Property name, can include "." * @return the data object identified by the propName. * NullObject.NULL if the data object is really null */ public Object get(ManagedObject mo, String propName) { return get(mo.getMOR(), propName); }
ListView createListView(List<ManagedObject> mos) throws RuntimeFault, RemoteException;