Search in sources :

Example 1 with UcsBladeResponse

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

the class AssociateUcsProfileToBladeCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        UcsBladeResponse rsp = mgr.associateProfileToBlade(this);
        rsp.setResponseName(getCommandName());
        this.setResponseObject(rsp);
    } catch (Exception e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : UcsBladeResponse(org.apache.cloudstack.api.response.UcsBladeResponse) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 2 with UcsBladeResponse

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

the class UcsManagerImpl method associateProfileToBlade.

@Override
public UcsBladeResponse associateProfileToBlade(AssociateUcsProfileToBladeCmd cmd) {
    QueryBuilder<UcsBladeVO> q = QueryBuilder.create(UcsBladeVO.class);
    q.and(q.entity().getUcsManagerId(), Op.EQ, cmd.getUcsManagerId());
    q.and(q.entity().getId(), Op.EQ, cmd.getBladeId());
    UcsBladeVO bvo = q.find();
    if (bvo == null) {
        throw new IllegalArgumentException(String.format("cannot find UCS blade[id:%s, ucs manager id:%s]", cmd.getBladeId(), cmd.getUcsManagerId()));
    }
    if (bvo.getHostId() != null) {
        throw new CloudRuntimeException(String.format("blade[id:%s,  dn:%s] has been associated with host[id:%s]", bvo.getId(), bvo.getDn(), bvo.getHostId()));
    }
    UcsManagerVO mgrvo = ucsDao.findById(cmd.getUcsManagerId());
    String cookie = getCookie(cmd.getUcsManagerId());
    String pdn = cloneProfile(mgrvo.getId(), cmd.getProfileDn(), "profile-for-blade-" + bvo.getId());
    String ucscmd = UcsCommands.associateProfileToBlade(cookie, pdn, bvo.getDn());
    UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
    String res = client.call(ucscmd);
    int count = 0;
    int timeout = 600;
    while (count < timeout) {
        if (isProfileAssociated(mgrvo.getId(), bvo.getDn())) {
            break;
        }
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            throw new CloudRuntimeException(e);
        }
        count += 2;
    }
    if (count >= timeout) {
        throw new CloudRuntimeException(String.format("associating profile[%s] to balde[%s] timeout after 600 seconds", pdn, bvo.getDn()));
    }
    bvo.setProfileDn(pdn);
    bladeDao.update(bvo.getId(), bvo);
    UcsBladeResponse rsp = bladeVOToResponse(bvo);
    s_logger.debug(String.format("successfully associated profile[%s] to blade[%s]", pdn, bvo.getDn()));
    return rsp;
}
Also used : UcsBladeVO(com.cloud.ucs.database.UcsBladeVO) UcsManagerVO(com.cloud.ucs.database.UcsManagerVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UcsBladeResponse(org.apache.cloudstack.api.response.UcsBladeResponse)

Example 3 with UcsBladeResponse

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

the class UcsManagerImpl method bladeVOToResponse.

private UcsBladeResponse bladeVOToResponse(UcsBladeVO vo) {
    UcsBladeResponse rsp = new UcsBladeResponse();
    rsp.setObjectName("ucsblade");
    rsp.setId(vo.getUuid());
    rsp.setDn(vo.getDn());
    rsp.setHostId(hostIdToUuid(vo.getHostId()));
    rsp.setAssociatedProfileDn(vo.getProfileDn());
    rsp.setUcsManagerId(ucsManagerIdToUuid(vo.getUcsManagerId()));
    return rsp;
}
Also used : UcsBladeResponse(org.apache.cloudstack.api.response.UcsBladeResponse)

Example 4 with UcsBladeResponse

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

the class UcsManagerImpl method listUcsBlades.

@Override
public ListResponse<UcsBladeResponse> listUcsBlades(ListUcsBladeCmd cmd) {
    QueryBuilder<UcsBladeVO> serv = QueryBuilder.create(UcsBladeVO.class);
    serv.and(serv.entity().getUcsManagerId(), Op.EQ, cmd.getUcsManagerId());
    List<UcsBladeVO> vos = serv.list();
    List<UcsBladeResponse> rsps = new ArrayList<UcsBladeResponse>(vos.size());
    for (UcsBladeVO vo : vos) {
        UcsBladeResponse rsp = bladeVOToResponse(vo);
        rsps.add(rsp);
    }
    ListResponse<UcsBladeResponse> response = new ListResponse<UcsBladeResponse>();
    response.setResponses(rsps);
    return response;
}
Also used : UcsBladeVO(com.cloud.ucs.database.UcsBladeVO) ListResponse(org.apache.cloudstack.api.response.ListResponse) UcsBladeResponse(org.apache.cloudstack.api.response.UcsBladeResponse) ArrayList(java.util.ArrayList)

Aggregations

UcsBladeResponse (org.apache.cloudstack.api.response.UcsBladeResponse)4 UcsBladeVO (com.cloud.ucs.database.UcsBladeVO)2 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 UcsManagerVO (com.cloud.ucs.database.UcsManagerVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ArrayList (java.util.ArrayList)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1