use of com.vmware.vim25.PerfCounterInfo in project opennms by OpenNMS.
the class VmwareViJavaAccessTest method setUp.
@Before
public void setUp() throws Exception {
// setup required objects
managedObjectReferenceManagedEntity = new ManagedObjectReference();
managedObjectReferenceManagedEntity.setType("ManagedEntity");
managedObjectReferenceManagedEntity.setVal("moIdMe");
managedObjectReferenceVirtualMachine = new ManagedObjectReference();
managedObjectReferenceVirtualMachine.setType("VirtualMachine");
managedObjectReferenceVirtualMachine.setVal("moIdVm");
managedObjectReferenceHostSystem = new ManagedObjectReference();
managedObjectReferenceHostSystem.setType("HostSystem");
managedObjectReferenceHostSystem.setVal("moIdHs");
// setup VmwareViJavaAccess
vmwareViJavaAccess = new VmwareViJavaAccess("hostname", "username", "password") {
@Override
protected void relax() {
}
};
// setup PerformanceManager
mockPerformanceManager = createMock(PerformanceManager.class);
// setup ServiceInstance mock
mockServiceInstance = createMock(ServiceInstance.class);
// setup ServerConnection
mockServerConnection = new ServerConnection(new URL("https://hostname/sdk"), new VimPortType(new WSClient("https://hostname/sdk") {
@Override
protected SSLSocketFactory getTrustAllSocketFactory(boolean ignoreCert) throws RemoteException {
return null;
}
}), mockServiceInstance);
// setup AboutInfo
mockAboutInfo = createMock(AboutInfo.class);
expectNew(ServiceInstance.class, new Class<?>[] { URL.class, String.class, String.class }, new URL("https://hostname/sdk"), "username", "password").andReturn(mockServiceInstance).anyTimes();
expect(mockServiceInstance.getServerConnection()).andReturn(mockServerConnection).anyTimes();
expect(mockServiceInstance.getPerformanceManager()).andReturn(mockPerformanceManager).anyTimes();
expect(mockServiceInstance.getAboutInfo()).andReturn(mockAboutInfo).anyTimes();
managedEntity = new ManagedEntity(null, managedObjectReferenceManagedEntity);
virtualMachine = new VirtualMachine(null, managedObjectReferenceVirtualMachine);
hostSystem = new HostSystem(null, managedObjectReferenceHostSystem);
// setup MorUtil
mockStatic(MorUtil.class);
expect(MorUtil.createExactManagedEntity(mockServerConnection, managedObjectReferenceManagedEntity)).andReturn(managedEntity).anyTimes();
expect(MorUtil.createExactManagedEntity(mockServerConnection, managedObjectReferenceVirtualMachine)).andReturn(virtualMachine).anyTimes();
expect(MorUtil.createExactManagedEntity(mockServerConnection, managedObjectReferenceHostSystem)).andReturn(hostSystem).anyTimes();
// setup about info
expect(mockAboutInfo.getApiVersion()).andReturn("2.x");
expect(mockAboutInfo.getApiVersion()).andReturn("3.x");
expect(mockAboutInfo.getApiVersion()).andReturn("4.x");
expect(mockAboutInfo.getApiVersion()).andReturn("5.x");
expect(mockAboutInfo.getApiVersion()).andReturn("6.x");
expect(mockAboutInfo.getApiVersion()).andReturn("x");
// setup performance data
int refreshRate = 100;
int metricCount = 15;
int instanceModifier = 5;
perfQuerySpec = new PerfQuerySpec();
perfQuerySpec.setEntity(managedEntity.getMOR());
perfQuerySpec.setMaxSample(new Integer(1));
perfQuerySpec.setIntervalId(refreshRate);
perfEntityMetricBases = new PerfEntityMetricBase[metricCount];
perfCounterInfos = new PerfCounterInfo[metricCount];
for (int i = 0; i < metricCount; i++) {
ElementDescription groupInfo = new ElementDescription();
groupInfo.setKey("key" + i);
ElementDescription nameInfo = new ElementDescription();
nameInfo.setKey("name" + i);
perfCounterInfos[i] = new PerfCounterInfo();
perfCounterInfos[i].setKey(i);
perfCounterInfos[i].setGroupInfo(groupInfo);
perfCounterInfos[i].setNameInfo(nameInfo);
perfCounterInfos[i].setRollupType(PerfSummaryType.average);
perfEntityMetricBases[i] = new PerfEntityMetric();
PerfMetricIntSeries[] perfMetricIntSeries;
int instanceCount = (i % instanceModifier) + 1;
perfMetricIntSeries = new PerfMetricIntSeries[instanceCount];
for (int b = 0; b < instanceCount; b++) {
PerfMetricId perfMetricId = new PerfMetricId();
perfMetricId.setCounterId(i);
if (instanceCount == 1) {
perfMetricId.setInstance(null);
} else {
perfMetricId.setInstance("instance" + b);
}
perfMetricIntSeries[b] = new PerfMetricIntSeries();
perfMetricIntSeries[b].setValue(new long[] { (long) 42 });
perfMetricIntSeries[b].setId(perfMetricId);
}
((PerfEntityMetric) perfEntityMetricBases[i]).setValue(perfMetricIntSeries);
}
// setup PerfProviderSummary
mockPerfProviderSummary = createMock(PerfProviderSummary.class);
expect(mockPerformanceManager.queryPerfProviderSummary(managedEntity)).andReturn(mockPerfProviderSummary).anyTimes();
expect(mockPerfProviderSummary.getRefreshRate()).andReturn(refreshRate).anyTimes();
expect(mockPerformanceManager.getPerfCounter()).andReturn(perfCounterInfos).anyTimes();
expect(mockPerformanceManager.queryPerf(anyObject(PerfQuerySpec[].class))).andReturn(perfEntityMetricBases).anyTimes();
// setup network info
HostNetworkInfo hostNetworkInfo = new HostNetworkInfo();
int numberOfVnics = 3;
HostVirtualNic[] hostVirtualNics = new HostVirtualNic[numberOfVnics];
for (int i = 0; i < numberOfVnics; i++) {
HostVirtualNicSpec hostVirtualNicSpec = new HostVirtualNicSpec();
HostIpConfig hostIpConfig = new HostIpConfig();
hostIpConfig.setIpAddress("192.168.1." + (i + 1));
hostVirtualNicSpec.setIp(hostIpConfig);
hostVirtualNics[i] = new HostVirtualNic();
hostVirtualNics[i].setSpec(hostVirtualNicSpec);
}
hostNetworkInfo.setVnic(hostVirtualNics);
HostVirtualNic[] hostVirtualConsoleNics = new HostVirtualNic[numberOfVnics];
for (int i = 0; i < numberOfVnics; i++) {
HostVirtualNicSpec hostVirtualNicSpec = new HostVirtualNicSpec();
HostIpConfig hostIpConfig = new HostIpConfig();
hostIpConfig.setIpAddress("192.168.2." + (i + 1));
hostVirtualNicSpec.setIp(hostIpConfig);
hostVirtualConsoleNics[i] = new HostVirtualNic();
hostVirtualConsoleNics[i].setSpec(hostVirtualNicSpec);
}
hostNetworkInfo.setConsoleVnic(hostVirtualConsoleNics);
HostServiceTicket hostServiceTicket = new HostServiceTicket();
hostServiceTicket.setSessionId("sessionId");
// setup HostSystem
mockHostSystem = createMock(HostSystem.class);
// setup HostNetworkSystem
mockHostNetworkSystem = createMock(HostNetworkSystem.class);
// setup CIMClient
mockCIMClient = createPartialMock(CIMClient.class, "enumerateInstances");
// setup the cim objects
cimObjects = new ArrayList<CIMObject>();
int cimObjectCount = 5;
for (int i = 0; i < cimObjectCount; i++) {
CIMInstance cimInstance = new CIMInstance();
cimInstance.setName("cimInstance" + i);
cimObjects.add(cimInstance);
}
expect(mockHostSystem.getName()).andReturn("mockesxi01.local").anyTimes();
expect(mockHostSystem.getHostNetworkSystem()).andReturn(mockHostNetworkSystem).anyTimes();
expect(mockHostSystem.acquireCimServicesTicket()).andReturn(hostServiceTicket).anyTimes();
expect(mockHostNetworkSystem.getNetworkInfo()).andReturn(hostNetworkInfo).anyTimes();
expectNew(CIMClient.class, new Class<?>[] { CIMNameSpace.class, Principal.class, Object.class }, anyObject(), anyObject(), anyObject()).andReturn(mockCIMClient).anyTimes();
suppress(method(CIMClient.class, "useMPost"));
expect(mockCIMClient.enumerateInstances(new CIMObjectPath("cimClass"))).andReturn(Collections.enumeration(cimObjects)).anyTimes();
}
use of com.vmware.vim25.PerfCounterInfo 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.PerfCounterInfo 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.PerfCounterInfo in project opennms by OpenNMS.
the class VmwareViJavaAccess method getPerfCounterInfoMap.
/**
* This method retrieves the performance counters available.
*
* @return a map of performance counters
*/
public Map<Integer, PerfCounterInfo> getPerfCounterInfoMap() {
if (m_perfCounterInfoMap == null) {
m_perfCounterInfoMap = new HashMap<Integer, PerfCounterInfo>();
PerfCounterInfo[] perfCounterInfos = getPerformanceManager().getPerfCounter();
for (PerfCounterInfo perfCounterInfo : perfCounterInfos) {
m_perfCounterInfoMap.put(perfCounterInfo.getKey(), perfCounterInfo);
}
}
return m_perfCounterInfoMap;
}
use of com.vmware.vim25.PerfCounterInfo in project cloudstack by apache.
the class PerfCounterInfoMapper method lookup.
public PerfCounterInfo[] lookup(String groupName, String counterName, PerfSummaryType rollupType) {
assert (groupName != null);
assert (counterName != null);
Map<String, List<PerfCounterInfo>> groupMap = _mapCounterInfos.get(groupName);
if (groupMap == null)
return null;
List<PerfCounterInfo> counterInfoList = groupMap.get(counterName);
if (counterInfoList == null)
return null;
if (rollupType == null) {
return counterInfoList.toArray(new PerfCounterInfo[0]);
}
for (PerfCounterInfo info : counterInfoList) {
if (info.getRollupType() == rollupType)
return new PerfCounterInfo[] { info };
}
return null;
}
Aggregations