Search in sources :

Example 36 with Provider

use of com.cloud.legacymodel.network.Network.Provider 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);
    }
}
Also used : StaticRoute(com.cloud.legacymodel.network.vpc.StaticRoute) NetworkVO(com.cloud.network.dao.NetworkVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.legacymodel.network.Network.Provider) PrivateGateway(com.cloud.legacymodel.network.vpc.PrivateGateway) VpcProvider(com.cloud.network.element.VpcProvider) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 37 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class VpcManagerImpl method applyVpcPrivateGateway.

@Override
@ActionEvent(eventType = EventTypes.EVENT_PRIVATE_GATEWAY_CREATE, eventDescription = "Applying VPC private gateway", async = true)
public PrivateGateway applyVpcPrivateGateway(final long gatewayId, final boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException {
    final VpcGatewayVO vo = _vpcGatewayDao.findById(gatewayId);
    boolean success = true;
    try {
        final List<Provider> providersToImplement = getVpcProviders(vo.getVpcId());
        final PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
        for (final VpcProvider provider : getVpcElements()) {
            if (providersToImplement.contains(provider.getProvider())) {
                if (!provider.createPrivateGateway(gateway)) {
                    success = false;
                }
            }
        }
        if (success) {
            s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
            if (vo.getState() != VpcGateway.State.Ready) {
                vo.setState(VpcGateway.State.Ready);
                _vpcGatewayDao.update(vo.getId(), vo);
                s_logger.debug("Marke gateway " + gateway + " with state " + VpcGateway.State.Ready);
            }
            CallContext.current().setEventDetails("Private Gateway Id: " + gatewayId);
            return getVpcPrivateGateway(gatewayId);
        } else {
            s_logger.warn("Private gateway " + gateway + " failed to apply on the backend");
            return null;
        }
    } finally {
        if (!success) {
            if (destroyOnFailure) {
                s_logger.debug("Destroying private gateway " + vo + " that failed to start");
                // fail, destroyPrivateGateway is already called
                if (deletePrivateGatewayFromTheDB(getVpcPrivateGateway(gatewayId))) {
                    s_logger.warn("Successfully destroyed vpc " + vo + " that failed to start");
                } else {
                    s_logger.warn("Failed to destroy vpc " + vo + " that failed to start");
                }
            }
        }
    }
}
Also used : VpcProvider(com.cloud.network.element.VpcProvider) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.legacymodel.network.Network.Provider) PrivateGateway(com.cloud.legacymodel.network.vpc.PrivateGateway) ActionEvent(com.cloud.event.ActionEvent)

Example 38 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class VpcManagerImpl method checkCapabilityPerServiceProvider.

protected void checkCapabilityPerServiceProvider(final Set<Provider> providers, final Capability capability, final Service service) {
    // TODO Shouldn't it fail it there are no providers?
    if (providers != null) {
        for (final Provider provider : providers) {
            final NetworkElement element = _ntwkModel.getElementImplementingProvider(provider.getName());
            final Map<Service, Map<Capability, String>> capabilities = element.getCapabilities();
            if (capabilities != null && !capabilities.isEmpty()) {
                final Map<Capability, String> connectivityCapabilities = capabilities.get(service);
                if (connectivityCapabilities == null || connectivityCapabilities != null && !connectivityCapabilities.keySet().contains(capability)) {
                    throw new InvalidParameterValueException(String.format("Provider %s does not support %s  capability.", provider.getName(), capability.getName()));
                }
            }
        }
    }
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.legacymodel.network.Network.Capability) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService) Map(java.util.Map) HashMap(java.util.HashMap) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.legacymodel.network.Network.Provider)

Example 39 with Provider

use of com.cloud.legacymodel.network.Network.Provider 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;
}
Also used : ServiceOffering(com.cloud.offering.ServiceOffering) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) VlanVO(com.cloud.dc.VlanVO) Map(java.util.Map) HashMap(java.util.HashMap) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.legacymodel.network.Network.Provider) DB(com.cloud.utils.db.DB)

Example 40 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class VpcManagerImpl method shutdownVpc.

@Override
public boolean shutdownVpc(final long vpcId) throws ConcurrentOperationException, ResourceUnavailableException {
    final CallContext ctx = CallContext.current();
    final Account caller = ctx.getCallingAccount();
    // check if vpc exists
    final Vpc vpc = _vpcDao.findById(vpcId);
    if (vpc == null) {
        throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId);
    }
    // permission check
    _accountMgr.checkAccess(caller, null, false, vpc);
    // shutdown provider
    s_logger.debug("Shutting down vpc " + vpc);
    // TODO - shutdown all vpc resources here (ACLs, gateways, etc)
    boolean success = true;
    final List<Provider> providersToImplement = getVpcProviders(vpc.getId());
    final ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(ctx.getCallingUserId()), caller);
    for (final VpcProvider element : getVpcElements()) {
        if (providersToImplement.contains(element.getProvider())) {
            if (element.shutdownVpc(vpc, context)) {
                s_logger.debug("Vpc " + vpc + " has been shutdown succesfully");
            } else {
                s_logger.warn("Vpc " + vpc + " failed to shutdown");
                success = false;
            }
        }
    }
    return success;
}
Also used : VpcProvider(com.cloud.network.element.VpcProvider) Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Vpc(com.cloud.legacymodel.network.vpc.Vpc) CallContext(com.cloud.context.CallContext) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.legacymodel.network.Network.Provider) ReservationContext(com.cloud.vm.ReservationContext)

Aggregations

Provider (com.cloud.legacymodel.network.Network.Provider)55 Service (com.cloud.legacymodel.network.Network.Service)29 HashSet (java.util.HashSet)25 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)22 HashMap (java.util.HashMap)22 Set (java.util.Set)22 ArrayList (java.util.ArrayList)21 NetworkElement (com.cloud.network.element.NetworkElement)19 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)15 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)14 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)14 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)13 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)13 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)12 ResourceLimitService (com.cloud.user.ResourceLimitService)12 Network (com.cloud.legacymodel.network.Network)11 VpcProvider (com.cloud.network.element.VpcProvider)10 NicProfile (com.cloud.vm.NicProfile)10 SortedSet (java.util.SortedSet)10 NetworkVO (com.cloud.network.dao.NetworkVO)8