public static void main(String[] args) { try { getConnectionParameters(args); if (help) { printUsage(); return; } long bTime = System.currentTimeMillis(); connect(); printHostProductDetails(); long eTime = System.currentTimeMillis(); System.out.println("Total time in milli secs to get the product line id: " + (eTime - bTime)); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); printUsage(); } catch (SOAPFaultException sfe) { printSoapFaultException(sfe); } catch (Exception e) { e.printStackTrace(); } finally { try { disconnect(); } catch (SOAPFaultException sfe) { printSoapFaultException(sfe); } catch (Exception e) { System.out.println("Failed to disconnect - " + e.getMessage()); e.printStackTrace(); } } }
public static void main(String[] args) { try { getConnectionParameters(args); getInputParameters(args); if (help) { printUsage(); return; } connect(); displayStats(); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); printUsage(); } catch (SOAPFaultException sfe) { printSoapFaultException(sfe); } catch (Exception e) { e.printStackTrace(); } finally { try { disconnect(); } catch (SOAPFaultException sfe) { printSoapFaultException(sfe); } catch (Exception e) { System.out.println("Failed to disconnect - " + e.getMessage()); e.printStackTrace(); } } }
private static void createAndShowGUI(String firstColumnName, List<String> statNames) { try { String lookAndFeel = UIManager.getSystemLookAndFeelClassName(); UIManager.setLookAndFeel(lookAndFeel); JFrame.setDefaultLookAndFeelDecorated(true); } catch (SOAPFaultException sfe) { printSoapFaultException(sfe); } catch (Exception e) { e.printStackTrace(); } JFrame frame = new JFrame("VITop"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String[] columnNamesArray = new String[statNames.size() + 1]; columnNamesArray[0] = firstColumnName; for (int i = 0; i < statNames.size(); i++) { columnNamesArray[i + 1] = statNames.get(i); } statsTable = new StatsTable(columnNamesArray); statsTable.setOpaque(true); frame.setContentPane(statsTable); frame.pack(); frame.setVisible(true); }
/* * main method for debugging */ public static void main(String[] args) { try { // System.setProperty("uselocal", "true"); SimpleHelloTester tester = new SimpleHelloTester("SimpleHelloTester"); tester.testHello(); tester.testHelloOneWay(); } catch (Exception e) { e.printStackTrace(); } }
/** * Retrieves the MOREF of the host. * * @param hostName : * @return */ private static ManagedObjectReference getHostByHostName(String hostName) { ManagedObjectReference retVal = null; ManagedObjectReference rootFolder = serviceContent.getRootFolder(); try { TraversalSpec tSpec = getHostSystemTraversalSpec(); // Create Property Spec PropertySpec propertySpec = new PropertySpec(); propertySpec.setAll(Boolean.FALSE); propertySpec.getPathSet().add("name"); propertySpec.setType("HostSystem"); // Now create Object Spec ObjectSpec objectSpec = new ObjectSpec(); objectSpec.setObj(rootFolder); objectSpec.setSkip(Boolean.TRUE); objectSpec.getSelectSet().add(tSpec); // Create PropertyFilterSpec using the PropertySpec and ObjectPec // created above. PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec(); propertyFilterSpec.getPropSet().add(propertySpec); propertyFilterSpec.getObjectSet().add(objectSpec); List<PropertyFilterSpec> listpfs = new ArrayList<PropertyFilterSpec>(1); listpfs.add(propertyFilterSpec); List<ObjectContent> listobjcont = retrievePropertiesAllObjects(listpfs); if (listobjcont != null) { for (ObjectContent oc : listobjcont) { ManagedObjectReference mr = oc.getObj(); String hostnm = null; List<DynamicProperty> listDynamicProps = oc.getPropSet(); DynamicProperty[] dps = listDynamicProps.toArray(new DynamicProperty[listDynamicProps.size()]); if (dps != null) { for (DynamicProperty dp : dps) { hostnm = (String) dp.getVal(); } } if (hostnm != null && hostnm.equals(hostName)) { retVal = mr; break; } } } else { System.out.println("The Object Content is Null"); } } catch (SOAPFaultException sfe) { printSoapFaultException(sfe); } catch (Exception e) { e.printStackTrace(); } return retVal; }
private static void refreshStats() { try { PerfCompositeMetric metric = vimPort.queryPerfComposite(perfManager, querySpec); XMLGregorianCalendar latestTs = displayStats(querySpec.getMetricId(), metric); if (latestTs != null) { querySpec.setStartTime(latestTs); } } catch (SOAPFaultException sfe) { printSoapFaultException(sfe); } catch (Exception ex) { ex.printStackTrace(); } }
/** * Determines of a method 'methodName' exists for the Object 'obj'. * * @param obj The Object to check * @param methodName The method name * @param parameterTypes Array of Class objects for the parameter types * @return true if the method exists, false otherwise */ private static boolean methodExists(Object obj, String methodName, Class[] parameterTypes) { boolean exists = false; try { Method method = obj.getClass().getMethod(methodName, parameterTypes); if (method != null) { exists = true; } } catch (SOAPFaultException sfe) { printSoapFaultException(sfe); } catch (Exception e) { e.printStackTrace(); } return exists; }
/** Prints the Host names. */ private static void printHostProductDetails() { try { setHostSystemAttributesList(); TraversalSpec tSpec = getHostSystemTraversalSpec(); // Create Property Spec PropertySpec propertySpec = new PropertySpec(); propertySpec.setAll(Boolean.FALSE); propertySpec.getPathSet().addAll(hostSystemAttributesArr); propertySpec.setType("HostSystem"); // Now create Object Spec ObjectSpec objectSpec = new ObjectSpec(); objectSpec.setObj(rootRef); objectSpec.setSkip(Boolean.TRUE); objectSpec.getSelectSet().add(tSpec); // Create PropertyFilterSpec using the PropertySpec and ObjectPec // created above. PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec(); propertyFilterSpec.getPropSet().add(propertySpec); propertyFilterSpec.getObjectSet().add(objectSpec); List<PropertyFilterSpec> pfSpecList = new ArrayList<PropertyFilterSpec>(1); pfSpecList.add(propertyFilterSpec); List<ObjectContent> listobjcont = retrievePropertiesAllObjects(pfSpecList); if (listobjcont != null) { for (ObjectContent oc : listobjcont) { List<DynamicProperty> dpList = oc.getPropSet(); if (dpList != null) { for (DynamicProperty dp : dpList) { System.out.println(dp.getName() + " : " + dp.getVal()); } } System.out.println("\n\n***************************************************************"); } } } catch (SOAPFaultException sfe) { printSoapFaultException(sfe); } catch (Exception e) { e.printStackTrace(); } }
/** * Uses the new RetrievePropertiesEx method to emulate the now deprecated RetrieveProperties * method. * * @param listpfs * @return list of object content * @throws Exception */ private static List<ObjectContent> retrievePropertiesAllObjects(List<PropertyFilterSpec> listpfs) throws Exception { RetrieveOptions propObjectRetrieveOpts = new RetrieveOptions(); List<ObjectContent> listobjcontent = new ArrayList<ObjectContent>(); try { 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()); } } } } catch (SOAPFaultException sfe) { printSoapFaultException(sfe); } catch (Exception e) { System.out.println(" : Failed Getting Contents"); e.printStackTrace(); } return listobjcontent; }