ValidateRolesUtil { public static void validateRolesForShrink(String appManagerConfPath, NodeGroupInfo groupInfo) { String blacklistJson; String filePath = appManagerConfPath + File.separator + Constants.rolesBlacklistForShrink; try { blacklistJson = SerialUtils.dataFromFile(filePath); } catch (IOException e) { String errMsg = appManagerConfPath + ": " + e.getMessage(); throw SoftwareManagementPluginException.READ_BLACKLIST_FOR_SCALE_IN_FAILED(errMsg); } Gson gson = new Gson(); Set<String> blacklist = new HashSet(gson.fromJson(blacklistJson, List.class)); logger.info("roles in blackList are: " + blacklist.toString()); List<String> roles = groupInfo.getRoles(); List<String> invalidRoles = null; for (String role : roles) { if (blacklist.contains(role)) { if (invalidRoles == null) { invalidRoles = new ArrayList<String>(); } invalidRoles.add(role); } } if (invalidRoles != null) { throw SoftwareManagementPluginException.INVALID_ROLES_TO_SHRINK(invalidRoles.toString()); } }  static void validateRolesForShrink(String appManagerConfPath, NodeGroupInfo groupInfo);  }
@Test(expectedExceptions = SoftwareManagementPluginException.class) public void testValidateRolesForShrinkFailed() { groupInfo.getRoles().add("hadoop_namenode"); ValidateRolesUtil.validateRolesForShrink(fileDir, groupInfo); }
@Test public void testValidateRolesForShrinkSucceed() { groupInfo.getRoles().add("hadoop_tasktracker"); ValidateRolesUtil.validateRolesForShrink(fileDir, groupInfo); }