return toNodeGroupRead(false);
}
// this method should be called inside a transaction
public NodeGroupRead toNodeGroupRead(boolean ignoreObsoleteNode) {
NodeGroupRead nodeGroupRead = new NodeGroupRead();
nodeGroupRead.setName(this.name);
nodeGroupRead.setCpuNum(this.cpuNum);
nodeGroupRead.setMemCapacityMB(this.memorySize);
nodeGroupRead.setSwapRatio(this.swapRatio);
nodeGroupRead.setInstanceNum(this.getRealInstanceNum(ignoreObsoleteNode));
Gson gson = new Gson();
@SuppressWarnings("unchecked")
List<String> groupRoles = gson.fromJson(roles, List.class);
nodeGroupRead.setRoles(groupRoles);
StorageRead storage = new StorageRead();
storage.setType(this.storageType.toString());
storage.setSizeGB(this.storageSize);
// set dsNames/dsNames4Data/dsNames4System
List<String> datastoreNameList = getVcDatastoreNameList();
if (datastoreNameList != null && !datastoreNameList.isEmpty())
storage.setDsNames(datastoreNameList);
if (getSdDatastoreNameList() != null
&& !getSdDatastoreNameList().isEmpty())
storage.setDsNames4System(getSdDatastoreNameList());
if (getDdDatastoreNameList() != null
&& !getDdDatastoreNameList().isEmpty())
storage.setDsNames4Data(getDdDatastoreNameList());
nodeGroupRead.setStorage(storage);
List<NodeRead> nodeList = new ArrayList<NodeRead>();
for (NodeEntity node : this.nodes) {
if (ignoreObsoleteNode && (node.isObsoleteNode()
|| node.isDisconnected())) {
continue;
}
nodeList.add(node.toNodeRead(true));
}
nodeGroupRead.setInstances(nodeList);
List<GroupAssociation> associations = new ArrayList<GroupAssociation>();
for (NodeGroupAssociation relation : groupAssociations) {
GroupAssociation association = new GroupAssociation();
association.setReference(relation.getReferencedGroup());
association.setType(relation.getAssociationType());
associations.add(association);
}
PlacementPolicy policy = new PlacementPolicy();
policy.setInstancePerHost(instancePerHost);
policy.setGroupAssociations(associations);
policy.setGroupRacks(new Gson().fromJson(groupRacks, GroupRacks.class));
nodeGroupRead.setPlacementPolicies(policy);
return nodeGroupRead;
}