Search in sources :

Example 96 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class XcpServerDiscoverer method processConnect.

@Override
public void processConnect(final com.cloud.host.Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    if (!(cmd instanceof StartupRoutingCommand)) {
        return;
    }
    final long agentId = agent.getId();
    final StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
    if (startup.getHypervisorType() != HypervisorType.XenServer) {
        s_logger.debug("Not XenServer so moving on.");
        return;
    }
    final HostVO host = _hostDao.findById(agentId);
    final ClusterVO cluster = _clusterDao.findById(host.getClusterId());
    if (cluster.getGuid() == null) {
        cluster.setGuid(startup.getPool());
        _clusterDao.update(cluster.getId(), cluster);
    } else if (!cluster.getGuid().equals(startup.getPool())) {
        final String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + startup.getPool();
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
    }
    final Map<String, String> details = startup.getHostDetails();
    final String prodBrand = details.get("product_brand").trim();
    final String prodVersion = details.get("product_version").trim();
    final String hotfix = details.get(XenserverConfigs.XS620HotFix);
    final String prodVersionTextShort = details.get("product_version_text_short");
    final String resource = createServerResource(prodBrand, prodVersion, prodVersionTextShort, hotfix).getClass().getName();
    if (!resource.equals(host.getResource())) {
        final String msg = "host " + host.getPrivateIpAddress() + " changed from " + host.getResource() + " to " + resource;
        s_logger.debug(msg);
        host.setResource(resource);
        host.setSetup(false);
        _hostDao.update(agentId, host);
        throw new HypervisorVersionChangedException(msg);
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Setting up host " + agentId);
    }
    final HostEnvironment env = new HostEnvironment();
    final SetupCommand setup = new SetupCommand(env);
    if (_setupMultipath) {
        setup.setMultipathOn();
    }
    if (!host.isSetup()) {
        setup.setNeedSetup(true);
    }
    try {
        final Answer answer = _agentMgr.send(agentId, setup);
        if (answer != null && answer.getResult() && answer instanceof SetupAnswer) {
            host.setSetup(true);
            host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60);
            host.setHypervisorVersion(prodVersion);
            _hostDao.update(host.getId(), host);
            if (((SetupAnswer) answer).needReconnect()) {
                throw new ConnectionException(false, "Reinitialize agent after setup.");
            }
            return;
        } else {
            s_logger.warn("Unable to setup agent " + agentId + " due to " + ((answer != null) ? answer.getDetails() : "return null"));
        }
    } catch (final AgentUnavailableException e) {
        s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
    } catch (final OperationTimedoutException e) {
        s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e);
    }
    throw new ConnectionException(true, "Reinitialize agent after setup.");
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ClusterVO(com.cloud.dc.ClusterVO) HostEnvironment(com.cloud.host.HostEnvironment) SetupCommand(com.cloud.agent.api.SetupCommand) HostVO(com.cloud.host.HostVO) SetupAnswer(com.cloud.agent.api.SetupAnswer) HypervisorVersionChangedException(com.cloud.utils.exception.HypervisorVersionChangedException) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) SetupAnswer(com.cloud.agent.api.SetupAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ConnectionException(com.cloud.exception.ConnectionException)

Example 97 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class AlertManagerImpl method checkForAlerts.

public void checkForAlerts() {
    recalculateCapacity();
    // abort if we can't possibly send an alert...
    if (_emailAlert == null) {
        return;
    }
    // Get all datacenters, pods and clusters in the system.
    final List<Zone> zones = zoneRepository.findByRemovedIsNull();
    final List<ClusterVO> clusterList = _clusterDao.listAll();
    final List<HostPodVO> podList = _podDao.listAll();
    // Get capacity types at different levels
    final List<Short> dataCenterCapacityTypes = getCapacityTypesAtZoneLevel();
    final List<Short> podCapacityTypes = getCapacityTypesAtPodLevel();
    final List<Short> clusterCapacityTypes = getCapacityTypesAtClusterLevel();
    // Generate Alerts for Zone Level capacities
    for (final Zone zone : zones) {
        for (final Short capacityType : dataCenterCapacityTypes) {
            final List<SummedCapacity> capacity;
            capacity = _capacityDao.findCapacityBy(capacityType.intValue(), zone.getId(), null, null);
            if (capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) {
                capacity.add(getUsedStats(capacityType, zone.getId(), null, null));
            }
            if (capacity == null || capacity.size() == 0) {
                continue;
            }
            final double totalCapacity = capacity.get(0).getTotalCapacity();
            final double usedCapacity = capacity.get(0).getUsedCapacity();
            if (totalCapacity != 0 && usedCapacity / totalCapacity > _capacityTypeThresholdMap.get(capacityType)) {
                generateEmailAlert(zone, null, null, totalCapacity, usedCapacity, capacityType);
            }
        }
    }
    // Generate Alerts for Pod Level capacities
    for (final HostPodVO pod : podList) {
        for (final Short capacityType : podCapacityTypes) {
            final List<SummedCapacity> capacity = _capacityDao.findCapacityBy(capacityType.intValue(), pod.getDataCenterId(), pod.getId(), null);
            if (capacity == null || capacity.size() == 0) {
                continue;
            }
            final double totalCapacity = capacity.get(0).getTotalCapacity();
            final double usedCapacity = capacity.get(0).getUsedCapacity();
            if (totalCapacity != 0 && usedCapacity / totalCapacity > _capacityTypeThresholdMap.get(capacityType)) {
                generateEmailAlert(zoneRepository.findOne(pod.getDataCenterId()), pod, null, totalCapacity, usedCapacity, capacityType);
            }
        }
    }
    // Generate Alerts for Cluster Level capacities
    for (final ClusterVO cluster : clusterList) {
        for (final Short capacityType : clusterCapacityTypes) {
            final List<SummedCapacity> capacity;
            capacity = _capacityDao.findCapacityBy(capacityType.intValue(), cluster.getDataCenterId(), null, cluster.getId());
            // cpu and memory allocated capacity notification threshold can be defined at cluster level, so getting the value if they are defined at cluster level
            final double threshold;
            switch(capacityType) {
                case Capacity.CAPACITY_TYPE_STORAGE:
                    capacity.add(getUsedStats(capacityType, cluster.getDataCenterId(), cluster.getPodId(), cluster.getId()));
                    threshold = StorageCapacityThreshold.valueIn(cluster.getId());
                    break;
                case Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED:
                    threshold = StorageAllocatedCapacityThreshold.valueIn(cluster.getId());
                    break;
                case Capacity.CAPACITY_TYPE_CPU:
                    threshold = CPUCapacityThreshold.valueIn(cluster.getId());
                    break;
                case Capacity.CAPACITY_TYPE_MEMORY:
                    threshold = MemoryCapacityThreshold.valueIn(cluster.getId());
                    break;
                default:
                    threshold = _capacityTypeThresholdMap.get(capacityType);
            }
            if (capacity == null || capacity.size() == 0) {
                continue;
            }
            final double totalCapacity = capacity.get(0).getTotalCapacity();
            final double usedCapacity = capacity.get(0).getUsedCapacity() + capacity.get(0).getReservedCapacity();
            if (totalCapacity != 0 && usedCapacity / totalCapacity > threshold) {
                generateEmailAlert(zoneRepository.findOne(cluster.getDataCenterId()), ApiDBUtils.findPodById(cluster.getPodId()), cluster, totalCapacity, usedCapacity, capacityType);
            }
        }
    }
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) Zone(com.cloud.db.model.Zone) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity) HostPodVO(com.cloud.dc.HostPodVO)

Example 98 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerTest method checkIfPodIsDeletableFailureOnClusterTest.

@Test(expected = CloudRuntimeException.class)
public void checkIfPodIsDeletableFailureOnClusterTest() {
    final HostPodVO hostPodVO = Mockito.mock(HostPodVO.class);
    Mockito.when(hostPodVO.getDataCenterId()).thenReturn(new Random().nextLong());
    Mockito.when(_podDao.findById(anyLong())).thenReturn(hostPodVO);
    final ClusterVO clusterVO = Mockito.mock(ClusterVO.class);
    final ArrayList<ClusterVO> arrayList = new ArrayList<>();
    arrayList.add(clusterVO);
    Mockito.when(_privateIpAddressDao.countIPs(anyLong(), anyLong(), anyBoolean())).thenReturn(0);
    Mockito.when(_volumeDao.findByPod(anyLong())).thenReturn(new ArrayList<>());
    Mockito.when(_hostDao.findByPodId(anyLong())).thenReturn(new ArrayList<>());
    Mockito.when(_vmInstanceDao.listByPodId(anyLong())).thenReturn(new ArrayList<>());
    Mockito.when(_clusterDao.listByPodId(anyLong())).thenReturn(arrayList);
    configurationMgr.checkIfPodIsDeletable(new Random().nextLong());
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) Random(java.util.Random) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) Test(org.junit.Test)

Example 99 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class ExplicitDedicationProcessor method updateAvoidList.

private ExcludeList updateAvoidList(final List<DedicatedResourceVO> dedicatedResources, final ExcludeList avoidList, final Zone zone) {
    final ExcludeList includeList = new ExcludeList();
    for (final DedicatedResourceVO dr : dedicatedResources) {
        if (dr.getHostId() != null) {
            includeList.addHost(dr.getHostId());
            final HostVO dedicatedHost = _hostDao.findById(dr.getHostId());
            includeList.addCluster(dedicatedHost.getClusterId());
            includeList.addPod(dedicatedHost.getPodId());
        }
        if (dr.getClusterId() != null) {
            includeList.addCluster(dr.getClusterId());
            // add all hosts inside this in includeList
            final List<HostVO> hostList = _hostDao.findByClusterId(dr.getClusterId());
            for (final HostVO host : hostList) {
                final DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
                if (dHost != null && !dedicatedResources.contains(dHost)) {
                    avoidList.addHost(host.getId());
                } else {
                    includeList.addHost(host.getId());
                }
            }
            final ClusterVO dedicatedCluster = _clusterDao.findById(dr.getClusterId());
            includeList.addPod(dedicatedCluster.getPodId());
        }
        if (dr.getPodId() != null) {
            includeList.addPod(dr.getPodId());
            // add all cluster under this pod in includeList
            final List<ClusterVO> clusterList = _clusterDao.listByPodId(dr.getPodId());
            for (final ClusterVO cluster : clusterList) {
                final DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId());
                if (dCluster != null && !dedicatedResources.contains(dCluster)) {
                    avoidList.addCluster(cluster.getId());
                } else {
                    includeList.addCluster(cluster.getId());
                }
            }
            // add all hosts inside this pod in includeList
            final List<HostVO> hostList = _hostDao.findByPodId(dr.getPodId());
            for (final HostVO host : hostList) {
                final DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
                if (dHost != null && !dedicatedResources.contains(dHost)) {
                    avoidList.addHost(host.getId());
                } else {
                    includeList.addHost(host.getId());
                }
            }
        }
        if (dr.getDataCenterId() != null) {
            includeList.addZone(dr.getDataCenterId());
            // add all Pod under this data center in includeList
            final List<HostPodVO> podList = _podDao.listByDataCenterId(dr.getDataCenterId());
            for (final HostPodVO pod : podList) {
                final DedicatedResourceVO dPod = _dedicatedDao.findByPodId(pod.getId());
                if (dPod != null && !dedicatedResources.contains(dPod)) {
                    avoidList.addPod(pod.getId());
                } else {
                    includeList.addPod(pod.getId());
                }
            }
            final List<ClusterVO> clusterList = _clusterDao.listClustersByDcId(dr.getDataCenterId());
            for (final ClusterVO cluster : clusterList) {
                final DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId());
                if (dCluster != null && !dedicatedResources.contains(dCluster)) {
                    avoidList.addCluster(cluster.getId());
                } else {
                    includeList.addCluster(cluster.getId());
                }
            }
            // add all hosts inside this in includeList
            final List<HostVO> hostList = _hostDao.listByDataCenterId(dr.getDataCenterId());
            for (final HostVO host : hostList) {
                final DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
                if (dHost != null && !dedicatedResources.contains(dHost)) {
                    avoidList.addHost(host.getId());
                } else {
                    includeList.addHost(host.getId());
                }
            }
        }
    }
    // Update avoid list using includeList.
    // add resources in avoid list which are not in include list.
    final List<HostPodVO> pods = _podDao.listByDataCenterId(zone.getId());
    final List<ClusterVO> clusters = _clusterDao.listClustersByDcId(zone.getId());
    final List<HostVO> hosts = _hostDao.listByDataCenterId(zone.getId());
    final Set<Long> podsInIncludeList = includeList.getPodsToAvoid();
    final Set<Long> clustersInIncludeList = includeList.getClustersToAvoid();
    final Set<Long> hostsInIncludeList = includeList.getHostsToAvoid();
    for (final HostPodVO pod : pods) {
        if (podsInIncludeList != null && !podsInIncludeList.contains(pod.getId())) {
            avoidList.addPod(pod.getId());
        }
    }
    for (final ClusterVO cluster : clusters) {
        if (clustersInIncludeList != null && !clustersInIncludeList.contains(cluster.getId())) {
            avoidList.addCluster(cluster.getId());
        }
    }
    for (final HostVO host : hosts) {
        if (hostsInIncludeList != null && !hostsInIncludeList.contains(host.getId())) {
            avoidList.addHost(host.getId());
        }
    }
    return avoidList;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) ClusterVO(com.cloud.dc.ClusterVO) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO)

Example 100 with ClusterVO

use of com.cloud.dc.ClusterVO in project cosmic by MissionCriticalCloud.

the class OCFS2ManagerImpl method prepareNodes.

@Override
public boolean prepareNodes(final Long clusterId) {
    final ClusterVO cluster = _clusterDao.findById(clusterId);
    if (cluster == null) {
        throw new CloudRuntimeException("Cannot find cluster for ID " + clusterId);
    }
    final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
    sc.and(sc.entity().getClusterId(), Op.EQ, clusterId);
    sc.and(sc.entity().getPodId(), Op.EQ, cluster.getPodId());
    sc.and(sc.entity().getDataCenterId(), Op.EQ, cluster.getDataCenterId());
    sc.and(sc.entity().getType(), Op.EQ, Host.Type.Routing);
    final List<HostVO> hosts = sc.list();
    if (hosts.isEmpty()) {
        s_logger.debug("There is no host in cluster " + clusterId + ", no need to prepare OCFS2 nodes");
        return true;
    }
    return prepareNodes(getClusterName(clusterId), hosts);
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostVO(com.cloud.host.HostVO)

Aggregations

ClusterVO (com.cloud.dc.ClusterVO)151 HostVO (com.cloud.host.HostVO)72 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)66 ArrayList (java.util.ArrayList)55 HostPodVO (com.cloud.dc.HostPodVO)46 DataCenterVO (com.cloud.dc.DataCenterVO)38 ConfigurationException (javax.naming.ConfigurationException)37 HashMap (java.util.HashMap)28 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)24 Map (java.util.Map)24 DiscoveryException (com.cloud.exception.DiscoveryException)21 DB (com.cloud.utils.db.DB)21 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)20 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 Account (com.cloud.user.Account)17 List (java.util.List)17 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)17 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)16 ClusterDetailsVO (com.cloud.dc.ClusterDetailsVO)15 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)14