Search in sources :

Example 1 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project opennms by OpenNMS.

the class VmwareConfigBuilder method lookupMetrics.

private void lookupMetrics(String collectionName, String managedObjectId) throws Exception {
    ManagedObjectReference managedObjectReference = new ManagedObjectReference();
    managedObjectReference.setType("ManagedEntity");
    managedObjectReference.setVal(managedObjectId);
    ManagedEntity managedEntity = MorUtil.createExactManagedEntity(serviceInstance.getServerConnection(), managedObjectReference);
    int refreshRate = performanceManager.queryPerfProviderSummary(managedEntity).getRefreshRate();
    PerfQuerySpec perfQuerySpec = new PerfQuerySpec();
    perfQuerySpec.setEntity(managedEntity.getMOR());
    perfQuerySpec.setMaxSample(Integer.valueOf(1));
    perfQuerySpec.setIntervalId(refreshRate);
    PerfEntityMetricBase[] perfEntityMetricBases = performanceManager.queryPerf(new PerfQuerySpec[] { perfQuerySpec });
    HashMap<String, TreeSet<VMwareConfigMetric>> groupMap = new HashMap<String, TreeSet<VMwareConfigMetric>>();
    HashMap<String, Boolean> multiInstance = new HashMap<String, Boolean>();
    if (perfEntityMetricBases != null) {
        for (int i = 0; i < perfEntityMetricBases.length; i++) {
            PerfMetricSeries[] perfMetricSeries = ((PerfEntityMetric) perfEntityMetricBases[i]).getValue();
            for (int j = 0; perfMetricSeries != null && j < perfMetricSeries.length; j++) {
                if (perfMetricSeries[j] instanceof PerfMetricIntSeries) {
                    long[] longs = ((PerfMetricIntSeries) perfMetricSeries[j]).getValue();
                    if (longs.length == 1) {
                        PerfCounterInfo perfCounterInfo = perfCounterInfoMap.get(perfMetricSeries[j].getId().getCounterId());
                        String instanceName = perfMetricSeries[j].getId().getInstance();
                        String humanReadableName = getHumanReadableName(perfCounterInfo);
                        String aliasName = getAliasName(perfCounterInfo);
                        String groupName = perfCounterInfo.getGroupInfo().getKey();
                        String normalizedGroupName = normalizeGroupName(groupName);
                        Boolean b = multiInstance.get(getHumanReadableName(perfCounterInfo));
                        if (b == null) {
                            b = Boolean.valueOf(instanceName != null && !"".equals(instanceName));
                        } else {
                            b = Boolean.valueOf(b.booleanValue() || (instanceName != null && !"".equals(instanceName)));
                        }
                        if (!b) {
                            groupName = "Node";
                            normalizedGroupName = "Node";
                        }
                        if (!groupMap.containsKey(normalizedGroupName)) {
                            groupMap.put(normalizedGroupName, new TreeSet<VMwareConfigMetric>());
                        }
                        TreeSet<VMwareConfigMetric> counterSet = groupMap.get(normalizedGroupName);
                        multiInstance.put(getHumanReadableName(perfCounterInfo), b);
                        counterSet.add(new VMwareConfigMetric(perfCounterInfo, humanReadableName, aliasName, b, normalizedGroupName));
                    }
                }
            }
        }
    }
    collections.put(collectionName, groupMap);
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) PerfCounterInfo(com.vmware.vim25.PerfCounterInfo) PerfMetricSeries(com.vmware.vim25.PerfMetricSeries) HashMap(java.util.HashMap) PerfEntityMetricBase(com.vmware.vim25.PerfEntityMetricBase) PerfMetricIntSeries(com.vmware.vim25.PerfMetricIntSeries) TreeSet(java.util.TreeSet) PerfQuerySpec(com.vmware.vim25.PerfQuerySpec) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) PerfEntityMetric(com.vmware.vim25.PerfEntityMetric)

Example 2 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project CloudStack-archive by CloudStack-extras.

the class DatacenterMO method getOwnerDatacenter.

public static Pair<DatacenterMO, String> getOwnerDatacenter(VmwareContext context, ManagedObjectReference morEntity) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datacenter");
    pSpec.setPathSet(new String[] { "name" });
    TraversalSpec entityParentTraversal = new TraversalSpec();
    entityParentTraversal.setType("ManagedEntity");
    entityParentTraversal.setPath("parent");
    entityParentTraversal.setName("entityParentTraversal");
    entityParentTraversal.setSelectSet(new SelectionSpec[] { new SelectionSpec(null, null, "entityParentTraversal") });
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(morEntity);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { entityParentTraversal });
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setPropSet(new PropertySpec[] { pSpec });
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    ObjectContent[] ocs = context.getService().retrieveProperties(context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
    assert (ocs != null);
    assert (ocs[0].getObj() != null);
    assert (ocs[0].getPropSet(0) != null);
    assert (ocs[0].getPropSet(0).getVal() != null);
    String dcName = ocs[0].getPropSet(0).getVal().toString();
    return new Pair<DatacenterMO, String>(new DatacenterMO(context, ocs[0].getObj()), dcName);
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) SelectionSpec(com.vmware.vim25.SelectionSpec) Pair(com.cloud.utils.Pair)

Example 3 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project CloudStack-archive by CloudStack-extras.

the class VmwareContext method getHostMorByPath.

public ManagedObjectReference getHostMorByPath(String inventoryPath) throws Exception {
    assert (inventoryPath != null);
    String[] tokens;
    if (inventoryPath.startsWith("/"))
        tokens = inventoryPath.substring(1).split("/");
    else
        tokens = inventoryPath.split("/");
    ManagedObjectReference mor = getRootFolder();
    for (int i = 0; i < tokens.length; i++) {
        String token = tokens[i];
        ObjectContent[] ocs;
        if (mor.getType().equalsIgnoreCase("Datacenter")) {
            PropertySpec pSpec = new PropertySpec();
            pSpec.setType("ManagedEntity");
            pSpec.setPathSet(new String[] { "name" });
            TraversalSpec dcHostFolderTraversal = new TraversalSpec();
            dcHostFolderTraversal.setType("Datacenter");
            dcHostFolderTraversal.setPath("hostFolder");
            dcHostFolderTraversal.setName("dcHostFolderTraversal");
            ObjectSpec oSpec = new ObjectSpec();
            oSpec.setObj(mor);
            oSpec.setSkip(Boolean.TRUE);
            oSpec.setSelectSet(new SelectionSpec[] { dcHostFolderTraversal });
            PropertyFilterSpec pfSpec = new PropertyFilterSpec();
            pfSpec.setPropSet(new PropertySpec[] { pSpec });
            pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
            ocs = getService().retrieveProperties(getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
        } else if (mor.getType().equalsIgnoreCase("Folder")) {
            PropertySpec pSpec = new PropertySpec();
            pSpec.setType("ManagedEntity");
            pSpec.setPathSet(new String[] { "name" });
            TraversalSpec folderChildrenTraversal = new TraversalSpec();
            folderChildrenTraversal.setType("Folder");
            folderChildrenTraversal.setPath("childEntity");
            folderChildrenTraversal.setName("folderChildrenTraversal");
            ObjectSpec oSpec = new ObjectSpec();
            oSpec.setObj(mor);
            oSpec.setSkip(Boolean.TRUE);
            oSpec.setSelectSet(new SelectionSpec[] { folderChildrenTraversal });
            PropertyFilterSpec pfSpec = new PropertyFilterSpec();
            pfSpec.setPropSet(new PropertySpec[] { pSpec });
            pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
            ocs = getService().retrieveProperties(getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
        } else if (mor.getType().equalsIgnoreCase("ClusterComputeResource")) {
            PropertySpec pSpec = new PropertySpec();
            pSpec.setType("ManagedEntity");
            pSpec.setPathSet(new String[] { "name" });
            TraversalSpec clusterHostTraversal = new TraversalSpec();
            clusterHostTraversal.setType("ClusterComputeResource");
            clusterHostTraversal.setPath("host");
            clusterHostTraversal.setName("folderChildrenTraversal");
            ObjectSpec oSpec = new ObjectSpec();
            oSpec.setObj(mor);
            oSpec.setSkip(Boolean.TRUE);
            oSpec.setSelectSet(new SelectionSpec[] { clusterHostTraversal });
            PropertyFilterSpec pfSpec = new PropertyFilterSpec();
            pfSpec.setPropSet(new PropertySpec[] { pSpec });
            pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
            ocs = getService().retrieveProperties(getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
        } else {
            s_logger.error("Invalid inventory path, path element can only be datacenter and folder");
            return null;
        }
        if (ocs != null && ocs.length > 0) {
            boolean found = false;
            for (ObjectContent oc : ocs) {
                String name = oc.getPropSet()[0].getVal().toString();
                if (name.equalsIgnoreCase(token) || name.equalsIgnoreCase("host")) {
                    mor = oc.getObj();
                    found = true;
                    if (name.equalsIgnoreCase("host"))
                        i--;
                    break;
                }
            }
            if (!found) {
                s_logger.error("Path element points to an un-existing inventory entity");
                return null;
            }
        } else {
            s_logger.error("Path element points to an un-existing inventory entity");
            return null;
        }
    }
    return mor;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) SelectionSpec(com.vmware.vim25.SelectionSpec) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 4 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project opennms by OpenNMS.

the class VmwareViJavaAccessTest method testQueryPerformanceValues.

@Test
public void testQueryPerformanceValues() {
    replay(mockPerformanceManager, mockPerfProviderSummary, mockServiceInstance, ServiceInstance.class);
    VmwarePerformanceValues vmwarePerformanceValues = null;
    try {
        vmwareViJavaAccess.connect();
        vmwarePerformanceValues = vmwareViJavaAccess.queryPerformanceValues(managedEntity);
    } catch (MalformedURLException e) {
        Assert.fail(e.getMessage());
    } catch (RemoteException e) {
        Assert.fail(e.getMessage());
    }
    Assert.assertNotNull(vmwarePerformanceValues);
    for (int i = 0; i < perfCounterInfos.length; i++) {
        PerfCounterInfo perfCounterInfo = perfCounterInfos[i];
        String expectedName = perfCounterInfo.getGroupInfo().getKey() + "." + perfCounterInfo.getNameInfo().getKey() + "." + perfCounterInfo.getRollupType().toString();
        if (vmwarePerformanceValues.hasInstances(expectedName)) {
            Set<String> instances = vmwarePerformanceValues.getInstances(expectedName);
            Assert.assertEquals(instances.size(), ((PerfEntityMetric) perfEntityMetricBases[i]).getValue().length);
            PerfMetricIntSeries[] perfMetricIntSeries = (PerfMetricIntSeries[]) ((PerfEntityMetric) perfEntityMetricBases[i]).getValue();
            for (int b = 0; b < perfMetricIntSeries.length; b++) {
                Assert.assertTrue(instances.contains(perfMetricIntSeries[b].getId().getInstance()));
            }
        } else {
            Assert.assertEquals(1, ((PerfEntityMetric) perfEntityMetricBases[i]).getValue().length);
        }
    }
    verify(mockPerformanceManager, mockPerfProviderSummary, mockServiceInstance, ServiceInstance.class);
}
Also used : PerfMetricIntSeries(com.vmware.vim25.PerfMetricIntSeries) MalformedURLException(java.net.MalformedURLException) PerfCounterInfo(com.vmware.vim25.PerfCounterInfo) VmwarePerformanceValues(org.opennms.netmgt.collectd.vmware.vijava.VmwarePerformanceValues) RemoteException(java.rmi.RemoteException) PerfEntityMetric(com.vmware.vim25.PerfEntityMetric) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project coprhd-controller by CoprHD.

the class VcenterApiClient method createManagedEntityMap.

/*
     * Provide names of the vCenter elements and method will locate the MangedEntity representation
     * Each search is done within context of previous entity thus there is a dependency
     * Cluster
     * Datacenter
     * Host
     * Parameters are optional (ie, leave host null to only search datacenter and cluster)
     * Must provide parent element name or child will not be searched
     * hostConnectedPoweredOn ensures host is operational and ready for calls
     */
private Map<String, ManagedEntity> createManagedEntityMap(String datacenterName, String clusterNameOrMoRef, String hostname, boolean hostConnectedPoweredOn) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
    if (serviceInstance == null) {
        _log.error("Invoke setup to open connection before using client");
        throw new VcenterSystemException("Invoke setup to open connection before using client");
    }
    try {
        Map<String, ManagedEntity> vcenterManagedEntityMap = new HashMap<String, ManagedEntity>();
        if (datacenterName != null && !datacenterName.trim().equals("")) {
            Datacenter datacenter = (Datacenter) new InventoryNavigator(serviceInstance.getRootFolder()).searchManagedEntity("Datacenter", datacenterName);
            if (datacenter == null) {
                _log.error("Datacenter " + datacenterName + " does not exist");
                throw new VcenterObjectNotFoundException("Datacenter " + datacenterName + " does not exist");
            }
            vcenterManagedEntityMap.put("Datacenter", datacenter);
            if (clusterNameOrMoRef != null && !clusterNameOrMoRef.trim().equals("")) {
                ClusterComputeResource clusterComputeResource = searchClusterComputeResource(datacenterName, clusterNameOrMoRef);
                vcenterManagedEntityMap.put("ClusterComputeResource", clusterComputeResource);
                if (hostname != null && !hostname.trim().equals("")) {
                    HostSystem hostSystem = findByHostname(clusterComputeResource, hostname);
                    if (hostSystem == null) {
                        _log.error("Host " + hostname + " does not exist");
                        throw new VcenterObjectNotFoundException("Host " + hostname + " does not exist");
                    }
                    if (hostConnectedPoweredOn) {
                        checkHostConnectedPoweredOn(hostSystem);
                    }
                    vcenterManagedEntityMap.put("HostSystem", hostSystem);
                }
            }
        }
        return vcenterManagedEntityMap;
    } catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
        throw e;
    } catch (Exception e) {
        _log.error("getVcenterObjects exception " + e);
        throw new VcenterSystemException(e.getLocalizedMessage());
    }
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) HashMap(java.util.HashMap) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) InventoryNavigator(com.vmware.vim25.mo.InventoryNavigator) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) Datacenter(com.vmware.vim25.mo.Datacenter) HostSystem(com.vmware.vim25.mo.HostSystem) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)

Aggregations

ManagedEntity (com.vmware.vim25.mo.ManagedEntity)24 RemoteException (java.rmi.RemoteException)14 InventoryNavigator (com.vmware.vim25.mo.InventoryNavigator)12 MalformedURLException (java.net.MalformedURLException)10 HostSystem (com.vmware.vim25.mo.HostSystem)7 VirtualMachine (com.vmware.vim25.mo.VirtualMachine)6 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)5 ObjectSpec (com.vmware.vim25.ObjectSpec)5 PerfCounterInfo (com.vmware.vim25.PerfCounterInfo)5 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)5 PropertySpec (com.vmware.vim25.PropertySpec)5 TraversalSpec (com.vmware.vim25.TraversalSpec)5 Datastore (com.vmware.vim25.mo.Datastore)5 ArrayList (java.util.ArrayList)5 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)4 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)4 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)4 VcenterSystemException (com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)4 ObjectContent (com.vmware.vim25.ObjectContent)4 SelectionSpec (com.vmware.vim25.SelectionSpec)4