use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.
the class ApiResponseHelper method createUpgradeRouterTemplateResponse.
@Override
public ListResponse<UpgradeRouterTemplateResponse> createUpgradeRouterTemplateResponse(List<Long> jobIds) {
ListResponse<UpgradeRouterTemplateResponse> response = new ListResponse<UpgradeRouterTemplateResponse>();
List<UpgradeRouterTemplateResponse> responses = new ArrayList<UpgradeRouterTemplateResponse>();
for (Long jobId : jobIds) {
UpgradeRouterTemplateResponse routerResponse = new UpgradeRouterTemplateResponse();
AsyncJob job = _entityMgr.findById(AsyncJob.class, jobId);
routerResponse.setAsyncJobId((job.getUuid()));
routerResponse.setObjectName("asyncjobs");
responses.add(routerResponse);
}
response.setResponses(responses);
return response;
}
use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.
the class QuotaTariffListCmd method execute.
@Override
public void execute() {
final Pair<List<QuotaTariffVO>, Integer> result = _responseBuilder.listQuotaTariffPlans(this);
final List<QuotaTariffResponse> responses = new ArrayList<QuotaTariffResponse>();
for (final QuotaTariffVO resource : result.first()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Result desc=" + resource.getDescription() + " date=" + resource.getEffectiveOn() + " val=" + resource.getCurrencyValue());
}
responses.add(_responseBuilder.createQuotaTariffResponse(resource));
}
final ListResponse<QuotaTariffResponse> response = new ListResponse<QuotaTariffResponse>();
response.setResponses(responses, result.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.
the class ListSimulatorHAStateTransitions method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
final Host host = _resourceService.getHost(getHostId());
if (host == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find host by ID: " + getHostId());
}
final SimulatorHAProvider simulatorHAProvider = (SimulatorHAProvider) haManager.getHAProvider(SimulatorHAProvider.class.getSimpleName().toLowerCase());
List<SimulatorHAStateResponse> recentStates = new ArrayList<>();
if (simulatorHAProvider != null) {
recentStates = simulatorHAProvider.listHAStateTransitions(host.getId());
}
final ListResponse<SimulatorHAStateResponse> response = new ListResponse<>();
response.setResponses(recentStates);
response.setResponseName(getCommandName());
response.setObjectName("simulatorhastatetransition");
setResponseObject(response);
}
use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.
the class ListPaloAltoFirewallsCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
List<ExternalFirewallDeviceVO> fwDevices = _paFwService.listPaloAltoFirewalls(this);
ListResponse<PaloAltoFirewallResponse> response = new ListResponse<PaloAltoFirewallResponse>();
List<PaloAltoFirewallResponse> fwDevicesResponse = new ArrayList<PaloAltoFirewallResponse>();
if (fwDevices != null && !fwDevices.isEmpty()) {
for (ExternalFirewallDeviceVO fwDeviceVO : fwDevices) {
PaloAltoFirewallResponse deviceResponse = _paFwService.createPaloAltoFirewallResponse(fwDeviceVO);
fwDevicesResponse.add(deviceResponse);
}
}
response.setResponses(fwDevicesResponse);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.
the class UnmanagedVMsManagerImpl method listUnmanagedInstances.
@Override
public ListResponse<UnmanagedInstanceResponse> listUnmanagedInstances(ListUnmanagedInstancesCmd cmd) {
final Account caller = CallContext.current().getCallingAccount();
if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
throw new PermissionDeniedException(String.format("Cannot perform this operation, Calling account is not root admin: %s", caller.getUuid()));
}
final Long clusterId = cmd.getClusterId();
if (clusterId == null) {
throw new InvalidParameterValueException(String.format("Cluster ID cannot be null"));
}
final Cluster cluster = clusterDao.findById(clusterId);
if (cluster == null) {
throw new InvalidParameterValueException(String.format("Cluster ID: %d cannot be found", clusterId));
}
if (cluster.getHypervisorType() != Hypervisor.HypervisorType.VMware) {
throw new InvalidParameterValueException(String.format("VM ingestion is currently not supported for hypervisor: %s", cluster.getHypervisorType().toString()));
}
String keyword = cmd.getKeyword();
if (StringUtils.isNotEmpty(keyword)) {
keyword = keyword.toLowerCase();
}
List<HostVO> hosts = resourceManager.listHostsInClusterByStatus(clusterId, Status.Up);
List<String> additionalNameFilters = getAdditionalNameFilters(cluster);
List<UnmanagedInstanceResponse> responses = new ArrayList<>();
for (HostVO host : hosts) {
if (host.isInMaintenanceStates()) {
continue;
}
List<String> managedVms = new ArrayList<>();
managedVms.addAll(additionalNameFilters);
managedVms.addAll(getHostManagedVms(host));
GetUnmanagedInstancesCommand command = new GetUnmanagedInstancesCommand();
command.setInstanceName(cmd.getName());
command.setManagedInstancesNames(managedVms);
Answer answer = agentManager.easySend(host.getId(), command);
if (!(answer instanceof GetUnmanagedInstancesAnswer)) {
continue;
}
GetUnmanagedInstancesAnswer unmanagedInstancesAnswer = (GetUnmanagedInstancesAnswer) answer;
HashMap<String, UnmanagedInstanceTO> unmanagedInstances = new HashMap<>(unmanagedInstancesAnswer.getUnmanagedInstances());
Set<String> keys = unmanagedInstances.keySet();
for (String key : keys) {
UnmanagedInstanceTO instance = unmanagedInstances.get(key);
if (StringUtils.isNotEmpty(keyword) && !instance.getName().toLowerCase().contains(keyword)) {
continue;
}
responses.add(createUnmanagedInstanceResponse(instance, cluster, host));
}
}
ListResponse<UnmanagedInstanceResponse> listResponses = new ListResponse<>();
listResponses.setResponses(responses, responses.size());
return listResponses;
}
Aggregations