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

项目:oscm    文件:ManagedObjectAccessor.java   
/**
 * Retrieve contents for a single object based on the property collector
 * registered with the service.
 *
 * @param collector
 *            Property collector registered with service
 * @param mobj
 *            Managed Object Reference to get contents for
 * @param properties
 *            names of properties of object to retrieve
 *
 * @return retrieved object contents
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 */
private ObjectContent[] getObjectProperties(ManagedObjectReference mobj,
        String[] properties)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    if (mobj == null) {
        return null;
    }

    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getPropSet().add(new PropertySpec());
    if ((properties == null || properties.length == 0)) {
        spec.getPropSet().get(0).setAll(Boolean.TRUE);
    } else {
        spec.getPropSet().get(0).setAll(Boolean.FALSE);
    }
    spec.getPropSet().get(0).setType(mobj.getType());
    spec.getPropSet().get(0).getPathSet().addAll(Arrays.asList(properties));
    spec.getObjectSet().add(new ObjectSpec());
    spec.getObjectSet().get(0).setObj(mobj);
    spec.getObjectSet().get(0).setSkip(Boolean.FALSE);
    List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
    listpfs.add(spec);
    List<ObjectContent> listobjcont = retrievePropertiesAllObjects(listpfs);
    return listobjcont.toArray(new ObjectContent[listobjcont.size()]);
}
项目:photon-model    文件:VSphereAdapterResourceEnumerationService.java   
/**
 * This method executes in a thread managed by {@link #enumerationThreadPool}.
 *
 * @param client
 * @throws Exception
 */
private void startEnumerationProcess(ComputeStateWithDescription parent,
        EnumerationClient client)
        throws Exception {
    if (parent.description.regionId == null) {
        // not implemented if no datacenter is provided
        return;
    }

    PropertyFilterSpec spec = client.createResourcesFilterSpec();

    try {
        for (UpdateSet updateSet : client.pollForUpdates(spec)) {
            processUpdates(updateSet);
            if (!this.startedEnumProcessesByHost.containsKey(parent.documentSelfLink)) {
                break;
            }
        }
    } catch (Exception e) {
        // destroy connection and let global error handler process it further
        client.close();
        throw e;
    }
}
项目:photon-model    文件:WaitForValues.java   
private PropertyFilterSpec propertyFilterSpec(ManagedObjectReference objmor,
        String[] filterProps, String[] propsToMatch) {
    PropertyFilterSpec spec = new PropertyFilterSpec();
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(objmor);
    oSpec.setSkip(Boolean.FALSE);
    spec.getObjectSet().add(oSpec);

    Set<String> uniqPropSet = new HashSet<>(Arrays.asList(filterProps));
    uniqPropSet.addAll(Arrays.asList(propsToMatch));

    PropertySpec pSpec = new PropertySpec();
    pSpec.getPathSet().addAll(new ArrayList<>(uniqPropSet));
    pSpec.setType(objmor.getType());
    spec.getPropSet().add(pSpec);
    return spec;
}
项目:development    文件:ManagedObjectAccessor.java   
/**
 * Retrieve contents for a single object based on the property collector
 * registered with the service.
 *
 * @param collector
 *            Property collector registered with service
 * @param mobj
 *            Managed Object Reference to get contents for
 * @param properties
 *            names of properties of object to retrieve
 *
 * @return retrieved object contents
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 */
private ObjectContent[] getObjectProperties(ManagedObjectReference mobj,
        String[] properties)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    if (mobj == null) {
        return null;
    }

    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getPropSet().add(new PropertySpec());
    if ((properties == null || properties.length == 0)) {
        spec.getPropSet().get(0).setAll(Boolean.TRUE);
    } else {
        spec.getPropSet().get(0).setAll(Boolean.FALSE);
    }
    spec.getPropSet().get(0).setType(mobj.getType());
    spec.getPropSet().get(0).getPathSet().addAll(Arrays.asList(properties));
    spec.getObjectSet().add(new ObjectSpec());
    spec.getObjectSet().get(0).setObj(mobj);
    spec.getObjectSet().get(0).setSkip(Boolean.FALSE);
    List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1);
    listpfs.add(spec);
    List<ObjectContent> listobjcont = retrievePropertiesAllObjects(listpfs);
    return listobjcont.toArray(new ObjectContent[listobjcont.size()]);
}
项目:contrail-vcenter-plugin    文件:VCenterNotify.java   
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);
    }

}
项目:vijava    文件:ManagedObjectWatcher.java   
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);
}
项目:cs-actions    文件:MoRefHandler.java   
/**
 * Method to retrieve properties of a {@link ManagedObjectReference}
 *
 * @param entityMor {@link ManagedObjectReference} of the entity
 * @param props     Array of properties to be looked up
 * @return Map of the property name and its corresponding value
 * @throws InvalidPropertyFaultMsg If a property does not exist
 * @throws RuntimeFaultFaultMsg
 */
public Map<String, Object> entityProps(ManagedObjectReference entityMor, String[] props)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    final HashMap<String, Object> retVal = new HashMap<>();
    // Create PropertyFilterSpec using the PropertySpec and ObjectPec
    PropertyFilterSpec[] propertyFilterSpecs = {new PropertyFilterSpecBuilder().propSet(
            // Create Property Spec
            new PropertySpecBuilder().all(false).type(entityMor.getType()).pathSet(props))
            .objectSet(
            // Now create Object Spec
            new ObjectSpecBuilder().obj(entityMor))};

    List<ObjectContent> objCont = vimPort.retrievePropertiesEx(serviceContent.getPropertyCollector(),
            Arrays.asList(propertyFilterSpecs), new RetrieveOptions()).getObjects();

    if (objCont != null) {
        for (ObjectContent oc : objCont) {
            List<DynamicProperty> dps = oc.getPropSet();
            for (DynamicProperty dp : dps) {
                retVal.put(dp.getName(), dp.getVal());
            }
        }
    }

    return retVal;
}
项目:cs-actions    文件:MoRefHandler.java   
private PropertyFilterSpec[] propertyFilterSpecs(ManagedObjectReference container,
                                                 String morefType,
                                                 String... morefProperties
) throws RuntimeFaultFaultMsg {
    ManagedObjectReference viewManager = serviceContent.getViewManager();
    ManagedObjectReference containerView = vimPort.createContainerView(viewManager, container,
            Arrays.asList(morefType), true);

    return new PropertyFilterSpec[]{
            new PropertyFilterSpecBuilder().propSet(new PropertySpecBuilder().all(false)
                    .type(morefType).pathSet(morefProperties)).objectSet(new ObjectSpecBuilder()
                    .obj(containerView).skip(true).selectSet(new TraversalSpecBuilder()
                            .name(ManagedObjectType.VIEW.getValue())
                            .path(ManagedObjectType.VIEW.getValue())
                            .skip(false)
                            .type(ManagedObjectType.CONTAINER_VIEW.getValue())))};
}
项目:cloudstack    文件:HostDatastoreSystemMO.java   
public List<ObjectContent> getDatastorePropertiesOnHostDatastoreSystem(String[] propertyPaths) throws Exception {

        PropertySpec pSpec = new PropertySpec();
        pSpec.setType("Datastore");
        pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));

        TraversalSpec hostDsSys2DatastoreTraversal = new TraversalSpec();
        hostDsSys2DatastoreTraversal.setType("HostDatastoreSystem");
        hostDsSys2DatastoreTraversal.setPath("datastore");
        hostDsSys2DatastoreTraversal.setName("hostDsSys2DatastoreTraversal");

        ObjectSpec oSpec = new ObjectSpec();
        oSpec.setObj(_mor);
        oSpec.setSkip(Boolean.TRUE);
        oSpec.getSelectSet().add(hostDsSys2DatastoreTraversal);

        PropertyFilterSpec pfSpec = new PropertyFilterSpec();
        pfSpec.getPropSet().add(pSpec);
        pfSpec.getObjectSet().add(oSpec);
        List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
        pfSpecArr.add(pfSpec);

        return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
    }
项目:cloudstack    文件:DatacenterMO.java   
public List<ObjectContent> getDatastorePropertiesOnDatacenter(String[] propertyPaths) throws Exception {

        PropertySpec pSpec = new PropertySpec();
        pSpec.setType("Datastore");
        pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));

        TraversalSpec dc2DatastoreTraversal = new TraversalSpec();
        dc2DatastoreTraversal.setType("Datacenter");
        dc2DatastoreTraversal.setPath("datastore");
        dc2DatastoreTraversal.setName("dc2DatastoreTraversal");

        ObjectSpec oSpec = new ObjectSpec();
        oSpec.setObj(_mor);
        oSpec.setSkip(Boolean.TRUE);
        oSpec.getSelectSet().add(dc2DatastoreTraversal);

        PropertyFilterSpec pfSpec = new PropertyFilterSpec();
        pfSpec.getPropSet().add(pSpec);
        pfSpec.getObjectSet().add(oSpec);
        List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
        pfSpecArr.add(pfSpec);

        return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);

    }
项目:cloudstack    文件:VmwareClient.java   
private List<ObjectContent> retrieveMoRefProperties(ManagedObjectReference mObj, List<String> props) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setAll(false);
    pSpec.setType(mObj.getType());
    pSpec.getPathSet().addAll(props);

    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(mObj);
    oSpec.setSkip(false);
    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getPropSet().add(pSpec);
    spec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> specArr = new ArrayList<PropertyFilterSpec>();
    specArr.add(spec);

    return vimPort.retrieveProperties(getPropCol(), specArr);
}
项目:oscm    文件:ManagedObjectAccessor.java   
/**
 * Uses the new RetrievePropertiesEx method to emulate the now deprecated
 * RetrieveProperties method
 *
 * @param filterSpecs
 * @return list of object content
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 * @throws Exception
 */
private List<ObjectContent> retrievePropertiesAllObjects(
        List<PropertyFilterSpec> filterSpecs)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    RetrieveOptions retrieveOptions = new RetrieveOptions();
    ManagedObjectReference collector = serviceContent
            .getPropertyCollector();

    List<ObjectContent> contents = new ArrayList<ObjectContent>();

    RetrieveResult results = vimPort.retrievePropertiesEx(collector,
            filterSpecs, retrieveOptions);
    if (results != null && results.getObjects() != null
            && !results.getObjects().isEmpty()) {
        contents.addAll(results.getObjects());
    }
    String token = null;
    if (results != null && results.getToken() != null) {
        token = results.getToken();
    }
    while (token != null && token.length() > 0) {
        results = vimPort.continueRetrievePropertiesEx(collector, token);
        token = null;
        if (results != null) {
            token = results.getToken();
            if (results.getObjects() != null
                    && !results.getObjects().isEmpty()) {
                contents.addAll(results.getObjects());
            }
        }
    }

    return contents;
}
项目:photon-model    文件:EnumerationClient.java   
private ManagedObjectReference createPropertyCollectorWithFilter(PropertyFilterSpec spec)
        throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    ManagedObjectReference pc = createPropertyCollector();
    boolean partialUpdates = false;
    getVimPort().createFilter(pc, spec, partialUpdates);
    return pc;
}
项目:photon-model    文件:EnumerationClient.java   
public PropertyFilterSpec createVmFilterSpec(ManagedObjectReference dc) {
    ObjectSpec ospec = new ObjectSpec();
    ospec.setObj(dc);
    ospec.setSkip(false);

    ospec.getSelectSet().addAll(buildFullTraversal());

    PropertySpec vmSpec = new PropertySpec();
    vmSpec.setType(VimNames.TYPE_VM);
    vmSpec.getPathSet().addAll(Arrays.asList(
            VimPath.vm_config_name,
            VimPath.vm_config_instanceUuid,
            VimPath.vm_config_changeVersion,
            VimPath.vm_config_hardware_device,
            VimPath.vm_config_hardware_memoryMB,
            VimPath.vm_summary_config_numCpu,
            VimPath.vm_config_template,
            VimPath.vm_runtime_host,
            VimPath.vm_guest_net,
            VimPath.vm_guest_hostName,
            VimPath.vm_runtime_powerState,
            VimPath.vm_runtime_maxCpuUsage,
            VimPath.vm_runtime_maxMemoryUsage,
            VimPath.vm_summary_guest_ipAddress,
            VimPath.vm_summary_guest_hostName,
            VimPath.vm_snapshot_rootSnapshotList
    ));

    PropertyFilterSpec filterSpec = new PropertyFilterSpec();
    filterSpec.getObjectSet().add(ospec);
    filterSpec.getPropSet().add(vmSpec);

    return filterSpec;
}
项目:photon-model    文件:EnumerationClient.java   
ObjectContentIterator(ManagedObjectReference pc, PropertyFilterSpec spec) {
    this.pc = pc;
    this.spec = spec;

    this.opts = new RetrieveOptions();
    this.opts.setMaxObjects(DEFAULT_FETCH_PAGE_SIZE);
}
项目:photon-model    文件:VSphereAdapterImageEnumerationService.java   
private void processAllTemplates(Set<String> oldImages, String endpointLink, String taskLink,
        EnumerationClient client, List<String> tenantLinks) throws RuntimeFaultFaultMsg {
    PropertyFilterSpec spec = client.createVmFilterSpec(client.getDatacenter());
    for (List<ObjectContent> page : client.retrieveObjects(spec)) {
        Phaser phaser = new Phaser(1);
        for (ObjectContent oc : page) {
            if (!VimUtils.isVirtualMachine(oc.getObj())) {
                continue;
            }

            VmOverlay vm = new VmOverlay(oc);
            if (!vm.isTemplate()) {
                continue;
            }

            ImageState state = makeImageFromTemplate(vm);
            state.documentSelfLink = buildStableImageLink(endpointLink, state.id);
            state.endpointLink = endpointLink;
            state.tenantLinks = tenantLinks;
            state.regionId = VimUtils.convertMoRefToString(client.getDatacenter());

            oldImages.remove(state.documentSelfLink);
            phaser.register();

            Operation.createPost(PhotonModelUriUtils.createInventoryUri(getHost(), ImageService.FACTORY_LINK))
                    .setBody(state)
                    .setCompletion((o, e) -> phaser.arrive())
                    .sendWith(this);
        }

        phaser.arriveAndAwaitAdvance();
    }
}
项目:photon-model    文件:EnumerationClientTest.java   
@Test
public void test() throws Exception {
    String url = System.getProperty(TestProperties.VC_URL);

    if (url == null) {
        return;
    }

    String username = System.getProperty(TestProperties.VC_USERNAME);
    String password = System.getProperty(TestProperties.VC_PASSWORD);

    String datacenter = System.getProperty(TestProperties.VC_DATECENTER_ID);
    ManagedObjectReference datacenterMoRef = VimUtils.convertStringToMoRef(datacenter);

    BasicConnection conn = new BasicConnection();

    conn.setURI(URI.create(url));
    conn.setUsername(username);
    conn.setPassword(password);
    conn.setIgnoreSslErrors(true);

    conn.setRequestTimeout(30, TimeUnit.SECONDS);
    conn.connect();

    ComputeStateWithDescription parent = new ComputeStateWithDescription();
    ComputeDescription desc = new ComputeDescription();
    parent.description = desc;

    EnumerationClient client = new EnumerationClient(conn, parent);

    PropertyFilterSpec spec = client.createResourcesFilterSpec();

    for (List<ObjectContent> page : client.retrieveObjects(spec)) {
        for (ObjectContent cont : page) {
            this.logger.info(VimUtils.convertMoRefToString(cont.getObj()));
        }
    }
}
项目:photon-model    文件:Finder.java   
private List<ObjectContent> ancestrySet(ManagedObjectReference ref)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ObjectSpec ospec = new ObjectSpec();
    ospec.setObj(ref);
    ospec.setSkip(false);

    TraversalSpec tspec = new TraversalSpec();
    tspec.setSkip(false);
    tspec.setPath("parent");
    tspec.setType("ManagedEntity");
    tspec.setName("traverseParent");

    SelectionSpec selSpec = new SelectionSpec();
    selSpec.setName("traverseParent");

    tspec.getSelectSet().add(selSpec);

    ospec.getSelectSet().add(tspec);

    PropertySpec pspec = new PropertySpec();
    pspec.setType("ManagedEntity");
    pspec.getPathSet().add("name");
    pspec.getPathSet().add("parent");

    PropertyFilterSpec filter = new PropertyFilterSpec();
    filter.getObjectSet().add(ospec);
    filter.getPropSet().add(pspec);

    return this.connection.getVimPort()
            .retrieveProperties(this.connection.getServiceContent().getPropertyCollector(),
                    Collections.singletonList(filter));

}
项目:photon-model    文件:Lister.java   
private List<Element> listResourcePool()
        throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ObjectSpec ospec = new ObjectSpec();
    ospec.setObj(this.start);
    ospec.setSkip(true);

    for (String f : new String[] { "resourcePool" }) {
        TraversalSpec tspec = new TraversalSpec();
        tspec.setPath(f);
        tspec.setSkip(false);
        tspec.setType("ResourcePool");

        ospec.getSelectSet().add(tspec);
    }

    List<PropertySpec> pspecs = new ArrayList<>();
    for (String t : new String[] { "ResourcePool" }) {
        PropertySpec pspec = new PropertySpec();
        pspec.setType(t);
        pspec.getPathSet().add("name");

        pspecs.add(pspec);
    }

    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getObjectSet().add(ospec);
    spec.getPropSet().addAll(pspecs);

    return callPropertyCollectorAndConvert(spec);
}
项目:photon-model    文件:Lister.java   
private List<Element> listComputeResource()
        throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ObjectSpec ospec = new ObjectSpec();
    ospec.setSkip(true);
    ospec.setObj(this.start);

    for (String f : new String[] { "host", "resourcePool" }) {
        TraversalSpec tspec = new TraversalSpec();
        tspec.setPath(f);
        tspec.setType("ComputeResource");
        tspec.setSkip(false);

        ospec.getSelectSet().add(tspec);
    }

    PropertyFilterSpec filter = new PropertyFilterSpec();
    filter.getObjectSet().add(ospec);

    for (String t : new String[] { "HostSystem", "ResourcePool" }) {
        PropertySpec pspec = new PropertySpec();
        pspec.setType(t);
        pspec.getPathSet().add("name");

        filter.getPropSet().add(pspec);
    }

    return callPropertyCollectorAndConvert(filter);
}
项目:photon-model    文件:Lister.java   
private List<Element> listDatacenter()
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, FinderException {
    ObjectSpec ospec = new ObjectSpec();
    ospec.setObj(this.start);
    ospec.setSkip(true);

    // Include every datastore folder in the select set
    String[] fields = {
            "vmFolder",
            "hostFolder",
            "datastoreFolder",
            "networkFolder" };

    for (String f : fields) {
        TraversalSpec tspec = new TraversalSpec();
        tspec.setPath(f);
        tspec.setSkip(false);
        tspec.setType("Datacenter");

        ospec.getSelectSet().add(tspec);
    }

    PropertySpec pspec = new PropertySpec();
    pspec.setType("Folder");
    pspec.getPathSet().add("name");

    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getObjectSet().add(ospec);
    spec.getPropSet().add(pspec);

    return callPropertyCollectorAndConvert(spec);
}
项目:photon-model    文件:GetMoRef.java   
/**
 * Returns the raw RetrieveResult object for the provided container filtered on properties list
 *
 * @param container       - container to look in
 * @param morefType       - type to filter for
 * @param morefProperties - properties to include
 * @return com.vmware.vim25.RetrieveResult for this query
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 */
public RetrieveResult containerViewByType(
        final ManagedObjectReference container,
        final String morefType,
        final RetrieveOptions retrieveOptions,
        final String... morefProperties
) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    init();

    PropertyFilterSpec[] propertyFilterSpecs = propertyFilterSpecs(container, morefType,
            morefProperties);

    return containerViewByType(container, morefType, morefProperties, retrieveOptions,
            propertyFilterSpecs);
}
项目:photon-model    文件:GetMoRef.java   
public PropertyFilterSpec[] propertyFilterSpecs(
        ManagedObjectReference container,
        String morefType,
        String... morefProperties
) throws RuntimeFaultFaultMsg {
    init();

    ManagedObjectReference viewManager = this.serviceContent.getViewManager();
    ManagedObjectReference containerView =
            this.vimPort.createContainerView(viewManager, container,
                    Arrays.asList(morefType), true);

    return new PropertyFilterSpec[] {
            new PropertyFilterSpecBuilder()
                    .propSet(
                            new PropertySpecBuilder()
                                    .all(Boolean.FALSE)
                                    .type(morefType)
                                    .pathSet(morefProperties)
                    )
                    .objectSet(
                    new ObjectSpecBuilder()
                            .obj(containerView)
                            .skip(Boolean.TRUE)
                            .selectSet(
                                    new TraversalSpecBuilder()
                                            .name("view")
                                            .path("view")
                                            .skip(false)
                                            .type("ContainerView")
                            )
            )
    };
}
项目:photon-model    文件:GetMoRef.java   
public RetrieveResult containerViewByType(
        final ManagedObjectReference container,
        final String morefType,
        final String[] morefProperties,
        final RetrieveOptions retrieveOptions,
        final PropertyFilterSpec... propertyFilterSpecs
) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    init();
    return this.vimPort.retrievePropertiesEx(
            this.serviceContent.getPropertyCollector(),
            Arrays.asList(propertyFilterSpecs),
            retrieveOptions
    );
}
项目:photon-model    文件:GetMoRef.java   
/**
 * Returns all the MOREFs of the specified type that are present under the
 * folder
 *
 * @param folder    {@link ManagedObjectReference} of the folder to begin the search
 *                  from
 * @param morefType Type of the managed entity that needs to be searched
 * @return Map of name and MOREF of the managed objects present. If none
 *         exist then empty Map is returned
 * @throws InvalidPropertyFaultMsg
 *
 * @throws RuntimeFaultFaultMsg
 *
 */
public Map<String, ManagedObjectReference> inFolderByType(
        final ManagedObjectReference folder, final String morefType,
        final RetrieveOptions retrieveOptions
) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    final PropertyFilterSpec[] propertyFilterSpecs = propertyFilterSpecs(folder, morefType,
            "name");

    // reuse this property collector again later to scroll through results
    final ManagedObjectReference propertyCollector = this.serviceContent.getPropertyCollector();

    RetrieveResult results = this.vimPort.retrievePropertiesEx(
            propertyCollector,
            Arrays.asList(propertyFilterSpecs),
            retrieveOptions);

    final Map<String, ManagedObjectReference> tgtMoref = new HashMap<>();
    while (results != null && !results.getObjects().isEmpty()) {
        resultsToTgtMorefMap(results, tgtMoref);
        final String token = results.getToken();
        // if we have a token, we can scroll through additional results, else there's nothing to do.
        results =
                (token != null) ?
                        this.vimPort.continueRetrievePropertiesEx(propertyCollector, token) : null;
    }

    return tgtMoref;
}
项目:photon-model    文件:GetMoRef.java   
/**
 * Method to retrieve properties of a {@link ManagedObjectReference}
 *
 * @param entityMor {@link ManagedObjectReference} of the entity
 * @param props     Array of properties to be looked up
 * @return Map of the property name and its corresponding value
 * @throws InvalidPropertyFaultMsg If a property does not exist
 * @throws RuntimeFaultFaultMsg
 */
public Map<String, Object> entityProps(
        ManagedObjectReference entityMor, String... props)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    init();

    final HashMap<String, Object> retVal = new HashMap<>();

    // Create PropertyFilterSpec using the PropertySpec and ObjectPec
    PropertyFilterSpec[] propertyFilterSpecs = {
            new PropertyFilterSpecBuilder()
                    .propSet(
                            // Create Property Spec
                            new PropertySpecBuilder()
                                    .all(Boolean.FALSE)
                                    .type(entityMor.getType())
                                    .pathSet(props)
                    )
                    .objectSet(
                    // Now create Object Spec
                    new ObjectSpecBuilder()
                            .obj(entityMor)
            )
    };

    List<ObjectContent> oCont =
            this.vimPort.retrievePropertiesEx(this.serviceContent.getPropertyCollector(),
                    Arrays.asList(propertyFilterSpecs), new RetrieveOptions()).getObjects();

    if (oCont != null) {
        for (ObjectContent oc : oCont) {
            List<DynamicProperty> dps = oc.getPropSet();
            for (DynamicProperty dp : dps) {
                retVal.put(dp.getName(), dp.getVal());
            }
        }
    }
    return retVal;
}
项目:vsphere-automation-sdk-java    文件:WaitForValues.java   
private PropertyFilterSpec propertyFilterSpec(ManagedObjectReference objmor,
        String[] filterProps) {
    PropertyFilterSpec spec = new PropertyFilterSpec();
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(objmor);
    oSpec.setSkip(Boolean.FALSE);
    spec.getObjectSet().add(oSpec);

    PropertySpec pSpec = new PropertySpec();
    pSpec.getPathSet().addAll(Arrays.asList(filterProps));
    pSpec.setType(objmor.getType());
    spec.getPropSet().add(pSpec);
    return spec;
}
项目:vsphere-automation-sdk-java    文件:VimUtil.java   
/**
 * Uses the new RetrievePropertiesEx method to emulate the now deprecated
 * RetrieveProperties method.
 *
 * @param listpfs
 * @return list of object content
 * @throws Exception
 */
public static List<ObjectContent> retrievePropertiesAllObjects(
        VimPortType vimPort, ManagedObjectReference propCollectorRef,
        List<PropertyFilterSpec> listpfs)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    RetrieveOptions propObjectRetrieveOpts = new RetrieveOptions();
    List<ObjectContent> listobjcontent = new ArrayList<ObjectContent>();

    RetrieveResult rslts = vimPort.retrievePropertiesEx(propCollectorRef,
            listpfs, propObjectRetrieveOpts);
    if (rslts != null && rslts.getObjects() != null
            && !rslts.getObjects().isEmpty()) {
        listobjcontent.addAll(rslts.getObjects());
    }
    String token = null;
    if (rslts != null && rslts.getToken() != null) {
        token = rslts.getToken();
    }
    while (token != null && !token.isEmpty()) {
        rslts = vimPort.continueRetrievePropertiesEx(propCollectorRef,
                token);
        token = null;
        if (rslts != null) {
            token = rslts.getToken();
            if (rslts.getObjects() != null
                    && !rslts.getObjects().isEmpty()) {
                listobjcontent.addAll(rslts.getObjects());
            }
        }
    }

    return listobjcontent;
}
项目:development    文件:ManagedObjectAccessor.java   
/**
 * Uses the new RetrievePropertiesEx method to emulate the now deprecated
 * RetrieveProperties method
 *
 * @param filterSpecs
 * @return list of object content
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 * @throws Exception
 */
private List<ObjectContent> retrievePropertiesAllObjects(
        List<PropertyFilterSpec> filterSpecs)
        throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {

    RetrieveOptions retrieveOptions = new RetrieveOptions();
    ManagedObjectReference collector = serviceContent
            .getPropertyCollector();

    List<ObjectContent> contents = new ArrayList<ObjectContent>();

    RetrieveResult results = vimPort.retrievePropertiesEx(collector,
            filterSpecs, retrieveOptions);
    if (results != null && results.getObjects() != null
            && !results.getObjects().isEmpty()) {
        contents.addAll(results.getObjects());
    }
    String token = null;
    if (results != null && results.getToken() != null) {
        token = results.getToken();
    }
    while (token != null && token.length() > 0) {
        results = vimPort.continueRetrievePropertiesEx(collector, token);
        token = null;
        if (results != null) {
            token = results.getToken();
            if (results.getObjects() != null
                    && !results.getObjects().isEmpty()) {
                contents.addAll(results.getObjects());
            }
        }
    }

    return contents;
}
项目: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    文件:ManagedObjectWatcher.java   
public void watch(PropertyFilterSpec pfs) 
{
    try
    {
        PropertyFilter pf = pc.createFilter(pfs, true); //report only nesting properties, not enclosing ones.
        filters.add(pf);
    } catch(RemoteException re)
    {
        throw new RuntimeException(re);
    }
}
项目:vijava    文件:VMEventsMonitor.java   
private PropertyFilterSpec createEventFilterSpec()
{
    // 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(_eventHistoryCollector.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(_eventHistoryCollector.getMOR());
    objSpec.setSkip(new Boolean(false));

    // Get Event objects in "latestPage" from "EventHistoryCollector"
    // and no "traversl" 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;
}
项目:vijava    文件:ManagedObject.java   
protected ObjectContent retrieveObjectProperties(String[] properties) 
{
    ObjectSpec oSpec = PropertyCollectorUtil.creatObjectSpec(
            getMOR(), Boolean.FALSE, null);

    PropertySpec pSpec = PropertyCollectorUtil.createPropertySpec(
            getMOR().getType(),
            properties == null || properties.length == 0, //if true, all props of this obj are to be read regardless of propName
            properties);

    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    pfSpec.setPropSet(new PropertySpec[] { pSpec });

    PropertyCollector pc = getServerConnection().getServiceInstance().getPropertyCollector();

    ObjectContent[] objs;
    try
    {
        objs = pc.retrieveProperties(new PropertyFilterSpec[] { pfSpec });
    } catch(Exception e)
    {
        throw new RuntimeException(e);
    }

    if (objs == null || objs[0]==null)
        return null;
    else
        return objs[0];
}
项目:GraphiteReceiver    文件:Utils.java   
private static RetrieveResult getRetrieveResult(String clusterName, VimConnection connection, ManagedObjectReference rootFolder) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    List<String> clusterList = new ArrayList<String>();
    clusterList.add("ComputeResource");
    clusterList.add("HostSystem");
    clusterList.add("VirtualMachine");

    ManagedObjectReference rootFolderAux = (clusterName == null)? connection.getRootFolder():rootFolder;
    ManagedObjectReference viewManager = connection.getVimPort().createContainerView(connection.getViewManager(), rootFolderAux, clusterList, true);

    if(viewManager == null) {
        logger.debug("cViewRef is null: " + clusterName);
        return null;
    }
    logger.debug("cViewRef is not null: " + clusterName);

    ObjectSpec objectSpec = new ObjectSpec();
    objectSpec.setObj(viewManager);
    objectSpec.setSkip(true);
    objectSpec.getSelectSet().add(getTraversalSpec(clusterName));

    PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec();
    propertyFilterSpec.getObjectSet().add(objectSpec);

    if(clusterName == null){
        propertyFilterSpec.getPropSet().add(getPropertySpec("ComputeResource"));
    }else{
        propertyFilterSpec.getPropSet().add(getPropertySpec("HostSystem"));
        propertyFilterSpec.getPropSet().add(getPropertySpec("VirtualMachine"));
    }
    List<PropertyFilterSpec> propertyFilterSpecs = new LinkedList<PropertyFilterSpec>();
    propertyFilterSpecs.add(propertyFilterSpec);
    return connection.getVimPort().retrievePropertiesEx(connection.getPropertyCollector(), propertyFilterSpecs, new RetrieveOptions());
}
项目:cs-actions    文件:GetObjectProperties.java   
/**
 * Retrieve contents for a single object based on the property collector
 * registered with the service.
 *
 * @param mor        Managed Object Reference to get contents for
 * @param properties names of properties of object to retrieve
 * @return retrieved object contents
 */
@NotNull
public static ObjectContent[] getObjectProperties(ConnectionResources connectionResources,
                                                  ManagedObjectReference mor,
                                                  String[] properties)
        throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    if (mor == null) {
        return new ObjectContent[0];
    }

    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getPropSet().add(new PropertySpec());

    if ((properties == null || properties.length == 0)) {
        spec.getPropSet().get(0).setAll(true);
    } else {
        spec.getPropSet().get(0).setAll(false);
    }

    spec.getPropSet().get(0).setType(mor.getType());
    spec.getPropSet().get(0).getPathSet().addAll(Arrays.asList(properties));
    spec.getObjectSet().add(new ObjectSpec());
    spec.getObjectSet().get(0).setObj(mor);
    spec.getObjectSet().get(0).setSkip(false);

    List<PropertyFilterSpec> propertyFilterSpecs = new ArrayList<>(1);
    propertyFilterSpecs.add(spec);
    List<ObjectContent> objectContentList = retrievePropertiesAllObjects(connectionResources, propertyFilterSpecs);

    return objectContentList.toArray(new ObjectContent[objectContentList.size()]);
}
项目:cs-actions    文件:GetObjectProperties.java   
/**
 * Uses the new RetrievePropertiesEx method to emulate the now deprecated
 * RetrieveProperties method
 *
 * @param propertyFilterSpecList
 * @return list of object content
 * @throws Exception
 */
private static List<ObjectContent> retrievePropertiesAllObjects(ConnectionResources connectionResources,
                                                               List<PropertyFilterSpec> propertyFilterSpecList)
        throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {

    VimPortType vimPort = connectionResources.getVimPortType();
    ManagedObjectReference serviceInstance = connectionResources.getServiceInstance();
    ServiceContent serviceContent = vimPort.retrieveServiceContent(serviceInstance);
    ManagedObjectReference propertyCollectorReference = serviceContent.getPropertyCollector();
    RetrieveOptions propertyObjectRetrieveOptions = new RetrieveOptions();
    List<ObjectContent> objectContentList = new ArrayList<>();

    RetrieveResult results = vimPort.retrievePropertiesEx(propertyCollectorReference,
            propertyFilterSpecList,
            propertyObjectRetrieveOptions);

    if (results != null && results.getObjects() != null && !results.getObjects().isEmpty()) {
        objectContentList.addAll(results.getObjects());
    }

    String token = null;
    if (results != null && results.getToken() != null) {
        token = results.getToken();
    }

    while (token != null && !token.isEmpty()) {
        results = vimPort.continueRetrievePropertiesEx(propertyCollectorReference, token);
        token = null;
        if (results != null) {
            token = results.getToken();
            if (results.getObjects() != null && !results.getObjects().isEmpty()) {
                objectContentList.addAll(results.getObjects());
            }
        }
    }

    return objectContentList;
}
项目:cs-actions    文件:WaitForValues.java   
private PropertyFilterSpec propertyFilterSpec(ManagedObjectReference objmor, String[] filterProps) {
    ObjectSpec objSpec = new ObjectSpec();
    objSpec.setObj(objmor);
    objSpec.setSkip(false);

    PropertySpec propSpec = new PropertySpec();
    propSpec.getPathSet().addAll(Arrays.asList(filterProps));
    propSpec.setType(objmor.getType());

    PropertyFilterSpec spec = new PropertyFilterSpec();
    spec.getObjectSet().add(objSpec);
    spec.getPropSet().add(propSpec);

    return spec;
}
项目:cs-actions    文件:MoRefHandler.java   
public ManagedObjectReference findManagedObjectReferenceByTypeAndId(final ManagedObjectReference folder,
                                                                    final String morefType,
                                                                    final RetrieveOptions retrieveOptions, final String id) throws Exception {
    final PropertyFilterSpec[] propertyFilterSpecs = propertyFilterSpecs(folder, morefType);
    final ManagedObjectReference searchedReference = findComponentReference(propertyFilterSpecs, retrieveOptions, id);
    if (searchedReference != null) {
        return searchedReference;
    }
    throw new RuntimeException(String.format(REFERENCE_TYPE_WITH_ID_NOT_FOUND, morefType, id));
}
项目:cs-actions    文件:MoRefHandler.java   
private ManagedObjectReference findComponentReference(final PropertyFilterSpec[] propertyFilterSpecs,
                                                      final RetrieveOptions retrieveOptions, final String id) throws Exception {
    String token = null;
    ManagedObjectReference searched;
    do {
        final RetrieveResult retrieveResult = retrievePropertiesEx(Arrays.asList(propertyFilterSpecs), retrieveOptions, token);
        token = retrieveResult.getToken();
        searched = getFromRetrieveResult(retrieveResult, id);
    } while (searched == null && StringUtilities.isNotEmpty(token));
    return searched;
}