Search in sources :

Example 1 with HostEnvironment

use of com.cloud.host.HostEnvironment 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 2 with HostEnvironment

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

the class XcpServerDiscoverer method processConnect.

@Override
public void processConnect(com.cloud.host.Host agent, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
    if (!(cmd instanceof StartupRoutingCommand)) {
        return;
    }
    long agentId = agent.getId();
    StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
    if (startup.getHypervisorType() != HypervisorType.XenServer) {
        s_logger.debug("Not XenServer so moving on.");
        return;
    }
    HostVO host = _hostDao.findById(agentId);
    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())) {
        String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + startup.getPool();
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
    }
    Map<String, String> details = startup.getHostDetails();
    String prodBrand = details.get("product_brand").trim();
    String prodVersion = details.get("product_version").trim();
    String hotfix = details.get(XenserverConfigs.XS620HotFix);
    String prodVersionTextShort = details.get("product_version_text_short");
    String resource = createServerResource(prodBrand, prodVersion, prodVersionTextShort, hotfix).getClass().getName();
    if (!resource.equals(host.getResource())) {
        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);
    }
    HostEnvironment env = new HostEnvironment();
    SetupCommand setup = new SetupCommand(env);
    if (_setupMultipath) {
        setup.setMultipathOn();
    }
    if (!host.isSetup()) {
        setup.setNeedSetup(true);
    }
    try {
        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 (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) 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 3 with HostEnvironment

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

the class NotAValidCommand method testSetupCommand.

@Test
public void testSetupCommand() {
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final HostEnvironment env = Mockito.mock(HostEnvironment.class);
    final SetupCommand setupCommand = new SetupCommand(env);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getHost()).thenReturn(xsHost);
    final Answer answer = wrapper.execute(setupCommand, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) HostEnvironment(com.cloud.host.HostEnvironment) PvlanSetupCommand(com.cloud.agent.api.PvlanSetupCommand) SetupCommand(com.cloud.agent.api.SetupCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with HostEnvironment

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

the class XenServer610WrapperTest method testSetupCommand.

@Test
public void testSetupCommand() {
    final XenServer610Resource xenServer610Resource = new XenServer610Resource();
    final HostEnvironment env = Mockito.mock(HostEnvironment.class);
    final SetupCommand setupCommand = new SetupCommand(env);
    final Answer answer = xenServer610Resource.executeRequest(setupCommand);
    assertFalse(answer.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) XenServer610Resource(com.cloud.hypervisor.xenserver.resource.XenServer610Resource) HostEnvironment(com.cloud.host.HostEnvironment) SetupCommand(com.cloud.agent.api.SetupCommand) Test(org.junit.Test)

Example 5 with HostEnvironment

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

the class XenServer56WrapperTest method testSetupCommand.

@Test
public void testSetupCommand() {
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final HostEnvironment env = Mockito.mock(HostEnvironment.class);
    final SetupCommand setupCommand = new SetupCommand(env);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(xenServer56Resource.getHost()).thenReturn(xsHost);
    final Answer answer = wrapper.execute(setupCommand, xenServer56Resource);
    verify(xenServer56Resource, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) HostEnvironment(com.cloud.host.HostEnvironment) SetupCommand(com.cloud.agent.api.SetupCommand) Test(org.junit.Test)

Aggregations

SetupCommand (com.cloud.agent.api.SetupCommand)10 HostEnvironment (com.cloud.host.HostEnvironment)10 Answer (com.cloud.agent.api.Answer)8 Test (org.junit.Test)6 ClusterVO (com.cloud.dc.ClusterVO)4 HostVO (com.cloud.host.HostVO)4 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)4 SetupAnswer (com.cloud.agent.api.SetupAnswer)3 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)3 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)3 ConnectionException (com.cloud.exception.ConnectionException)3 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2 PvlanSetupCommand (com.cloud.agent.api.PvlanSetupCommand)2 RebootAnswer (com.cloud.agent.api.RebootAnswer)2 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)2 XenServer610Resource (com.cloud.hypervisor.xenserver.resource.XenServer610Resource)2 HypervisorVersionChangedException (com.cloud.utils.exception.HypervisorVersionChangedException)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2