VcVmUtil { public static boolean runSPOnSingleVM(NodeEntity node, Callable<Void> call) { if (node.getMoId() == null) { logger.info("VC vm does not exist for node: " + node.getVmName()); return false; } VcVirtualMachine vcVm = VcCache.getIgnoreMissing(node.getMoId()); if (vcVm == null) { logger.info("VC vm does not exist for node: " + node.getVmName()); return false; } @SuppressWarnings("unchecked") Callable<Void>[] storeProceduresArray = new Callable[1]; storeProceduresArray[0] = call; NoProgressUpdateCallback callback = new NoProgressUpdateCallback(); try { ExecutionResult[] result = Scheduler .executeStoredProcedures( com.vmware.aurora.composition.concurrent.Priority.BACKGROUND, storeProceduresArray, callback); if (result == null) { logger.error("No result from composition layer"); return false; } else { if (result[0].finished && result[0].throwable == null) { logger.info("successfully run operation on vm for node: " + node.getVmName()); return true; } else { String message = result[0].throwable.getMessage(); throw BddException.VC_EXCEPTION(result[0].throwable, message); } } } catch (InterruptedException e) { logger.error("error in executing store procedure on single node " + node.getVmName(), e); throw BddException.INTERNAL(e, e.getMessage()); } }  static boolean checkIpAddresses(final VcVirtualMachine vcVm); static List<String> getAllIpAddresses(final VcVirtualMachine vcVm); static Set<String> getAllIpAddresses(final VcVirtualMachine vcVm,
         final Set<String> portGroups, boolean inSession); static String getIpAddressOfPortGroup(final VcVirtualMachine vcVm,
         final String portGroup, boolean inSession); static ArrayList<String> getNodePrimaryMgtIPV4sFromEntitys(List<NodeEntity> nodes); static void populateNicInfo(final NicEntity nicEntity,
         final String moid, final String pgName); static String getGuestHostName(final VcVirtualMachine vcVm,
         boolean inSession); static boolean setBaseNodeForVm(BaseNode vNode, String vmId); static boolean verifyFTState(final VcVirtualMachine vm); static VirtualDisk findVirtualDisk(String vmMobId, String externalAddr); static String fetchDiskUUID(final String vmMobId, final String diskExtAddress); static void populateDiskInfo(final DiskEntity diskEntity,
         final String vmMobId); static boolean isDatastoreAccessible(String dsMobId); static void updateVm(String vmId); static boolean configIOShares(final String vmId,
         final Priority ioShares); static boolean runSPOnSingleVM(NodeEntity node, Callable<Void> call); static VcResourcePool getTargetRp(String clusterName,
         String groupName, NodeEntity node); static VmSchema getVmSchema(ClusterCreate spec, String nodeGroup,
         List<DiskSpec> diskSet, String templateVmId, String templateVmSnapId); static long makeVmMemoryDivisibleBy4(long memory); static void addBootupUUID(Map<String, String> bootupConfigs); static String getVolumes(String moid, List<Disk> disks); static List<DiskSpec> toDiskSpecList(Collection<DiskEntity> diskEntityCollection); static void sortDiskOrder(List<DiskSpec> diskSpecs); static String getVolumesFromSpecs(String moid, List<DiskSpec> diskEntities); static void destroyVm(final String vmId); static void destroyVm(final String vmId, Boolean inSession); static VcVirtualMachine findVmInRp(final VcResourcePool rp, final String vmName); static void rename(final String vmId, final String newName); static void enableFt(final VcVirtualMachine vm); static void disableHa(final VcVirtualMachine vm); static void enableDiskUUID(final VcVirtualMachine vm); static boolean enableOvfEnvTransport(final VcVirtualMachine vm); static boolean validateCPU(final String vmId, final int cpuNum); static boolean enableSyncTimeWithHost(final VcVirtualMachine vm); static void checkAndCreateSnapshot(final VmSchema vmSchema); static String getHostNameFromIpV4(VcVirtualMachine vcVm, String ipV4); static String getMgtHostName(VcVirtualMachine vcVm, String primaryMgtIpV4); static final String NIC_LABEL_PREFIX; }
@Test(enabled = false) public void testRunSPOnSingleVMNoVM() { NodeEntity node = new NodeEntity(); Callable<Void> callable = getCallable(); boolean result = VcVmUtil.runSPOnSingleVM(node, callable); Assert.assertTrue(result == false, "Should get false, but got " + result); node.setMoId("vm-001"); result = VcVmUtil.runSPOnSingleVM(node, callable); Assert.assertTrue(result == false, "Should get false, but got " + result); MockVcCache.setGetFlag(true); MockTmScheduler.setResultIsNull(true); result = VcVmUtil.runSPOnSingleVM(node, callable); Assert.assertTrue(result == false, "Should get false, but got " + result); }
@Test public void testRunSPOnSingleVMException() { NodeEntity node = new NodeEntity(); node.setMoId("vm-001"); MockVcCache.setGetFlag(true); MockTmScheduler.setResultIsNull(false); MockTmScheduler.setFlag(VmOperation.START_VM, false); Callable<Void> callable = getCallable(); try { VcVmUtil.runSPOnSingleVM(node, callable); Assert.assertTrue(false, "Should get exception, but not."); } catch (BddException e) { } }
@Test public void testRunSPOnSingleVMPositive() { NodeEntity node = new NodeEntity(); node.setMoId("vm-001"); MockVcCache.setGetFlag(true); MockTmScheduler.setResultIsNull(false); MockTmScheduler.setFlag(VmOperation.START_VM, true); Callable<Void> callable = getCallable(); boolean result = VcVmUtil.runSPOnSingleVM(node, callable); Assert.assertTrue(result, "Should get true, but got " + result); }