com.vmware.vim25.mo.util.PropertyCollectorUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vijava Show documentation
Show all versions of vijava Show documentation
Java API for accessing VMWare web services API
The newest version!
/*================================================================================
Copyright (c) 2008 VMware, Inc. All Rights Reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of VMware, Inc. nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
================================================================================*/
package com.vmware.vim25.mo.util;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import com.vmware.vim25.*;
import com.vmware.vim25.mo.*;
/**
* Utility class for the PropertyCollector API.
* @author Steve JIN ([email protected])
*/
public class PropertyCollectorUtil
{
final public static Object NULL = new Object();
/**
* Retrieves properties from multiple managed objects.
* @param mos the array of managed objects which could be of single type or mixed types. When they are mix-typed,
* the moType must be super type of all these managed objects.
* @param moType the type of the managed object. This managed object type must have all the properties defined as
* in propPaths.
* @param propPaths the array of property path which has dot as separator, for example, "name", "guest.toolsStatus".
* @return an array of Hashtable whose order is the same as the mos array. Each Hashtable has the properties for
* one managed object. Note: some of the properties you want to retrieve might not be set, and therefore you don't
* have an entry in the Hashtable at all. In other words, it's possible for you to get null for a property from the
* resulted Hashtable.
* @throws InvalidProperty
* @throws RuntimeFault
* @throws RemoteException
*/
public static Hashtable[] retrieveProperties(ManagedObject[] mos, String moType,
String[] propPaths) throws InvalidProperty,
RuntimeFault, RemoteException
{
if( mos==null )
throw new IllegalArgumentException("Managed object array cannot be null.");
if( mos.length ==0 || mos[0]==null )
return new Hashtable[] {};
PropertyCollector pc = mos[0].getServerConnection().getServiceInstance().getPropertyCollector();
ObjectSpec[] oss = new ObjectSpec[mos.length];
for(int i=0; i tSpecs = buildFullTraversalV2NoFolder();
// Recurse through the folders
TraversalSpec visitFolders = createTraversalSpec( "visitFolders",
"Folder", "childEntity",
new String[] {"visitFolders", "dcToHf", "dcToVmf", "crToH", "crToRp", "HToVm", "rpToVm"});
SelectionSpec[] sSpecs = new SelectionSpec[tSpecs.size() + 1];
sSpecs[0] = visitFolders;
for(int i=1; i buildFullTraversalV2NoFolder()
{
// Recurse through all ResourcePools
TraversalSpec rpToRp = createTraversalSpec( "rpToRp",
"ResourcePool", "resourcePool",
new String[]{ "rpToRp", "rpToVm"});
// Recurse through all ResourcePools
TraversalSpec rpToVm = createTraversalSpec( "rpToVm",
"ResourcePool", "vm",
new SelectionSpec[] {});
// Traversal through ResourcePool branch
TraversalSpec crToRp = createTraversalSpec( "crToRp",
"ComputeResource", "resourcePool",
new String[]{ "rpToRp", "rpToVm" });
// Traversal through host branch
TraversalSpec crToH = createTraversalSpec( "crToH",
"ComputeResource", "host",
new SelectionSpec[] {});
// Traversal through hostFolder branch
TraversalSpec dcToHf = createTraversalSpec( "dcToHf",
"Datacenter", "hostFolder",
new String[] {"visitFolders"});
// Traversal through vmFolder branch
TraversalSpec dcToVmf = createTraversalSpec( "dcToVmf",
"Datacenter", "vmFolder",
new String[] {"visitFolders"});
TraversalSpec HToVm = createTraversalSpec( "HToVm",
"HostSystem", "vm",
new String[] {"visitFolders"});
return Arrays.asList(dcToVmf,dcToHf,crToH,crToRp,rpToRp,HToVm, rpToVm);
}
/**
* This method creates a SelectionSpec[] to traverses the entire
* inventory tree starting at a Folder
* @return The SelectionSpec[]
*/
public static SelectionSpec [] buildFullTraversalV4()
{
List tSpecs = buildFullTraversalV2NoFolder();
TraversalSpec dcToDs = createTraversalSpec( "dcToDs",
"Datacenter", "datastoreFolder",
new String[] {"visitFolders"});
TraversalSpec vAppToRp = createTraversalSpec( "vAppToRp",
"VirtualApp", "resourcePool",
new String[] {"rpToRp", "vAppToRp"});
/**
* Copyright 2009 Altor Networks, contribution by Elsa Bignoli
* @author Elsa Bignoli ([email protected])
*/
// Traversal through netFolder branch
TraversalSpec dcToNetf = createTraversalSpec( "dcToNetf",
"Datacenter", "networkFolder",
new String[] {"visitFolders"});
// Recurse through the folders
TraversalSpec visitFolders = createTraversalSpec( "visitFolders",
"Folder", "childEntity",
new String[] {"visitFolders", "dcToHf", "dcToVmf", "dcToDs", "dcToNetf", "crToH", "crToRp", "HToVm", "rpToVm"});
SelectionSpec[] sSpecs = new SelectionSpec[tSpecs.size() + 4];
sSpecs[0] = visitFolders;
sSpecs[1] = dcToDs;
sSpecs[2] = dcToNetf;
sSpecs[3] = vAppToRp;
for(int i=4; i