Search in sources :

Example 11 with PingCommand

use of com.cloud.agent.api.PingCommand in project cosmic by MissionCriticalCloud.

the class NiciraNvpResourceTest method testPingCommandStatusFail.

@Test
public void testPingCommandStatusFail() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final ControlClusterStatus ccs = mock(ControlClusterStatus.class);
    when(ccs.getClusterStatus()).thenReturn("unstable");
    when(nvpApi.getControlClusterStatus()).thenReturn(ccs);
    final PingCommand ping = resource.getCurrentStatus(42);
    assertTrue(ping == null);
}
Also used : ControlClusterStatus(com.cloud.network.nicira.ControlClusterStatus) PingCommand(com.cloud.agent.api.PingCommand) Test(org.junit.Test)

Example 12 with PingCommand

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

the class Agent method processOtherTask.

public void processOtherTask(final 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() + ". Won't reconnect to mgt server, as connection is still alive");
            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();
        if (command.getContextParam("logid") != null) {
            MDC.put("logcontextid", command.getContextParam("logid"));
        }
        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) SetupKeystoreAnswer(org.apache.cloudstack.ca.SetupKeystoreAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) SetupMSListAnswer(org.apache.cloudstack.agent.lb.SetupMSListAnswer) StartupAnswer(com.cloud.agent.api.StartupAnswer) SetupCertificateAnswer(org.apache.cloudstack.ca.SetupCertificateAnswer) StartupCommand(com.cloud.agent.api.StartupCommand) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) SetupCertificateCommand(org.apache.cloudstack.ca.SetupCertificateCommand) SetupKeyStoreCommand(org.apache.cloudstack.ca.SetupKeyStoreCommand) PingCommand(com.cloud.agent.api.PingCommand) PostCertificateRenewalCommand(org.apache.cloudstack.ca.PostCertificateRenewalCommand) MaintainCommand(com.cloud.agent.api.MaintainCommand) SetupMSListCommand(org.apache.cloudstack.agent.lb.SetupMSListCommand) ShutdownCommand(com.cloud.agent.api.ShutdownCommand) Command(com.cloud.agent.api.Command) ReadyCommand(com.cloud.agent.api.ReadyCommand) CronCommand(com.cloud.agent.api.CronCommand) Request(com.cloud.agent.transport.Request) PingCommand(com.cloud.agent.api.PingCommand)

Example 13 with PingCommand

use of com.cloud.agent.api.PingCommand in project cosmic by MissionCriticalCloud.

the class Agent method processOtherTask.

public void processOtherTask(final Task task) {
    final Object obj = task.get();
    if (obj instanceof Response) {
        if (System.currentTimeMillis() - _lastPingResponseTime > _pingInterval * agentProperties.getPingRetries()) {
            logger.error("Ping Interval has gone past " + _pingInterval * agentProperties.getPingRetries() + ". Won't reconnect to mgt server, as connection is still alive");
            return;
        }
        final PingCommand ping = resource.getCurrentStatus(getId());
        final Request request = new Request(_id, -1, ping, false);
        request.setSequence(getNextSequence());
        if (logger.isDebugEnabled()) {
            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) {
            logger.warn("Unable to send request: " + request.toString());
        }
    } else if (obj instanceof Request) {
        final Request req = (Request) obj;
        final Command command = req.getCommand();
        if (command.getContextParam("logid") != null) {
            MDC.put("logcontextid", command.getContextParam("logid"));
        }
        Answer answer = null;
        _inProgress.incrementAndGet();
        try {
            answer = resource.executeRequest(command);
        } finally {
            _inProgress.decrementAndGet();
        }
        if (answer != null) {
            final Response response = new Response(req, answer);
            if (logger.isDebugEnabled()) {
                logger.debug("Watch Sent: " + response.toString());
            }
            try {
                task.getLink().send(response.toBytes());
            } catch (final ClosedChannelException e) {
                logger.warn("Unable to send response: " + response.toString());
            }
        }
    } else {
        logger.warn("Ignoring an unknown task");
    }
}
Also used : Response(com.cloud.agent.transport.Response) ClosedChannelException(java.nio.channels.ClosedChannelException) 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) ReadyCommand(com.cloud.agent.api.ReadyCommand) CronCommand(com.cloud.agent.api.CronCommand) Request(com.cloud.agent.transport.Request) PingCommand(com.cloud.agent.api.PingCommand)

Example 14 with PingCommand

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

the class CiscoVnmcResourceTest method testPingCommandStatusFail.

@Test
public void testPingCommandStatusFail() throws ConfigurationException, ExecutionException {
    _resource.setConnection(_connection);
    when(_connection.login()).thenReturn(false);
    PingCommand ping = _resource.getCurrentStatus(1);
    assertTrue(ping == null);
}
Also used : PingCommand(com.cloud.agent.api.PingCommand) Test(org.junit.Test)

Example 15 with PingCommand

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

the class AgentRoutingResource method getCurrentStatus.

@Override
public PingCommand getCurrentStatus(long id) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        MockConfigurationVO config = _simMgr.getMockConfigurationDao().findByNameBottomUP(agentHost.getDataCenterId(), agentHost.getPodId(), agentHost.getClusterId(), agentHost.getId(), "PingCommand");
        if (config != null) {
            Map<String, String> configParameters = config.getParameters();
            for (Map.Entry<String, String> entry : configParameters.entrySet()) {
                if (entry.getKey().equalsIgnoreCase("result")) {
                    String value = entry.getValue();
                    if (value.equalsIgnoreCase("fail")) {
                        return null;
                    }
                }
            }
        }
        config = _simMgr.getMockConfigurationDao().findByNameBottomUP(agentHost.getDataCenterId(), agentHost.getPodId(), agentHost.getClusterId(), agentHost.getId(), "PingRoutingWithNwGroupsCommand");
        if (config != null) {
            String message = config.getJsonResponse();
            if (message != null) {
                // json response looks like {"<Type>":....}
                String objectType = message.split(":")[0].substring(2).replace("\"", "");
                String objectData = message.substring(message.indexOf(':') + 1, message.length() - 1);
                if (objectType != null) {
                    Class<?> clz = null;
                    try {
                        clz = Class.forName(objectType);
                    } catch (ClassNotFoundException e) {
                        s_logger.info("[ignored] ping returned class", e);
                    }
                    if (clz != null) {
                        StringReader reader = new StringReader(objectData);
                        JsonReader jsonReader = new JsonReader(reader);
                        jsonReader.setLenient(true);
                        return (PingCommand) s_gson.fromJson(jsonReader, clz);
                    }
                }
            }
        }
    } catch (Exception e) {
        txn.rollback();
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    if (isStopped()) {
        return null;
    }
    HashMap<String, Pair<Long, Long>> nwGrpStates = _simMgr.syncNetworkGroups(hostGuid);
    return new PingRoutingWithNwGroupsCommand(getType(), id, getHostVmStateReport(), nwGrpStates);
}
Also used : MockConfigurationVO(com.cloud.simulator.MockConfigurationVO) ConfigurationException(javax.naming.ConfigurationException) PingCommand(com.cloud.agent.api.PingCommand) PingRoutingWithNwGroupsCommand(com.cloud.agent.api.PingRoutingWithNwGroupsCommand) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.cloud.utils.Pair)

Aggregations

PingCommand (com.cloud.agent.api.PingCommand)23 Test (org.junit.Test)15 ControlClusterStatus (com.cloud.network.nicira.ControlClusterStatus)8 Answer (com.cloud.agent.api.Answer)4 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)4 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)3 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)3 Command (com.cloud.agent.api.Command)3 CronCommand (com.cloud.agent.api.CronCommand)3 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)3 MaintainCommand (com.cloud.agent.api.MaintainCommand)3 ShutdownCommand (com.cloud.agent.api.ShutdownCommand)3 StartupAnswer (com.cloud.agent.api.StartupAnswer)3 StartupCommand (com.cloud.agent.api.StartupCommand)3 Request (com.cloud.agent.transport.Request)3 Response (com.cloud.agent.transport.Response)3 Output (com.cloud.network.schema.showvcs.Output)3 VcsNodeInfo (com.cloud.network.schema.showvcs.VcsNodeInfo)3 ClosedChannelException (java.nio.channels.ClosedChannelException)3 ReadyCommand (com.cloud.agent.api.ReadyCommand)2