use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class NetworkOrchestrator method implementNetworkElementsAndResources.
@Override
public void implementNetworkElementsAndResources(final DeployDestination dest, final ReservationContext context, final Network network, final NetworkOffering offering) throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException {
// Associate a source NAT IP (if one isn't already associated with the network) if this is a
// 1) 'Isolated' or 'Shared' guest virtual network in the advance zone
// 2) network has sourceNat service
// 3) network offering does not support a shared source NAT rule
final boolean sharedSourceNat = offering.isSharedSourceNat();
final DataCenter zone = _dcDao.findById(network.getDataCenterId());
if (!sharedSourceNat && _networkModel.areServicesSupportedInNetwork(network.getId(), Service.SourceNat) && (network.getGuestType() == Network.GuestType.Isolated || network.getGuestType() == Network.GuestType.Shared && zone.getNetworkType() == NetworkType.Advanced)) {
List<IPAddressVO> ips = null;
final Account owner = _entityMgr.findById(Account.class, network.getAccountId());
if (network.getVpcId() != null) {
ips = _ipAddressDao.listByAssociatedVpc(network.getVpcId(), true);
if (ips.isEmpty()) {
final Vpc vpc = _vpcMgr.getActiveVpc(network.getVpcId());
s_logger.debug("Creating a source nat ip for vpc " + vpc);
_vpcMgr.assignSourceNatIpAddressToVpc(owner, vpc);
}
} else {
ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true);
if (ips.isEmpty()) {
s_logger.debug("Creating a source nat ip for network " + network);
_ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
}
}
}
// get providers to implement
final List<Provider> providersToImplement = getNetworkProviders(network.getId());
implementNetworkElements(dest, context, network, offering, providersToImplement);
// Reset the extra DHCP option that may have been cleared per nic.
List<NicVO> nicVOs = _nicDao.listByNetworkId(network.getId());
for (NicVO nicVO : nicVOs) {
if (nicVO.getState() == Nic.State.Reserved) {
configureExtraDhcpOptions(network, nicVO.getId());
}
}
for (final NetworkElement element : networkElements) {
if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
((AggregatedCommandExecutor) element).prepareAggregatedExecution(network, dest);
}
}
try {
// reapply all the firewall/staticNat/lb rules
s_logger.debug("Reprogramming network " + network + " as a part of network implement");
if (!reprogramNetworkRules(network.getId(), CallContext.current().getCallingAccount(), network)) {
s_logger.warn("Failed to re-program the network as a part of network " + network + " implement");
// see DataCenterVO.java
final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid());
throw ex;
}
for (final NetworkElement element : networkElements) {
if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
if (!((AggregatedCommandExecutor) element).completeAggregatedExecution(network, dest)) {
s_logger.warn("Failed to re-program the network as a part of network " + network + " implement due to aggregated commands execution failure!");
// see DataCenterVO.java
final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid());
throw ex;
}
}
}
} finally {
for (final NetworkElement element : networkElements) {
if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
((AggregatedCommandExecutor) element).cleanupAggregatedExecution(network, dest);
}
}
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class NetworkOrchestrator method restartNetwork.
@Override
public boolean restartNetwork(final Long networkId, final Account callerAccount, final User callerUser, final boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
boolean status = true;
boolean restartRequired = false;
final NetworkVO network = _networksDao.findById(networkId);
s_logger.debug("Restarting network " + networkId + "...");
final ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount);
final NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId());
final DeployDestination dest = new DeployDestination(_dcDao.findById(network.getDataCenterId()), null, null, null);
if (cleanup) {
if (!rollingRestartRouters(network, offering, dest, context)) {
status = false;
restartRequired = true;
}
setRestartRequired(network, restartRequired);
return status;
}
s_logger.debug("Implementing the network " + network + " elements and resources as a part of network restart without cleanup");
try {
implementNetworkElementsAndResources(dest, context, network, offering);
setRestartRequired(network, false);
return true;
} catch (final Exception ex) {
s_logger.warn("Failed to implement network " + network + " elements and resources as a part of network restart due to ", ex);
return false;
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class NetworkOrchestrator method cleanupConfigForServicesInNetwork.
@Override
public void cleanupConfigForServicesInNetwork(List<String> services, final Network network) {
long networkId = network.getId();
Account caller = _accountDao.findById(Account.ACCOUNT_ID_SYSTEM);
long userId = User.UID_SYSTEM;
// remove all PF/Static Nat rules for the network
s_logger.info("Services:" + services + " are no longer supported in network:" + network.getUuid() + " after applying new network offering:" + network.getNetworkOfferingId() + " removing the related configuration");
if (services.contains(Service.StaticNat.getName()) || services.contains(Service.PortForwarding.getName())) {
try {
if (_rulesMgr.revokeAllPFStaticNatRulesForNetwork(networkId, userId, caller)) {
s_logger.debug("Successfully cleaned up portForwarding/staticNat rules for network id=" + networkId);
} else {
s_logger.warn("Failed to release portForwarding/StaticNat rules as a part of network id=" + networkId + " cleanup");
}
if (services.contains(Service.StaticNat.getName())) {
// removing static nat configured on ips.
// optimizing the db operations using transaction.
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(network.getId());
for (IPAddressVO ip : ips) {
ip.setOneToOneNat(false);
ip.setAssociatedWithVmId(null);
ip.setVmIp(null);
_ipAddressDao.update(ip.getId(), ip);
}
}
});
}
} catch (ResourceUnavailableException ex) {
s_logger.warn("Failed to release portForwarding/StaticNat rules as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex);
}
}
if (services.contains(Service.SourceNat.getName())) {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
List<IPAddressVO> ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true);
// removing static nat configured on ips.
for (IPAddressVO ip : ips) {
ip.setSourceNat(false);
_ipAddressDao.update(ip.getId(), ip);
}
}
});
}
if (services.contains(Service.Lb.getName())) {
// remove all LB rules for the network
if (_lbMgr.removeAllLoadBalanacersForNetwork(networkId, caller, userId)) {
s_logger.debug("Successfully cleaned up load balancing rules for network id=" + networkId);
} else {
s_logger.warn("Failed to cleanup LB rules as a part of network id=" + networkId + " cleanup");
}
}
if (services.contains(Service.Firewall.getName())) {
// revoke all firewall rules for the network
try {
if (_firewallMgr.revokeAllFirewallRulesForNetwork(networkId, userId, caller)) {
s_logger.debug("Successfully cleaned up firewallRules rules for network id=" + networkId);
} else {
s_logger.warn("Failed to cleanup Firewall rules as a part of network id=" + networkId + " cleanup");
}
} catch (ResourceUnavailableException ex) {
s_logger.warn("Failed to cleanup Firewall rules as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex);
}
}
// do not remove vpn service for vpc networks.
if (services.contains(Service.Vpn.getName()) && network.getVpcId() == null) {
RemoteAccessVpnVO vpn = _remoteAccessVpnDao.findByAccountAndNetwork(network.getAccountId(), networkId);
try {
_vpnMgr.destroyRemoteAccessVpnForIp(vpn.getServerAddressId(), caller, true);
} catch (ResourceUnavailableException ex) {
s_logger.warn("Failed to cleanup remote access vpn resources of network:" + network.getUuid() + " due to Exception: ", ex);
}
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class NetworkOrchestrator method removeDhcpServiceInSubnet.
@DB
@Override
public void removeDhcpServiceInSubnet(final Nic nic) {
final Network network = _networksDao.findById(nic.getNetworkId());
final DhcpServiceProvider dhcpServiceProvider = getDhcpServiceProvider(network);
try {
final NicIpAliasVO ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(nic.getIPv4Gateway(), network.getId(), NicIpAlias.State.active);
if (ipAlias != null) {
ipAlias.setState(NicIpAlias.State.revoked);
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
_nicIpAliasDao.update(ipAlias.getId(), ipAlias);
final IPAddressVO aliasIpaddressVo = _publicIpAddressDao.findByIpAndSourceNetworkId(ipAlias.getNetworkId(), ipAlias.getIp4Address());
_publicIpAddressDao.unassignIpAddress(aliasIpaddressVo.getId());
}
});
if (!dhcpServiceProvider.removeDhcpSupportForSubnet(network)) {
s_logger.warn("Failed to remove the ip alias on the router, marking it as removed in db and freed the allocated ip " + ipAlias.getIp4Address());
}
}
} catch (final ResourceUnavailableException e) {
// failed to remove the dhcpconfig on the router.
s_logger.info("Unable to delete the ip alias due to unable to contact the virtualrouter.");
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class VMEntityManagerImpl method deployVirtualMachine.
@Override
public void deployVirtualMachine(String reservationId, VMEntityVO vmEntityVO, String caller, Map<VirtualMachineProfile.Param, Object> params, boolean deployOnGivenHost) throws InsufficientCapacityException, ResourceUnavailableException {
// grab the VM Id and destination using the reservationId.
VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
VMReservationVO vmReservation = _reservationDao.findByReservationId(reservationId);
if (vmReservation != null) {
DataCenterDeployment reservedPlan = new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(), vmReservation.getHostId(), null, null);
try {
_itMgr.start(vm.getUuid(), params, reservedPlan, _planningMgr.getDeploymentPlannerByName(vmReservation.getDeploymentPlanner()));
} catch (Exception ex) {
// the instance may be started on another host instead of the intended one.
if (!deployOnGivenHost) {
DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null);
if (reservedPlan.getAvoids() != null) {
plan.setAvoids(reservedPlan.getAvoids());
}
_itMgr.start(vm.getUuid(), params, plan, null);
} else {
throw ex;
}
}
} else {
// no reservation found. Let VirtualMachineManager retry
_itMgr.start(vm.getUuid(), params, null, null);
}
}
Aggregations