}
@Test
public void testValidateRoleDependency() {
ClusterBlueprint blueprint = new ClusterBlueprint();
List<String> failedMsgList = new ArrayList<String>();
assertEquals(false, validator.validateRoleDependency(failedMsgList, blueprint));
NodeGroupInfo compute = new NodeGroupInfo();
NodeGroupInfo data = new NodeGroupInfo();
List<NodeGroupInfo> nodeGroupInfos = new ArrayList<NodeGroupInfo>();
nodeGroupInfos.add(compute);
nodeGroupInfos.add(data);
blueprint.setNodeGroups(nodeGroupInfos);
assertEquals(false, validator.validateRoleDependency(failedMsgList, blueprint));
assertEquals(2, failedMsgList.size());
failedMsgList.clear();
blueprint.setExternalHDFS("hdfs://192.168.0.2:9000");
compute.setRoles(Arrays.asList(HadoopRole.HADOOP_TASKTRACKER.toString()));
data.setRoles(Arrays.asList(HadoopRole.HADOOP_DATANODE.toString()));
assertEquals(false, validator.validateRoleDependency(failedMsgList, blueprint));
assertEquals(2, failedMsgList.size());
assertEquals("Duplicate NameNode or DataNode role.", failedMsgList.get(0));
assertEquals("Missing JobTracker or ResourceManager role.",
failedMsgList.get(1));
failedMsgList.clear();
blueprint.setExternalHDFS("");
nodeGroupInfos = new ArrayList<NodeGroupInfo>();
nodeGroupInfos.add(compute);
blueprint.setNodeGroups(nodeGroupInfos);
assertEquals(false, validator.validateRoleDependency(failedMsgList, blueprint));
assertEquals(1, failedMsgList.size());
assertEquals("Missing role(s): hadoop_jobtracker for service: MAPRED.", failedMsgList.get(0));
failedMsgList.clear();
NodeGroupInfo master = new NodeGroupInfo();
master.setRoles(Arrays.asList(HadoopRole.HADOOP_JOBTRACKER_ROLE
.toString()));
nodeGroupInfos = new ArrayList<NodeGroupInfo>();
nodeGroupInfos.add(master);
nodeGroupInfos.add(compute);
blueprint.setNodeGroups(nodeGroupInfos);
assertEquals(false, validator.validateRoleDependency(failedMsgList, blueprint));
assertEquals(1, failedMsgList.size());
assertEquals("Some dependent services " + EnumSet.of(ServiceType.HDFS)
+ " " + ServiceType.MAPRED
+ " relies on cannot be found in the spec file.",