Search in sources :

Example 46 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class MidoNetPublicNetworkGuru method allocate.

@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
    if (nic == null) {
        nic = new NicProfile(Nic.ReservationStrategy.Create, null, null, null, null);
    }
    s_logger.debug("allocate called with network: " + network + " nic: " + nic + " vm: " + vm);
    DataCenter dc = _dcDao.findById(network.getDataCenterId());
    if (nic.getRequestedIPv4() != null) {
        throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + nic);
    }
    getIp(nic, dc, vm, network);
    if (nic.getIPv4Address() == null) {
        nic.setReservationStrategy(Nic.ReservationStrategy.Start);
    } else if (vm.getVirtualMachine().getType() == VirtualMachine.Type.DomainRouter) {
        nic.setReservationStrategy(Nic.ReservationStrategy.Managed);
    } else {
        nic.setReservationStrategy(Nic.ReservationStrategy.Create);
    }
    nic.setBroadcastUri(generateBroadcastUri(network));
    return nic;
}
Also used : DataCenter(com.cloud.dc.DataCenter) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NicProfile(com.cloud.vm.NicProfile)

Example 47 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class MidoNetPublicNetworkGuru method updateNetworkProfile.

@Override
public void updateNetworkProfile(NetworkProfile networkProfile) {
    DataCenter dc = _dcDao.findById(networkProfile.getDataCenterId());
    networkProfile.setDns1(dc.getDns1());
    networkProfile.setDns2(dc.getDns2());
}
Also used : DataCenter(com.cloud.dc.DataCenter)

Example 48 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class ConfigurationManagerImpl method searchForNetworkOfferings.

@Override
public Pair<List<? extends NetworkOffering>, Integer> searchForNetworkOfferings(final ListNetworkOfferingsCmd cmd) {
    Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
    isAscending = isAscending == null ? Boolean.TRUE : isAscending;
    final Filter searchFilter = new Filter(NetworkOfferingVO.class, "sortKey", isAscending, null, null);
    final Account caller = CallContext.current().getCallingAccount();
    final SearchCriteria<NetworkOfferingVO> sc = _networkOfferingDao.createSearchCriteria();
    final Long id = cmd.getId();
    final Object name = cmd.getNetworkOfferingName();
    final Object displayText = cmd.getDisplayText();
    final Object trafficType = cmd.getTrafficType();
    final Object isDefault = cmd.getIsDefault();
    final Object specifyVlan = cmd.getSpecifyVlan();
    final Object availability = cmd.getAvailability();
    final Object state = cmd.getState();
    final Long zoneId = cmd.getZoneId();
    DataCenter zone = null;
    final Long networkId = cmd.getNetworkId();
    final String guestIpType = cmd.getGuestIpType();
    final List<String> supportedServicesStr = cmd.getSupportedServices();
    final Object specifyIpRanges = cmd.getSpecifyIpRanges();
    final String tags = cmd.getTags();
    final Boolean isTagged = cmd.isTagged();
    final Boolean forVpc = cmd.getForVpc();
    if (zoneId != null) {
        zone = _entityMgr.findById(DataCenter.class, zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Unable to find the zone by id=" + zoneId);
        }
    }
    final Object keyword = cmd.getKeyword();
    if (keyword != null) {
        final SearchCriteria<NetworkOfferingVO> ssc = _networkOfferingDao.createSearchCriteria();
        ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("name", SearchCriteria.Op.SC, ssc);
    }
    if (name != null) {
        sc.addAnd("name", SearchCriteria.Op.EQ, name);
    }
    if (guestIpType != null) {
        sc.addAnd("guestType", SearchCriteria.Op.EQ, guestIpType);
    }
    if (displayText != null) {
        sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%");
    }
    if (trafficType != null) {
        sc.addAnd("trafficType", SearchCriteria.Op.EQ, trafficType);
    }
    if (isDefault != null) {
        sc.addAnd("isDefault", SearchCriteria.Op.EQ, isDefault);
    }
    // only root admin can list network offering with specifyVlan = true
    if (specifyVlan != null) {
        sc.addAnd("specifyVlan", SearchCriteria.Op.EQ, specifyVlan);
    }
    if (availability != null) {
        sc.addAnd("availability", SearchCriteria.Op.EQ, availability);
    }
    if (state != null) {
        sc.addAnd("state", SearchCriteria.Op.EQ, state);
    }
    if (specifyIpRanges != null) {
        sc.addAnd("specifyIpRanges", SearchCriteria.Op.EQ, specifyIpRanges);
    }
    if (zone != null) {
        if (zone.getNetworkType() == NetworkType.Basic) {
            // basic zone, and shouldn't display networkOfferings
            return new Pair<List<? extends NetworkOffering>, Integer>(new ArrayList<NetworkOffering>(), 0);
        }
    }
    // Don't return system network offerings to the user
    sc.addAnd("systemOnly", SearchCriteria.Op.EQ, false);
    // if networkId is specified, list offerings available for upgrade only
    // (for this network)
    Network network = null;
    if (networkId != null) {
        // check if network exists and the caller can operate with it
        network = _networkModel.getNetwork(networkId);
        if (network == null) {
            throw new InvalidParameterValueException("Unable to find the network by id=" + networkId);
        }
        // Don't allow to update system network
        final NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId());
        if (offering.isSystemOnly()) {
            throw new InvalidParameterValueException("Can't update system networks");
        }
        _accountMgr.checkAccess(caller, null, true, network);
        final List<Long> offeringIds = _networkModel.listNetworkOfferingsForUpgrade(networkId);
        if (!offeringIds.isEmpty()) {
            sc.addAnd("id", SearchCriteria.Op.IN, offeringIds.toArray());
        } else {
            return new Pair<List<? extends NetworkOffering>, Integer>(new ArrayList<NetworkOffering>(), 0);
        }
    }
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    }
    if (tags != null) {
        sc.addAnd("tags", SearchCriteria.Op.EQ, tags);
    }
    if (isTagged != null) {
        if (isTagged) {
            sc.addAnd("tags", SearchCriteria.Op.NNULL);
        } else {
            sc.addAnd("tags", SearchCriteria.Op.NULL);
        }
    }
    final List<NetworkOfferingVO> offerings = _networkOfferingDao.search(sc, searchFilter);
    final Boolean sourceNatSupported = cmd.getSourceNatSupported();
    final List<String> pNtwkTags = new ArrayList<String>();
    boolean checkForTags = false;
    if (zone != null) {
        final List<PhysicalNetworkVO> pNtwks = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, TrafficType.Guest);
        if (pNtwks.size() > 1) {
            checkForTags = true;
            // go through tags
            for (final PhysicalNetworkVO pNtwk : pNtwks) {
                final List<String> pNtwkTag = pNtwk.getTags();
                if (pNtwkTag == null || pNtwkTag.isEmpty()) {
                    throw new CloudRuntimeException("Tags are not defined for physical network in the zone id=" + zoneId);
                }
                pNtwkTags.addAll(pNtwkTag);
            }
        }
    }
    // filter by supported services
    final boolean listBySupportedServices = supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty();
    final boolean checkIfProvidersAreEnabled = zoneId != null;
    final boolean parseOfferings = listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled || forVpc != null || network != null;
    if (parseOfferings) {
        final List<NetworkOfferingVO> supportedOfferings = new ArrayList<NetworkOfferingVO>();
        Service[] supportedServices = null;
        if (listBySupportedServices) {
            supportedServices = new Service[supportedServicesStr.size()];
            int i = 0;
            for (final String supportedServiceStr : supportedServicesStr) {
                final Service service = Service.getService(supportedServiceStr);
                if (service == null) {
                    throw new InvalidParameterValueException("Invalid service specified " + supportedServiceStr);
                } else {
                    supportedServices[i] = service;
                }
                i++;
            }
        }
        for (final NetworkOfferingVO offering : offerings) {
            boolean addOffering = true;
            List<Service> checkForProviders = new ArrayList<Service>();
            if (checkForTags) {
                if (!pNtwkTags.contains(offering.getTags())) {
                    continue;
                }
            }
            if (listBySupportedServices) {
                addOffering = addOffering && _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), supportedServices);
            }
            if (checkIfProvidersAreEnabled) {
                if (supportedServices != null && supportedServices.length > 0) {
                    checkForProviders = Arrays.asList(supportedServices);
                } else {
                    checkForProviders = _networkModel.listNetworkOfferingServices(offering.getId());
                }
                addOffering = addOffering && _networkModel.areServicesEnabledInZone(zoneId, offering, checkForProviders);
            }
            if (sourceNatSupported != null) {
                addOffering = addOffering && _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Network.Service.SourceNat) == sourceNatSupported;
            }
            if (forVpc != null) {
                addOffering = addOffering && isOfferingForVpc(offering) == forVpc.booleanValue();
            } else if (network != null) {
                addOffering = addOffering && isOfferingForVpc(offering) == (network.getVpcId() != null);
            }
            if (addOffering) {
                supportedOfferings.add(offering);
            }
        }
        // Now apply pagination
        final List<? extends NetworkOffering> wPagination = StringUtils.applyPagination(supportedOfferings, cmd.getStartIndex(), cmd.getPageSizeVal());
        if (wPagination != null) {
            final Pair<List<? extends NetworkOffering>, Integer> listWPagination = new Pair<List<? extends NetworkOffering>, Integer>(wPagination, offerings.size());
            return listWPagination;
        }
        return new Pair<List<? extends NetworkOffering>, Integer>(supportedOfferings, supportedOfferings.size());
    } else {
        final List<? extends NetworkOffering> wPagination = StringUtils.applyPagination(offerings, cmd.getStartIndex(), cmd.getPageSizeVal());
        if (wPagination != null) {
            final Pair<List<? extends NetworkOffering>, Integer> listWPagination = new Pair<List<? extends NetworkOffering>, Integer>(wPagination, offerings.size());
            return listWPagination;
        }
        return new Pair<List<? extends NetworkOffering>, Integer>(offerings, offerings.size());
    }
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair) NetworkOffering(com.cloud.offering.NetworkOffering) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) NetworkService(com.cloud.network.NetworkService) ManagementService(com.cloud.server.ManagementService) ResourceLimitService(com.cloud.user.ResourceLimitService) AffinityGroupService(org.apache.cloudstack.affinity.AffinityGroupService) DataCenter(com.cloud.dc.DataCenter) Filter(com.cloud.utils.db.Filter) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO)

Example 49 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class FirstFitPlanner method scanClustersForDestinationInZoneOrPod.

private List<Long> scanClustersForDestinationInZoneOrPod(long id, boolean isZone, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) {
    VirtualMachine vm = vmProfile.getVirtualMachine();
    ServiceOffering offering = vmProfile.getServiceOffering();
    DataCenter dc = dcDao.findById(vm.getDataCenterId());
    int requiredCpu = offering.getCpu() * offering.getSpeed();
    long requiredRam = offering.getRamSize() * 1024L * 1024L;
    //list clusters under this zone by cpu and ram capacity
    Pair<List<Long>, Map<Long, Double>> clusterCapacityInfo = listClustersByCapacity(id, requiredCpu, requiredRam, avoid, isZone);
    List<Long> prioritizedClusterIds = clusterCapacityInfo.first();
    if (!prioritizedClusterIds.isEmpty()) {
        if (avoid.getClustersToAvoid() != null) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Removing from the clusterId list these clusters from avoid set: " + avoid.getClustersToAvoid());
            }
            prioritizedClusterIds.removeAll(avoid.getClustersToAvoid());
        }
        if (!isRootAdmin(vmProfile)) {
            List<Long> disabledClusters = new ArrayList<Long>();
            if (isZone) {
                disabledClusters = listDisabledClusters(plan.getDataCenterId(), null);
            } else {
                disabledClusters = listDisabledClusters(plan.getDataCenterId(), id);
            }
            if (!disabledClusters.isEmpty()) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Removing from the clusterId list these clusters that are disabled/clusters under disabled pods: " + disabledClusters);
                }
                prioritizedClusterIds.removeAll(disabledClusters);
            }
        }
        removeClustersCrossingThreshold(prioritizedClusterIds, avoid, vmProfile, plan);
        String hostTagOnOffering = offering.getHostTag();
        if (hostTagOnOffering != null) {
            removeClustersWithoutMatchingTag(prioritizedClusterIds, hostTagOnOffering);
        }
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No clusters found having a host with enough capacity, returning.");
        }
        return null;
    }
    if (!prioritizedClusterIds.isEmpty()) {
        List<Long> clusterList = reorderClusters(id, isZone, clusterCapacityInfo, vmProfile, plan);
        //return checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc);
        return clusterList;
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No clusters found after removing disabled clusters and clusters in avoid list, returning.");
        }
        return null;
    }
}
Also used : DataCenter(com.cloud.dc.DataCenter) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 50 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class ExtractVolumeCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Volume Id: " + getId());
    String uploadUrl = _volumeService.extractVolume(this);
    if (uploadUrl != null) {
        ExtractResponse response = new ExtractResponse();
        response.setResponseName(getCommandName());
        response.setObjectName("volume");
        Volume vol = _entityMgr.findById(Volume.class, id);
        response.setId(vol.getUuid());
        response.setName(vol.getName());
        DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
        response.setMode(mode);
        response.setState(Upload.Status.DOWNLOAD_URL_CREATED.toString());
        Account account = _entityMgr.findById(Account.class, getEntityOwnerId());
        response.setAccountId(account.getUuid());
        response.setUrl(uploadUrl);
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract volume");
    }
}
Also used : Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) ExtractResponse(org.apache.cloudstack.api.response.ExtractResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Volume(com.cloud.storage.Volume)

Aggregations

DataCenter (com.cloud.dc.DataCenter)144 Account (com.cloud.user.Account)50 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)37 NetworkVO (com.cloud.network.dao.NetworkVO)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)32 Network (com.cloud.network.Network)30 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)27 ArrayList (java.util.ArrayList)27 DeployDestination (com.cloud.deploy.DeployDestination)25 NetworkOffering (com.cloud.offering.NetworkOffering)23 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)17 IPAddressVO (com.cloud.network.dao.IPAddressVO)17 DB (com.cloud.utils.db.DB)17 Domain (com.cloud.domain.Domain)16 ReservationContext (com.cloud.vm.ReservationContext)16 HostVO (com.cloud.host.HostVO)15 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)13 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)13 PhysicalNetwork (com.cloud.network.PhysicalNetwork)11 ServiceOffering (com.cloud.offering.ServiceOffering)11