Search in sources :

Example 61 with HostPodVO

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

the class ResourceManagerImpl method fillRoutingHostVO.

@Override
public HostVO fillRoutingHostVO(final HostVO host, final StartupRoutingCommand ssCmd, final HypervisorType hyType, Map<String, String> details, final List<String> hostTags) {
    if (host.getPodId() == null) {
        s_logger.error("Host " + ssCmd.getPrivateIpAddress() + " sent incorrect pod, pod id is null");
        throw new IllegalArgumentException("Host " + ssCmd.getPrivateIpAddress() + " sent incorrect pod, pod id is null");
    }
    final ClusterVO clusterVO = _clusterDao.findById(host.getClusterId());
    if (clusterVO.getHypervisorType() != hyType) {
        throw new IllegalArgumentException("Can't add host whose hypervisor type is: " + hyType + " into cluster: " + clusterVO.getId() + " whose hypervisor type is: " + clusterVO.getHypervisorType());
    }
    final Map<String, String> hostDetails = ssCmd.getHostDetails();
    if (hostDetails != null) {
        if (details != null) {
            details.putAll(hostDetails);
        } else {
            details = hostDetails;
        }
    }
    final HostPodVO pod = _podDao.findById(host.getPodId());
    final DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
    checkIPConflicts(pod, dc, ssCmd.getPrivateIpAddress(), ssCmd.getPublicIpAddress(), ssCmd.getPublicIpAddress(), ssCmd.getPublicNetmask());
    host.setType(com.cloud.host.Host.Type.Routing);
    host.setDetails(details);
    host.setCaps(ssCmd.getCapabilities());
    host.setCpuSockets(ssCmd.getCpuSockets());
    host.setCpus(ssCmd.getCpus());
    host.setTotalMemory(ssCmd.getMemory());
    host.setHypervisorType(hyType);
    host.setHypervisorVersion(ssCmd.getHypervisorVersion());
    host.setGpuGroups(ssCmd.getGpuGroupDetails());
    return host;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) HostPodVO(com.cloud.dc.HostPodVO)

Example 62 with HostPodVO

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

the class HostPodDaoImpl method remove.

@Override
public boolean remove(Long id) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    HostPodVO pod = createForUpdate();
    pod.setName(null);
    update(id, pod);
    boolean result = super.remove(id);
    txn.commit();
    return result;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) HostPodVO(com.cloud.dc.HostPodVO)

Example 63 with HostPodVO

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

the class CloudZonesStartupProcessor method updateComputeHost.

protected void updateComputeHost(final HostVO host, final StartupCommand startup, final Host.Type type) throws AgentAuthnException {
    String zoneToken = startup.getDataCenter();
    if (zoneToken == null) {
        s_logger.warn("No Zone Token passed in, cannot not find zone for the agent");
        throw new AgentAuthnException("No Zone Token passed in, cannot not find zone for agent");
    }
    DataCenterVO zone = _zoneDao.findByToken(zoneToken);
    if (zone == null) {
        zone = _zoneDao.findByName(zoneToken);
        if (zone == null) {
            try {
                long zoneId = Long.parseLong(zoneToken);
                zone = _zoneDao.findById(zoneId);
                if (zone == null) {
                    throw new AgentAuthnException("Could not find zone for agent with token " + zoneToken);
                }
            } catch (NumberFormatException nfe) {
                throw new AgentAuthnException("Could not find zone for agent with token " + zoneToken);
            }
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Successfully loaded the DataCenter from the zone token passed in ");
    }
    long zoneId = zone.getId();
    ResourceDetail maxHostsInZone = _zoneDetailsDao.findDetail(zoneId, ZoneConfig.MaxHosts.key());
    if (maxHostsInZone != null) {
        long maxHosts = Long.parseLong(maxHostsInZone.getValue());
        long currentCountOfHosts = _hostDao.countRoutingHostsByDataCenter(zoneId);
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Number of hosts in Zone:" + currentCountOfHosts + ", max hosts limit: " + maxHosts);
        }
        if (currentCountOfHosts >= maxHosts) {
            throw new AgentAuthnException("Number of running Routing hosts in the Zone:" + zone.getName() + " is already at the max limit:" + maxHosts + ", cannot start one more host");
        }
    }
    HostPodVO pod = null;
    if (startup.getPrivateIpAddress() == null) {
        s_logger.warn("No private IP address passed in for the agent, cannot not find pod for agent");
        throw new AgentAuthnException("No private IP address passed in for the agent, cannot not find pod for agent");
    }
    if (startup.getPrivateNetmask() == null) {
        s_logger.warn("No netmask passed in for the agent, cannot not find pod for agent");
        throw new AgentAuthnException("No netmask passed in for the agent, cannot not find pod for agent");
    }
    if (host.getPodId() != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Pod is already created for this agent, looks like agent is reconnecting...");
        }
        pod = _podDao.findById(host.getPodId());
        if (!checkCIDR(type, pod, startup.getPrivateIpAddress(), startup.getPrivateNetmask())) {
            pod = null;
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Subnet of Pod does not match the subnet of the agent, not using this Pod: " + host.getPodId());
            }
        } else {
            updatePodNetmaskIfNeeded(pod, startup.getPrivateNetmask());
        }
    }
    if (pod == null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Trying to detect the Pod to use from the agent's ip address and netmask passed in ");
        }
        //deduce pod
        boolean podFound = false;
        List<HostPodVO> podsInZone = _podDao.listByDataCenterId(zoneId);
        for (HostPodVO hostPod : podsInZone) {
            if (checkCIDR(type, hostPod, startup.getPrivateIpAddress(), startup.getPrivateNetmask())) {
                pod = hostPod;
                //found the default POD having the same subnet.
                updatePodNetmaskIfNeeded(pod, startup.getPrivateNetmask());
                podFound = true;
                break;
            }
        }
        if (!podFound) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Creating a new Pod since no default Pod found that matches the agent's ip address and netmask passed in ");
            }
            if (startup.getGatewayIpAddress() == null) {
                s_logger.warn("No Gateway IP address passed in for the agent, cannot create a new pod for the agent");
                throw new AgentAuthnException("No Gateway IP address passed in for the agent, cannot create a new pod for the agent");
            }
            //auto-create a new pod, since pod matching the agent's ip is not found
            String podName = "POD-" + (podsInZone.size() + 1);
            try {
                String gateway = startup.getGatewayIpAddress();
                String cidr = NetUtils.getCidrFromGatewayAndNetmask(gateway, startup.getPrivateNetmask());
                String[] cidrPair = cidr.split("\\/");
                String cidrAddress = cidrPair[0];
                long cidrSize = Long.parseLong(cidrPair[1]);
                String startIp = NetUtils.getIpRangeStartIpFromCidr(cidrAddress, cidrSize);
                String endIp = NetUtils.getIpRangeEndIpFromCidr(cidrAddress, cidrSize);
                pod = _configurationManager.createPod(-1, podName, zoneId, gateway, cidr, startIp, endIp, null, true);
            } catch (Exception e) {
                // no longer tolerate exception during the cluster creation phase
                throw new CloudRuntimeException("Unable to create new Pod " + podName + " in Zone: " + zoneId, e);
            }
        }
    }
    final StartupRoutingCommand scc = (StartupRoutingCommand) startup;
    ClusterVO cluster = null;
    if (host.getClusterId() != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Cluster is already created for this agent, looks like agent is reconnecting...");
        }
        cluster = _clusterDao.findById(host.getClusterId());
    }
    if (cluster == null) {
        //auto-create cluster - assume one host per cluster
        String clusterName = "Cluster-" + startup.getPrivateIpAddress();
        ClusterVO existingCluster = _clusterDao.findBy(clusterName, pod.getId());
        if (existingCluster != null) {
            cluster = existingCluster;
        } else {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Creating a new Cluster for this agent with name: " + clusterName + " in Pod: " + pod.getId() + ", in Zone:" + zoneId);
            }
            cluster = new ClusterVO(zoneId, pod.getId(), clusterName);
            cluster.setHypervisorType(scc.getHypervisorType().toString());
            try {
                cluster = _clusterDao.persist(cluster);
            } catch (Exception e) {
                // no longer tolerate exception during the cluster creation phase
                throw new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod " + pod.getId() + " and data center " + zoneId, e);
            }
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Detected Zone: " + zoneId + ", Pod: " + pod.getId() + ", Cluster:" + cluster.getId());
    }
    host.setDataCenterId(zone.getId());
    host.setPodId(pod.getId());
    host.setClusterId(cluster.getId());
    host.setPrivateIpAddress(startup.getPrivateIpAddress());
    host.setPrivateNetmask(startup.getPrivateNetmask());
    host.setPrivateMacAddress(startup.getPrivateMacAddress());
    host.setPublicIpAddress(startup.getPublicIpAddress());
    host.setPublicMacAddress(startup.getPublicMacAddress());
    host.setPublicNetmask(startup.getPublicNetmask());
    host.setStorageIpAddress(startup.getStorageIpAddress());
    host.setStorageMacAddress(startup.getStorageMacAddress());
    host.setStorageNetmask(startup.getStorageNetmask());
    host.setVersion(startup.getVersion());
    host.setName(startup.getName());
    host.setType(type);
    host.setStorageUrl(startup.getIqn());
    host.setLastPinged(System.currentTimeMillis() >> 10);
    host.setCaps(scc.getCapabilities());
    host.setCpus(scc.getCpus());
    host.setTotalMemory(scc.getMemory());
    host.setSpeed(scc.getSpeed());
    HypervisorType hyType = scc.getHypervisorType();
    host.setHypervisorType(hyType);
    host.setHypervisorVersion(scc.getHypervisorVersion());
    updateHostDetails(host, scc);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) ResourceDetail(org.apache.cloudstack.api.ResourceDetail) HostPodVO(com.cloud.dc.HostPodVO) ConfigurationException(javax.naming.ConfigurationException) ConnectionException(com.cloud.exception.ConnectionException) AgentAuthnException(com.cloud.agent.manager.authn.AgentAuthnException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) AgentAuthnException(com.cloud.agent.manager.authn.AgentAuthnException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 64 with HostPodVO

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

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 Zone zone = _zoneRepository.findOne(host.getDataCenterId());
                    final HostPodVO podVO = _podDao.findById(host.getPodId());
                    final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + zone.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 Zone zone = _zoneRepository.findOne(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: " + zone.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) Zone(com.cloud.db.model.Zone) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO)

Example 65 with HostPodVO

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

the class ResourceChecker method checkIfPodExists.

public HostPodVO checkIfPodExists(final Long hostPodId) {
    logger.debug("Checking if pod " + hostPodId + " exists");
    final HostPodVO pod = hostPodDao.findById(hostPodId);
    if (pod == null) {
        throw new InvalidParameterValueException("Can't find pod by id " + hostPodId);
    }
    return pod;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) HostPodVO(com.cloud.dc.HostPodVO)

Aggregations

HostPodVO (com.cloud.dc.HostPodVO)126 ArrayList (java.util.ArrayList)52 HostVO (com.cloud.host.HostVO)47 ClusterVO (com.cloud.dc.ClusterVO)46 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)46 DataCenterVO (com.cloud.dc.DataCenterVO)39 Account (com.cloud.user.Account)25 DB (com.cloud.utils.db.DB)25 Test (org.junit.Test)23 ConfigurationException (javax.naming.ConfigurationException)22 TransactionStatus (com.cloud.utils.db.TransactionStatus)21 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 VMInstanceVO (com.cloud.vm.VMInstanceVO)18 Random (java.util.Random)18 VolumeVO (com.cloud.storage.VolumeVO)17 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)16 HashMap (java.util.HashMap)16 List (java.util.List)16 Zone (com.cloud.db.model.Zone)15 DataCenter (com.cloud.dc.DataCenter)14