Search in sources :

Example 41 with ListResponse

use of com.cloud.api.response.ListResponse in project CloudStack-archive by CloudStack-extras.

the class ListSwiftsCmd method execute.

@Override
public void execute() {
    List<? extends Swift> result = _resourceService.listSwifts(this);
    ListResponse<SwiftResponse> response = new ListResponse<SwiftResponse>();
    List<SwiftResponse> swiftResponses = new ArrayList<SwiftResponse>();
    if (result != null) {
        SwiftResponse swiftResponse = null;
        for (Swift swift : result) {
            swiftResponse = _responseGenerator.createSwiftResponse(swift);
            swiftResponse.setResponseName(getCommandName());
            swiftResponse.setObjectName("swift");
            swiftResponses.add(swiftResponse);
        }
    }
    response.setResponses(swiftResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) SwiftResponse(com.cloud.api.response.SwiftResponse) ArrayList(java.util.ArrayList) Swift(com.cloud.storage.Swift)

Example 42 with ListResponse

use of com.cloud.api.response.ListResponse in project CloudStack-archive by CloudStack-extras.

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) {
            for (Cluster cluster : result) {
                ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
                clusterResponses.add(clusterResponse);
            }
        } else {
            throw new ServerApiException(BaseCmd.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(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    } catch (ResourceInUseException ex) {
        s_logger.warn("Exception: ", ex);
        ServerApiException e = new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
        for (IdentityProxy proxyObj : ex.getIdProxyList()) {
            e.addProxyObject(proxyObj.getTableName(), proxyObj.getValue(), proxyObj.getidFieldName());
        }
        throw e;
    }
}
Also used : IdentityProxy(com.cloud.utils.IdentityProxy) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) ResourceInUseException(com.cloud.exception.ResourceInUseException) ArrayList(java.util.ArrayList) ClusterResponse(com.cloud.api.response.ClusterResponse) Cluster(com.cloud.org.Cluster) DiscoveryException(com.cloud.exception.DiscoveryException)

Example 43 with ListResponse

use of com.cloud.api.response.ListResponse in project CloudStack-archive by CloudStack-extras.

the class AddHostCmd method execute.

@Override
public void execute() {
    try {
        List<? extends Host> result = _resourceService.discoverHosts(this);
        ListResponse<HostResponse> response = new ListResponse<HostResponse>();
        List<HostResponse> hostResponses = new ArrayList<HostResponse>();
        if (result != null && result.size() > 0) {
            for (Host host : result) {
                HostResponse hostResponse = _responseGenerator.createHostResponse(host);
                hostResponses.add(hostResponse);
            }
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add host");
        }
        response.setResponses(hostResponses);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (DiscoveryException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) HostResponse(com.cloud.api.response.HostResponse) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host) DiscoveryException(com.cloud.exception.DiscoveryException)

Example 44 with ListResponse

use of com.cloud.api.response.ListResponse in project CloudStack-archive by CloudStack-extras.

the class ListEventTypesCmd method execute.

@Override
public void execute() {
    String[] result = _mgr.listEventTypes();
    ListResponse<EventTypeResponse> response = new ListResponse<EventTypeResponse>();
    ArrayList<EventTypeResponse> responses = new ArrayList<EventTypeResponse>();
    if (result != null) {
        for (String eventType : result) {
            EventTypeResponse eventTypeResponse = new EventTypeResponse();
            eventTypeResponse.setName(eventType);
            eventTypeResponse.setObjectName("eventtype");
            responses.add(eventTypeResponse);
        }
    }
    response.setResponses(responses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : EventTypeResponse(com.cloud.api.response.EventTypeResponse) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList)

Example 45 with ListResponse

use of com.cloud.api.response.ListResponse in project CloudStack-archive by CloudStack-extras.

the class ListEventsCmd method execute.

@Override
public void execute() {
    List<? extends Event> result = _mgr.searchForEvents(this);
    ListResponse<EventResponse> response = new ListResponse<EventResponse>();
    List<EventResponse> eventResponses = new ArrayList<EventResponse>();
    for (Event event : result) {
        eventResponses.add(_responseGenerator.createEventResponse(event));
    }
    response.setResponses(eventResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) EventResponse(com.cloud.api.response.EventResponse) ArrayList(java.util.ArrayList) Event(com.cloud.event.Event)

Aggregations

ListResponse (com.cloud.api.response.ListResponse)57 ArrayList (java.util.ArrayList)54 ServerApiException (com.cloud.api.ServerApiException)7 TemplateResponse (com.cloud.api.response.TemplateResponse)3 ClusterResponse (com.cloud.api.response.ClusterResponse)2 DomainResponse (com.cloud.api.response.DomainResponse)2 HostResponse (com.cloud.api.response.HostResponse)2 Domain (com.cloud.domain.Domain)2 DiscoveryException (com.cloud.exception.DiscoveryException)2 Host (com.cloud.host.Host)2 Cluster (com.cloud.org.Cluster)2 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)2 Alert (com.cloud.alert.Alert)1 AccountResponse (com.cloud.api.response.AccountResponse)1 AlertResponse (com.cloud.api.response.AlertResponse)1 AsyncJobResponse (com.cloud.api.response.AsyncJobResponse)1 ConfigurationResponse (com.cloud.api.response.ConfigurationResponse)1 DiskOfferingResponse (com.cloud.api.response.DiskOfferingResponse)1 DomainRouterResponse (com.cloud.api.response.DomainRouterResponse)1 EventResponse (com.cloud.api.response.EventResponse)1