@Scheduled(fixedRateString = "${collection.interval:30000}") public void forwardMetricsToInsights() throws InvalidProperty, RuntimeFault, RemoteException { long start = startTiming(); int datastoreCount = 0; for (String name : datastores) { Datastore datastore = (Datastore) inventoryNavigator.searchManagedEntity("Datastore", name); if (datastore != null) { Map<String, Object> attributes = Maps.newHashMap(); attributes.put("platform_instance", cfInstanceName); attributes.put("type", "datastore"); attributes.put("name", name); attributes.put("capacity", bytesToGb(datastore.getSummary().getCapacity())); attributes.put("free_space", bytesToGb(datastore.getSummary().getFreeSpace())); attributes.put("uncommitted", bytesToGb(datastore.getSummary().getUncommitted())); insights.recordCustomEvent("cf_iaas_metrics", attributes); datastoreCount++; } else { LOG.error("Unable to find datastore {}", name); } } endTiming(start, datastoreCount); }
private List<String> getValidCdromOnHost() throws InvalidProperty, RuntimeFault, RemoteException { List<String> result = new ArrayList<String>(); EnvironmentBrowser envBrower = vm.getEnvironmentBrowser(); ConfigTarget configTarget; try { configTarget = envBrower.queryConfigTarget(null); } catch (Exception ex) { throw new RuntimeException("Error in getting Cdrom devices from host."); } if(configTarget != null && configTarget.cdRom != null) { for(VirtualMachineCdromInfo cdromInfo : configTarget.cdRom) { result.add(cdromInfo.name); } } return result; }
private List<ManagedEntity> getHostMachines(Folder rootFolder, List<Map<String, Object>> hostConfigs) { List<ManagedEntity> hostEntities = new ArrayList<ManagedEntity>(); for (Map<String, Object> hostConfig : hostConfigs) { String hostName = (String) hostConfig.get("host"); try { if ("*".equals(hostName)) { hostEntities = Arrays.asList(new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem")); } else { ManagedEntity hostSystem = new InventoryNavigator(rootFolder).searchManagedEntity("HostSystem", hostName); if (hostSystem != null) { hostEntities.add(hostSystem); } else { logger.error("Could not find Host with name " + hostName); } } } catch (InvalidProperty invalidProperty) { logger.error("Unable to get the host details", invalidProperty); } catch (RuntimeFault runtimeFault) { logger.error("Unable to get the host details", runtimeFault); } catch (RemoteException e) { logger.error("Unable to get the host details", e); } } return hostEntities; }
private VirtualMachineRelocateSpec configureRelocateSpec(ResourcePool resourcePool, Datastore datastore, VirtualMachine master) throws Exception, InvalidProperty, RuntimeFault, RemoteException { VirtualMachineRelocateSpec rSpec = new VirtualMachineRelocateSpec(); if (cloningStrategy.equals("linked")) { ArrayList<Integer> diskKeys = getIndependentVirtualDiskKeys(master); if (diskKeys.size() > 0) { Datastore[] dss = master.getDatastores(); VirtualMachineRelocateSpecDiskLocator[] diskLocator = new VirtualMachineRelocateSpecDiskLocator[diskKeys.size()]; int count = 0; for (Integer key : diskKeys) { diskLocator[count] = new VirtualMachineRelocateSpecDiskLocator(); diskLocator[count].setDatastore(dss[0].getMOR()); diskLocator[count] .setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.moveAllDiskBackingsAndDisallowSharing .toString()); diskLocator[count].setDiskId(key); count = count + 1; } rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.createNewChildDiskBacking.toString()); rSpec.setDisk(diskLocator); } else { rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.createNewChildDiskBacking.toString()); } } else if (cloningStrategy.equals("full")) { rSpec.setDatastore(datastore.getMOR()); rSpec.setPool(resourcePool.getMOR()); //rSpec.setHost(); } else throw new Exception(String.format("Cloning strategy %s not supported", cloningStrategy)); return rSpec; }
public void should_report_isdone_for_error_tasks() throws ExecutionException, InterruptedException { VmwareTaskWrapper taskWrapper = new VmwareTaskWrapper(new Callable<Task>() { @Override public Task call() throws Exception { return new Task(null, null){ @Override public TaskInfo getTaskInfo() throws InvalidProperty, RuntimeFault, RemoteException { throw new RuntimeException("getTaskInfo exception"); } @Override public String waitForTask() throws RuntimeFault, RemoteException, InterruptedException { throw new RuntimeException("getTaskInfo exception"); } @Override public void cancelTask() throws RuntimeFault, RemoteException { throw new RuntimeException("getTaskInfo exception"); } }; } }, "myTask"); final Future<CloudTaskResult> async = taskWrapper.executeOrGetResultAsync(); int cnt = 0; while (!async.isDone()){ cnt++; assertTrue(cnt < 5); } final CloudTaskResult result = async.get(); assertTrue(result.isHasErrors()); }
private void validateCdromHostDevice(String hostDevice) throws InvalidProperty, RuntimeFault, RemoteException { List<String> validCdList = getValidCdromOnHost(); if (!validCdList.contains(hostDevice)) { throw new RuntimeException("Invalid host device path for CD drives."); } }
/** Create a new virtual network adapter on the VM * Your MAC address should start with 00:50:56 */ public void createNetworkAdapter(VirtualNetworkAdapterType type, String networkName, String macAddress, boolean wakeOnLan, boolean startConnected) throws InvalidProperty, RuntimeFault, RemoteException, InterruptedException { VirtualMachinePowerState powerState = vm.getRuntime().getPowerState(); String vmVerStr = vm.getConfig().getVersion(); int vmVer = Integer.parseInt(vmVerStr.substring(vmVerStr.length()-2)); if((powerState == VirtualMachinePowerState.suspended) || (powerState == VirtualMachinePowerState.suspended && vmVer < 7)) { throw new InvalidPowerState(); } HostSystem host = new HostSystem(vm.getServerConnection(), vm.getRuntime().getHost()); ComputeResource cr = (ComputeResource) host.getParent(); EnvironmentBrowser envBrowser = cr.getEnvironmentBrowser(); ConfigTarget configTarget = envBrowser.queryConfigTarget(host); VirtualMachineConfigOption vmCfgOpt = envBrowser.queryConfigOption(null, host); type = validateNicType(vmCfgOpt.getGuestOSDescriptor(), vm.getConfig().getGuestId(), type); VirtualDeviceConfigSpec nicSpec = createNicSpec(type, networkName, macAddress, wakeOnLan, startConnected, configTarget); VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); vmConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec []{nicSpec}); Task task = vm.reconfigVM_Task(vmConfigSpec); task.waitForTask(200, 100); }
/** * Get multiple properties by their paths * @param propPaths an array of strings for property path * @return a Hashtable holding with the property path as key, and the value. * @throws InvalidProperty * @throws RuntimeFault * @throws RemoteException */ public Hashtable getPropertiesByPaths(String[] propPaths) throws InvalidProperty, RuntimeFault, RemoteException { Hashtable[] pht = PropertyCollectorUtil.retrieveProperties( new ManagedObject[] { this }, getMOR().getType(), propPaths); if(pht.length!=0) return pht[0]; else return null; }
/** * Create an instance of {@link JAXBElement }{@code <}{@link InvalidProperty }{@code >}} * */ @XmlElementDecl(namespace = "urn:pbm", name = "InvalidPropertyFault") public JAXBElement<InvalidProperty> createInvalidPropertyFault(InvalidProperty value) { return new JAXBElement<InvalidProperty>(_InvalidPropertyFault_QNAME, InvalidProperty.class, null, value); }
public void addCdDriveFromIso(String isoPath, boolean startConnected) throws InvalidProperty, RuntimeFault, RemoteException, InterruptedException { addCdDrive(isoPath, null, startConnected); }
public void addCdDriveFromHost(String hostDevice, boolean startConnected) throws InvalidProperty, RuntimeFault, RemoteException, InterruptedException { addCdDrive(null, hostDevice, startConnected); }
public TaskInfo getTaskInfo() throws InvalidProperty, RuntimeFault, RemoteException { return (TaskInfo) getCurrentProperty(PROPNAME_INFO); }
/** @since SDK4.1 */ public void cancelRetrievePropertiesEx(String token) throws InvalidProperty, RuntimeFault, RemoteException { getVimService().cancelRetrievePropertiesEx(getMOR(), token); }
/** @since SDK4.1 */ public RetrieveResult continueRetrievePropertiesEx(String token) throws InvalidProperty, RuntimeFault, RemoteException { return getVimService().continueRetrievePropertiesEx(getMOR(), token); }
public PropertyFilter createFilter(PropertyFilterSpec spec, boolean partialUpdates) throws InvalidProperty, RuntimeFault, RemoteException { ManagedObjectReference mor = getVimService().createFilter(getMOR(), spec, partialUpdates); return new PropertyFilter(getServerConnection(), mor); }
/** @deprecated as of SDK4.1 */ public ObjectContent[] retrieveProperties(PropertyFilterSpec[] specSet) throws InvalidProperty, RuntimeFault, RemoteException { return getVimService().retrieveProperties(getMOR(), specSet); }
/** @since SDK4.1 */ public RetrieveResult retrievePropertiesEx(PropertyFilterSpec[] specSet, RetrieveOptions options) throws InvalidProperty, RuntimeFault, RemoteException { return getVimService().retrievePropertiesEx(getMOR(), specSet, options); }