Search in sources :

Example 1 with ReadyCommand

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

the class LibvirtComputingResourceTest method testReadyCommand.

@Test
public void testReadyCommand() {
    final ReadyCommand command = new ReadyCommand(1l);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) ReadyCommand(com.cloud.agent.api.ReadyCommand) Test(org.junit.Test)

Example 2 with ReadyCommand

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

the class NotAValidCommand method testReadyCommand.

@Test
public void testReadyCommand() {
    final ReadyCommand readyCommand = new ReadyCommand();
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(readyCommand, citrixResourceBase);
    assertFalse(answer.getResult());
}
Also used : 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) ReadyCommand(com.cloud.agent.api.ReadyCommand) Test(org.junit.Test)

Example 3 with ReadyCommand

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

the class AgentManagerImpl method handleConnectedAgent.

private AgentAttache handleConnectedAgent(final Link link, final StartupCommand[] startup, final Request request) {
    AgentAttache attache = null;
    ReadyCommand ready = null;
    try {
        final HostVO host = _resourceMgr.createHostVOForConnectedAgent(startup);
        if (host != null) {
            ready = new ReadyCommand(host.getDataCenterId(), host.getId());
            attache = createAttacheForConnect(host, link);
            attache = notifyMonitorsOfConnection(attache, startup, false);
        }
    } catch (final Exception e) {
        s_logger.debug("Failed to handle host connection: " + e.toString());
        ready = new ReadyCommand(null);
        ready.setDetails(e.toString());
    } finally {
        if (ready == null) {
            ready = new ReadyCommand(null);
        }
    }
    try {
        if (attache == null) {
            final Request readyRequest = new Request(-1, -1, ready, false);
            link.send(readyRequest.getBytes());
        } else {
            easySend(attache.getId(), ready);
        }
    } catch (final Exception e) {
        s_logger.debug("Failed to send ready command:" + e.toString());
    }
    return attache;
}
Also used : ReadyCommand(com.cloud.agent.api.ReadyCommand) Request(com.cloud.agent.transport.Request) HostVO(com.cloud.host.HostVO) ConnectionException(com.cloud.exception.ConnectionException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) TaskExecutionException(com.cloud.utils.exception.TaskExecutionException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ClosedChannelException(java.nio.channels.ClosedChannelException) HypervisorVersionChangedException(com.cloud.utils.exception.HypervisorVersionChangedException) NioConnectionException(com.cloud.utils.exception.NioConnectionException) UnsupportedVersionException(com.cloud.exception.UnsupportedVersionException)

Example 4 with ReadyCommand

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

the class Ovm3HypervisorResourceTest method readyCommandTest.

@Test
public void readyCommandTest() throws ConfigurationException {
    hypervisor = support.prepare(configTest.getParams());
    ReadyCommand ready = new ReadyCommand();
    Answer ra = hypervisor.executeRequest(ready);
    results.basicBooleanTest(ra.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) ReadyCommand(com.cloud.agent.api.ReadyCommand) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) Test(org.junit.Test) CloudStackPluginTest(com.cloud.hypervisor.ovm3.objects.CloudStackPluginTest) NetworkTest(com.cloud.hypervisor.ovm3.objects.NetworkTest) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest) Ovm3ConfigurationTest(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest)

Example 5 with ReadyCommand

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

the class Agent method processRequest.

protected void processRequest(final Request request, final Link link) {
    boolean requestLogged = false;
    Response response = null;
    try {
        final Command[] cmds = request.getCommands();
        final Answer[] answers = new Answer[cmds.length];
        for (int i = 0; i < cmds.length; i++) {
            final Command cmd = cmds[i];
            Answer answer;
            try {
                if (cmd.getContextParam("logid") != null) {
                    MDC.put("logcontextid", cmd.getContextParam("logid"));
                }
                if (s_logger.isDebugEnabled()) {
                    if (// ensures request is logged only once per method call
                    !requestLogged) {
                        final String requestMsg = request.toString();
                        if (requestMsg != null) {
                            s_logger.debug("Request:" + requestMsg);
                        }
                        requestLogged = true;
                    }
                    s_logger.debug("Processing command: " + cmd.toString());
                }
                if (cmd instanceof CronCommand) {
                    final CronCommand watch = (CronCommand) cmd;
                    scheduleWatch(link, request, (long) watch.getInterval() * 1000, watch.getInterval() * 1000);
                    answer = new Answer(cmd, true, null);
                } else if (cmd instanceof ShutdownCommand) {
                    final ShutdownCommand shutdown = (ShutdownCommand) cmd;
                    s_logger.debug("Received shutdownCommand, due to: " + shutdown.getReason());
                    cancelTasks();
                    _reconnectAllowed = false;
                    answer = new Answer(cmd, true, null);
                } else if (cmd instanceof ReadyCommand && ((ReadyCommand) cmd).getDetails() != null) {
                    s_logger.debug("Not ready to connect to mgt server: " + ((ReadyCommand) cmd).getDetails());
                    System.exit(1);
                    return;
                } else if (cmd instanceof MaintainCommand) {
                    s_logger.debug("Received maintainCommand");
                    cancelTasks();
                    _reconnectAllowed = false;
                    answer = new MaintainAnswer((MaintainCommand) cmd);
                } else if (cmd instanceof AgentControlCommand) {
                    answer = null;
                    synchronized (_controlListeners) {
                        for (final IAgentControlListener listener : _controlListeners) {
                            answer = listener.processControlRequest(request, (AgentControlCommand) cmd);
                            if (answer != null) {
                                break;
                            }
                        }
                    }
                    if (answer == null) {
                        s_logger.warn("No handler found to process cmd: " + cmd.toString());
                        answer = new AgentControlAnswer(cmd);
                    }
                } else {
                    if (cmd instanceof ReadyCommand) {
                        processReadyCommand(cmd);
                    }
                    _inProgress.incrementAndGet();
                    try {
                        answer = _resource.executeRequest(cmd);
                    } finally {
                        _inProgress.decrementAndGet();
                    }
                    if (answer == null) {
                        s_logger.debug("Response: unsupported command" + cmd.toString());
                        answer = Answer.createUnsupportedCommandAnswer(cmd);
                    }
                }
            } catch (final Throwable th) {
                s_logger.warn("Caught: ", th);
                final StringWriter writer = new StringWriter();
                th.printStackTrace(new PrintWriter(writer));
                answer = new Answer(cmd, false, writer.toString());
            }
            answers[i] = answer;
            if (!answer.getResult() && request.stopOnError()) {
                for (i++; i < cmds.length; i++) {
                    answers[i] = new Answer(cmds[i], false, "Stopped by previous failure");
                }
                break;
            }
        }
        response = new Response(request, answers);
    } finally {
        if (s_logger.isDebugEnabled()) {
            final String responseMsg = response.toString();
            if (responseMsg != null) {
                s_logger.debug(response.toString());
            }
        }
        if (response != null) {
            try {
                link.send(response.toBytes());
            } catch (final ClosedChannelException e) {
                s_logger.warn("Unable to send response: " + response.toString());
            }
        }
    }
}
Also used : MaintainCommand(com.cloud.agent.api.MaintainCommand) ClosedChannelException(java.nio.channels.ClosedChannelException) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) CronCommand(com.cloud.agent.api.CronCommand) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) ShutdownCommand(com.cloud.agent.api.ShutdownCommand) Response(com.cloud.agent.transport.Response) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) StartupAnswer(com.cloud.agent.api.StartupAnswer) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) StringWriter(java.io.StringWriter) StartupCommand(com.cloud.agent.api.StartupCommand) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) PingCommand(com.cloud.agent.api.PingCommand) MaintainCommand(com.cloud.agent.api.MaintainCommand) ShutdownCommand(com.cloud.agent.api.ShutdownCommand) Command(com.cloud.agent.api.Command) ReadyCommand(com.cloud.agent.api.ReadyCommand) CronCommand(com.cloud.agent.api.CronCommand) ReadyCommand(com.cloud.agent.api.ReadyCommand) PrintWriter(java.io.PrintWriter)

Aggregations

ReadyCommand (com.cloud.agent.api.ReadyCommand)10 Answer (com.cloud.agent.api.Answer)8 ConfigurationException (javax.naming.ConfigurationException)4 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)3 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)3 ConnectionException (com.cloud.exception.ConnectionException)3 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 ClosedChannelException (java.nio.channels.ClosedChannelException)3 Test (org.junit.Test)3 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)2 MaintainCommand (com.cloud.agent.api.MaintainCommand)2 ReadyAnswer (com.cloud.agent.api.ReadyAnswer)2 SetupAnswer (com.cloud.agent.api.SetupAnswer)2 StartupAnswer (com.cloud.agent.api.StartupAnswer)2 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)2 Listener (com.cloud.agent.Listener)1 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)1 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)1 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)1