Search in sources :

Example 1 with BaremetalRctResponse

use of com.cloud.baremetal.networkservice.BaremetalRctResponse in project cloudstack by apache.

the class BaremetalVlanManagerImpl method addRct.

@Override
public BaremetalRctResponse addRct(AddBaremetalRctCmd cmd) {
    try {
        List<BaremetalRctVO> existings = rctDao.listAll();
        if (!existings.isEmpty()) {
            throw new CloudRuntimeException(String.format("there is some RCT existing. A CloudStack deployment accepts only one RCT"));
        }
        URL url = new URL(cmd.getRctUrl());
        RestTemplate rest = new RestTemplate();
        String rctStr = rest.getForObject(url.toString(), String.class);
        // validate it's right format
        BaremetalRct rct = gson.fromJson(rctStr, BaremetalRct.class);
        QueryBuilder<BaremetalRctVO> sc = QueryBuilder.create(BaremetalRctVO.class);
        sc.and(sc.entity().getUrl(), SearchCriteria.Op.EQ, cmd.getRctUrl());
        BaremetalRctVO vo = sc.find();
        if (vo == null) {
            vo = new BaremetalRctVO();
            vo.setRct(gson.toJson(rct));
            vo.setUrl(cmd.getRctUrl());
            vo = rctDao.persist(vo);
        } else {
            vo.setRct(gson.toJson(rct));
            rctDao.update(vo.getId(), vo);
        }
        BaremetalRctResponse rsp = new BaremetalRctResponse();
        rsp.setUrl(vo.getUrl());
        rsp.setId(vo.getUuid());
        rsp.setObjectName("baremetalrct");
        return rsp;
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(String.format("%s is not a legal http url", cmd.getRctUrl()));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) BaremetalRctVO(com.cloud.baremetal.database.BaremetalRctVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) RestTemplate(org.springframework.web.client.RestTemplate) BaremetalRctResponse(com.cloud.baremetal.networkservice.BaremetalRctResponse) URL(java.net.URL)

Example 2 with BaremetalRctResponse

use of com.cloud.baremetal.networkservice.BaremetalRctResponse in project cloudstack by apache.

the class AddBaremetalRctCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        BaremetalRctResponse rsp = vlanMgr.addRct(this);
        this.setResponseObject(rsp);
    } catch (Exception e) {
        s_logger.warn(String.format("unable to add baremetal RCT[%s]", getRctUrl()), e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : BaremetalRctResponse(com.cloud.baremetal.networkservice.BaremetalRctResponse) 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 3 with BaremetalRctResponse

use of com.cloud.baremetal.networkservice.BaremetalRctResponse in project cloudstack by apache.

the class ListBaremetalRctCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        ListResponse<BaremetalRctResponse> response = new ListResponse<>();
        List<BaremetalRctResponse> rctResponses = new ArrayList<>();
        BaremetalRctResponse rsp = vlanMgr.listRct();
        if (rsp != null) {
            rctResponses.add(rsp);
        }
        response.setResponses(rctResponses);
        response.setResponseName(getCommandName());
        response.setObjectName("baremetalrcts");
        this.setResponseObject(response);
    } catch (Exception e) {
        s_logger.debug("Exception happened while executing ListBaremetalRctCmd", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) BaremetalRctResponse(com.cloud.baremetal.networkservice.BaremetalRctResponse) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 4 with BaremetalRctResponse

use of com.cloud.baremetal.networkservice.BaremetalRctResponse in project cloudstack by apache.

the class BaremetalVlanManagerImpl method listRct.

@Override
public BaremetalRctResponse listRct() {
    List<BaremetalRctVO> vos = rctDao.listAll();
    if (!vos.isEmpty()) {
        BaremetalRctVO vo = vos.get(0);
        BaremetalRctResponse rsp = new BaremetalRctResponse();
        rsp.setId(vo.getUuid());
        rsp.setUrl(vo.getUrl());
        rsp.setObjectName("baremetalrct");
        return rsp;
    }
    return null;
}
Also used : BaremetalRctVO(com.cloud.baremetal.database.BaremetalRctVO) BaremetalRctResponse(com.cloud.baremetal.networkservice.BaremetalRctResponse)

Aggregations

BaremetalRctResponse (com.cloud.baremetal.networkservice.BaremetalRctResponse)4 BaremetalRctVO (com.cloud.baremetal.database.BaremetalRctVO)2 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)2 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 RestTemplate (org.springframework.web.client.RestTemplate)1