use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VirtualRouterElement method configureDhcpSupport.
protected boolean configureDhcpSupport(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, Service service) throws ResourceUnavailableException {
if (canHandle(network, service)) {
if (vm.getType() != VirtualMachine.Type.User) {
return false;
}
final VirtualMachineProfile uservm = vm;
final List<DomainRouterVO> routers = getRouters(network, dest);
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
return networkTopology.configDhcpForSubnet(network, nic, uservm, dest, routers);
}
return false;
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VirtualRouterElement method completeAggregatedExecution.
@Override
public boolean completeAggregatedExecution(final Network network, final DeployDestination dest) throws ResourceUnavailableException {
final List<DomainRouterVO> routers = getRouters(network, dest);
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
NetworkDetailVO networkDetail = _networkDetailsDao.findDetail(network.getId(), Network.updatingInSequence);
boolean updateInSequence = "true".equalsIgnoreCase((networkDetail != null ? networkDetail.getValue() : null));
if (updateInSequence) {
DomainRouterVO router = routers.get(0);
router.setUpdateState(VirtualRouter.UpdateState.UPDATE_COMPLETE);
_routerDao.persist(router);
}
boolean result = false;
try {
result = _routerMgr.completeAggregatedExecution(network, routers);
} finally {
if (!result && updateInSequence) {
// fail the network update. even if one router fails we fail the network update.
updateToFailedState(network);
}
}
return result;
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VirtualRouterElement method addPasswordAndUserdata.
@Override
public boolean addPasswordAndUserdata(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
boolean result = true;
if (canHandle(network, Service.UserData)) {
if (vm.getType() != VirtualMachine.Type.User) {
return false;
}
final VirtualMachineProfile uservm = vm;
List<java.lang.String[]> vmData = uservm.getVmData();
uservm.setVmData(vmData);
final List<DomainRouterVO> routers = getRouters(network, dest);
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
for (final DomainRouterVO domainRouterVO : routers) {
result = result && networkTopology.applyUserData(network, nic, uservm, dest, domainRouterVO);
}
}
return result;
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VirtualRouterElement method removeDhcpEntry.
@Override
public boolean removeDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vmProfile) throws ResourceUnavailableException {
boolean result = true;
if (canHandle(network, Service.Dhcp)) {
if (vmProfile.getType() != VirtualMachine.Type.User) {
return false;
}
final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), VirtualRouter.Role.VIRTUAL_ROUTER);
if (CollectionUtils.isEmpty(routers)) {
throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
}
final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
for (final DomainRouterVO domainRouterVO : routers) {
if (domainRouterVO.getState() != VirtualMachine.State.Running) {
continue;
}
result = result && networkTopology.removeDhcpEntry(network, nic, vmProfile, domainRouterVO);
}
}
return result;
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VirtualRouterElement method prepare.
@Override
public boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (vm.getType() != VirtualMachine.Type.User || vm.getHypervisorType() == HypervisorType.BareMetal) {
return false;
}
if (!canHandle(network, null)) {
return false;
}
final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
if (offering.isSystemOnly()) {
return false;
}
if (!_networkMdl.isProviderEnabledInPhysicalNetwork(_networkMdl.getPhysicalNetworkId(network), getProvider().getName())) {
return false;
}
final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setGuestNetwork(network).setDeployDestination(dest).setAccountOwner(_accountMgr.getAccount(network.getAccountId())).setParams(vm.getParameters()).build();
final List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
}
return true;
}
Aggregations