Search in sources :

Example 11 with Command

use of com.cloud.legacymodel.communication.command.Command in project cosmic by MissionCriticalCloud.

the class DirectAgentAttache method send.

@Override
public void send(final Request req) throws AgentUnavailableException {
    req.logD("Executing: ", true);
    if (req instanceof Response) {
        final Response resp = (Response) req;
        final Answer[] answers = resp.getAnswers();
        if (answers != null && answers[0] instanceof StartupAnswer) {
            final StartupAnswer startup = (StartupAnswer) answers[0];
            final int interval = startup.getPingInterval();
            this._futures.add(this._agentMgr.getCronJobPool().scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
        }
    } else {
        final Command[] cmds = req.getCommands();
        if (cmds.length > 0 && !(cmds[0] instanceof CronCommand)) {
            queueTask(new Task(req));
            scheduleFromQueue();
        } else {
            final CronCommand cmd = (CronCommand) cmds[0];
            this._futures.add(this._agentMgr.getCronJobPool().scheduleAtFixedRate(new CronTask(req), cmd.getInterval(), cmd.getInterval(), TimeUnit.SECONDS));
        }
    }
}
Also used : Response(com.cloud.common.transport.Response) StartupAnswer(com.cloud.legacymodel.communication.answer.StartupAnswer) StartupAnswer(com.cloud.legacymodel.communication.answer.StartupAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) Command(com.cloud.legacymodel.communication.command.Command) CronCommand(com.cloud.legacymodel.communication.command.CronCommand) PingCommand(com.cloud.legacymodel.communication.command.PingCommand) CronCommand(com.cloud.legacymodel.communication.command.CronCommand)

Example 12 with Command

use of com.cloud.legacymodel.communication.command.Command in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method sendToPool.

@Override
public Pair<Long, Answer[]> sendToPool(final StoragePool pool, final long[] hostIdsToTryFirst, final List<Long> hostIdsToAvoid, final Commands cmds) throws StorageUnavailableException {
    final List<Long> hostIds = getUpHostsInPool(pool.getId());
    Collections.shuffle(hostIds);
    if (hostIdsToTryFirst != null) {
        for (int i = hostIdsToTryFirst.length - 1; i >= 0; i--) {
            if (hostIds.remove(hostIdsToTryFirst[i])) {
                hostIds.add(0, hostIdsToTryFirst[i]);
            }
        }
    }
    if (hostIdsToAvoid != null) {
        hostIds.removeAll(hostIdsToAvoid);
    }
    if (hostIds == null || hostIds.isEmpty()) {
        throw new StorageUnavailableException("Unable to send command to the pool " + pool.getId() + " due to there is no enabled hosts up in this cluster", pool.getId());
    }
    for (final Long hostId : hostIds) {
        try {
            final List<Answer> answers = new ArrayList<>();
            final Command[] cmdArray = cmds.toCommands();
            for (final Command cmd : cmdArray) {
                final long targetHostId = this._hvGuruMgr.getGuruProcessedCommandTargetHost(hostId, cmd);
                answers.add(this._agentMgr.send(targetHostId, cmd));
            }
            return new Pair<>(hostId, answers.toArray(new Answer[answers.size()]));
        } catch (final AgentUnavailableException e) {
            s_logger.debug("Unable to send storage pool command to " + pool + " via " + hostId, e);
        } catch (final OperationTimedoutException e) {
            s_logger.debug("Unable to send storage pool command to " + pool + " via " + hostId, e);
        }
    }
    throw new StorageUnavailableException("Unable to send command to the pool ", pool.getId());
}
Also used : OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) ArrayList(java.util.ArrayList) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) Answer(com.cloud.legacymodel.communication.answer.Answer) StorageUnavailableException(com.cloud.legacymodel.exceptions.StorageUnavailableException) Command(com.cloud.legacymodel.communication.command.Command) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) Pair(com.cloud.legacymodel.utils.Pair)

Example 13 with Command

use of com.cloud.legacymodel.communication.command.Command in project cosmic by MissionCriticalCloud.

the class TemplateManagerImpl method attachISOToVM.

private boolean attachISOToVM(final long vmId, final long isoId, final boolean attach) {
    final UserVmVO vm = this._userVmDao.findById(vmId);
    if (vm == null) {
        return false;
    } else if (vm.getState() != State.Running) {
        return true;
    }
    // prepare ISO ready to mount on hypervisor resource level
    final TemplateInfo tmplt = prepareIso(isoId, vm.getDataCenterId());
    final String vmName = vm.getInstanceName();
    final HostVO host = this._hostDao.findById(vm.getHostId());
    if (host == null) {
        s_logger.warn("Host: " + vm.getHostId() + " does not exist");
        return false;
    }
    final DataTO isoTO = tmplt.getTO();
    final DiskTO disk = new DiskTO(isoTO, null, null, VolumeType.ISO);
    final Command cmd;
    if (attach) {
        cmd = new AttachCommand(disk, vmName);
    } else {
        cmd = new DettachCommand(disk, vmName);
    }
    final Answer a = this._agentMgr.easySend(vm.getHostId(), cmd);
    return a != null && a.getResult();
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) UserVmVO(com.cloud.vm.UserVmVO) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) DataTO(com.cloud.legacymodel.to.DataTO) DettachCommand(com.cloud.legacymodel.communication.command.DettachCommand) ComputeChecksumCommand(com.cloud.legacymodel.communication.command.ComputeChecksumCommand) TemplateOrVolumePostUploadCommand(com.cloud.legacymodel.communication.command.TemplateOrVolumePostUploadCommand) Command(com.cloud.legacymodel.communication.command.Command) AttachCommand(com.cloud.legacymodel.communication.command.AttachCommand) DestroyCommand(com.cloud.legacymodel.communication.command.DestroyCommand) DettachCommand(com.cloud.legacymodel.communication.command.DettachCommand) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) VMTemplateHostVO(com.cloud.storage.VMTemplateHostVO) HostVO(com.cloud.host.HostVO) AttachCommand(com.cloud.legacymodel.communication.command.AttachCommand) DiskTO(com.cloud.legacymodel.to.DiskTO)

Example 14 with Command

use of com.cloud.legacymodel.communication.command.Command in project cosmic by MissionCriticalCloud.

the class Agent method sendStartup.

public void sendStartup(final Link link) {
    final StartupCommand[] startup = this.resource.initialize();
    if (startup != null) {
        final Command[] commands = new Command[startup.length];
        for (int i = 0; i < startup.length; i++) {
            setupStartupCommand(startup[i]);
            commands[i] = startup[i];
        }
        final Request request = new Request(this._id != null ? this._id : -1, -1, commands, false, false);
        request.setSequence(getNextSequence());
        if (logger.isDebugEnabled()) {
            logger.debug("Sending Startup: " + request.toString());
        }
        lockStartupTask(link);
        try {
            link.send(request.toBytes());
        } catch (final ClosedChannelException e) {
            logger.warn("Unable to send request: " + request.toString());
        }
    }
}
Also used : StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) ClosedChannelException(java.nio.channels.ClosedChannelException) MaintainCommand(com.cloud.legacymodel.communication.command.MaintainCommand) ReadyCommand(com.cloud.legacymodel.communication.command.ReadyCommand) CronCommand(com.cloud.legacymodel.communication.command.CronCommand) PingCommand(com.cloud.legacymodel.communication.command.PingCommand) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) Command(com.cloud.legacymodel.communication.command.Command) AgentControlCommand(com.cloud.legacymodel.communication.command.agentcontrol.AgentControlCommand) ShutdownCommand(com.cloud.legacymodel.communication.command.ShutdownCommand) Request(com.cloud.common.transport.Request)

Example 15 with Command

use of com.cloud.legacymodel.communication.command.Command 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() - this._lastPingResponseTime > this._pingInterval * this.agentConfiguration.getPingRetries()) {
            logger.error("Ping Interval has gone past " + this._pingInterval * this.agentConfiguration.getPingRetries() + ". Won't reconnect to mgt server, as connection is still alive");
            return;
        }
        final PingCommand ping = this.resource.getCurrentStatus(getId());
        final Request request = new Request(this._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;
        this._inProgress.incrementAndGet();
        try {
            answer = this.resource.executeRequest(command);
        } finally {
            this._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.common.transport.Response) ClosedChannelException(java.nio.channels.ClosedChannelException) MaintainAnswer(com.cloud.legacymodel.communication.answer.MaintainAnswer) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) StartupAnswer(com.cloud.legacymodel.communication.answer.StartupAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) MaintainCommand(com.cloud.legacymodel.communication.command.MaintainCommand) ReadyCommand(com.cloud.legacymodel.communication.command.ReadyCommand) CronCommand(com.cloud.legacymodel.communication.command.CronCommand) PingCommand(com.cloud.legacymodel.communication.command.PingCommand) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) Command(com.cloud.legacymodel.communication.command.Command) AgentControlCommand(com.cloud.legacymodel.communication.command.agentcontrol.AgentControlCommand) ShutdownCommand(com.cloud.legacymodel.communication.command.ShutdownCommand) Request(com.cloud.common.transport.Request) PingCommand(com.cloud.legacymodel.communication.command.PingCommand)

Aggregations

Command (com.cloud.legacymodel.communication.command.Command)21 Answer (com.cloud.legacymodel.communication.answer.Answer)13 StartupCommand (com.cloud.legacymodel.communication.command.startup.StartupCommand)10 AgentControlCommand (com.cloud.legacymodel.communication.command.agentcontrol.AgentControlCommand)9 PingCommand (com.cloud.legacymodel.communication.command.PingCommand)8 ReadyCommand (com.cloud.legacymodel.communication.command.ReadyCommand)7 ShutdownCommand (com.cloud.legacymodel.communication.command.ShutdownCommand)7 StartupRoutingCommand (com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand)7 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)7 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)7 PingRoutingCommand (com.cloud.legacymodel.communication.command.PingRoutingCommand)6 StartupAnswer (com.cloud.legacymodel.communication.answer.StartupAnswer)5 Response (com.cloud.common.transport.Response)4 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)4 CheckHealthCommand (com.cloud.legacymodel.communication.command.CheckHealthCommand)4 CronCommand (com.cloud.legacymodel.communication.command.CronCommand)4 MaintainCommand (com.cloud.legacymodel.communication.command.MaintainCommand)4 StartupProxyCommand (com.cloud.legacymodel.communication.command.startup.StartupProxyCommand)4 StartupSecondaryStorageCommand (com.cloud.legacymodel.communication.command.startup.StartupSecondaryStorageCommand)4 StartupStorageCommand (com.cloud.legacymodel.communication.command.startup.StartupStorageCommand)4