本文整理汇总了Java中com.cloud.utils.db.Transaction类的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于com.cloud.utils.db包,在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateNic
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
@DB
protected void updateNic(final NicVO nic, final long networkId, final int count) {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
_nicDao.update(nic.getId(), nic);
if (nic.getVmType() == VirtualMachine.Type.User) {
s_logger.debug("Changing active number of nics for network id=" + networkId + " on " + count);
_networksDao.changeActiveNicsBy(networkId, count);
}
if (nic.getVmType() == VirtualMachine.Type.User
|| nic.getVmType() == VirtualMachine.Type.DomainRouter && _networksDao.findById(networkId).getTrafficType() == TrafficType.Guest) {
_networksDao.setCheckForGc(networkId);
}
}
});
}
示例2: reallocate
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
@DB
@Override
public boolean reallocate(final VirtualMachineProfile vm, final DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException {
final VMInstanceVO vmInstance = _vmDao.findById(vm.getId());
final Zone dc = _zoneRepository.findOne(vmInstance.getDataCenterId());
if (dc.getNetworkType() == com.cloud.model.enumeration.NetworkType.Basic) {
final List<NicVO> nics = _nicDao.listByVmId(vmInstance.getId());
final NetworkVO network = _networksDao.findById(nics.get(0).getNetworkId());
final LinkedHashMap<Network, List<? extends NicProfile>> profiles = new LinkedHashMap<>();
profiles.put(network, new ArrayList<>());
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientCapacityException>() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) throws InsufficientCapacityException {
cleanupNics(vm);
allocate(vm, profiles);
}
});
}
return true;
}
示例3: removeVmSecondaryIpsOfNic
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
private boolean removeVmSecondaryIpsOfNic(final long nicId) {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
final List<NicSecondaryIpVO> ipList = _nicSecondaryIpDao.listByNicId(nicId);
if (ipList != null) {
for (final NicSecondaryIpVO ip : ipList) {
_nicSecondaryIpDao.remove(ip.getId());
}
s_logger.debug("Revoving nic secondary ip entry ...");
}
}
});
return true;
}
示例4: resetHostPowerStateTracking
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
@Override
@DB
public void resetHostPowerStateTracking(final long hostId) {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
final SearchCriteria<VMInstanceVO> sc = createSearchCriteria();
sc.addAnd("powerHostId", SearchCriteria.Op.EQ, hostId);
final VMInstanceVO instance = createForUpdate();
instance.setPowerStateUpdateCount(0);
instance.setPowerStateUpdateTime(DateUtil.currentGMTTime());
update(instance, sc);
}
});
}
示例5: markPublicIpAsAllocated
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
@DB
@Override
public void markPublicIpAsAllocated(final IPAddressVO addr) {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
final Account owner = _accountMgr.getAccount(addr.getAllocatedToAccountId());
synchronized (this) {
if (_ipAddressDao.lockRow(addr.getId(), true) != null) {
final IPAddressVO userIp = _ipAddressDao.findById(addr.getId());
if (userIp.getState() == IpAddress.State.Allocating || addr.getState() == IpAddress.State.Free) {
addr.setState(IpAddress.State.Allocated);
_ipAddressDao.update(addr.getId(), addr);
// Save usage event
if (owner.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
if (updateIpResourceCount(addr)) {
_resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.public_ip);
}
}
}
}
}
}
});
}
示例6: markIpAsUnavailable
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
@DB
@Override
public IPAddressVO markIpAsUnavailable(final long addrId) {
final IPAddressVO ip = _ipAddressDao.findById(addrId);
if (ip.getAllocatedToAccountId() == null && ip.getAllocatedTime() == null) {
s_logger.trace("Ip address id=" + addrId + " is already released");
return ip;
}
if (ip.getState() != State.Releasing) {
return Transaction.execute(new TransactionCallback<IPAddressVO>() {
@Override
public IPAddressVO doInTransaction(final TransactionStatus status) {
if (updateIpResourceCount(ip)) {
_resourceLimitMgr.decrementResourceCount(_ipAddressDao.findById(addrId).getAllocatedToAccountId(), ResourceType.public_ip);
}
return _ipAddressDao.markAsUnavailable(addrId);
}
});
}
return ip;
}
示例7: removeInstanceFromGroups
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
@Override
@DB
public void removeInstanceFromGroups(final long userVmId) {
if (_securityGroupVMMapDao.countSGForVm(userVmId) < 1) {
s_logger.trace("No security groups found for vm id=" + userVmId + ", returning");
return;
}
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
final UserVm userVm = _userVMDao.acquireInLockTable(userVmId); // ensures that duplicate entries are not created in
// addInstance
if (userVm == null) {
s_logger.warn("Failed to acquire lock on user vm id=" + userVmId);
}
final int n = _securityGroupVMMapDao.deleteVM(userVmId);
s_logger.info("Disassociated " + n + " network groups " + " from uservm " + userVmId);
_userVMDao.releaseFromLockTable(userVmId);
}
});
s_logger.debug("Security group mappings are removed successfully for vm id=" + userVmId);
}
示例8: deallocate
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
@Override
@DB
public void deallocate(final Network network, final NicProfile nic, final VirtualMachineProfile vm) {
if (network.getSpecifyIpRanges()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIPv4Address());
}
final IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIPv4Address());
if (ip != null) {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
_ipAddrMgr.markIpAsUnavailable(ip.getId());
_ipAddressDao.unassignIpAddress(ip.getId());
}
});
}
nic.deallocate();
}
}
示例9: deallocate
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
@Override
@DB
public void deallocate(final Network network, final NicProfile nic, final VirtualMachineProfile vm) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("public network deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIPv4Address());
}
final IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIPv4Address());
if (ip != null && nic.getReservationStrategy() != ReservationStrategy.Managed) {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
_ipAddrMgr.markIpAsUnavailable(ip.getId());
_ipAddressDao.unassignIpAddress(ip.getId());
}
});
}
nic.deallocate();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Deallocated nic: " + nic);
}
}
示例10: removeVpnUser
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
@DB
@Override
public boolean removeVpnUser(final long vpnOwnerId, final String username, final Account caller) {
final VpnUserVO user = _vpnUsersDao.findByAccountAndUsername(vpnOwnerId, username);
if (user == null) {
throw new InvalidParameterValueException("Could not find vpn user " + username);
}
_accountMgr.checkAccess(caller, null, true, user);
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
user.setState(State.Revoke);
_vpnUsersDao.update(user.getId(), user);
}
});
return true;
}
示例11: removeNicSecondaryIP
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
private boolean removeNicSecondaryIP(final NicSecondaryIpVO ipVO, final boolean lastIp) {
final long nicId = ipVO.getNicId();
final NicVO nic = _nicDao.findById(nicId);
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
if (lastIp) {
nic.setSecondaryIp(false);
s_logger.debug("Setting nics secondary ip to false ...");
_nicDao.update(nicId, nic);
}
s_logger.debug("Revoving nic secondary ip entry ...");
_nicSecondaryIpDao.remove(ipVO.getId());
}
});
return true;
}
示例12: revokeStaticRoutesForVpc
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
@DB
private boolean revokeStaticRoutesForVpc(final long vpcId, final Account caller)
throws ResourceUnavailableException {
// get all static routes for the vpc
final List<StaticRouteVO> routes = _staticRouteDao.listByVpcId(vpcId);
s_logger.debug("Found " + routes.size() + " to revoke for the vpc " + vpcId);
if (!routes.isEmpty()) {
// mark all of them as revoke
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
for (final StaticRouteVO route : routes) {
markStaticRouteForRevoke(route, caller);
}
}
});
return applyStaticRoutesForVpc(vpcId);
}
return true;
}
示例13: revokeRule
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
@Override
@DB
public void revokeRule(final FirewallRuleVO rule, final Account caller, final long userId, final boolean needUsageEvent) {
if (caller != null) {
_accountMgr.checkAccess(caller, null, true, rule);
}
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
if (rule.getState() == State.Staged) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found a rule that is still in stage state so just removing it: " + rule);
}
removeRule(rule);
} else if (rule.getState() == State.Add || rule.getState() == State.Active) {
rule.setState(State.Revoke);
_firewallDao.update(rule.getId(), rule);
}
}
});
}
示例14: deleteAccountFromProject
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
@Override
@DB
public boolean deleteAccountFromProject(final long projectId, final long accountId) {
return Transaction.execute(new TransactionCallback<Boolean>() {
@Override
public Boolean doInTransaction(final TransactionStatus status) {
boolean success;
//remove account
final ProjectAccountVO projectAccount = _projectAccountDao.findByProjectIdAccountId(projectId, accountId);
success = _projectAccountDao.remove(projectAccount.getId());
//remove all invitations for account
if (success) {
s_logger.debug("Removed account " + accountId + " from project " + projectId + " , cleaning up old invitations for account/project...");
final ProjectInvitation invite = _projectInvitationDao.findByAccountIdProjectId(accountId, projectId);
if (invite != null) {
success = success && _projectInvitationDao.remove(invite.getId());
}
}
return success;
}
});
}
示例15: updateLoginAttempts
import com.cloud.utils.db.Transaction; //导入依赖的package包/类
@DB
public void updateLoginAttempts(final Long id, final int attempts, final boolean toDisable) {
try {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
final UserAccountVO user;
user = _userAccountDao.lockRow(id, true);
user.setLoginAttempts(attempts);
if (toDisable) {
user.setState(State.disabled.toString());
}
_userAccountDao.update(id, user);
}
});
} catch (final Exception e) {
s_logger.error("Failed to update login attempts for user with id " + id);
}
}