Search in sources :

Example 1 with HostEnvironment

use of com.cloud.legacymodel.dc.HostEnvironment in project cosmic by MissionCriticalCloud.

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(this.citrixResourceBase.getHost()).thenReturn(xsHost);
    final Answer answer = wrapper.execute(setupCommand, this.citrixResourceBase);
    verify(this.citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) HostEnvironment(com.cloud.legacymodel.dc.HostEnvironment) PvlanSetupCommand(com.cloud.legacymodel.communication.command.PvlanSetupCommand) SetupCommand(com.cloud.legacymodel.communication.command.SetupCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with HostEnvironment

use of com.cloud.legacymodel.dc.HostEnvironment in project cosmic by MissionCriticalCloud.

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(this.xenServer56Resource.getHost()).thenReturn(xsHost);
    final Answer answer = wrapper.execute(setupCommand, this.xenServer56Resource);
    verify(this.xenServer56Resource, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) HostEnvironment(com.cloud.legacymodel.dc.HostEnvironment) SetupCommand(com.cloud.legacymodel.communication.command.SetupCommand) Test(org.junit.Test)

Example 3 with HostEnvironment

use of com.cloud.legacymodel.dc.HostEnvironment in project cosmic by MissionCriticalCloud.

the class XcpServerDiscoverer method processConnect.

@Override
public void processConnect(final com.cloud.legacymodel.dc.Host agent, final StartupCommand[] startupCommands, final boolean forRebalance) throws ConnectionException {
    for (final StartupCommand startupCommand : startupCommands) {
        if (!(startupCommand instanceof StartupRoutingCommand)) {
            return;
        }
        final long agentId = agent.getId();
        final StartupRoutingCommand startup = (StartupRoutingCommand) startupCommand;
        if (startup.getHypervisorType() != HypervisorType.XenServer) {
            s_logger.debug("Not XenServer so moving on.");
            return;
        }
        final HostVO host = this._hostDao.findById(agentId);
        final ClusterVO cluster = this._clusterDao.findById(host.getClusterId());
        if (cluster.getGuid() == null) {
            cluster.setGuid(startup.getPool());
            this._clusterDao.update(cluster.getId(), cluster);
        } else if (!cluster.getGuid().equals(startup.getPool())) {
            final String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + startup.getPool();
            s_logger.warn(msg);
            throw new CloudRuntimeException(msg);
        }
        final Map<String, String> details = startup.getHostDetails();
        final String prodBrand = details.get("product_brand").trim();
        final String prodVersion = details.get("product_version").trim();
        final String hotfix = details.get(XenserverConfigs.XS620HotFix);
        final String prodVersionTextShort = details.get("product_version_text_short");
        final String resource = createServerResource(prodBrand, prodVersion, prodVersionTextShort, hotfix).getClass().getName();
        if (!resource.equals(host.getResource())) {
            final String msg = "host " + host.getPrivateIpAddress() + " changed from " + host.getResource() + " to " + resource;
            s_logger.debug(msg);
            host.setResource(resource);
            host.setSetup(false);
            this._hostDao.update(agentId, host);
            throw new HypervisorVersionChangedException(msg);
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Setting up host " + agentId);
        }
        final HostEnvironment env = new HostEnvironment();
        final SetupCommand setup = new SetupCommand(env);
        if (this._setupMultipath) {
            setup.setMultipathOn();
        }
        if (!host.isSetup()) {
            setup.setNeedSetup(true);
        }
        try {
            final Answer answer = this._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);
                this._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 (final AgentUnavailableException e) {
            s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
        } catch (final 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.legacymodel.exceptions.OperationTimedoutException) ClusterVO(com.cloud.dc.ClusterVO) HostEnvironment(com.cloud.legacymodel.dc.HostEnvironment) SetupCommand(com.cloud.legacymodel.communication.command.SetupCommand) HostVO(com.cloud.host.HostVO) SetupAnswer(com.cloud.legacymodel.communication.answer.SetupAnswer) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) HypervisorVersionChangedException(com.cloud.legacymodel.exceptions.HypervisorVersionChangedException) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) SetupAnswer(com.cloud.legacymodel.communication.answer.SetupAnswer) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException)

Example 4 with HostEnvironment

use of com.cloud.legacymodel.dc.HostEnvironment in project cosmic by MissionCriticalCloud.

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.legacymodel.communication.answer.Answer) XenServer610Resource(com.cloud.hypervisor.xenserver.resource.XenServer610Resource) HostEnvironment(com.cloud.legacymodel.dc.HostEnvironment) SetupCommand(com.cloud.legacymodel.communication.command.SetupCommand) Test(org.junit.Test)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)4 SetupCommand (com.cloud.legacymodel.communication.command.SetupCommand)4 HostEnvironment (com.cloud.legacymodel.dc.HostEnvironment)4 Test (org.junit.Test)3 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)2 ClusterVO (com.cloud.dc.ClusterVO)1 HostVO (com.cloud.host.HostVO)1 XenServer610Resource (com.cloud.hypervisor.xenserver.resource.XenServer610Resource)1 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)1 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)1 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)1 SetupAnswer (com.cloud.legacymodel.communication.answer.SetupAnswer)1 PvlanSetupCommand (com.cloud.legacymodel.communication.command.PvlanSetupCommand)1 StartupCommand (com.cloud.legacymodel.communication.command.startup.StartupCommand)1 StartupRoutingCommand (com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand)1 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 ConnectionException (com.cloud.legacymodel.exceptions.ConnectionException)1 HypervisorVersionChangedException (com.cloud.legacymodel.exceptions.HypervisorVersionChangedException)1