Search in sources :

Example 1 with Link

use of com.cloud.utils.nio.Link in project cosmic by MissionCriticalCloud.

the class ConnectedAgentAttacheTest method testEqualsFalseDiffId.

@Test
public void testEqualsFalseDiffId() throws Exception {
    final Link link1 = mock(Link.class);
    final ConnectedAgentAttache agentAttache1 = new ConnectedAgentAttache(null, 1, null, link1, false);
    final ConnectedAgentAttache agentAttache2 = new ConnectedAgentAttache(null, 2, null, link1, false);
    assertFalse(agentAttache1.equals(agentAttache2));
}
Also used : Link(com.cloud.utils.nio.Link) Test(org.junit.Test)

Example 2 with Link

use of com.cloud.utils.nio.Link in project cloudstack by apache.

the class ConnectedAgentAttacheTest method testEqualsFalseNull.

@Test
public void testEqualsFalseNull() throws Exception {
    Link link = mock(Link.class);
    ConnectedAgentAttache agentAttache1 = new ConnectedAgentAttache(null, 0, null, link, false);
    assertFalse(agentAttache1.equals(null));
}
Also used : Link(com.cloud.utils.nio.Link) Test(org.junit.Test)

Example 3 with Link

use of com.cloud.utils.nio.Link in project cloudstack by apache.

the class ConnectedAgentAttacheTest method testEqualsFalseDiffLink.

@Test
public void testEqualsFalseDiffLink() throws Exception {
    Link link1 = mock(Link.class);
    Link link2 = mock(Link.class);
    ConnectedAgentAttache agentAttache1 = new ConnectedAgentAttache(null, 0, null, link1, false);
    ConnectedAgentAttache agentAttache2 = new ConnectedAgentAttache(null, 0, null, link2, false);
    assertFalse(agentAttache1.equals(agentAttache2));
}
Also used : Link(com.cloud.utils.nio.Link) Test(org.junit.Test)

Example 4 with Link

use of com.cloud.utils.nio.Link in project CloudStack-archive by CloudStack-extras.

the class Agent method processOtherTask.

public void processOtherTask(Task task) {
    final Object obj = task.get();
    if (obj instanceof Response) {
        if ((System.currentTimeMillis() - _lastPingResponseTime) > _pingInterval * _shell.getPingRetries()) {
            s_logger.error("Ping Interval has gone past " + _pingInterval * _shell.getPingRetries() + ".  Attempting to reconnect.");
            final Link link = task.getLink();
            reconnect(link);
            return;
        }
        final PingCommand ping = _resource.getCurrentStatus(getId());
        final Request request = new Request(_id, -1, ping, false);
        request.setSequence(getNextSequence());
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Sending ping: " + request.toString());
        }
        try {
            task.getLink().send(request.toBytes());
            //if i can send pingcommand out, means the link is ok
            setLastPingResponseTime();
        } catch (final ClosedChannelException e) {
            s_logger.warn("Unable to send request: " + request.toString());
        }
    } else if (obj instanceof Request) {
        final Request req = (Request) obj;
        final Command command = req.getCommand();
        Answer answer = null;
        _inProgress.incrementAndGet();
        try {
            answer = _resource.executeRequest(command);
        } finally {
            _inProgress.decrementAndGet();
        }
        if (answer != null) {
            final Response response = new Response(req, answer);
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Watch Sent: " + response.toString());
            }
            try {
                task.getLink().send(response.toBytes());
            } catch (final ClosedChannelException e) {
                s_logger.warn("Unable to send response: " + response.toString());
            }
        }
    } else {
        s_logger.warn("Ignoring an unknown task");
    }
}
Also used : Response(com.cloud.agent.transport.Response) ClosedChannelException(java.nio.channels.ClosedChannelException) UpgradeAnswer(com.cloud.agent.api.UpgradeAnswer) StartupAnswer(com.cloud.agent.api.StartupAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) MaintainCommand(com.cloud.agent.api.MaintainCommand) StartupCommand(com.cloud.agent.api.StartupCommand) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) ShutdownCommand(com.cloud.agent.api.ShutdownCommand) Command(com.cloud.agent.api.Command) PingCommand(com.cloud.agent.api.PingCommand) ModifySshKeysCommand(com.cloud.agent.api.ModifySshKeysCommand) UpgradeCommand(com.cloud.agent.api.UpgradeCommand) CronCommand(com.cloud.agent.api.CronCommand) Request(com.cloud.agent.transport.Request) Link(com.cloud.utils.nio.Link) PingCommand(com.cloud.agent.api.PingCommand)

Example 5 with Link

use of com.cloud.utils.nio.Link in project cosmic by MissionCriticalCloud.

the class ConnectedAgentAttacheTest method testEqualsFalseDiffClass.

@Test
public void testEqualsFalseDiffClass() throws Exception {
    final Link link1 = mock(Link.class);
    final ConnectedAgentAttache agentAttache1 = new ConnectedAgentAttache(null, 1, null, link1, false);
    assertFalse(agentAttache1.equals("abc"));
}
Also used : Link(com.cloud.utils.nio.Link) Test(org.junit.Test)

Aggregations

Link (com.cloud.utils.nio.Link)11 Test (org.junit.Test)10 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)1 Answer (com.cloud.agent.api.Answer)1 Command (com.cloud.agent.api.Command)1 CronCommand (com.cloud.agent.api.CronCommand)1 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)1 MaintainCommand (com.cloud.agent.api.MaintainCommand)1 ModifySshKeysCommand (com.cloud.agent.api.ModifySshKeysCommand)1 PingCommand (com.cloud.agent.api.PingCommand)1 ShutdownCommand (com.cloud.agent.api.ShutdownCommand)1 StartupAnswer (com.cloud.agent.api.StartupAnswer)1 StartupCommand (com.cloud.agent.api.StartupCommand)1 UpgradeAnswer (com.cloud.agent.api.UpgradeAnswer)1 UpgradeCommand (com.cloud.agent.api.UpgradeCommand)1 Request (com.cloud.agent.transport.Request)1 Response (com.cloud.agent.transport.Response)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1