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);
}
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);
}
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;
}
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);
}
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());
}
}
Aggregations