VcVmUtil { public static VcResourcePool getTargetRp(String clusterName, String groupName, NodeEntity node) { String clusterRpName = ConfigInfo.getSerengetiUUID() + "-" + clusterName; VcResourcePoolEntity rpEntity = node.getVcRp(); String vcRPName = ""; VcResourcePool rp = null; try { VcCluster cluster = VcResourceUtils.findVcCluster(rpEntity.getVcCluster()); if (!cluster.getConfig().getDRSEnabled()) { logger.debug("DRS disabled for cluster " + rpEntity.getVcCluster() + ", put VM under cluster directly."); return cluster.getRootRP(); } if (CommonUtil.isBlank(rpEntity.getVcResourcePool())) { vcRPName = clusterRpName + "/" + groupName; } else { vcRPName = rpEntity.getVcResourcePool() + "/" + clusterRpName + "/" + groupName; } rp = VcResourceUtils.findRPInVCCluster(rpEntity.getVcCluster(), vcRPName); } catch (Exception e) { logger.error("Failed to get VC resource pool " + vcRPName + " in vc cluster " + rpEntity.getVcCluster(), e); throw ClusteringServiceException.TARGET_VC_RP_NOT_FOUND( rpEntity.getVcCluster(), vcRPName); } if (rp == null) { throw ClusteringServiceException.TARGET_VC_RP_NOT_FOUND( rpEntity.getVcCluster(), vcRPName); } return rp; }  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 public void testGetTargetRp() { NodeEntity node = new NodeEntity(); VcResourcePoolEntity rpEntity = new VcResourcePoolEntity(); rpEntity.setVcCluster("test-cluster"); rpEntity.setVcResourcePool("test-rp"); node.setVcRp(rpEntity); VcVmUtil.getTargetRp("test-cluster", "test-group", node); }
@Test public void testGetTargetRpException() { NodeEntity node = new NodeEntity(); VcResourcePoolEntity rpEntity = new VcResourcePoolEntity(); rpEntity.setVcCluster("test-cluster"); rpEntity.setVcResourcePool("test-rp"); node.setVcRp(rpEntity); MockVcResourceUtils.setFlag(false); try { VcVmUtil.getTargetRp("test-cluster", "test-group", node); Assert.assertTrue(false, "Should get exception for cannot get resource pool."); } catch (ClusteringServiceException e) { } }
@Test public void testGetTargetRpDisabledDRS() { NodeEntity node = new NodeEntity(); VcResourcePoolEntity rpEntity = new VcResourcePoolEntity(); rpEntity.setVcCluster("test-cluster"); rpEntity.setVcResourcePool("test-rp"); node.setVcRp(rpEntity); MockVcResourceUtils.setDisableDRS(true); VcResourcePool rp = VcVmUtil.getTargetRp("test-cluster", "test-group", node); Assert.assertTrue(rp.getName() != null, "Should get root rp, but got " + rp.getName()); Assert.assertTrue(rp.getName().equals("root"), "Should get root rp, but got " + rp.getName()); }