cluster.setDistro("apache");
cluster.setTopologyPolicy(TopologyType.NONE);
cluster.setStatus(ClusterStatus.PROVISIONING);
List<NodeGroupEntity> nodeGroups = new LinkedList<NodeGroupEntity>();
NodeGroupEntity hdfsGroup = new NodeGroupEntity(HDFS_GROUP);
hdfsGroup.setCluster(cluster);
hdfsGroup.setCpuNum(1);
hdfsGroup.setMemorySize(2048);
hdfsGroup.setStorageSize(20);
hdfsGroup.setStorageType(DatastoreType.LOCAL);
hdfsGroup.setDefineInstanceNum(2);
hdfsGroup.setHaFlag("on");
List<NodeEntity> hdfsNodes = new LinkedList<NodeEntity>();
NodeEntity hdfsNode1 = new NodeEntity();
NodeEntity hdfsNode2 = new NodeEntity();
hdfsNode1.setVmName("hdfsNode1");
hdfsNode2.setVmName("hdfsNode2");
VcResourcePoolEntity vcRp1 = new VcResourcePoolEntity();
vcRp1.setName("RP1");
vcRp1.setVcCluster("Cluster1");
vcRp1.setVcResourcePool("VcRp1");
resourcePoolDao.insert(vcRp1);
hdfsNode1.setVcRp(vcRp1);
hdfsNodes.add(hdfsNode1);
hdfsNodes.add(hdfsNode2);
hdfsGroup.setNodes(hdfsNodes);
ArrayList<String> roleStr = new ArrayList<String>();
roleStr.add(HADOOP_ROLE);
roleStr.add(DATA_NODE_ROLE);
hdfsGroup.setRoles((new Gson()).toJson(roleStr));
nodeGroups.add(hdfsGroup);
NodeGroupEntity computeGroup = new NodeGroupEntity(COMPUTE_GROUP);
computeGroup.setCluster(cluster);
computeGroup.setCpuNum(1);
computeGroup.setMemorySize(2048);
computeGroup.setStorageSize(20);
computeGroup.setStorageType(DatastoreType.SHARED);
computeGroup.setDefineInstanceNum(1);
computeGroup.setHaFlag("on");
List<NodeEntity> computeNodes = new LinkedList<NodeEntity>();
NodeEntity computeNode1 = new NodeEntity();
computeNode1.setVmName("computeNode1");
computeNodes.add(computeNode1);
computeGroup.setNodes(computeNodes);
roleStr.clear();
roleStr.add(HADOOP_ROLE);
roleStr.add(COMPUTE_NODE_ROLE);
computeGroup.setRoles((new Gson()).toJson(roleStr));
Set<NodeGroupAssociation> associations =
new HashSet<NodeGroupAssociation>();
NodeGroupAssociation association = new NodeGroupAssociation();
association.setReferencedGroup(HDFS_GROUP);
association.setAssociationType(GroupAssociationType.STRICT);
association.setNodeGroup(computeGroup);
associations.add(association);
computeGroup.setGroupAssociations(associations);
nodeGroups.add(computeGroup);
cluster.setNodeGroups(nodeGroups);
// test insert()
clusterDao.insert(cluster);
ClusterEntity clusterRead = clusterDao.findByName(CLUSTER_NAME);
Assert.assertNotNull(clusterRead);
Assert.assertTrue(clusterRead.getNodeGroups().size() == 2);
NodeGroupEntity groupRead =
nodeGroupDao.findByName(clusterRead, COMPUTE_GROUP);
Assert.assertNotNull(groupRead);
Assert.assertTrue(groupRead.getCpuNum() == 1);
Assert.assertTrue(groupRead.getGroupAssociations().size() == 1);
// test updateStatus()
clusterDao.updateStatus(CLUSTER_NAME, ClusterStatus.VHM_RUNNING);
clusterRead = clusterDao.findByName(CLUSTER_NAME);
Assert.assertTrue(clusterRead.getStatus() == ClusterStatus.VHM_RUNNING);