Search in sources :

Example 76 with ListResponse

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

the class ListProjectRolePermissionsCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    List<ProjectRolePermission> projectRolePermissions = projRoleService.findAllProjectRolePermissions(getProjectId(), getProjectRoleId());
    final ProjectRole projectRole = projRoleService.findProjectRole(getProjectRoleId(), getProjectId());
    final ListResponse<ProjectRolePermissionResponse> response = new ListResponse<>();
    final List<ProjectRolePermissionResponse> rolePermissionResponses = new ArrayList<>();
    for (final ProjectRolePermission rolePermission : projectRolePermissions) {
        ProjectRole role = projectRole;
        if (role == null) {
            role = projRoleService.findProjectRole(rolePermission.getProjectRoleId(), rolePermission.getProjectId());
        }
        rolePermissionResponses.add(setupResponse(role, rolePermission));
    }
    response.setResponses(rolePermissionResponses);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ProjectRolePermission(org.apache.cloudstack.acl.ProjectRolePermission) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ProjectRolePermissionResponse(org.apache.cloudstack.api.response.ProjectRolePermissionResponse) ProjectRole(org.apache.cloudstack.acl.ProjectRole)

Example 77 with ListResponse

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

the class ListTrafficTypeImplementorsCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    List<Pair<TrafficType, String>> results = _networkService.listTrafficTypeImplementor(this);
    ListResponse<TrafficTypeImplementorResponse> response = new ListResponse<TrafficTypeImplementorResponse>();
    List<TrafficTypeImplementorResponse> responses = new ArrayList<TrafficTypeImplementorResponse>();
    for (Pair<TrafficType, String> r : results) {
        TrafficTypeImplementorResponse p = new TrafficTypeImplementorResponse();
        p.setTrafficType(r.first().toString());
        p.setImplementor(r.second());
        p.setObjectName("traffictypeimplementorresponse");
        responses.add(p);
    }
    response.setResponses(responses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) TrafficTypeImplementorResponse(org.apache.cloudstack.api.response.TrafficTypeImplementorResponse) ArrayList(java.util.ArrayList) Pair(com.cloud.utils.Pair) TrafficType(com.cloud.network.Networks.TrafficType)

Example 78 with ListResponse

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

the class ListUsageRecordsCmd 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>();
    Map<String, Set<ResourceTagResponse>> resourceTagResponseMap = null;
    if (usageRecords != null) {
        // read the resource tags details for all the resources in usage data and store in Map
        if (null != includeTags && includeTags) {
            resourceTagResponseMap = _responseGenerator.getUsageResourceTags();
        }
        for (Usage usageRecord : usageRecords.first()) {
            UsageRecordResponse usageResponse = _responseGenerator.createUsageResponse(usageRecord, resourceTagResponseMap, getOldFormat());
            if (usageResponse != null) {
                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) Set(java.util.Set) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 79 with ListResponse

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

the class PrepareTemplateCmd method execute.

@Override
public void execute() {
    ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
    VirtualMachineTemplate vmTemplate = _templateService.prepareTemplate(templateId, zoneId, storageId);
    List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Full, vmTemplate, zoneId, true);
    response.setResponses(templateResponses);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse)

Example 80 with ListResponse

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

the class ListTrafficTypesCmd method execute.

@Override
public void execute() {
    Pair<List<? extends PhysicalNetworkTrafficType>, Integer> trafficTypes = _networkService.listTrafficTypes(getPhysicalNetworkId());
    ListResponse<TrafficTypeResponse> response = new ListResponse<TrafficTypeResponse>();
    List<TrafficTypeResponse> trafficTypesResponses = new ArrayList<TrafficTypeResponse>();
    if (trafficTypes != null) {
        for (PhysicalNetworkTrafficType trafficType : trafficTypes.first()) {
            TrafficTypeResponse trafficTypeResponse = _responseGenerator.createTrafficTypeResponse(trafficType);
            trafficTypesResponses.add(trafficTypeResponse);
        }
        response.setResponses(trafficTypesResponses, trafficTypes.second());
        response.setResponseName(getCommandName());
    }
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) TrafficTypeResponse(org.apache.cloudstack.api.response.TrafficTypeResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PhysicalNetworkTrafficType(com.cloud.network.PhysicalNetworkTrafficType)

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