Search in sources :

Example 81 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class HypervServerDiscoverer method processConnect.

@Override
public final void processConnect(final Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    // Limit the commands we can process
    if (!(cmd instanceof StartupRoutingCommand)) {
        return;
    }
    StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
    // assert
    if (startup.getHypervisorType() != HypervisorType.Hyperv) {
        s_logger.debug("Not Hyper-V hypervisor, so moving on.");
        return;
    }
    long agentId = agent.getId();
    HostVO host = _hostDao.findById(agentId);
    // Our Hyper-V machines are not participating in pools, and the pool id
    // we provide them is not persisted.
    // This means the pool id can vary.
    ClusterVO cluster = _clusterDao.findById(host.getClusterId());
    if (cluster.getGuid() == null) {
        cluster.setGuid(startup.getPool());
        _clusterDao.update(cluster.getId(), cluster);
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Setting up host " + agentId);
    }
    HostEnvironment env = new HostEnvironment();
    SetupCommand setup = new SetupCommand(env);
    if (!host.isSetup()) {
        setup.setNeedSetup(true);
    }
    try {
        SetupAnswer answer = (SetupAnswer) _agentMgr.send(agentId, setup);
        if (answer != null && answer.getResult()) {
            host.setSetup(true);
            // TODO: clean up magic numbers below
            host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60);
            _hostDao.update(host.getId(), host);
            if (answer.needReconnect()) {
                throw new ConnectionException(false, "Reinitialize agent after setup.");
            }
            return;
        } else {
            String reason = answer.getDetails();
            if (reason == null) {
                reason = " details were null";
            }
            s_logger.warn("Unable to setup agent " + agentId + " due to " + reason);
        }
    // Error handling borrowed from XcpServerDiscoverer, may need to be
    // updated.
    } catch (AgentUnavailableException e) {
        s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
    } catch (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) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) HostEnvironment(com.cloud.host.HostEnvironment) SetupCommand(com.cloud.agent.api.SetupCommand) HostVO(com.cloud.host.HostVO) ConnectionException(com.cloud.exception.ConnectionException) SetupAnswer(com.cloud.agent.api.SetupAnswer)

Example 82 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class BaremetalDhcpManagerImpl method addVirtualMachineIntoNetwork.

@Override
public boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException {
    Long zoneId = profile.getVirtualMachine().getDataCenterId();
    Long podId = profile.getVirtualMachine().getPodIdToDeployIn();
    List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Type.BaremetalDhcp, null, podId, zoneId);
    if (hosts.size() == 0) {
        throw new CloudRuntimeException("No external Dhcp found in zone " + zoneId + " pod " + podId);
    }
    if (hosts.size() > 1) {
        throw new CloudRuntimeException("Something wrong, more than 1 external Dhcp found in zone " + zoneId + " pod " + podId);
    }
    HostVO h = hosts.get(0);
    String dns = nic.getIPv4Dns1();
    if (dns == null) {
        dns = nic.getIPv4Dns2();
    }
    DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIPv4Address(), profile.getVirtualMachine().getHostName(), null, dns, nic.getIPv4Gateway(), null, _ntwkModel.getExecuteInSeqNtwkElmtCmd());
    String errMsg = String.format("Set dhcp entry on external DHCP %1$s failed(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName());
    // prepareBareMetalDhcpEntry(nic, dhcpCommand);
    try {
        Answer ans = _agentMgr.send(h.getId(), dhcpCommand);
        if (ans.getResult()) {
            s_logger.debug(String.format("Set dhcp entry on external DHCP %1$s successfully(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName()));
            return true;
        } else {
            s_logger.debug(errMsg + " " + ans.getDetails());
            throw new ResourceUnavailableException(errMsg, DataCenter.class, zoneId);
        }
    } catch (Exception e) {
        s_logger.debug(errMsg, e);
        throw new ResourceUnavailableException(errMsg + e.getMessage(), DataCenter.class, zoneId);
    }
}
Also used : Answer(com.cloud.agent.api.Answer) DataCenter(com.cloud.dc.DataCenter) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DhcpEntryCommand(com.cloud.agent.api.routing.DhcpEntryCommand) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) HostVO(com.cloud.host.HostVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException)

Example 83 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class Ovm3FenceBuilder method fenceOff.

@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
    if (host.getHypervisorType() != HypervisorType.Ovm3) {
        LOGGER.debug("Don't know how to fence non Ovm3 hosts " + host.getHypervisorType());
        return null;
    } else {
        LOGGER.debug("Fencing " + vm + " on host " + host + " with params: " + fenceParams);
    }
    List<HostVO> hosts = resourceMgr.listAllHostsInCluster(host.getClusterId());
    FenceCommand fence = new FenceCommand(vm, host);
    for (HostVO h : hosts) {
        if (h.getHypervisorType() == HypervisorType.Ovm3 && h.getStatus() == Status.Up && h.getId() != host.getId()) {
            FenceAnswer answer;
            try {
                answer = (FenceAnswer) agentMgr.send(h.getId(), fence);
            } catch (AgentUnavailableException | OperationTimedoutException e) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Moving on to the next host because " + h.toString() + " is unavailable", e);
                }
                continue;
            }
            if (answer != null && answer.getResult()) {
                return true;
            }
        }
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
    }
    return false;
}
Also used : FenceCommand(com.cloud.agent.api.FenceCommand) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) FenceAnswer(com.cloud.agent.api.FenceAnswer) HostVO(com.cloud.host.HostVO)

Example 84 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class Ovm3VmSupport method execute.

/* do migrations of VMs in a simple way just inside a cluster for now */
public MigrateAnswer execute(final MigrateCommand cmd) {
    final String vmName = cmd.getVmName();
    String destUuid = cmd.getHostGuid();
    String destIp = cmd.getDestinationIp();
    State state = State.Error;
    /*
         * TODO: figure out non pooled migration, works from CLI but not from
         * the agent... perhaps pause the VM and then migrate it ? for now just
         * stop the VM.
         */
    String msg = "Migrating " + vmName + " to " + destIp;
    LOGGER.info(msg);
    if (!config.getAgentInOvm3Cluster() && !config.getAgentInOvm3Pool()) {
        try {
            Xen xen = new Xen(c);
            Xen.Vm vm = xen.getRunningVmConfig(vmName);
            HostVO destHost = resourceMgr.findHostByGuid(destUuid);
            if (destHost == null) {
                msg = "Unable to find migration target host in DB " + destUuid + " with ip " + destIp;
                LOGGER.info(msg);
                return new MigrateAnswer(cmd, false, msg, null);
            }
            xen.stopVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid());
            msg = destHost.toString();
            state = State.Stopping;
            return new MigrateAnswer(cmd, false, msg, null);
        } catch (Ovm3ResourceException e) {
            msg = "Unpooled VM Migrate of " + vmName + " to " + destUuid + " failed due to: " + e.getMessage();
            LOGGER.debug(msg, e);
            return new MigrateAnswer(cmd, false, msg, null);
        } finally {
            /* shouldn't we just reinitialize completely as a last resort ? */
            hypervisor.setVmState(vmName, state);
        }
    } else {
        try {
            Xen xen = new Xen(c);
            Xen.Vm vm = xen.getRunningVmConfig(vmName);
            if (vm == null) {
                state = State.Stopped;
                msg = vmName + " is no running on " + config.getAgentHostname();
                return new MigrateAnswer(cmd, false, msg, null);
            }
            /* not a storage migration!!! */
            xen.migrateVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid(), destIp);
            state = State.Stopping;
            msg = "Migration of " + vmName + " successfull";
            return new MigrateAnswer(cmd, true, msg, null);
        } catch (Ovm3ResourceException e) {
            msg = "Pooled VM Migrate" + ": Migration of " + vmName + " to " + destIp + " failed due to " + e.getMessage();
            LOGGER.debug(msg, e);
            return new MigrateAnswer(cmd, false, msg, null);
        } finally {
            hypervisor.setVmState(vmName, state);
        }
    }
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) State(com.cloud.vm.VirtualMachine.State) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) HostVO(com.cloud.host.HostVO)

Example 85 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class XenServerFencer method fenceOff.

@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
    if (host.getHypervisorType() != HypervisorType.XenServer) {
        s_logger.debug("Don't know how to fence non XenServer hosts " + host.getHypervisorType());
        return null;
    }
    List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(host.getClusterId());
    FenceCommand fence = new FenceCommand(vm, host);
    for (HostVO h : hosts) {
        if (h.getHypervisorType() == HypervisorType.XenServer) {
            if (h.getStatus() != Status.Up) {
                continue;
            }
            if (h.getId() == host.getId()) {
                continue;
            }
            FenceAnswer answer;
            try {
                Answer ans = _agentMgr.send(h.getId(), fence);
                if (!(ans instanceof FenceAnswer)) {
                    s_logger.debug("Answer is not fenceanswer.  Result = " + ans.getResult() + "; Details = " + ans.getDetails());
                    continue;
                }
                answer = (FenceAnswer) ans;
            } catch (AgentUnavailableException e) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e);
                }
                continue;
            } catch (OperationTimedoutException e) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e);
                }
                continue;
            }
            if (answer != null && answer.getResult()) {
                return true;
            }
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
    }
    return false;
}
Also used : FenceAnswer(com.cloud.agent.api.FenceAnswer) Answer(com.cloud.agent.api.Answer) FenceCommand(com.cloud.agent.api.FenceCommand) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) FenceAnswer(com.cloud.agent.api.FenceAnswer) HostVO(com.cloud.host.HostVO)

Aggregations

HostVO (com.cloud.host.HostVO)631 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)223 ArrayList (java.util.ArrayList)178 Answer (com.cloud.agent.api.Answer)105 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)95 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)91 Test (org.junit.Test)81 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)75 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)74 ClusterVO (com.cloud.dc.ClusterVO)72 Account (com.cloud.user.Account)67 HashMap (java.util.HashMap)67 VMInstanceVO (com.cloud.vm.VMInstanceVO)60 ConfigurationException (javax.naming.ConfigurationException)60 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)58 DataCenterVO (com.cloud.dc.DataCenterVO)50 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)48 HostPodVO (com.cloud.dc.HostPodVO)47 DB (com.cloud.utils.db.DB)47 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)46