Search in sources :

Example 1 with ClusterVMMetaDataSyncCommand

use of com.cloud.legacymodel.communication.command.ClusterVMMetaDataSyncCommand in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testClusterVMMetaDataSyncCommand.

@Test
public void testClusterVMMetaDataSyncCommand() {
    final String uuid = "6172d8b7-ba10-4a70-93f9-ecaf41f51d53";
    final Connection conn = Mockito.mock(Connection.class);
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final Pool pool = PowerMockito.mock(Pool.class);
    final Pool.Record poolr = Mockito.mock(Pool.Record.class);
    final Host.Record hostr = Mockito.mock(Host.Record.class);
    final Host master = Mockito.mock(Host.class);
    final ClusterVMMetaDataSyncCommand vmDataSync = new ClusterVMMetaDataSyncCommand(10, 1l);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(this.citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(this.citrixResourceBase.getHost()).thenReturn(xsHost);
        when(this.citrixResourceBase.getHost().getUuid()).thenReturn(uuid);
        when(xsHost.getPool()).thenReturn("pool");
        PowerMockito.mockStatic(Pool.class);
        when(Pool.getByUuid(conn, "pool")).thenReturn(pool);
        PowerMockito.mockStatic(Pool.Record.class);
        when(pool.getRecord(conn)).thenReturn(poolr);
        poolr.master = master;
        when(poolr.master.getRecord(conn)).thenReturn(hostr);
        hostr.uuid = uuid;
    } catch (final XenAPIException | XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(vmDataSync, this.citrixResourceBase);
    verify(this.citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) ClusterVMMetaDataSyncCommand(com.cloud.legacymodel.communication.command.ClusterVMMetaDataSyncCommand) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Host(com.xensource.xenapi.Host) 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) Pool(com.xensource.xenapi.Pool) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with ClusterVMMetaDataSyncCommand

use of com.cloud.legacymodel.communication.command.ClusterVMMetaDataSyncCommand in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method processConnect.

@Override
public void processConnect(final Host agent, final StartupCommand[] startupCommands, final boolean forRebalance) throws ConnectionException {
    for (final StartupCommand startupCommand : startupCommands) {
        if (!(startupCommand instanceof StartupRoutingCommand)) {
            return;
        }
        s_logger.debug("Received startup command from hypervisor host. host id: " + agent.getId());
        _syncMgr.resetHostSyncState(agent.getId());
        if (forRebalance) {
            s_logger.debug("Not processing listener " + this + " as connect happens on rebalance process");
            return;
        }
        final Long clusterId = agent.getClusterId();
        final long agentId = agent.getId();
        if (agent.getHypervisorType() == HypervisorType.XenServer) {
            // only for Xen
            // initiate the cron job
            final ClusterVMMetaDataSyncCommand syncVMMetaDataCmd = new ClusterVMMetaDataSyncCommand(ClusterVMMetaDataSyncInterval.value(), clusterId);
            try {
                final long seq_no = _agentMgr.send(agentId, new Commands(syncVMMetaDataCmd), this);
                s_logger.debug("Cluster VM metadata sync started with jobid " + seq_no);
            } catch (final AgentUnavailableException e) {
                s_logger.error("The Cluster VM metadata sync process failed for cluster id " + clusterId + " with ", e);
            }
        }
    }
}
Also used : StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) ClusterVMMetaDataSyncCommand(com.cloud.legacymodel.communication.command.ClusterVMMetaDataSyncCommand) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand)

Aggregations

ClusterVMMetaDataSyncCommand (com.cloud.legacymodel.communication.command.ClusterVMMetaDataSyncCommand)2 Commands (com.cloud.agent.manager.Commands)1 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)1 Answer (com.cloud.legacymodel.communication.answer.Answer)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 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 Connection (com.xensource.xenapi.Connection)1 Host (com.xensource.xenapi.Host)1 Pool (com.xensource.xenapi.Pool)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1