use of com.cloud.exception.ConcurrentOperationException in project cloudstack by apache.
the class VpcVirtualRouterElement method createPrivateGateway.
@Override
public boolean createPrivateGateway(final PrivateGateway gateway) throws ConcurrentOperationException, ResourceUnavailableException {
if (gateway.getType() != VpcGateway.Type.Private) {
s_logger.warn("Type of vpc gateway is not " + VpcGateway.Type.Private);
return true;
}
final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(gateway.getVpcId());
if (routers == null || routers.isEmpty()) {
s_logger.debug(getName() + " element doesn't need to create Private gateway on the backend; VPC virtual " + "router doesn't exist in the vpc id=" + gateway.getVpcId());
return true;
}
s_logger.info("Adding VPC routers to Guest Network: " + routers.size() + " to be added!");
final DataCenterVO dcVO = _dcDao.findById(gateway.getZoneId());
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
boolean result = true;
final Network network = _networkDao.findById(gateway.getNetworkId());
final boolean isPrivateGateway = true;
for (final DomainRouterVO domainRouterVO : routers) {
if (networkTopology.setupPrivateGateway(gateway, domainRouterVO)) {
try {
final List<NetworkACLItemVO> rules = _networkACLItemDao.listByACL(gateway.getNetworkACLId());
result = result && networkTopology.applyNetworkACLs(network, rules, domainRouterVO, isPrivateGateway);
} catch (final Exception ex) {
s_logger.debug("Failed to apply network acl id " + gateway.getNetworkACLId() + " on gateway ");
return false;
}
}
}
return result;
}
use of com.cloud.exception.ConcurrentOperationException in project cloudstack by apache.
the class VpcVirtualRouterElement method getRouters.
@Override
protected List<DomainRouterVO> getRouters(final Network network, final DeployDestination dest) {
//1st time it runs the domain router of the VM shall be returned
List<DomainRouterVO> routers = super.getRouters(network, dest);
if (routers.size() > 0) {
return routers;
}
//For the 2nd time it returns the VPC routers.
final Long vpcId = network.getVpcId();
if (vpcId == null) {
s_logger.error("Network " + network + " is not associated with any VPC");
return routers;
}
final Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
if (vpc == null) {
s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
return routers;
}
final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setGuestNetwork(network).setVpc(vpc).setDeployDestination(dest).setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).build();
try {
routers = routerDeploymentDefinition.deployVirtualRouter();
} catch (final ConcurrentOperationException e) {
s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
} catch (final InsufficientCapacityException e) {
s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
} catch (final ResourceUnavailableException e) {
s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
}
return routers;
}
use of com.cloud.exception.ConcurrentOperationException in project cloudstack by apache.
the class CreatePortableIpRangeCmd method create.
@Override
public void create() throws ResourceAllocationException {
try {
PortableIpRange portableIpRange = _configService.createPortableIpRange(this);
if (portableIpRange != null) {
this.setEntityId(portableIpRange.getId());
this.setEntityUuid(portableIpRange.getUuid());
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create portable public IP range");
}
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
}
use of com.cloud.exception.ConcurrentOperationException 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 {
final NetworkVO network = _networksDao.findById(networkId);
s_logger.debug("Restarting network " + networkId + "...");
final ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount);
if (cleanup) {
// shutdown the network
s_logger.debug("Shutting down the network id=" + networkId + " as a part of network restart");
if (!shutdownNetworkElementsAndResources(context, true, network)) {
s_logger.debug("Failed to shutdown the network elements and resources as a part of network restart: " + network.getState());
setRestartRequired(network, true);
return false;
}
} else {
s_logger.debug("Skip the shutting down of network id=" + networkId);
}
// implement the network elements and rules again
final DeployDestination dest = new DeployDestination(_dcDao.findById(network.getDataCenterId()), null, null, null);
s_logger.debug("Implementing the network " + network + " elements and resources as a part of network restart");
final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
try {
implementNetworkElementsAndResources(dest, context, network, offering);
setRestartRequired(network, true);
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.ConcurrentOperationException in project cloudstack by apache.
the class NetworkOrchestrator method releaseNic.
@DB
protected void releaseNic(final VirtualMachineProfile vmProfile, final long nicId) throws ConcurrentOperationException, ResourceUnavailableException {
final Pair<Network, NicProfile> networkToRelease = Transaction.execute(new TransactionCallback<Pair<Network, NicProfile>>() {
@Override
public Pair<Network, NicProfile> doInTransaction(final TransactionStatus status) {
final NicVO nic = _nicDao.lockRow(nicId, true);
if (nic == null) {
throw new ConcurrentOperationException("Unable to acquire lock on nic " + nic);
}
final Nic.State originalState = nic.getState();
final NetworkVO network = _networksDao.findById(nic.getNetworkId());
if (originalState == Nic.State.Reserved || originalState == Nic.State.Reserving) {
if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
nic.setState(Nic.State.Releasing);
_nicDao.update(nic.getId(), nic);
final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
if (guru.release(profile, vmProfile, nic.getReservationId())) {
applyProfileToNicForRelease(nic, profile);
nic.setState(Nic.State.Allocated);
if (originalState == Nic.State.Reserved) {
updateNic(nic, network.getId(), -1);
} else {
_nicDao.update(nic.getId(), nic);
}
}
// Perform release on network elements
return new Pair<Network, NicProfile>(network, profile);
} else {
nic.setState(Nic.State.Allocated);
updateNic(nic, network.getId(), -1);
}
}
return null;
}
});
// cleanup the entry in vm_network_map
if (vmProfile.getType().equals(VirtualMachine.Type.User)) {
final NicVO nic = _nicDao.findById(nicId);
if (nic != null) {
final NetworkVO vmNetwork = _networksDao.findById(nic.getNetworkId());
final VMNetworkMapVO vno = _vmNetworkMapDao.findByVmAndNetworkId(vmProfile.getVirtualMachine().getId(), vmNetwork.getId());
if (vno != null) {
_vmNetworkMapDao.remove(vno.getId());
}
}
}
if (networkToRelease != null) {
final Network network = networkToRelease.first();
final NicProfile profile = networkToRelease.second();
final List<Provider> providersToImplement = getNetworkProviders(network.getId());
for (final NetworkElement element : networkElements) {
if (providersToImplement.contains(element.getProvider())) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + element.getName() + " to release " + profile);
}
//NOTE: Context appear to never be used in release method
//implementations. Consider removing it from interface Element
element.release(network, profile, vmProfile, null);
}
}
}
}
Aggregations