Search in sources :

Example 1 with ProcessQueueEntry

use of com.walmartlabs.concord.server.process.queue.ProcessQueueEntry in project concord by walmartlabs.

the class Dispatcher method sendResponse.

private void sendResponse(Match match) {
    WebSocketChannel channel = match.request.channel;
    long correlationId = match.request.request.getCorrelationId();
    ProcessQueueEntry item = match.response;
    try {
        SecretReference secret = null;
        if (item.repoId() != null) {
            secret = dao.getSecretReference(item.repoId());
        }
        // backward compatibility with old process queue entries that are not normalized
        Imports imports = importsNormalizerFactory.forProject(item.projectId()).normalize(item.imports());
        ProcessResponse resp = new ProcessResponse(correlationId, sessionTokenCreator.create(item.key()), item.key().getInstanceId(), secret != null ? secret.orgName : null, item.repoUrl(), item.repoPath(), item.commitId(), item.commitBranch(), secret != null ? secret.secretName : null, imports);
        if (!channelManager.sendResponse(channel.getChannelId(), resp)) {
            log.warn("sendResponse ['{}'] -> failed", correlationId);
        }
        logManager.info(item.key(), "Acquired by: " + channel.getUserAgent());
    } catch (Exception e) {
        log.error("sendResponse ['{}'] -> failed (instanceId: {})", correlationId, item.key().getInstanceId());
    }
}
Also used : WebSocketChannel(com.walmartlabs.concord.server.websocket.WebSocketChannel) ProcessQueueEntry(com.walmartlabs.concord.server.process.queue.ProcessQueueEntry) Imports(com.walmartlabs.concord.imports.Imports) ProcessResponse(com.walmartlabs.concord.server.queueclient.message.ProcessResponse)

Example 2 with ProcessQueueEntry

use of com.walmartlabs.concord.server.process.queue.ProcessQueueEntry in project concord by walmartlabs.

the class Dispatcher method match.

private List<Match> match(DSLContext tx, List<Request> requests) {
    // we need it modifiable
    List<Request> inbox = new ArrayList<>(requests);
    int offset = 0;
    List<Match> matches = new ArrayList<>();
    while (true) {
        // fetch the next few ENQUEUED processes from the DB
        List<ProcessQueueEntry> candidates = dao.next(tx, offset, batchSize);
        if (candidates.isEmpty()) {
            break;
        }
        // filter out the candidates that shouldn't be dispatched at the moment (e.g. due to concurrency limits)
        for (ProcessQueueEntry e : candidates) {
            // find request/agent who can handle process
            Request req = findRequest(e, inbox);
            if (req == null) {
                continue;
            }
            // "startingProcesses" are the currently collected "matches"
            // we keep them in a separate collection to simplify the filtering
            List<ProcessQueueEntry> startingProcesses = matches.stream().map(m -> m.response).collect(Collectors.toList());
            if (pass(tx, e, startingProcesses)) {
                matches.add(new Match(req, e));
                inbox.remove(req);
                if (inbox.isEmpty()) {
                    break;
                }
            }
        }
        if (inbox.isEmpty()) {
            break;
        }
        offset += batchSize;
    }
    for (Match m : matches) {
        ProcessQueueEntry candidate = m.response;
        // mark the process as STARTING
        queueManager.updateAgentId(tx, candidate.key(), m.request.channel.getAgentId(), ProcessStatus.STARTING);
    }
    return matches;
}
Also used : ORGANIZATIONS(com.walmartlabs.concord.server.jooq.tables.Organizations.ORGANIZATIONS) Histogram(com.codahale.metrics.Histogram) MessageType(com.walmartlabs.concord.server.queueclient.message.MessageType) java.util(java.util) PROCESS_QUEUE(com.walmartlabs.concord.server.jooq.tables.ProcessQueue.PROCESS_QUEUE) DSL(org.jooq.impl.DSL) LoggerFactory(org.slf4j.LoggerFactory) ProcessQueueManager(com.walmartlabs.concord.server.process.queue.ProcessQueueManager) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ProcessQueueEntry(com.walmartlabs.concord.server.process.queue.ProcessQueueEntry) Singleton(javax.inject.Singleton) SECRETS(com.walmartlabs.concord.server.jooq.tables.Secrets.SECRETS) Matcher(com.walmartlabs.concord.common.Matcher) ProcessQueueConfiguration(com.walmartlabs.concord.server.cfg.ProcessQueueConfiguration) Inject(javax.inject.Inject) Locks(com.walmartlabs.concord.server.Locks) org.jooq(org.jooq) AbstractDao(com.walmartlabs.concord.db.AbstractDao) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) Imports(com.walmartlabs.concord.imports.Imports) SessionTokenCreator(com.walmartlabs.concord.server.process.SessionTokenCreator) MainDB(com.walmartlabs.concord.db.MainDB) ProcessResponse(com.walmartlabs.concord.server.queueclient.message.ProcessResponse) Named(javax.inject.Named) WebSocketChannelManager(com.walmartlabs.concord.server.websocket.WebSocketChannelManager) ConcordObjectMapper(com.walmartlabs.concord.server.ConcordObjectMapper) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) REPOSITORIES(com.walmartlabs.concord.server.jooq.tables.Repositories.REPOSITORIES) PeriodicTask(com.walmartlabs.concord.server.PeriodicTask) ProcessLogManager(com.walmartlabs.concord.server.process.logs.ProcessLogManager) ExclusiveMode(com.walmartlabs.concord.runtime.v2.model.ExclusiveMode) ProcessQueue(com.walmartlabs.concord.server.jooq.tables.ProcessQueue) ProcessStatus(com.walmartlabs.concord.server.sdk.ProcessStatus) Collectors(java.util.stream.Collectors) ImportsNormalizerFactory(com.walmartlabs.concord.server.process.ImportsNormalizerFactory) ProcessRequest(com.walmartlabs.concord.server.queueclient.message.ProcessRequest) TimeUnit(java.util.concurrent.TimeUnit) PROJECTS(com.walmartlabs.concord.server.jooq.tables.Projects.PROJECTS) OffsetDateTime(java.time.OffsetDateTime) MetricUtils.withTimer(com.walmartlabs.concord.server.metrics.MetricUtils.withTimer) Timer(com.codahale.metrics.Timer) WebSocketChannel(com.walmartlabs.concord.server.websocket.WebSocketChannel) ProcessRequest(com.walmartlabs.concord.server.queueclient.message.ProcessRequest) ProcessQueueEntry(com.walmartlabs.concord.server.process.queue.ProcessQueueEntry)

Example 3 with ProcessQueueEntry

use of com.walmartlabs.concord.server.process.queue.ProcessQueueEntry in project concord by walmartlabs.

the class ExclusiveProcessFilter method findProcess.

@Override
protected List<UUID> findProcess(DSLContext tx, ProcessQueueEntry item, List<ProcessQueueEntry> startingProcesses) {
    UUID projectId = item.projectId();
    ExclusiveMode exclusive = item.exclusive();
    if (projectId == null || exclusive == null) {
        return Collections.emptyList();
    }
    boolean isWaitMode = exclusive.mode() == ExclusiveMode.Mode.wait;
    if (!isWaitMode) {
        return Collections.emptyList();
    }
    List<UUID> result = new ArrayList<>(dao.findProcess(tx, item, exclusive.group()));
    for (ProcessQueueEntry p : startingProcesses) {
        if (projectId.equals(p.projectId()) && groupEquals(exclusive, p.exclusive())) {
            result.add(p.key().getInstanceId());
        }
    }
    return result;
}
Also used : ProcessQueueEntry(com.walmartlabs.concord.server.process.queue.ProcessQueueEntry) ExclusiveMode(com.walmartlabs.concord.runtime.v2.model.ExclusiveMode)

Aggregations

ProcessQueueEntry (com.walmartlabs.concord.server.process.queue.ProcessQueueEntry)3 Imports (com.walmartlabs.concord.imports.Imports)2 ExclusiveMode (com.walmartlabs.concord.runtime.v2.model.ExclusiveMode)2 ProcessResponse (com.walmartlabs.concord.server.queueclient.message.ProcessResponse)2 WebSocketChannel (com.walmartlabs.concord.server.websocket.WebSocketChannel)2 Histogram (com.codahale.metrics.Histogram)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Timer (com.codahale.metrics.Timer)1 Matcher (com.walmartlabs.concord.common.Matcher)1 AbstractDao (com.walmartlabs.concord.db.AbstractDao)1 MainDB (com.walmartlabs.concord.db.MainDB)1 ConcordObjectMapper (com.walmartlabs.concord.server.ConcordObjectMapper)1 Locks (com.walmartlabs.concord.server.Locks)1 PeriodicTask (com.walmartlabs.concord.server.PeriodicTask)1 ProcessQueueConfiguration (com.walmartlabs.concord.server.cfg.ProcessQueueConfiguration)1 ORGANIZATIONS (com.walmartlabs.concord.server.jooq.tables.Organizations.ORGANIZATIONS)1 ProcessQueue (com.walmartlabs.concord.server.jooq.tables.ProcessQueue)1 PROCESS_QUEUE (com.walmartlabs.concord.server.jooq.tables.ProcessQueue.PROCESS_QUEUE)1 PROJECTS (com.walmartlabs.concord.server.jooq.tables.Projects.PROJECTS)1 REPOSITORIES (com.walmartlabs.concord.server.jooq.tables.Repositories.REPOSITORIES)1