Search in sources :

Example 1 with WebSocketChannel

use of com.walmartlabs.concord.server.websocket.WebSocketChannel 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 WebSocketChannel

use of com.walmartlabs.concord.server.websocket.WebSocketChannel in project concord by walmartlabs.

the class Dispatcher method sendResponse.

private void sendResponse(Match match, AgentCommand response) {
    WebSocketChannel channel = match.request.channel;
    long correlationId = match.request.request.getCorrelationId();
    CommandType type = CommandType.valueOf((String) response.getData().remove(Commands.TYPE_KEY));
    Map<String, Object> payload = new HashMap<>();
    payload.put("type", type.toString());
    payload.putAll(response.getData());
    boolean success = channelManager.sendResponse(channel.getChannelId(), CommandResponse.cancel(correlationId, payload));
    if (success) {
        log.info("sendResponse ['{}'] -> done", correlationId);
    } else {
        log.error("sendResponse ['{}'] -> failed", correlationId);
    }
}
Also used : CommandType(com.walmartlabs.concord.server.CommandType) WebSocketChannel(com.walmartlabs.concord.server.websocket.WebSocketChannel)

Aggregations

WebSocketChannel (com.walmartlabs.concord.server.websocket.WebSocketChannel)2 Imports (com.walmartlabs.concord.imports.Imports)1 CommandType (com.walmartlabs.concord.server.CommandType)1 ProcessQueueEntry (com.walmartlabs.concord.server.process.queue.ProcessQueueEntry)1 ProcessResponse (com.walmartlabs.concord.server.queueclient.message.ProcessResponse)1