Search in sources :

Example 21 with AgentUnavailableException

use of com.cloud.exception.AgentUnavailableException 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 22 with AgentUnavailableException

use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.

the class HypervStorageMotionStrategy method migrateVmWithVolumes.

private Answer migrateVmWithVolumes(VMInstanceVO vm, VirtualMachineTO to, Host srcHost, Host destHost, Map<VolumeInfo, DataStore> volumeToPool) throws AgentUnavailableException {
    // Initiate migration of a virtual machine with it's volumes.
    try {
        List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerto = new ArrayList<Pair<VolumeTO, StorageFilerTO>>();
        for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
            VolumeInfo volume = entry.getKey();
            VolumeTO volumeTo = new VolumeTO(volume, storagePoolDao.findById(volume.getPoolId()));
            StorageFilerTO filerTo = new StorageFilerTO((StoragePool) entry.getValue());
            volumeToFilerto.add(new Pair<VolumeTO, StorageFilerTO>(volumeTo, filerTo));
        }
        MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getPrivateIpAddress());
        MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer) agentMgr.send(srcHost.getId(), command);
        if (answer == null) {
            s_logger.error("Migration with storage of vm " + vm + " failed.");
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        } else if (!answer.getResult()) {
            s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails());
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost + ". " + answer.getDetails());
        } else {
            // Update the volume details after migration.
            updateVolumePathsAfterMigration(volumeToPool, answer.getVolumeTos());
        }
        return answer;
    } catch (OperationTimedoutException e) {
        s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e);
        throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId());
    }
}
Also used : MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) VolumeTO(com.cloud.agent.api.to.VolumeTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) Map(java.util.Map) Pair(com.cloud.utils.Pair)

Example 23 with AgentUnavailableException

use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.

the class SimulatorFencer method fenceOff.

@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
    if (host.getHypervisorType() != HypervisorType.Simulator) {
        s_logger.debug("Don't know how to fence non simulator 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.Simulator) {
            if (h.getStatus() != Status.Up) {
                continue;
            }
            if (h.getId() == host.getId()) {
                continue;
            }
            FenceAnswer answer = null;
            try {
                answer = (FenceAnswer) _agentMgr.send(h.getId(), fence);
            } catch (AgentUnavailableException e) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
                }
                continue;
            } catch (OperationTimedoutException e) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
                }
                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 : 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 24 with AgentUnavailableException

use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.

the class OvsTunnelManagerImpl method checkAndCreateTunnel.

@DB
protected void checkAndCreateTunnel(Network nw, Host host) {
    s_logger.debug("Creating tunnels with OVS tunnel manager");
    long hostId = host.getId();
    int key = getGreKey(nw);
    String bridgeName = generateBridgeName(nw, key);
    List<Long> toHostIds = new ArrayList<Long>();
    List<Long> fromHostIds = new ArrayList<Long>();
    List<Long> networkSpannedHosts = _ovsNetworkToplogyGuru.getNetworkSpanedHosts(nw.getId());
    for (Long rh : networkSpannedHosts) {
        if (rh == hostId) {
            continue;
        }
        OvsTunnelNetworkVO ta = _tunnelNetworkDao.getByFromToNetwork(hostId, rh.longValue(), nw.getId());
        // Try and create the tunnel even if a previous attempt failed
        if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) {
            s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + rh.longValue());
            if (ta == null) {
                createTunnelRecord(hostId, rh.longValue(), nw.getId(), key);
            }
            if (!toHostIds.contains(rh)) {
                toHostIds.add(rh);
            }
        }
        ta = _tunnelNetworkDao.getByFromToNetwork(rh.longValue(), hostId, nw.getId());
        // Try and create the tunnel even if a previous attempt failed
        if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) {
            s_logger.debug("Attempting to create tunnel from:" + rh.longValue() + " to:" + hostId);
            if (ta == null) {
                createTunnelRecord(rh.longValue(), hostId, nw.getId(), key);
            }
            if (!fromHostIds.contains(rh)) {
                fromHostIds.add(rh);
            }
        }
    }
    //TODO: Should we propagate the exception here?
    try {
        String myIp = getGreEndpointIP(host, nw);
        if (myIp == null)
            throw new GreTunnelException("Unable to retrieve the source " + "endpoint for the GRE tunnel." + "Failure is on host:" + host.getId());
        boolean noHost = true;
        for (Long i : toHostIds) {
            HostVO rHost = _hostDao.findById(i);
            String otherIp = getGreEndpointIP(rHost, nw);
            if (otherIp == null)
                throw new GreTunnelException("Unable to retrieve the remote " + "endpoint for the GRE tunnel." + "Failure is on host:" + rHost.getId());
            Commands cmds = new Commands(new OvsCreateTunnelCommand(otherIp, key, Long.valueOf(hostId), i, nw.getId(), myIp, bridgeName, nw.getUuid()));
            s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + i + " for the network " + nw.getId());
            s_logger.debug("Ask host " + hostId + " to create gre tunnel to " + i);
            Answer[] answers = _agentMgr.send(hostId, cmds);
            handleCreateTunnelAnswer(answers);
            noHost = false;
        }
        for (Long i : fromHostIds) {
            HostVO rHost = _hostDao.findById(i);
            String otherIp = getGreEndpointIP(rHost, nw);
            Commands cmds = new Commands(new OvsCreateTunnelCommand(myIp, key, i, Long.valueOf(hostId), nw.getId(), otherIp, bridgeName, nw.getUuid()));
            s_logger.debug("Ask host " + i + " to create gre tunnel to " + hostId);
            Answer[] answers = _agentMgr.send(i, cmds);
            handleCreateTunnelAnswer(answers);
            noHost = false;
        }
        // anyway. This will ensure VIF rules will be triggered
        if (noHost) {
            Commands cmds = new Commands(new OvsSetupBridgeCommand(bridgeName, hostId, nw.getId()));
            s_logger.debug("Ask host " + hostId + " to configure bridge for network:" + nw.getId());
            Answer[] answers = _agentMgr.send(hostId, cmds);
            handleSetupBridgeAnswer(answers);
        }
    } catch (GreTunnelException | OperationTimedoutException | AgentUnavailableException e) {
        // I really thing we should do a better handling of these exceptions
        s_logger.warn("Ovs Tunnel network created tunnel failed", e);
    }
}
Also used : OvsTunnelNetworkVO(com.cloud.network.ovs.dao.OvsTunnelNetworkVO) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) OvsCreateTunnelCommand(com.cloud.agent.api.OvsCreateTunnelCommand) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) Answer(com.cloud.agent.api.Answer) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) OvsSetupBridgeCommand(com.cloud.agent.api.OvsSetupBridgeCommand) DB(com.cloud.utils.db.DB)

Example 25 with AgentUnavailableException

use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.

the class SshKeysDistriMonitor method processConnect.

@Override
public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
    if (cmd instanceof StartupRoutingCommand) {
        if (((StartupRoutingCommand) cmd).getHypervisorType() == HypervisorType.KVM || ((StartupRoutingCommand) cmd).getHypervisorType() == HypervisorType.XenServer || ((StartupRoutingCommand) cmd).getHypervisorType() == HypervisorType.LXC) {
            /*TODO: Get the private/public keys here*/
            String pubKey = _configDao.getValue("ssh.publickey");
            String prvKey = _configDao.getValue("ssh.privatekey");
            try {
                ModifySshKeysCommand cmds = new ModifySshKeysCommand(pubKey, prvKey);
                Commands c = new Commands(cmds);
                _agentMgr.send(host.getId(), c, this);
            } catch (AgentUnavailableException e) {
                s_logger.debug("Failed to send keys to agent: " + host.getId());
            }
        }
    }
}
Also used : AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ModifySshKeysCommand(com.cloud.agent.api.ModifySshKeysCommand) Commands(com.cloud.agent.manager.Commands) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Aggregations

AgentUnavailableException (com.cloud.exception.AgentUnavailableException)74 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)56 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)30 Answer (com.cloud.agent.api.Answer)27 HostVO (com.cloud.host.HostVO)25 Commands (com.cloud.agent.manager.Commands)21 ArrayList (java.util.ArrayList)15 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)11 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)10 Command (com.cloud.agent.api.Command)9 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)9 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)9 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)8 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)8 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)8 GuestOSVO (com.cloud.storage.GuestOSVO)8 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)7 FenceCommand (com.cloud.agent.api.FenceCommand)6 VMSnapshotTO (com.cloud.agent.api.VMSnapshotTO)6 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6