ClusterManager { @ClusterManagerPointcut public Long asyncSetParam(String clusterName, Integer activeComputeNodeNum, Integer minComputeNodeNum, Integer maxComputeNodeNum, Boolean enableAuto, Priority ioPriority) throws Exception { if(enableAuto != null || activeComputeNodeNum != null || maxComputeNodeNum != null || minComputeNodeNum != null) { opsBlocker.blockUnsupportedOpsByCluster("asyncSetElasticity", clusterName); } ValidationUtils.validateVersion(clusterEntityMgr, clusterName); syncSetParam(clusterName, activeComputeNodeNum, minComputeNodeNum, maxComputeNodeNum, enableAuto, ioPriority); ClusterRead cluster = getClusterByName(clusterName, false); if (!cluster.getStatus().isActiveServiceStatus()) { String msg = "Cluster "+ clusterName +" is not running."; logger.error(msg); throw ClusterManagerException .SET_MANUAL_ELASTICITY_NOT_ALLOWED_ERROR(msg); } Map<String, JobParameter> param = new TreeMap<String, JobParameter>(); param.put(JobConstants.TIMESTAMP_JOB_PARAM, new JobParameter(new Date())); param.put(JobConstants.CLUSTER_NAME_JOB_PARAM, new JobParameter( clusterName)); if (activeComputeNodeNum == null) { param.put(JobConstants.VHM_ACTION_JOB_PARAM, new JobParameter( LimitInstruction.actionWaitForManual)); } else if (activeComputeNodeNum == -1) { param.put(JobConstants.VHM_ACTION_JOB_PARAM, new JobParameter( LimitInstruction.actionUnlimit)); } else { param.put(JobConstants.VHM_ACTION_JOB_PARAM, new JobParameter( LimitInstruction.actionSetTarget)); } if (activeComputeNodeNum != null) { param.put(JobConstants.ACTIVE_COMPUTE_NODE_NUMBER_JOB_PARAM, new JobParameter(Long.valueOf(activeComputeNodeNum))); } param.put(JobConstants.CLUSTER_SUCCESS_STATUS_JOB_PARAM, new JobParameter(ClusterStatus.RUNNING.name())); param.put(JobConstants.CLUSTER_FAILURE_STATUS_JOB_PARAM, new JobParameter(ClusterStatus.RUNNING.name())); JobParameters jobParameters = new JobParameters(param); try { clusterEntityMgr.updateClusterStatus(clusterName, ClusterStatus.VHM_RUNNING); return jobManager.runJob(JobConstants.SET_MANUAL_ELASTICITY_JOB_NAME, jobParameters); } catch (Exception e) { logger.error("Failed to set manual elasticity for cluster " + clusterName, e); clusterEntityMgr.updateClusterStatus(clusterName, ClusterStatus.RUNNING); throw e; } }  JobManager getJobManager(); void setJobManager(JobManager jobManager); ClusterConfigManager getClusterConfigMgr(); void setClusterConfigMgr(ClusterConfigManager clusterConfigMgr); INetworkService getNetworkManager(); void setNetworkManager(INetworkService networkManager); IResourceService getResMgr(); @Autowired void setResMgr(IResourceService resMgr); IClusterEntityManager getClusterEntityMgr(); @Autowired void setClusterEntityMgr(IClusterEntityManager clusterEntityMgr); RackInfoManager getRackInfoMgr(); @Autowired void setRackInfoMgr(RackInfoManager rackInfoMgr); IClusteringService getClusteringService(); @Autowired void setClusteringService(IClusteringService clusteringService); IClusterHealService getClusterHealService(); @Autowired void setClusterHealService(IClusterHealService clusterHealService); IExecutionService getExecutionService(); @Autowired void setExecutionService(IExecutionService executionService); @Autowired void setSoftwareManagerCollector(SoftwareManagerCollector softwareManagerCollector); @Autowired void setShrinkManager(ShrinkManager shrinkManager); Map<String, Object> getClusterConfigManifest(String clusterName,
         List<String> targets, boolean needAllocIp); File writeClusterSpecFile(String targetName, File workDir,
         boolean needAllocIp); ClusterRead getClusterByName(String clusterName, boolean realTime); ClusterCreate getClusterSpec(String clusterName); List<ClusterRead> getClusters(Boolean realTime); @ClusterManagerPointcut Long createCluster(ClusterCreate createSpec, org.apache.commons.configuration.Configuration newParams); @ClusterManagerPointcut Long configCluster(String clusterName, ClusterCreate createSpec); long enableLdap(String clusterName); Long resumeClusterCreation(String clusterName, org.apache.commons.configuration.Configuration newParams); @ClusterManagerPointcut Long deleteClusterByName(String clusterName); @ClusterManagerPointcut Long upgradeClusterByName(String clusterName); Long startCluster(String clusterName, boolean force); @ClusterManagerPointcut Long stopCluster(String clusterName); @ClusterManagerPointcut Long resizeCluster(String clusterName, String nodeGroupName,
         int instanceNum, boolean force, org.apache.commons.configuration.Configuration newParams); @SuppressWarnings("unchecked") List<String> syncSetParam(String clusterName,
         Integer activeComputeNodeNum, Integer minComputeNodeNum, Integer maxComputeNodeNum,
         Boolean enableAuto, Priority ioPriority); @ClusterManagerPointcut Long asyncSetParam(String clusterName, Integer activeComputeNodeNum,
         Integer minComputeNodeNum, Integer maxComputeNodeNum, Boolean enableAuto,
         Priority ioPriority); @ClusterManagerPointcut @Transactional void updateCluster(ClusterCreate clusterUpdate, boolean ignoreWarning, boolean appendResource); void prioritizeCluster(String clusterName, Priority ioShares); @ClusterManagerPointcut Long fixDiskFailures(String clusterName, String groupName); Map<String, String> getRackTopology(String clusterName, String topology); HadoopStack filterDistroFromAppManager(
         SoftwareManager softwareManager, String distroName); @ClusterManagerPointcut Long expandCluster(String clusterName,
                          NodeGroupCreate[] nodeGroupsAdd); Long clusterExpandExecute(String clusterName, NodeGroupCreate[] nodeGroupsAdd, ClusterCreate clusterSpec); void recoverClusters(List<VcClusterMap> clstMaps);  }
@Test(groups = { "TestClusterManager" }, dependsOnMethods = "testWriteClusterSpecFileWithUTF8") public void testAsyncSetParamIoPriorityFailed() throws Exception { ClusterEntity cluster = TestClusterEntityManager.assembleClusterEntity(TEST_CLUSTER_NAME); cluster.setStatus(ClusterStatus.RUNNING); clusterEntityMgr.insert(cluster); MockTmScheduler.setFlag(VmOperation.RECONFIGURE_VM, false); try { clusterMgr.asyncSetParam(TEST_CLUSTER_NAME, 3, 1, 4, true, Priority.HIGH); assertTrue(false, "Should get exception but not."); } catch (ClusterManagerException e) { List<NodeEntity> nodes = clusterEntityMgr.findAllNodes(TEST_CLUSTER_NAME); assertTrue(nodes.get(0).isActionFailed(), "Should get action failed, but got " + nodes.get(0).isActionFailed()); assertTrue(nodes.get(0).getErrMessage().endsWith("test failure"), "Should get error message: test failure, but got " + nodes.get(0).getErrMessage()); } }
@Test(groups = { "TestClusterManager" }, dependsOnMethods = "testAsyncSetParamIoPriorityFailed") public void testAsyncSetParamAutoElasticityFailed() throws Exception { ClusterEntity cluster = TestClusterEntityManager.assembleClusterEntity(TEST_CLUSTER_NAME); cluster.setStatus(ClusterStatus.RUNNING); cluster.setVhmMasterMoid("vm-001"); int i = 0; Set<NodeGroupEntity> groups = cluster.getNodeGroups(); for (NodeGroupEntity group : groups) { Set<NodeEntity> nodes = group.getNodes(); for (NodeEntity node : nodes) { i++; node.setMoId("vm-00" + i); } } clusterEntityMgr.insert(cluster); MockTmScheduler.setFlag(VmOperation.RECONFIGURE_VM, true); MockTmScheduler.setFlag(VmOperation.AUTO_ELASTICITY, false); try { clusterMgr.asyncSetParam(TEST_CLUSTER_NAME, 3, 1, 4, true, Priority.HIGH); assertTrue(false, "Should get exception but not."); } catch (ClusterManagerException e) { } }
@Test(groups = { "TestClusterManager" }, dependsOnMethods = "testAsyncSetParamAutoElasticityFailed") public void testAsyncSetParamAutoElasticitySuccess() throws Exception { ClusterEntity cluster = TestClusterEntityManager.assembleClusterEntity(TEST_CLUSTER_NAME); cluster.setStatus(ClusterStatus.RUNNING); cluster.setVhmMasterMoid("vm-001"); int i = 0; Set<NodeGroupEntity> groups = cluster.getNodeGroups(); for (NodeGroupEntity group : groups) { Set<NodeEntity> nodes = group.getNodes(); for (NodeEntity node : nodes) { i++; node.setMoId("vm-00" + i); } } clusterEntityMgr.insert(cluster); MockTmScheduler.setFlag(VmOperation.RECONFIGURE_VM, true); MockTmScheduler.setFlag(VmOperation.AUTO_ELASTICITY, true); clusterMgr.asyncSetParam(TEST_CLUSTER_NAME, 3, 1, 4, true, Priority.HIGH); assertTrue(true, "Should get exception but not."); }