Search in sources :

Example 76 with TransactionCallbackNoReturn

use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.

the class NetworkServiceImpl method removeNicSecondaryIP.

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(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;
}
Also used : TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) NicVO(com.cloud.vm.NicVO)

Example 77 with TransactionCallbackNoReturn

use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.

the class StorageManagerImpl method deleteImageStore.

@Override
public boolean deleteImageStore(DeleteImageStoreCmd cmd) {
    final long storeId = cmd.getId();
    // Verify that image store exists
    ImageStoreVO store = _imageStoreDao.findById(storeId);
    if (store == null) {
        throw new InvalidParameterValueException("Image store with id " + storeId + " doesn't exist");
    }
    _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), store.getDataCenterId());
    // Verify that there are no live snapshot, template, volume on the image
    // store to be deleted
    List<SnapshotDataStoreVO> snapshots = _snapshotStoreDao.listByStoreId(storeId, DataStoreRole.Image);
    if (snapshots != null && snapshots.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active snapshots backup!");
    }
    List<VolumeDataStoreVO> volumes = _volumeStoreDao.listByStoreId(storeId);
    if (volumes != null && volumes.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active volumes backup!");
    }
    // search if there are user templates stored on this image store, excluding system, builtin templates
    List<TemplateJoinVO> templates = _templateViewDao.listActiveTemplates(storeId);
    if (templates != null && templates.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active templates backup!");
    }
    // ready to delete
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            // first delete from image_store_details table, we need to do that since
            // we are not actually deleting record from main
            // image_data_store table, so delete cascade will not work
            _imageStoreDetailsDao.deleteDetails(storeId);
            _snapshotStoreDao.deletePrimaryRecordsForStore(storeId, DataStoreRole.Image);
            _volumeStoreDao.deletePrimaryRecordsForStore(storeId);
            _templateStoreDao.deletePrimaryRecordsForStore(storeId);
            _imageStoreDao.remove(storeId);
        }
    });
    return true;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Example 78 with TransactionCallbackNoReturn

use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.

the class OutOfBandManagementDaoImpl method executeExpireOwnershipSql.

private void executeExpireOwnershipSql(final String sql, final long resource) {
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            TransactionLegacy txn = TransactionLegacy.currentTxn();
            try (final PreparedStatement pstmt = txn.prepareAutoCloseStatement(sql)) {
                pstmt.setLong(1, resource);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                txn.rollback();
                LOG.warn("Failed to expire ownership for out-of-band management server id: " + resource);
            }
        }
    });
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) PreparedStatement(java.sql.PreparedStatement)

Example 79 with TransactionCallbackNoReturn

use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.

the class MidoNetPublicNetworkGuru method deallocate.

@Override
@DB
public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) {
    s_logger.debug("deallocate called with network: " + network + " nic: " + nic + " vm: " + 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() != Nic.ReservationStrategy.Managed) {
        Transaction.execute(new TransactionCallbackNoReturn() {

            @Override
            public void doInTransactionWithoutResult(TransactionStatus status) {
                _ipAddrMgr.markIpAsUnavailable(ip.getId());
                _ipAddressDao.unassignIpAddress(ip.getId());
            }
        });
    }
    nic.deallocate();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Deallocated nic: " + nic);
    }
}
Also used : TransactionStatus(com.cloud.utils.db.TransactionStatus) IPAddressVO(com.cloud.network.dao.IPAddressVO) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) DB(com.cloud.utils.db.DB)

Example 80 with TransactionCallbackNoReturn

use of com.cloud.utils.db.TransactionCallbackNoReturn in project cloudstack by apache.

the class IpAddressManagerImpl method transferPortableIP.

@DB
@Override
public void transferPortableIP(final long ipAddrId, long currentNetworkId, long newNetworkId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException {
    Network srcNetwork = _networksDao.findById(currentNetworkId);
    if (srcNetwork == null) {
        throw new InvalidParameterValueException("Invalid source network id " + currentNetworkId + " is given");
    }
    final Network dstNetwork = _networksDao.findById(newNetworkId);
    if (dstNetwork == null) {
        throw new InvalidParameterValueException("Invalid source network id " + newNetworkId + " is given");
    }
    final IPAddressVO ip = _ipAddressDao.findById(ipAddrId);
    if (ip == null) {
        throw new InvalidParameterValueException("Invalid portable ip address id is given");
    }
    assert (isPortableIpTransferableFromNetwork(ipAddrId, currentNetworkId));
    // disassociate portable IP with current network/VPC network
    if (srcNetwork.getVpcId() != null) {
        _vpcMgr.unassignIPFromVpcNetwork(ipAddrId, currentNetworkId);
    } else {
        disassociatePortableIPToGuestNetwork(ipAddrId, currentNetworkId);
    }
    // in user_ip_address and vlan tables so as to emulate portable IP as provisioned in destination data center
    if (srcNetwork.getDataCenterId() != dstNetwork.getDataCenterId()) {
        Transaction.execute(new TransactionCallbackNoReturn() {

            @Override
            public void doInTransactionWithoutResult(TransactionStatus status) {
                long physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(dstNetwork.getDataCenterId(), TrafficType.Public).getId();
                long publicNetworkId = _networkModel.getSystemNetworkByZoneAndTrafficType(dstNetwork.getDataCenterId(), TrafficType.Public).getId();
                ip.setDataCenterId(dstNetwork.getDataCenterId());
                ip.setPhysicalNetworkId(physicalNetworkId);
                ip.setSourceNetworkId(publicNetworkId);
                _ipAddressDao.update(ipAddrId, ip);
                VlanVO vlan = _vlanDao.findById(ip.getVlanId());
                vlan.setPhysicalNetworkId(physicalNetworkId);
                vlan.setNetworkId(publicNetworkId);
                vlan.setDataCenterId(dstNetwork.getDataCenterId());
                _vlanDao.update(ip.getVlanId(), vlan);
            }
        });
    }
    // associate portable IP with new network/VPC network
    associatePortableIPToGuestNetwork(ipAddrId, newNetworkId, false);
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            if (dstNetwork.getVpcId() != null) {
                ip.setVpcId(dstNetwork.getVpcId());
            } else {
                ip.setVpcId(null);
            }
            _ipAddressDao.update(ipAddrId, ip);
        }
    });
    // trigger an action event for the transfer of portable IP across the networks, so that external entities
    // monitoring for this event can initiate the route advertisement for the availability of IP from the zoe
    ActionEventUtils.onActionEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, Domain.ROOT_DOMAIN, EventTypes.EVENT_PORTABLE_IP_TRANSFER, "Portable IP associated is transferred from network " + currentNetworkId + " to " + newNetworkId);
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) IPAddressVO(com.cloud.network.dao.IPAddressVO) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) VlanVO(com.cloud.dc.VlanVO) DB(com.cloud.utils.db.DB)

Aggregations

TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)93 TransactionStatus (com.cloud.utils.db.TransactionStatus)93 DB (com.cloud.utils.db.DB)73 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)50 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)34 ArrayList (java.util.ArrayList)30 List (java.util.List)21 ActionEvent (com.cloud.event.ActionEvent)20 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)19 Account (com.cloud.user.Account)18 ConfigurationException (javax.naming.ConfigurationException)15 IPAddressVO (com.cloud.network.dao.IPAddressVO)14 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)11 Network (com.cloud.network.Network)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9 HostVO (com.cloud.host.HostVO)9 HashMap (java.util.HashMap)9 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)8 DataCenter (com.cloud.dc.DataCenter)7 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)7