Search in sources :

Example 1 with ReservationContextImpl

use of com.cloud.vm.ReservationContextImpl in project cloudstack by apache.

the class SspGuestNetworkGuru method release.

@Override
public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
    Network network = _networkDao.findById(nic.getNetworkId());
    _sspMgr.deleteNicEnv(network, nic, new ReservationContextImpl(reservationId, null, null));
    return super.release(nic, vm, reservationId);
}
Also used : Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ReservationContextImpl(com.cloud.vm.ReservationContextImpl)

Example 2 with ReservationContextImpl

use of com.cloud.vm.ReservationContextImpl 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;
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DeployDestination(com.cloud.deploy.DeployDestination) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ConnectionException(com.cloud.exception.ConnectionException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) ConfigurationException(javax.naming.ConfigurationException) ReservationContext(com.cloud.vm.ReservationContext)

Example 3 with ReservationContextImpl

use of com.cloud.vm.ReservationContextImpl in project cloudstack by apache.

the class NetworkOrchestrator method prepareNicForMigration.

@Override
public void prepareNicForMigration(final VirtualMachineProfile vm, final DeployDestination dest) {
    if (vm.getType().equals(VirtualMachine.Type.DomainRouter) && (vm.getHypervisorType().equals(HypervisorType.KVM) || vm.getHypervisorType().equals(HypervisorType.VMware))) {
        //Include nics hot plugged and not stored in DB
        prepareAllNicsForMigration(vm, dest);
        return;
    }
    final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
    final ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), null, null);
    for (final NicVO nic : nics) {
        final NetworkVO network = _networksDao.findById(nic.getNetworkId());
        final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
        final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
        final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network));
        if (guru instanceof NetworkMigrationResponder) {
            if (!((NetworkMigrationResponder) guru).prepareMigration(profile, network, vm, dest, context)) {
                // XXX: Transaction error
                s_logger.error("NetworkGuru " + guru + " prepareForMigration failed.");
            }
        }
        final List<Provider> providersToImplement = getNetworkProviders(network.getId());
        for (final NetworkElement element : networkElements) {
            if (providersToImplement.contains(element.getProvider())) {
                if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
                    throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId());
                }
                if (element instanceof NetworkMigrationResponder) {
                    if (!((NetworkMigrationResponder) element).prepareMigration(profile, network, vm, dest, context)) {
                        // XXX: Transaction error
                        s_logger.error("NetworkElement " + element + " prepareForMigration failed.");
                    }
                }
            }
        }
        guru.updateNicProfile(profile, network);
        vm.addNic(profile);
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkMigrationResponder(com.cloud.network.NetworkMigrationResponder) NetworkGuru(com.cloud.network.guru.NetworkGuru) NicProfile(com.cloud.vm.NicProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) DnsServiceProvider(com.cloud.network.element.DnsServiceProvider) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.network.Network.Provider) NetworkElement(com.cloud.network.element.NetworkElement) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NicVO(com.cloud.vm.NicVO)

Example 4 with ReservationContextImpl

use of com.cloud.vm.ReservationContextImpl in project cloudstack by apache.

the class VpcManagerImpl method deletePrivateGatewayFromTheDB.

@DB
protected boolean deletePrivateGatewayFromTheDB(final PrivateGateway gateway) {
    // check if there are ips allocted in the network
    final long networkId = gateway.getNetworkId();
    vpcTxCallable.setGateway(gateway);
    final ExecutorService txExecutor = Executors.newSingleThreadExecutor();
    final Future<Boolean> futureResult = txExecutor.submit(vpcTxCallable);
    boolean deleteNetworkFinal;
    try {
        deleteNetworkFinal = futureResult.get();
        if (deleteNetworkFinal) {
            final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
            final Account owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
            final ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
            _ntwkMgr.destroyNetwork(networkId, context, false);
            s_logger.debug("Deleted private network id=" + networkId);
        }
    } catch (final InterruptedException e) {
        s_logger.error("deletePrivateGatewayFromTheDB failed to delete network id " + networkId + "due to => ", e);
    } catch (final ExecutionException e) {
        s_logger.error("deletePrivateGatewayFromTheDB failed to delete network id " + networkId + "due to => ", e);
    }
    return true;
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ExecutionException(java.util.concurrent.ExecutionException) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) DB(com.cloud.utils.db.DB)

Example 5 with ReservationContextImpl

use of com.cloud.vm.ReservationContextImpl in project cloudstack by apache.

the class VpcManagerImpl method startVpc.

@Override
public boolean startVpc(final long vpcId, final boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    final CallContext ctx = CallContext.current();
    final Account caller = ctx.getCallingAccount();
    final User callerUser = _accountMgr.getActiveUser(ctx.getCallingUserId());
    // check if vpc exists
    final Vpc vpc = getActiveVpc(vpcId);
    if (vpc == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC by id specified");
        ex.addProxyObject(String.valueOf(vpcId), "VPC");
        throw ex;
    }
    // permission check
    _accountMgr.checkAccess(caller, null, false, vpc);
    final DataCenter dc = _entityMgr.findById(DataCenter.class, vpc.getZoneId());
    final DeployDestination dest = new DeployDestination(dc, null, null, null);
    final ReservationContext context = new ReservationContextImpl(null, null, callerUser, _accountMgr.getAccount(vpc.getAccountId()));
    boolean result = true;
    try {
        if (!startVpc(vpc, dest, context)) {
            s_logger.warn("Failed to start vpc " + vpc);
            result = false;
        }
    } catch (final Exception ex) {
        s_logger.warn("Failed to start vpc " + vpc + " due to ", ex);
        result = false;
    } finally {
        // do cleanup
        if (!result && destroyOnFailure) {
            s_logger.debug("Destroying vpc " + vpc + " that failed to start");
            if (destroyVpc(vpc, caller, callerUser.getId())) {
                s_logger.warn("Successfully destroyed vpc " + vpc + " that failed to start");
            } else {
                s_logger.warn("Failed to destroy vpc " + vpc + " that failed to start");
            }
        }
    }
    return result;
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DeployDestination(com.cloud.deploy.DeployDestination) CallContext(org.apache.cloudstack.context.CallContext) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ReservationContext(com.cloud.vm.ReservationContext)

Aggregations

ReservationContextImpl (com.cloud.vm.ReservationContextImpl)20 ReservationContext (com.cloud.vm.ReservationContext)19 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)10 NetworkVO (com.cloud.network.dao.NetworkVO)9 DeployDestination (com.cloud.deploy.DeployDestination)8 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)8 Account (com.cloud.user.Account)8 NicProfile (com.cloud.vm.NicProfile)7 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)6 DataCenter (com.cloud.dc.DataCenter)5 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)5 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)5 User (com.cloud.user.User)5 NicVO (com.cloud.vm.NicVO)5 ActionEvent (com.cloud.event.ActionEvent)4 Provider (com.cloud.network.Network.Provider)4 NetworkElement (com.cloud.network.element.NetworkElement)4 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)4 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)4