@SuppressWarnings("unchecked")
private NodeGroupCreate convertNodeGroups(ClusterEntity clusterEntity,
NodeGroupEntity ngEntity, String clusterName) {
Gson gson = new Gson();
List<String> groupRoles = gson.fromJson(ngEntity.getRoles(), List.class);
NodeGroupCreate group = new NodeGroupCreate();
group.setName(ngEntity.getName());
group.setRoles(groupRoles);
int cpu = ngEntity.getCpuNum();
if (cpu > 0) {
group.setCpuNum(cpu);
}
int memory = ngEntity.getMemorySize();
if (memory > 0) {
group.setMemCapacityMB(memory);
}
Float swapRatio = ngEntity.getSwapRatio();
if (swapRatio != null && swapRatio > 0) {
group.setSwapRatio(swapRatio);
}
if (ngEntity.getNodeType() != null) {
group.setInstanceType(ngEntity.getNodeType());
}
group.setInstanceNum(ngEntity.getDefineInstanceNum());
Integer instancePerHost = ngEntity.getInstancePerHost();
Set<NodeGroupAssociation> associonEntities =
ngEntity.getGroupAssociations();
String ngRacks = ngEntity.getGroupRacks();
if (instancePerHost == null
&& (associonEntities == null || associonEntities.isEmpty())
&& ngRacks == null) {
group.setPlacementPolicies(null);
} else {
PlacementPolicy policies = new PlacementPolicy();
policies.setInstancePerHost(instancePerHost);
if (ngRacks != null) {
policies.setGroupRacks((GroupRacks) new Gson().fromJson(ngRacks,
GroupRacks.class));
}
if (associonEntities != null) {
List<GroupAssociation> associons =
new ArrayList<GroupAssociation>(associonEntities.size());
for (NodeGroupAssociation ae : associonEntities) {
GroupAssociation a = new GroupAssociation();
a.setReference(ae.getReferencedGroup());
a.setType(ae.getAssociationType());
associons.add(a);
}
policies.setGroupAssociations(associons);
}
group.setPlacementPolicies(policies);
}
String rps = ngEntity.getVcRpNames();
if (rps != null && rps.length() > 0) {
logger.debug("resource pool specified at node group "
+ ngEntity.getName());
String[] rpNames = gson.fromJson(rps, String[].class);
List<VcCluster> vcClusters =
rpMgr.getVcResourcePoolByNameList(rpNames);
group.setVcClusters(vcClusters);
group.setRpNames(Arrays.asList(rpNames));
}
expandGroupStorage(ngEntity, group);
group.setHaFlag(ngEntity.getHaFlag());
if (ngEntity.getHadoopConfig() != null) {
Map<String, Object> hadoopConfig =
(new Gson()).fromJson(ngEntity.getHadoopConfig(), Map.class);
group.setConfiguration(hadoopConfig);
}
group.setVmFolderPath(ngEntity.getVmFolderPath());
return group;
}