Search in sources :

Example 96 with ListResponse

use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.

the class RegisterIsoCmdByAdmin method execute.

@Override
public void execute() throws ResourceAllocationException {
    VirtualMachineTemplate template = _templateService.registerIso(this);
    if (template != null) {
        ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
        List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(ResponseView.Full, template, zoneId, false);
        response.setResponses(templateResponses);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register iso");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse)

Example 97 with ListResponse

use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.

the class ListLoadBalancerRuleInstancesCmdByAdmin method execute.

@Override
public void execute() {
    Pair<List<? extends UserVm>, List<String>> vmServiceMap = _lbService.listLoadBalancerInstances(this);
    List<? extends UserVm> result = vmServiceMap.first();
    List<String> serviceStates = vmServiceMap.second();
    if (!isListLbVmip()) {
        // list lb instances
        ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
        List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
        if (result != null) {
            vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
            for (int i = 0; i < result.size(); i++) {
                vmResponses.get(i).setServiceState(serviceStates.get(i));
            }
        }
        response.setResponses(vmResponses);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        ListResponse<LoadBalancerRuleVmMapResponse> lbRes = new ListResponse<LoadBalancerRuleVmMapResponse>();
        List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
        List<LoadBalancerRuleVmMapResponse> listlbVmRes = new ArrayList<LoadBalancerRuleVmMapResponse>();
        if (result != null) {
            vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Full, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
            List<String> ipaddr = null;
            for (int i = 0; i < result.size(); i++) {
                LoadBalancerRuleVmMapResponse lbRuleVmIpResponse = new LoadBalancerRuleVmMapResponse();
                vmResponses.get(i).setServiceState(serviceStates.get(i));
                lbRuleVmIpResponse.setUserVmResponse(vmResponses.get(i));
                //get vm id from the uuid
                VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmResponses.get(i).getId());
                lbRuleVmIpResponse.setIpAddr(_lbService.listLbVmIpAddress(getId(), lbvm.getId()));
                lbRuleVmIpResponse.setObjectName("lbrulevmidip");
                listlbVmRes.add(lbRuleVmIpResponse);
            }
        }
        lbRes.setResponseName(getCommandName());
        lbRes.setResponses(listlbVmRes);
        setResponseObject(lbRes);
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) LoadBalancerRuleVmMapResponse(org.apache.cloudstack.api.response.LoadBalancerRuleVmMapResponse) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) UserVm(com.cloud.uservm.UserVm) List(java.util.List) ArrayList(java.util.ArrayList) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 98 with ListResponse

use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.

the class ListNetworksCmdByAdmin method execute.

@Override
public void execute() {
    Pair<List<? extends Network>, Integer> networks = _networkService.searchForNetworks(this);
    ListResponse<NetworkResponse> response = new ListResponse<NetworkResponse>();
    List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();
    for (Network network : networks.first()) {
        NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(ResponseView.Full, network);
        networkResponses.add(networkResponse);
    }
    response.setResponses(networkResponses, networks.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) Network(com.cloud.network.Network) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 99 with ListResponse

use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.

the class GetUsageRecordsCmd method execute.

@Override
public void execute() {
    Pair<List<? extends Usage>, Integer> usageRecords = _usageService.getUsageRecords(this);
    ListResponse<UsageRecordResponse> response = new ListResponse<UsageRecordResponse>();
    List<UsageRecordResponse> usageResponses = new ArrayList<UsageRecordResponse>();
    if (usageRecords != null) {
        for (Usage usageRecord : usageRecords.first()) {
            UsageRecordResponse usageResponse = _responseGenerator.createUsageResponse(usageRecord);
            usageResponse.setObjectName("usagerecord");
            usageResponses.add(usageResponse);
        }
        response.setResponses(usageResponses, usageRecords.second());
    }
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : UsageRecordResponse(org.apache.cloudstack.api.response.UsageRecordResponse) Usage(org.apache.cloudstack.usage.Usage) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 100 with ListResponse

use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.

the class ListRecurringSnapshotScheduleCmd method execute.

@Override
public void execute() {
    List<? extends SnapshotSchedule> snapshotSchedules = _snapshotService.findRecurringSnapshotSchedule(this);
    ListResponse<SnapshotScheduleResponse> response = new ListResponse<SnapshotScheduleResponse>();
    List<SnapshotScheduleResponse> snapshotScheduleResponses = new ArrayList<SnapshotScheduleResponse>();
    for (SnapshotSchedule snapshotSchedule : snapshotSchedules) {
        SnapshotScheduleResponse snapSchedResponse = _responseGenerator.createSnapshotScheduleResponse(snapshotSchedule);
        snapshotScheduleResponses.add(snapSchedResponse);
    }
    response.setResponses(snapshotScheduleResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) SnapshotScheduleResponse(org.apache.cloudstack.api.response.SnapshotScheduleResponse) ArrayList(java.util.ArrayList) SnapshotSchedule(com.cloud.storage.snapshot.SnapshotSchedule)

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