Search in sources :

Example 71 with ListResponse

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;
}
Also used : UpgradeRouterTemplateResponse(org.apache.cloudstack.api.response.UpgradeRouterTemplateResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) AsyncJob(org.apache.cloudstack.framework.jobs.AsyncJob)

Example 72 with ListResponse

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);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) QuotaTariffVO(org.apache.cloudstack.quota.vo.QuotaTariffVO) QuotaTariffResponse(org.apache.cloudstack.api.response.QuotaTariffResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 73 with ListResponse

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);
}
Also used : SimulatorHAProvider(org.apache.cloudstack.ha.SimulatorHAProvider) ServerApiException(org.apache.cloudstack.api.ServerApiException) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host) SimulatorHAStateResponse(com.cloud.api.response.SimulatorHAStateResponse)

Example 74 with ListResponse

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());
    }
}
Also used : ExternalFirewallDeviceVO(com.cloud.network.dao.ExternalFirewallDeviceVO) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PaloAltoFirewallResponse(com.cloud.api.response.PaloAltoFirewallResponse) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList)

Example 75 with ListResponse

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;
}
Also used : Account(com.cloud.user.Account) ListResponse(org.apache.cloudstack.api.response.ListResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cluster(com.cloud.org.Cluster) GetUnmanagedInstancesCommand(com.cloud.agent.api.GetUnmanagedInstancesCommand) HostVO(com.cloud.host.HostVO) UnmanagedInstanceResponse(org.apache.cloudstack.api.response.UnmanagedInstanceResponse) Answer(com.cloud.agent.api.Answer) GetUnmanagedInstancesAnswer(com.cloud.agent.api.GetUnmanagedInstancesAnswer) PrepareUnmanageVMInstanceAnswer(com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) GetUnmanagedInstancesAnswer(com.cloud.agent.api.GetUnmanagedInstancesAnswer) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Aggregations

ListResponse (org.apache.cloudstack.api.response.ListResponse)177 ArrayList (java.util.ArrayList)160 List (java.util.List)70 ServerApiException (org.apache.cloudstack.api.ServerApiException)49 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)32 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 Account (com.cloud.user.Account)10 Network (com.cloud.network.Network)9 Host (com.cloud.host.Host)8 NetworkResponse (org.apache.cloudstack.api.response.NetworkResponse)8 Test (org.junit.Test)8 DedicatedResources (com.cloud.dc.DedicatedResources)7 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)7 TemplateResponse (org.apache.cloudstack.api.response.TemplateResponse)7 Domain (com.cloud.domain.Domain)6 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)5 ApiDiscoveryResponse (org.apache.cloudstack.api.response.ApiDiscoveryResponse)5 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)4 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4