use of com.cloud.api.response.HAWorkerResponse in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method listHAWorkers.
@Override
public ListResponse<HAWorkerResponse> listHAWorkers(final ListHAWorkersCmd cmd) {
final ListResponse<HAWorkerResponse> haWorkerList = new ListResponse<>();
final List<HaWorkVO> haWorkers = _haDao.listAll();
final List<HAWorkerResponse> haWorkerResponses = new ArrayList<>();
haWorkers.stream().filter(haWorker -> {
final Account account = CallContext.current().getCallingAccount();
if (account.getDomainId() == Domain.ROOT_DOMAIN) {
return cmd.getId() == null || (cmd.getId() != null && cmd.getId() == haWorker.getId());
}
// Not a root administrator, check if the user owns the virtual machine
final VirtualMachine virtualMachine = _vmInstanceDao.findByIdIncludingRemoved(haWorker.getInstanceId());
return virtualMachine != null && virtualMachine.getDomainId() == account.getDomainId() && (cmd.getId() == null || (cmd.getId() != null && haWorker.getId() == cmd.getId()));
}).forEach(haWorker -> {
final HAWorkerResponse haWorkerResponse = new HAWorkerResponse();
haWorkerResponse.setObjectName("haworker");
haWorkerResponse.setId(haWorker.getId());
haWorkerResponse.setType(haWorker.getWorkType());
haWorkerResponse.setCreated(haWorker.getCreated());
haWorkerResponse.setStep(haWorker.getStep());
haWorkerResponse.setTaken(haWorker.getDateTaken());
haWorkerResponse.setState(haWorker.getPreviousState());
final VirtualMachine virtualMachine = _vmInstanceDao.findByIdIncludingRemoved(haWorker.getInstanceId());
if (virtualMachine != null) {
haWorkerResponse.setVirtualMachineId(virtualMachine.getUuid());
haWorkerResponse.setVirtualMachineName(virtualMachine.getInstanceName());
haWorkerResponse.setVirtualMachineState(virtualMachine.getState());
final Domain domain = _domainDao.findById(virtualMachine.getDomainId());
if (domain != null) {
haWorkerResponse.setDomainId(domain.getUuid());
haWorkerResponse.setDomainName(domain.getName());
}
}
final Host host = _hostDao.findById(haWorker.getHostId());
if (host != null) {
haWorkerResponse.setHypervisor(host.getName());
}
if (haWorker.getServerId() != null) {
final ManagementServerHost managementServerHost = _mgmtServerHostDao.findByMsid(haWorker.getServerId());
if (managementServerHost != null) {
haWorkerResponse.setManagementServerName(managementServerHost.getName());
}
}
haWorkerResponses.add(haWorkerResponse);
});
haWorkerList.setResponses(haWorkerResponses);
return haWorkerList;
}
Aggregations