Search in sources :

Example 1 with ListResponse

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

the class ListNuageVspDevicesCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        List<NuageVspDeviceVO> nuageDevices = _nuageVspManager.listNuageVspDevices(this);
        ListResponse<NuageVspDeviceResponse> response = new ListResponse<NuageVspDeviceResponse>();
        List<NuageVspDeviceResponse> nuageDevicesResponse = new ArrayList<NuageVspDeviceResponse>();
        if (nuageDevices != null && !nuageDevices.isEmpty()) {
            for (NuageVspDeviceVO nuageDeviceVO : nuageDevices) {
                NuageVspDeviceResponse nuageDeviceResponse = _nuageVspManager.createNuageVspDeviceResponse(nuageDeviceVO);
                nuageDevicesResponse.add(nuageDeviceResponse);
            }
        }
        response.setResponses(nuageDevicesResponse);
        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 : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) NuageVspDeviceResponse(com.cloud.api.response.NuageVspDeviceResponse)

Example 2 with ListResponse

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

the class ListPublicIpAddressesCmdByAdmin method execute.

@Override
public void execute() {
    Pair<List<? extends IpAddress>, Integer> result = _mgr.searchForIPAddresses(this);
    ListResponse<IPAddressResponse> response = new ListResponse<IPAddressResponse>();
    List<IPAddressResponse> ipAddrResponses = new ArrayList<IPAddressResponse>();
    for (IpAddress ipAddress : result.first()) {
        IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Full, ipAddress);
        ipResponse.setObjectName("publicipaddress");
        ipAddrResponses.add(ipResponse);
    }
    response.setResponses(ipAddrResponses, result.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IpAddress(com.cloud.network.IpAddress) IPAddressResponse(org.apache.cloudstack.api.response.IPAddressResponse)

Example 3 with ListResponse

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

the class ListRolesCmd method setupResponse.

private void setupResponse(final List<Role> roles) {
    final ListResponse<RoleResponse> response = new ListResponse<>();
    final List<RoleResponse> roleResponses = new ArrayList<>();
    for (final Role role : roles) {
        if (role == null) {
            continue;
        }
        final RoleResponse roleResponse = new RoleResponse();
        roleResponse.setId(role.getUuid());
        roleResponse.setRoleName(role.getName());
        roleResponse.setRoleType(role.getRoleType());
        roleResponse.setDescription(role.getDescription());
        roleResponse.setObjectName("role");
        roleResponses.add(roleResponse);
    }
    response.setResponses(roleResponses);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : Role(org.apache.cloudstack.acl.Role) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) RoleResponse(org.apache.cloudstack.api.response.RoleResponse)

Example 4 with ListResponse

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

the class RegisterTemplateCmdByAdmin method execute.

@Override
public void execute() throws ResourceAllocationException {
    try {
        VirtualMachineTemplate template = _templateService.registerTemplate(this);
        if (template != null) {
            ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
            List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Full, template, zoneId, false);
            response.setResponses(templateResponses);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register template");
        }
    } catch (URISyntaxException ex1) {
        s_logger.info(ex1);
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex1.getMessage());
    }
}
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) URISyntaxException(java.net.URISyntaxException)

Example 5 with ListResponse

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

the class IAMApiServiceImpl method listIAMGroups.

@Override
public ListResponse<IAMGroupResponse> listIAMGroups(Long iamGroupId, String iamGroupName, Long domainId, Long startIndex, Long pageSize) {
    // acl check
    Account caller = CallContext.current().getCallingAccount();
    Domain domain = null;
    if (domainId != null) {
        domain = _domainDao.findById(domainId);
        if (domain == null) {
            throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist");
        }
        _accountMgr.checkAccess(caller, domain);
    } else {
        domain = _domainDao.findById(caller.getDomainId());
    }
    String domainPath = domain.getPath();
    // search for groups
    Pair<List<IAMGroup>, Integer> result = _iamSrv.listIAMGroups(iamGroupId, iamGroupName, domainPath, startIndex, pageSize);
    // generate group response
    ListResponse<IAMGroupResponse> response = new ListResponse<IAMGroupResponse>();
    List<IAMGroupResponse> groupResponses = new ArrayList<IAMGroupResponse>();
    for (IAMGroup group : result.first()) {
        IAMGroupResponse resp = createIAMGroupResponse(group);
        groupResponses.add(resp);
    }
    response.setResponses(groupResponses, result.second());
    return response;
}
Also used : Account(com.cloud.user.Account) ListResponse(org.apache.cloudstack.api.response.ListResponse) IAMGroup(org.apache.cloudstack.iam.api.IAMGroup) ArrayList(java.util.ArrayList) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) IAMGroupResponse(org.apache.cloudstack.api.response.iam.IAMGroupResponse) List(java.util.List) ArrayList(java.util.ArrayList) Domain(com.cloud.domain.Domain)

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