Search in sources :

Example 6 with Command

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

the class DirectAgentTest method testDownloadTemplate.

@Test
public void testDownloadTemplate() {
    ImageStoreTO image = Mockito.mock(ImageStoreTO.class);
    PrimaryDataStoreTO primaryStore = Mockito.mock(PrimaryDataStoreTO.class);
    Mockito.when(primaryStore.getUuid()).thenReturn(getLocalStorageUuid());
    // Mockito.when(image.get).thenReturn(primaryStore);
    ImageStoreTO imageStore = Mockito.mock(ImageStoreTO.class);
    Mockito.when(imageStore.getProtocol()).thenReturn("http");
    TemplateObjectTO template = Mockito.mock(TemplateObjectTO.class);
    Mockito.when(template.getPath()).thenReturn(getTemplateUrl());
    Mockito.when(template.getDataStore()).thenReturn(imageStore);
    // Mockito.when(image.getTemplate()).thenReturn(template);
    // CopyTemplateToPrimaryStorageCmd cmd = new
    // CopyTemplateToPrimaryStorageCmd(image);
    Command cmd = null;
    try {
        agentMgr.send(hostId, cmd);
    } catch (AgentUnavailableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OperationTimedoutException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ImageStoreTO(org.apache.cloudstack.storage.to.ImageStoreTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) Command(com.cloud.agent.api.Command) ReadyCommand(com.cloud.agent.api.ReadyCommand) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) Test(org.testng.annotations.Test)

Example 7 with Command

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

the class AgentManagerImpl method connectAgent.

protected void connectAgent(final Link link, final Command[] cmds, final Request request) {
    // send startupanswer to agent in the very beginning, so agent can move on without waiting for the answer for an undetermined time, if we put this logic into another
    // thread pool.
    final StartupAnswer[] answers = new StartupAnswer[cmds.length];
    Command cmd;
    for (int i = 0; i < cmds.length; i++) {
        cmd = cmds[i];
        if (cmd instanceof StartupRoutingCommand || cmd instanceof StartupProxyCommand || cmd instanceof StartupSecondaryStorageCommand || cmd instanceof StartupStorageCommand) {
            answers[i] = new StartupAnswer((StartupCommand) cmds[i], 0, getPingInterval());
            break;
        }
    }
    Response response = null;
    response = new Response(request, answers[0], _nodeId, -1);
    try {
        link.send(response.toBytes());
    } catch (final ClosedChannelException e) {
        s_logger.debug("Failed to send startupanswer: " + e.toString());
    }
    _connectExecutor.execute(new HandleAgentConnectTask(link, cmds, request));
}
Also used : StartupAnswer(com.cloud.agent.api.StartupAnswer) StartupProxyCommand(com.cloud.agent.api.StartupProxyCommand) StartupCommand(com.cloud.agent.api.StartupCommand) Response(com.cloud.agent.transport.Response) ClosedChannelException(java.nio.channels.ClosedChannelException) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StartupCommand(com.cloud.agent.api.StartupCommand) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) PingCommand(com.cloud.agent.api.PingCommand) PingRoutingCommand(com.cloud.agent.api.PingRoutingCommand) SetHostParamsCommand(com.cloud.agent.api.SetHostParamsCommand) StartupSecondaryStorageCommand(com.cloud.agent.api.StartupSecondaryStorageCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ShutdownCommand(com.cloud.agent.api.ShutdownCommand) StartupProxyCommand(com.cloud.agent.api.StartupProxyCommand) CheckHealthCommand(com.cloud.agent.api.CheckHealthCommand) Command(com.cloud.agent.api.Command) ReadyCommand(com.cloud.agent.api.ReadyCommand) StartupSecondaryStorageCommand(com.cloud.agent.api.StartupSecondaryStorageCommand) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 8 with Command

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

the class AgentManagerImpl method checkForCommandsAndTag.

/**
     * @param commands
     * @return
     */
private Command[] checkForCommandsAndTag(final Commands commands) {
    final Command[] cmds = commands.toCommands();
    assert cmds.length > 0 : "Ask yourself this about a hundred times.  Why am I  sending zero length commands?";
    setEmptyAnswers(commands, cmds);
    for (final Command cmd : cmds) {
        tagCommand(cmd);
    }
    return cmds;
}
Also used : StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StartupCommand(com.cloud.agent.api.StartupCommand) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) PingCommand(com.cloud.agent.api.PingCommand) PingRoutingCommand(com.cloud.agent.api.PingRoutingCommand) SetHostParamsCommand(com.cloud.agent.api.SetHostParamsCommand) StartupSecondaryStorageCommand(com.cloud.agent.api.StartupSecondaryStorageCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ShutdownCommand(com.cloud.agent.api.ShutdownCommand) StartupProxyCommand(com.cloud.agent.api.StartupProxyCommand) CheckHealthCommand(com.cloud.agent.api.CheckHealthCommand) Command(com.cloud.agent.api.Command) ReadyCommand(com.cloud.agent.api.ReadyCommand)

Example 9 with Command

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

the class AgentManagerImpl method send.

@Override
public Answer[] send(final Long hostId, final Commands commands, int timeout) throws AgentUnavailableException, OperationTimedoutException {
    assert hostId != null : "Who's not checking the agent id before sending?  ... (finger wagging)";
    if (hostId == null) {
        throw new AgentUnavailableException(-1);
    }
    if (timeout <= 0) {
        timeout = Wait.value();
    }
    if (CheckTxnBeforeSending.value()) {
        if (!noDbTxn()) {
            throw new CloudRuntimeException("We do not allow transactions to be wrapped around commands sent to be executed on remote agents.  " + "We cannot predict how long it takes a command to complete.  " + "The transaction may be rolled back because the connection took too long.");
        }
    } else {
        assert noDbTxn() : "I know, I know.  Why are we so strict as to not allow txn across an agent call?  ...  Why are we so cruel ... Why are we such a dictator .... Too bad... Sorry...but NO AGENT COMMANDS WRAPPED WITHIN DB TRANSACTIONS!";
    }
    final Command[] cmds = checkForCommandsAndTag(commands);
    final AgentAttache agent = getAttache(hostId);
    if (agent == null || agent.isClosed()) {
        throw new AgentUnavailableException("agent not logged into this management server", hostId);
    }
    final Request req = new Request(hostId, agent.getName(), _nodeId, cmds, commands.stopOnError(), true);
    req.setSequence(agent.getNextSequence());
    final Answer[] answers = agent.send(req, timeout);
    notifyAnswersToMonitors(hostId, req.getSequence(), answers);
    commands.setAnswers(answers);
    return answers;
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) PingAnswer(com.cloud.agent.api.PingAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) StartupAnswer(com.cloud.agent.api.StartupAnswer) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StartupCommand(com.cloud.agent.api.StartupCommand) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) PingCommand(com.cloud.agent.api.PingCommand) PingRoutingCommand(com.cloud.agent.api.PingRoutingCommand) SetHostParamsCommand(com.cloud.agent.api.SetHostParamsCommand) StartupSecondaryStorageCommand(com.cloud.agent.api.StartupSecondaryStorageCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ShutdownCommand(com.cloud.agent.api.ShutdownCommand) StartupProxyCommand(com.cloud.agent.api.StartupProxyCommand) CheckHealthCommand(com.cloud.agent.api.CheckHealthCommand) Command(com.cloud.agent.api.Command) ReadyCommand(com.cloud.agent.api.ReadyCommand) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Request(com.cloud.agent.transport.Request)

Example 10 with Command

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

the class ClusteredAgentManagerImpl method propagateAgentEvent.

public Boolean propagateAgentEvent(final long agentId, final Event event) throws AgentUnavailableException {
    final String msPeer = getPeerName(agentId);
    if (msPeer == null) {
        return null;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Propagating agent change request event:" + event.toString() + " to agent:" + agentId);
    }
    final Command[] cmds = new Command[1];
    cmds[0] = new ChangeAgentCommand(agentId, event);
    final String ansStr = _clusterMgr.execute(msPeer, agentId, _gson.toJson(cmds), true);
    if (ansStr == null) {
        throw new AgentUnavailableException(agentId);
    }
    final Answer[] answers = _gson.fromJson(ansStr, Answer[].class);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Result for agent change is " + answers[0].getResult());
    }
    return answers[0].getResult();
}
Also used : ChangeAgentAnswer(com.cloud.agent.api.ChangeAgentAnswer) Answer(com.cloud.agent.api.Answer) CancelCommand(com.cloud.agent.api.CancelCommand) PropagateResourceEventCommand(com.cloud.agent.api.PropagateResourceEventCommand) ScheduleHostScanTaskCommand(com.cloud.agent.api.ScheduleHostScanTaskCommand) TransferAgentCommand(com.cloud.agent.api.TransferAgentCommand) ChangeAgentCommand(com.cloud.agent.api.ChangeAgentCommand) Command(com.cloud.agent.api.Command) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ChangeAgentCommand(com.cloud.agent.api.ChangeAgentCommand)

Aggregations

Command (com.cloud.agent.api.Command)33 Answer (com.cloud.agent.api.Answer)17 StartupCommand (com.cloud.agent.api.StartupCommand)17 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)13 PingCommand (com.cloud.agent.api.PingCommand)13 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)11 ShutdownCommand (com.cloud.agent.api.ShutdownCommand)10 PingRoutingCommand (com.cloud.agent.api.PingRoutingCommand)8 ReadyCommand (com.cloud.agent.api.ReadyCommand)8 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)8 MaintainCommand (com.cloud.agent.api.MaintainCommand)7 StartupAnswer (com.cloud.agent.api.StartupAnswer)7 StartupStorageCommand (com.cloud.agent.api.StartupStorageCommand)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)6 CronCommand (com.cloud.agent.api.CronCommand)6 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)5 PlugNicCommand (com.cloud.agent.api.PlugNicCommand)5 StartCommand (com.cloud.agent.api.StartCommand)5 Request (com.cloud.agent.transport.Request)5