Search in sources :

Example 31 with ListResponse

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

the class ListBigSwitchBcfDevicesCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        final List<BigSwitchBcfDeviceVO> bigswitchDevices = bigswitchBcfElementService.listBigSwitchBcfDevices(this);
        final ListResponse<BigSwitchBcfDeviceResponse> response = new ListResponse<BigSwitchBcfDeviceResponse>();
        final List<BigSwitchBcfDeviceResponse> bigswitchDevicesResponse = new ArrayList<BigSwitchBcfDeviceResponse>();
        if (bigswitchDevices != null && !bigswitchDevices.isEmpty()) {
            for (final BigSwitchBcfDeviceVO bigswitchDeviceVO : bigswitchDevices) {
                final BigSwitchBcfDeviceResponse bigswitchDeviceResponse = bigswitchBcfElementService.createBigSwitchBcfDeviceResponse(bigswitchDeviceVO);
                bigswitchDevicesResponse.add(bigswitchDeviceResponse);
            }
        }
        response.setResponses(bigswitchDevicesResponse);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage(), invalidParamExcp);
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage(), runtimeExcp);
    }
}
Also used : 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) BigSwitchBcfDeviceResponse(com.cloud.api.response.BigSwitchBcfDeviceResponse) BigSwitchBcfDeviceVO(com.cloud.network.BigSwitchBcfDeviceVO)

Example 32 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 33 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 34 with ListResponse

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

the class ListCfgsByCmd method execute.

@Override
public void execute() {
    Pair<List<? extends Configuration>, Integer> result = _mgr.searchForConfigurations(this);
    ListResponse<ConfigurationResponse> response = new ListResponse<ConfigurationResponse>();
    List<ConfigurationResponse> configResponses = new ArrayList<ConfigurationResponse>();
    for (Configuration cfg : result.first()) {
        ConfigurationResponse cfgResponse = _responseGenerator.createConfigurationResponse(cfg);
        cfgResponse.setObjectName("configuration");
        if (getZoneId() != null) {
            cfgResponse.setScope("zone");
        }
        if (getClusterId() != null) {
            cfgResponse.setScope("cluster");
        }
        if (getStoragepoolId() != null) {
            cfgResponse.setScope("storagepool");
        }
        if (getAccountId() != null) {
            cfgResponse.setScope("account");
        }
        if (getImageStoreId() != null) {
            cfgResponse.setScope("imagestore");
        }
        configResponses.add(cfgResponse);
    }
    response.setResponses(configResponses, result.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ConfigurationResponse(org.apache.cloudstack.api.response.ConfigurationResponse) Configuration(org.apache.cloudstack.config.Configuration) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 35 with ListResponse

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

the class AddClusterCmd method execute.

@Override
public void execute() {
    try {
        List<? extends Cluster> result = _resourceService.discoverCluster(this);
        ListResponse<ClusterResponse> response = new ListResponse<ClusterResponse>();
        List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();
        if (result != null && result.size() > 0) {
            for (Cluster cluster : result) {
                ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
                clusterResponses.add(clusterResponse);
            }
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add cluster");
        }
        response.setResponses(clusterResponses);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (DiscoveryException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (ResourceInUseException ex) {
        s_logger.warn("Exception: ", ex);
        ServerApiException e = new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
        for (String proxyObj : ex.getIdProxyList()) {
            e.addProxyObject(proxyObj);
        }
        throw e;
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceInUseException(com.cloud.exception.ResourceInUseException) ArrayList(java.util.ArrayList) ClusterResponse(org.apache.cloudstack.api.response.ClusterResponse) Cluster(com.cloud.org.Cluster) DiscoveryException(com.cloud.exception.DiscoveryException)

Aggregations

ListResponse (org.apache.cloudstack.api.response.ListResponse)149 ArrayList (java.util.ArrayList)134 List (java.util.List)62 ServerApiException (org.apache.cloudstack.api.ServerApiException)44 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)29 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)21 Network (com.cloud.network.Network)9 DedicatedResources (com.cloud.dc.DedicatedResources)8 NetworkResponse (org.apache.cloudstack.api.response.NetworkResponse)8 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)7 TemplateResponse (org.apache.cloudstack.api.response.TemplateResponse)7 Host (com.cloud.host.Host)6 Domain (com.cloud.domain.Domain)5 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)5 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)4 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 Account (com.cloud.user.Account)4