Search in sources :

Example 1 with ClusterVMMetaDataSyncCommand

use of com.cloud.agent.api.ClusterVMMetaDataSyncCommand in project cloudstack by apache.

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(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.getHost()).thenReturn(xsHost);
        when(citrixResourceBase.getHost().getUuid()).thenReturn(uuid);
        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 BadServerResponse e) {
        fail(e.getMessage());
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(vmDataSync, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) ClusterVMMetaDataSyncCommand(com.cloud.agent.api.ClusterVMMetaDataSyncCommand) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) 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.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) Pool(com.xensource.xenapi.Pool) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test)

Example 2 with ClusterVMMetaDataSyncCommand

use of com.cloud.agent.api.ClusterVMMetaDataSyncCommand in project cloudstack by apache.

the class VirtualMachineManagerImpl method processConnect.

@Override
public void processConnect(final Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    if (!(cmd instanceof StartupRoutingCommand)) {
        return;
    }
    if (s_logger.isDebugEnabled()) {
        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.fatal("The Cluster VM metadata sync process failed for cluster id " + clusterId + " with ", e);
        }
    }
}
Also used : ClusterVMMetaDataSyncCommand(com.cloud.agent.api.ClusterVMMetaDataSyncCommand) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Aggregations

ClusterVMMetaDataSyncCommand (com.cloud.agent.api.ClusterVMMetaDataSyncCommand)2 Answer (com.cloud.agent.api.Answer)1 RebootAnswer (com.cloud.agent.api.RebootAnswer)1 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)1 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)1 Commands (com.cloud.agent.manager.Commands)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)1 Connection (com.xensource.xenapi.Connection)1 Host (com.xensource.xenapi.Host)1 Pool (com.xensource.xenapi.Pool)1 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 Test (org.junit.Test)1