Search in sources :

Example 96 with DataCenterVO

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

the class ManagementServerImpl method listCapacities.

@Override
public List<CapacityVO> listCapacities(final ListCapacityCmd cmd) {
    final Integer capacityType = cmd.getType();
    Long zoneId = cmd.getZoneId();
    final Long podId = cmd.getPodId();
    final Long clusterId = cmd.getClusterId();
    final Boolean fetchLatest = cmd.getFetchLatest();
    zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), zoneId);
    if (fetchLatest != null && fetchLatest) {
        _alertMgr.recalculateCapacity();
    }
    final List<SummedCapacity> summedCapacities = _capacityDao.findCapacityBy(capacityType, zoneId, podId, clusterId);
    final List<CapacityVO> capacities = new ArrayList<CapacityVO>();
    for (final SummedCapacity summedCapacity : summedCapacities) {
        final CapacityVO capacity = new CapacityVO(null, summedCapacity.getDataCenterId(), summedCapacity.getPodId(), summedCapacity.getClusterId(), summedCapacity.getUsedCapacity() + summedCapacity.getReservedCapacity(), summedCapacity.getTotalCapacity(), summedCapacity.getCapacityType());
        capacities.add(capacity);
    }
    // op_host_Capacity contains only allocated stats and the real time
    // stats are stored "in memory".
    // Show Sec. Storage only when the api is invoked for the zone layer.
    List<DataCenterVO> dcList = new ArrayList<DataCenterVO>();
    if (zoneId == null && podId == null && clusterId == null) {
        dcList = ApiDBUtils.listZones();
    } else if (zoneId != null) {
        dcList.add(ApiDBUtils.findZoneById(zoneId));
    } else {
        if (clusterId != null) {
            zoneId = ApiDBUtils.findClusterById(clusterId).getDataCenterId();
        } else {
            zoneId = ApiDBUtils.findPodById(podId).getDataCenterId();
        }
        if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
            capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
        }
    }
    for (final DataCenterVO zone : dcList) {
        zoneId = zone.getId();
        if ((capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) && podId == null && clusterId == null) {
            capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, zoneId));
        }
        if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
            capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
        }
    }
    return capacities;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) CapacityVO(com.cloud.capacity.CapacityVO) ArrayList(java.util.ArrayList) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity)

Example 97 with DataCenterVO

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

the class TemplateServiceImpl method associateTemplateToZone.

// persist entry in template_zone_ref table. zoneId can be empty for
// region-wide image store, in that case,
// we will associate the template to all the zones.
@Override
public void associateTemplateToZone(long templateId, Long zoneId) {
    List<Long> dcs = new ArrayList<Long>();
    if (zoneId != null) {
        dcs.add(zoneId);
    } else {
        List<DataCenterVO> zones = _dcDao.listAll();
        for (DataCenterVO zone : zones) {
            dcs.add(zone.getId());
        }
    }
    for (Long id : dcs) {
        VMTemplateZoneVO tmpltZoneVO = _vmTemplateZoneDao.findByZoneTemplate(id, templateId);
        if (tmpltZoneVO == null) {
            tmpltZoneVO = new VMTemplateZoneVO(id, templateId, new Date());
            _vmTemplateZoneDao.persist(tmpltZoneVO);
        } else {
            tmpltZoneVO.setLastUpdated(new Date());
            _vmTemplateZoneDao.update(tmpltZoneVO.getId(), tmpltZoneVO);
        }
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) VMTemplateZoneVO(com.cloud.storage.VMTemplateZoneVO) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 98 with DataCenterVO

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

the class DirectAgentTest method setUp.

@Test(priority = -1)
public void setUp() {
    HostVO host = hostDao.findByGuid(getHostGuid());
    if (host != null) {
        hostId = host.getId();
        dcId = host.getDataCenterId();
        clusterId = host.getClusterId();
        return;
    }
    // create data center
    DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
    dc = dcDao.persist(dc);
    dcId = dc.getId();
    // create pod
    HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), getHostGateway(), getHostCidr(), 8, "test");
    pod = podDao.persist(pod);
    // create xenserver cluster
    ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
    cluster.setHypervisorType(HypervisorType.XenServer.toString());
    cluster.setClusterType(ClusterType.CloudManaged);
    cluster.setManagedState(ManagedState.Managed);
    cluster = clusterDao.persist(cluster);
    clusterId = cluster.getId();
    // create xenserver host
    host = new HostVO(getHostGuid());
    host.setName("devcloud xenserver host");
    host.setType(Host.Type.Routing);
    host.setHypervisorType(HypervisorType.XenServer);
    host.setPrivateIpAddress(getHostIp());
    host.setDataCenterId(dc.getId());
    host.setVersion("6.0.1");
    host.setAvailable(true);
    host.setSetup(true);
    host.setLastPinged(0);
    host.setResourceState(ResourceState.Enabled);
    host.setClusterId(cluster.getId());
    host = hostDao.persist(host);
    hostId = host.getId();
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) Test(org.testng.annotations.Test)

Example 99 with DataCenterVO

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

the class AgentManagerImpl method handleDisconnectWithInvestigation.

protected boolean handleDisconnectWithInvestigation(final AgentAttache attache, Status.Event event) {
    final long hostId = attache.getId();
    HostVO host = _hostDao.findById(hostId);
    if (host != null) {
        Status nextStatus = null;
        try {
            nextStatus = host.getStatus().getNextStatus(event);
        } catch (final NoTransitionException ne) {
            /*
                 * Agent may be currently in status of Down, Alert, Removed, namely there is no next status for some events. Why this can happen? Ask God not me. I hate there was
                 * no piece of comment for code handling race condition. God knew what race condition the code dealt with!
                 */
            s_logger.debug("Caught exception while getting agent's next status", ne);
        }
        if (nextStatus == Status.Alert) {
            /* OK, we are going to the bad status, let's see what happened */
            s_logger.info("Investigating why host " + hostId + " has disconnected with event " + event);
            Status determinedState = investigate(attache);
            // if state cannot be determined do nothing and bail out
            if (determinedState == null) {
                if ((System.currentTimeMillis() >> 10) - host.getLastPinged() > AlertWait.value()) {
                    s_logger.warn("Agent " + hostId + " state cannot be determined for more than " + AlertWait + "(" + AlertWait.value() + ") seconds, will go to Alert state");
                    determinedState = Status.Alert;
                } else {
                    s_logger.warn("Agent " + hostId + " state cannot be determined, do nothing");
                    return false;
                }
            }
            final Status currentStatus = host.getStatus();
            s_logger.info("The agent from host " + hostId + " state determined is " + determinedState);
            if (determinedState == Status.Down) {
                final String message = "Host is down: " + host.getId() + "-" + host.getName() + ". Starting HA on the VMs";
                s_logger.error(message);
                if (host.getType() != Host.Type.SecondaryStorage && host.getType() != Host.Type.ConsoleProxy) {
                    _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host down, " + host.getId(), message);
                }
                event = Status.Event.HostDown;
            } else if (determinedState == Status.Up) {
                /* Got ping response from host, bring it back */
                s_logger.info("Agent is determined to be up and running");
                agentStatusTransitTo(host, Status.Event.Ping, _nodeId);
                return false;
            } else if (determinedState == Status.Disconnected) {
                s_logger.warn("Agent is disconnected but the host is still up: " + host.getId() + "-" + host.getName());
                if (currentStatus == Status.Disconnected) {
                    if ((System.currentTimeMillis() >> 10) - host.getLastPinged() > AlertWait.value()) {
                        s_logger.warn("Host " + host.getId() + " has been disconnected past the wait time it should be disconnected.");
                        event = Status.Event.WaitedTooLong;
                    } else {
                        s_logger.debug("Host " + host.getId() + " has been determined to be disconnected but it hasn't passed the wait time yet.");
                        return false;
                    }
                } else if (currentStatus == Status.Up) {
                    final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
                    final HostPodVO podVO = _podDao.findById(host.getPodId());
                    final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
                    if (host.getType() != Host.Type.SecondaryStorage && host.getType() != Host.Type.ConsoleProxy) {
                        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host disconnected, " + hostDesc, "If the agent for host [" + hostDesc + "] is not restarted within " + AlertWait + " seconds, host will go to Alert state");
                    }
                    event = Status.Event.AgentDisconnected;
                }
            } else {
                // if we end up here we are in alert state, send an alert
                final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
                final HostPodVO podVO = _podDao.findById(host.getPodId());
                final String podName = podVO != null ? podVO.getName() : "NO POD";
                final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podName;
                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host in ALERT state, " + hostDesc, "In availability zone " + host.getDataCenterId() + ", host is in alert state: " + host.getId() + "-" + host.getName());
            }
        } else {
            s_logger.debug("The next status of agent " + host.getId() + " is not Alert, no need to investigate what happened");
        }
    }
    handleDisconnectWithoutInvestigation(attache, event, true, true);
    // Maybe the host magically reappeared?
    host = _hostDao.findById(hostId);
    if (host != null && host.getStatus() == Status.Down) {
        _haMgr.scheduleRestartForVmsOnHost(host, true);
    }
    return true;
}
Also used : Status(com.cloud.host.Status) DataCenterVO(com.cloud.dc.DataCenterVO) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO)

Example 100 with DataCenterVO

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

the class S3TemplateTest method setUp.

@Test(priority = -1)
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    // create data center
    DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
    dc = dcDao.persist(dc);
    dcId = dc.getId();
    // add s3 image store
    Map<String, Object> sParams = new HashMap<String, Object>();
    sParams.put("name", "test");
    sParams.put("protocol", "http");
    sParams.put("providerName", "S3");
    sParams.put("scope", ScopeType.REGION);
    sParams.put("role", DataStoreRole.Image);
    Map<String, String> sDetails = new HashMap<String, String>();
    sDetails.put(ApiConstants.S3_ACCESS_KEY, this.getS3AccessKey());
    sDetails.put(ApiConstants.S3_SECRET_KEY, this.getS3SecretKey());
    sDetails.put(ApiConstants.S3_BUCKET_NAME, this.getS3TemplateBucket());
    sDetails.put(ApiConstants.S3_END_POINT, this.getS3EndPoint());
    this.imageStoreHelper.createImageStore(sParams, sDetails);
    // add nfs cache storage
    Map<String, Object> cParams = new HashMap<String, Object>();
    cParams.put("name", "testCache");
    cParams.put("protocol", "nfs");
    cParams.put("providerName", DataStoreProvider.NFS_IMAGE);
    cParams.put("scope", ScopeType.ZONE);
    cParams.put("role", DataStoreRole.ImageCache);
    cParams.put("url", this.getSecondaryStorage());
    cParams.put("zoneId", dcId);
    this.imageStoreHelper.createImageStore(cParams);
    VMTemplateVO image = new VMTemplateVO();
    image.setTemplateType(TemplateType.SYSTEM);
    image.setUrl(this.getTemplateUrl());
    image.setUniqueName(UUID.randomUUID().toString());
    image.setName(UUID.randomUUID().toString());
    image.setPublicTemplate(false);
    image.setFeatured(false);
    image.setRequiresHvm(false);
    image.setBits(64);
    image.setFormat(Storage.ImageFormat.VHD);
    image.setEnablePassword(false);
    image.setEnableSshKey(false);
    image.setGuestOSId(133);
    image.setBootable(true);
    image.setPrepopulate(true);
    image.setCrossZones(true);
    image.setExtractable(true);
    image.setAccountId(2);
    image = templateDao.persist(image);
    templateId = image.getId();
    // inject mockito
    LocalHostEndpoint ep = new LocalHostEndpoint();
    ep.setResource(new MockLocalNfsSecondaryStorageResource());
    Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(ep);
    Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep);
    Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(ep);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) LocalHostEndpoint(org.apache.cloudstack.storage.LocalHostEndpoint) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) HashMap(java.util.HashMap) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) MockLocalNfsSecondaryStorageResource(org.apache.cloudstack.storage.MockLocalNfsSecondaryStorageResource) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) Test(org.testng.annotations.Test)

Aggregations

DataCenterVO (com.cloud.dc.DataCenterVO)214 ArrayList (java.util.ArrayList)60 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)54 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)53 HostVO (com.cloud.host.HostVO)42 Account (com.cloud.user.Account)37 NetworkVO (com.cloud.network.dao.NetworkVO)35 DomainRouterVO (com.cloud.vm.DomainRouterVO)33 HostPodVO (com.cloud.dc.HostPodVO)32 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)30 ClusterVO (com.cloud.dc.ClusterVO)27 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)27 DB (com.cloud.utils.db.DB)26 Network (com.cloud.network.Network)25 HashMap (java.util.HashMap)25 ConfigurationException (javax.naming.ConfigurationException)25 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)20 Test (org.junit.Test)20 NicProfile (com.cloud.vm.NicProfile)19 ActionEvent (com.cloud.event.ActionEvent)18