use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.
the class VpcManagerImpl method destroyVpc.
@Override
@DB
public boolean destroyVpc(final Vpc vpc, final Account caller, final Long callerUserId) throws ConcurrentOperationException, ResourceUnavailableException {
s_logger.debug("Destroying vpc " + vpc);
// don't allow to delete vpc if it's in use by existing non system
// networks (system networks are networks of a private gateway of the
// VPC,
// and they will get removed as a part of VPC cleanup
final int networksCount = _ntwkDao.getNonSystemNetworkCountByVpcId(vpc.getId());
if (networksCount > 0) {
throw new InvalidParameterValueException("Can't delete VPC " + vpc + " as its used by " + networksCount + " networks");
}
// mark VPC as inactive
if (vpc.getState() != Vpc.State.Inactive) {
s_logger.debug("Updating VPC " + vpc + " with state " + Vpc.State.Inactive + " as a part of vpc delete");
final VpcVO vpcVO = _vpcDao.findById(vpc.getId());
vpcVO.setState(Vpc.State.Inactive);
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
_vpcDao.update(vpc.getId(), vpcVO);
// decrement resource count
_resourceLimitMgr.decrementResourceCount(vpc.getAccountId(), ResourceType.vpc);
}
});
}
// shutdown VPC
if (!shutdownVpc(vpc.getId())) {
s_logger.warn("Failed to shutdown vpc " + vpc + " as a part of vpc destroy process");
return false;
}
// cleanup vpc resources
if (!cleanupVpcResources(vpc.getId(), caller, callerUserId)) {
s_logger.warn("Failed to cleanup resources for vpc " + vpc);
return false;
}
// executed successfully
if (_vpcDao.remove(vpc.getId())) {
s_logger.debug("Vpc " + vpc + " is destroyed succesfully");
return true;
} else {
s_logger.warn("Vpc " + vpc + " failed to destroy");
return false;
}
}
use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.
the class VpcManagerImpl method deleteVpcPrivateGateway.
@Override
@ActionEvent(eventType = EventTypes.EVENT_PRIVATE_GATEWAY_DELETE, eventDescription = "deleting private gateway")
@DB
public boolean deleteVpcPrivateGateway(final long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException {
final VpcGatewayVO gatewayVO = _vpcGatewayDao.acquireInLockTable(gatewayId);
if (gatewayVO == null || gatewayVO.getType() != VpcGateway.Type.Private) {
throw new ConcurrentOperationException("Unable to lock gateway " + gatewayId);
}
try {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
// don't allow to remove gateway when there are static
// routes associated with it
final long routeCount = _staticRouteDao.countRoutesByGateway(gatewayVO.getId());
if (routeCount > 0) {
throw new CloudRuntimeException("Can't delete private gateway " + gatewayVO + " as it has " + routeCount + " static routes applied. Remove the routes first");
}
gatewayVO.setState(VpcGateway.State.Deleting);
_vpcGatewayDao.update(gatewayVO.getId(), gatewayVO);
s_logger.debug("Marked gateway " + gatewayVO + " with state " + VpcGateway.State.Deleting);
}
});
// 1) delete the gateway on the backend
final List<Provider> providersToImplement = getVpcProviders(gatewayVO.getVpcId());
final PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
for (final VpcProvider provider : getVpcElements()) {
if (providersToImplement.contains(provider.getProvider())) {
if (provider.deletePrivateGateway(gateway)) {
s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
} else {
s_logger.warn("Private gateway " + gateway + " failed to apply on the backend");
gatewayVO.setState(VpcGateway.State.Ready);
_vpcGatewayDao.update(gatewayVO.getId(), gatewayVO);
s_logger.debug("Marked gateway " + gatewayVO + " with state " + VpcGateway.State.Ready);
return false;
}
}
}
// 2) Delete private gateway from the DB
return deletePrivateGatewayFromTheDB(gateway);
} finally {
if (gatewayVO != null) {
_vpcGatewayDao.releaseFromLockTable(gatewayId);
}
}
}
use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.
the class AsyncJobManagerImpl method updateAsyncJobAttachment.
@Override
@DB
public void updateAsyncJobAttachment(final long jobId, final String instanceType, final Long instanceId) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Update async-job attachment, job-" + jobId + ", instanceType: " + instanceType + ", instanceId: " + instanceId);
}
final AsyncJobVO job = _jobDao.findById(jobId);
publishOnEventBus(job, "update");
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
AsyncJobVO job = _jobDao.createForUpdate();
job.setInstanceType(instanceType);
job.setInstanceId(instanceId);
job.setLastUpdated(DateUtil.currentGMTTime());
_jobDao.update(jobId, job);
}
});
}
use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.
the class AsyncJobManagerImpl method updateAsyncJobStatus.
@Override
@DB
public void updateAsyncJobStatus(final long jobId, final int processStatus, final String resultObject) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Update async-job progress, job-" + jobId + ", processStatus: " + processStatus + ", result: " + resultObject);
}
final AsyncJobVO job = _jobDao.findById(jobId);
if (job == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("job-" + jobId + " no longer exists, we just log progress info here. progress status: " + processStatus);
}
return;
}
publishOnEventBus(job, "update");
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
job.setProcessStatus(processStatus);
if (resultObject != null) {
job.setResult(resultObject);
}
job.setLastUpdated(DateUtil.currentGMTTime());
_jobDao.update(jobId, job);
}
});
}
use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.
the class CiscoNexusVSMDeviceManagerImpl method deleteCiscoNexusVSM.
@DB
public boolean deleteCiscoNexusVSM(final long vsmId) throws ResourceInUseException {
CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId);
if (cisconexusvsm == null) {
// This entry is already not present. Return success.
return true;
}
// First, check whether this VSM is part of any non-empty cluster.
// Search ClusterVSMMap's table for a list of clusters using this vsmId.
List<ClusterVSMMapVO> clusterList = _clusterVSMDao.listByVSMId(vsmId);
if (clusterList != null) {
for (ClusterVSMMapVO record : clusterList) {
// If this cluster id has any hosts in it, fail this operation.
Long clusterId = record.getClusterId();
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
if (hosts != null && hosts.size() > 0) {
for (Host host : hosts) {
if (host.getType() == Host.Type.Routing) {
s_logger.info("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first");
throw new ResourceInUseException("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first");
}
}
}
}
}
// Iterate through the cluster list again, this time, delete the VSM.
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
// Remove the VSM entry in CiscoNexusVSMDeviceVO's table.
_ciscoNexusVSMDeviceDao.remove(vsmId);
// Remove the current record as well from ClusterVSMMapVO's table.
_clusterVSMDao.removeByVsmId(vsmId);
}
});
return true;
}
Aggregations