}
@Transactional
private void replaceNodeEntity(BaseNode vNode) {
logger.info("Add or replace node info for VM " + vNode.getVmName());
ClusterEntity cluster =
getClusterEntityMgr().findByName(vNode.getClusterName());
AuAssert.check(cluster != null);
NodeGroupEntity nodeGroupEntity =
getClusterEntityMgr().findByName(vNode.getClusterName(),
vNode.getGroupName());
AuAssert.check(nodeGroupEntity != null);
if (nodeGroupEntity.getNodes() == null) {
nodeGroupEntity.setNodes(new LinkedList<NodeEntity>());
}
boolean insert = false;
NodeEntity nodeEntity =
getClusterEntityMgr()
.findByName(nodeGroupEntity, vNode.getVmName());
// if node already exists, replace the value with new one from vNode.
if (nodeEntity == null) {
nodeEntity = new NodeEntity();
nodeGroupEntity.getNodes().add(nodeEntity);
insert = true;
}
nodeEntity.setVmName(vNode.getVmName());
setNodeStatus(nodeEntity, vNode);
if (vNode.getVmMobId() == null && nodeEntity.getMoId() != null) {
vNode.setVmMobId(nodeEntity.getMoId());
}
// set node version
nodeEntity.setVersion(cluster.getVersion());
//set vc resource pool entity
nodeEntity.setVcRp(rpDao.findByClusterAndRp(vNode.getTargetVcCluster(),
vNode.getTargetRp()));