Search in sources :

Example 1 with DedicateHostResponse

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

the class ListDedicatedHostsCmd method execute.

@Override
public void execute() {
    Pair<List<? extends DedicatedResourceVO>, Integer> result = dedicatedService.listDedicatedHosts(this);
    ListResponse<DedicateHostResponse> response = new ListResponse<DedicateHostResponse>();
    List<DedicateHostResponse> Responses = new ArrayList<DedicateHostResponse>();
    if (result != null) {
        for (DedicatedResources resource : result.first()) {
            DedicateHostResponse hostResponse = dedicatedService.createDedicateHostResponse(resource);
            Responses.add(hostResponse);
        }
        response.setResponses(Responses, result.second());
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to list dedicated hosts");
    }
}
Also used : DedicateHostResponse(org.apache.cloudstack.api.response.DedicateHostResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) DedicatedResources(com.cloud.dc.DedicatedResources) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO)

Example 2 with DedicateHostResponse

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

the class DedicatedResourceManagerImpl method createDedicateHostResponse.

@Override
public DedicateHostResponse createDedicateHostResponse(DedicatedResources resource) {
    DedicateHostResponse dedicateHostResponse = new DedicateHostResponse();
    HostVO host = _hostDao.findById(resource.getHostId());
    DomainVO domain = _domainDao.findById(resource.getDomainId());
    AccountVO account = _accountDao.findById(resource.getAccountId());
    AffinityGroup group = _affinityGroupDao.findById(resource.getAffinityGroupId());
    dedicateHostResponse.setId(resource.getUuid());
    dedicateHostResponse.setHostId(host.getUuid());
    dedicateHostResponse.setHostName(host.getName());
    dedicateHostResponse.setDomainId(domain.getUuid());
    dedicateHostResponse.setAffinityGroupId(group.getUuid());
    if (account != null) {
        dedicateHostResponse.setAccountId(account.getUuid());
    }
    dedicateHostResponse.setObjectName("dedicatedhost");
    return dedicateHostResponse;
}
Also used : DomainVO(com.cloud.domain.DomainVO) DedicateHostResponse(org.apache.cloudstack.api.response.DedicateHostResponse) AccountVO(com.cloud.user.AccountVO) HostVO(com.cloud.host.HostVO) AffinityGroup(org.apache.cloudstack.affinity.AffinityGroup)

Example 3 with DedicateHostResponse

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

the class DedicateHostCmd method execute.

@Override
public void execute() {
    List<? extends DedicatedResources> result = dedicatedService.dedicateHost(getHostId(), getDomainId(), getAccountName());
    ListResponse<DedicateHostResponse> response = new ListResponse<DedicateHostResponse>();
    List<DedicateHostResponse> hostResponseList = new ArrayList<DedicateHostResponse>();
    if (result != null) {
        for (DedicatedResources resource : result) {
            DedicateHostResponse hostResponse = dedicatedService.createDedicateHostResponse(resource);
            hostResponseList.add(hostResponse);
        }
        response.setResponses(hostResponseList);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate host");
    }
}
Also used : DedicateHostResponse(org.apache.cloudstack.api.response.DedicateHostResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) DedicatedResources(com.cloud.dc.DedicatedResources) ArrayList(java.util.ArrayList)

Aggregations

DedicateHostResponse (org.apache.cloudstack.api.response.DedicateHostResponse)3 DedicatedResources (com.cloud.dc.DedicatedResources)2 ArrayList (java.util.ArrayList)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 ListResponse (org.apache.cloudstack.api.response.ListResponse)2 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)1 DomainVO (com.cloud.domain.DomainVO)1 HostVO (com.cloud.host.HostVO)1 AccountVO (com.cloud.user.AccountVO)1 List (java.util.List)1 AffinityGroup (org.apache.cloudstack.affinity.AffinityGroup)1