Search in sources :

Example 6 with HostResponse

use of com.cloud.api.response.HostResponse 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 7 with HostResponse

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

the class ListHostsCmd method execute.

@Override
public void execute() {
    List<? extends Host> result = new ArrayList<Host>();
    List<? extends Host> hostsWithCapacity = new ArrayList<Host>();
    if (getVirtualMachineId() != null) {
        Pair<List<? extends Host>, List<? extends Host>> hostsForMigration = _mgr.listHostsForMigrationOfVM(getVirtualMachineId(), this.getStartIndex(), this.getPageSizeVal());
        result = hostsForMigration.first();
        hostsWithCapacity = hostsForMigration.second();
    } else {
        result = _mgr.searchForServers(this);
    }
    ListResponse<HostResponse> response = new ListResponse<HostResponse>();
    List<HostResponse> hostResponses = new ArrayList<HostResponse>();
    for (Host host : result) {
        HostResponse hostResponse = _responseGenerator.createHostResponse(host, getDetails());
        Boolean suitableForMigration = false;
        if (hostsWithCapacity.contains(host)) {
            suitableForMigration = true;
        }
        hostResponse.setSuitableForMigration(suitableForMigration);
        hostResponse.setObjectName("host");
        hostResponses.add(hostResponse);
    }
    response.setResponses(hostResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) HostResponse(com.cloud.api.response.HostResponse) ArrayList(java.util.ArrayList) List(java.util.List) Host(com.cloud.host.Host)

Aggregations

HostResponse (com.cloud.api.response.HostResponse)7 Host (com.cloud.host.Host)7 ServerApiException (com.cloud.api.ServerApiException)6 ListResponse (com.cloud.api.response.ListResponse)2 DiscoveryException (com.cloud.exception.DiscoveryException)2 ArrayList (java.util.ArrayList)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)1 List (java.util.List)1