use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.
the class IAMServiceImpl method removeIAMPolicyFromAccounts.
@Override
public void removeIAMPolicyFromAccounts(final Long policyId, final List<Long> acctIds) {
IAMPolicy policy = _aclPolicyDao.findById(policyId);
if (policy == null) {
throw new InvalidParameterValueException("Unable to find acl policy: " + policyId + "; failed to add policy to account.");
}
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
// add entries in acl_group_policy_map table
for (Long acctId : acctIds) {
IAMAccountPolicyMapVO acctMap = _aclAccountPolicyMapDao.findByAccountAndPolicy(acctId, policyId);
if (acctMap != null) {
// exists
_aclAccountPolicyMapDao.remove(acctMap.getId());
}
}
}
});
invalidateIAMCache();
}
use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.
the class IAMServiceImpl method addAccountsToGroup.
@DB
@Override
public IAMGroup addAccountsToGroup(final List<Long> acctIds, final Long groupId) {
// get the Acl Group entity
IAMGroup group = _aclGroupDao.findById(groupId);
if (group == null) {
throw new InvalidParameterValueException("Unable to find acl group: " + groupId + "; failed to add accounts to acl group.");
}
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
// add entries in acl_group_account_map table
for (Long acctId : acctIds) {
// check account permissions
IAMGroupAccountMapVO grMap = _aclGroupAccountMapDao.findByGroupAndAccount(groupId, acctId);
if (grMap == null) {
// not there already
grMap = new IAMGroupAccountMapVO(groupId, acctId);
_aclGroupAccountMapDao.persist(grMap);
}
}
}
});
invalidateIAMCache();
return group;
}
use of com.cloud.utils.db.TransactionCallbackNoReturn in project cosmic by MissionCriticalCloud.
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 cosmic by MissionCriticalCloud.
the class VpcManagerImpl method configure.
@Override
@DB
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
// configure default vpc offering
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCOfferingName) == null) {
s_logger.debug("Creating VPC offering " + VpcOffering.defaultVPCOfferingName);
final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(DEFAULT_SERVICES);
createVpcOffering(VpcOffering.defaultVPCOfferingName, VpcOffering.defaultVPCOfferingName, svcProviderMap, true, State.Enabled, null, null, false);
}
if (_vpcOffDao.findByUniqueName(VpcOffering.defaultRemoteGatewayVPCOfferingName) == null) {
s_logger.debug("Creating VPC offering " + VpcOffering.defaultRemoteGatewayVPCOfferingName);
final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(REMOTE_GATEWAY_SERVICES);
createVpcOffering(VpcOffering.defaultRemoteGatewayVPCOfferingName, VpcOffering.defaultRemoteGatewayVPCOfferingName, svcProviderMap, true, State.Enabled, null, null, false);
}
if (_vpcOffDao.findByUniqueName(VpcOffering.defaultRemoteGatewayWithVPNVPCOfferingName) == null) {
s_logger.debug("Creating VPC offering " + VpcOffering.defaultRemoteGatewayWithVPNVPCOfferingName);
final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(REMOTE_GATEWAY_WITH_VPN_SERVICES);
createVpcOffering(VpcOffering.defaultRemoteGatewayWithVPNVPCOfferingName, VpcOffering.defaultRemoteGatewayWithVPNVPCOfferingName, svcProviderMap, true, State.Enabled, null, null, false);
}
if (_vpcOffDao.findByUniqueName(VpcOffering.defaultInternalVPCOfferingName) == null) {
s_logger.debug("Creating VPC offering " + VpcOffering.defaultInternalVPCOfferingName);
final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(INTERNAL_VPC_SERVICES);
createVpcOffering(VpcOffering.defaultInternalVPCOfferingName, VpcOffering.defaultInternalVPCOfferingName, svcProviderMap, true, State.Enabled, null, null, false);
}
if (_vpcOffDao.findByUniqueName(VpcOffering.redundantVPCOfferingName) == null) {
s_logger.debug("Creating VPC offering " + VpcOffering.redundantVPCOfferingName);
// Link the default Redundant VPC offering to the two default router offerings
final ServiceOffering serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.routerDefaultOffUniqueName);
final ServiceOffering secondaryServiceOffering = _serviceOfferingDao.findByName(ServiceOffering.routerDefaultSecondaryOffUniqueName);
Long serviceOfferingId = null;
Long secondaryServiceOfferingId = null;
if (serviceOffering != null) {
serviceOfferingId = serviceOffering.getId();
}
if (secondaryServiceOffering != null) {
secondaryServiceOfferingId = secondaryServiceOffering.getId();
}
final Map<Service, Set<Provider>> svcProviderMap = getServiceSetMap(DEFAULT_SERVICES);
createVpcOffering(VpcOffering.redundantVPCOfferingName, VpcOffering.redundantVPCOfferingName, svcProviderMap, true, State.Enabled, serviceOfferingId, secondaryServiceOfferingId, true);
}
}
});
final Map<String, String> configs = _configDao.getConfiguration(params);
final String value = configs.get(Config.VpcCleanupInterval.key());
// 1 hour
_cleanupInterval = NumbersUtil.parseInt(value, 60 * 60);
final String maxNtwks = configs.get(Config.VpcMaxNetworks.key());
// max=3 is default
_maxNetworks = NumbersUtil.parseInt(maxNtwks, 3);
IpAddressSearch = _ipAddressDao.createSearchBuilder();
IpAddressSearch.and("accountId", IpAddressSearch.entity().getAllocatedToAccountId(), Op.EQ);
IpAddressSearch.and("dataCenterId", IpAddressSearch.entity().getDataCenterId(), Op.EQ);
IpAddressSearch.and("vpcId", IpAddressSearch.entity().getVpcId(), Op.EQ);
IpAddressSearch.and("associatedWithNetworkId", IpAddressSearch.entity().getAssociatedWithNetworkId(), Op.EQ);
final SearchBuilder<VlanVO> virtualNetworkVlanSB = _vlanDao.createSearchBuilder();
virtualNetworkVlanSB.and("vlanType", virtualNetworkVlanSB.entity().getVlanType(), Op.EQ);
IpAddressSearch.join("virtualNetworkVlanSB", virtualNetworkVlanSB, IpAddressSearch.entity().getVlanId(), virtualNetworkVlanSB.entity().getId(), JoinBuilder.JoinType.INNER);
IpAddressSearch.done();
return true;
}
use of com.cloud.utils.db.TransactionCallbackNoReturn in project cosmic by MissionCriticalCloud.
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 pointing to an ipaddress in the private gateway CIDR.
final List<? extends StaticRoute> routes = _staticRouteDao.listByVpcIdAndNotRevoked(gatewayVO.getVpcId());
final NetworkVO network = _ntwkDao.findById(gatewayVO.getNetworkId());
final List<String> wrongCidrs = new LinkedList<>();
for (final StaticRoute route : routes) {
if (NetUtils.isIpWithtInCidrRange(route.getGwIpAddress(), network.getCidr())) {
wrongCidrs.add(route.getCidr());
}
}
if (!wrongCidrs.isEmpty()) {
throw new InvalidParameterValueException("Unable to delete Private Gateway. Please remove these static routes pointing to the private gateway CIDR" + " before attempting to delete the gateway: " + wrongCidrs);
}
gatewayVO.setState(VpcGateway.State.Deleting);
_vpcGatewayDao.update(gatewayVO.getId(), gatewayVO);
s_logger.debug("Marked gateway " + gatewayVO + " with state " + VpcGateway.State.Deleting);
}
});
// 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;
}
}
}
return deletePrivateGatewayFromTheDB(gateway);
} finally {
_vpcGatewayDao.releaseFromLockTable(gatewayId);
}
}
Aggregations