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());
}
}
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;
}
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;
}
Aggregations