Search in sources :

Example 21 with ActiveSpan

use of io.opentracing.ActiveSpan in project batfish by batfish.

the class WorkItemTest method testExtractOnly.

@Test
public void testExtractOnly() {
    SpanContext sourceSpanContext = _workItem.getSourceSpan(_mockTracer);
    assertThat(sourceSpanContext, nullValue());
    try (ActiveSpan childSpan = _mockTracer.buildSpan("test dangling child").addReference(References.FOLLOWS_FROM, sourceSpanContext).startActive()) {
        assertThat(childSpan, notNullValue());
        assertThat(childSpan, instanceOf(ThreadLocalActiveSpan.class));
    }
}
Also used : SpanContext(io.opentracing.SpanContext) ThreadLocalActiveSpan(io.opentracing.util.ThreadLocalActiveSpan) ActiveSpan(io.opentracing.ActiveSpan) NoopActiveSpan(io.opentracing.NoopActiveSpanSource.NoopActiveSpan) ThreadLocalActiveSpan(io.opentracing.util.ThreadLocalActiveSpan) Test(org.junit.Test)

Example 22 with ActiveSpan

use of io.opentracing.ActiveSpan in project batfish by batfish.

the class Client method execute.

private boolean execute(WorkItem wItem, @Nullable FileWriter outWriter) {
    _logger.infof("work-id is %s\n", wItem.getId());
    ActiveSpan activeSpan = GlobalTracer.get().activeSpan();
    if (activeSpan != null) {
        activeSpan.setTag("work-id", wItem.getId().toString());
    }
    wItem.addRequestParam(BfConsts.ARG_LOG_LEVEL, _settings.getBatfishLogLevel());
    for (String option : _additionalBatfishOptions.keySet()) {
        wItem.addRequestParam(option, _additionalBatfishOptions.get(option));
    }
    boolean queueWorkResult = _workHelper.queueWork(wItem);
    _logger.infof("Queuing result: %s\n", queueWorkResult);
    if (!queueWorkResult) {
        return queueWorkResult;
    }
    boolean result = true;
    if (!_backgroundExecution) {
        _polledWorkItem = wItem;
        result = pollWorkAndGetAnswer(wItem, outWriter);
        _polledWorkItem = null;
    }
    return result;
}
Also used : ActiveSpan(io.opentracing.ActiveSpan)

Example 23 with ActiveSpan

use of io.opentracing.ActiveSpan in project batfish by batfish.

the class Client method pollWork.

private boolean pollWork(UUID wItemId, @Nullable FileWriter outWriter) {
    Pair<WorkStatusCode, String> response;
    try (ActiveSpan workStatusSpan = GlobalTracer.get().buildSpan("Waiting for work status").startActive()) {
        // avoid unused warning
        assert workStatusSpan != null;
        // Poll the work item until it finishes or fails.
        response = _workHelper.getWorkStatus(wItemId);
        if (response == null) {
            return false;
        }
        WorkStatusCode status = response.getFirst();
        Backoff backoff = Backoff.builder().withMaximumBackoff(Duration.ofSeconds(1)).build();
        while (!status.isTerminated() && backoff.hasNext()) {
            printWorkStatusResponse(response, false);
            try {
                Thread.sleep(backoff.nextBackoff().toMillis());
            } catch (InterruptedException e) {
                throw new BatfishException("Interrupted while waiting for work item to complete", e);
            }
            response = _workHelper.getWorkStatus(wItemId);
            if (response == null) {
                return false;
            }
            status = response.getFirst();
        }
        printWorkStatusResponse(response, false);
    }
    return true;
}
Also used : BatfishException(org.batfish.common.BatfishException) WorkStatusCode(org.batfish.common.CoordConsts.WorkStatusCode) ActiveSpan(io.opentracing.ActiveSpan) Backoff(org.batfish.common.util.Backoff)

Example 24 with ActiveSpan

use of io.opentracing.ActiveSpan in project batfish by batfish.

the class Client method processCommand.

boolean processCommand(String[] words, @Nullable FileWriter outWriter) {
    Command command;
    try {
        command = Command.fromName(words[0]);
    } catch (BatfishException e) {
        _logger.errorf("Command failed: %s\n", e.getMessage());
        return false;
    }
    List<String> options = getCommandOptions(words);
    List<String> parameters = getCommandParameters(words, options.size());
    try (ActiveSpan span = GlobalTracer.get().buildSpan(command.commandName()).startActive()) {
        // make span not show up as unused.
        assert span != null;
        return processCommand(command, words, outWriter, options, parameters);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
Also used : BatfishException(org.batfish.common.BatfishException) ActiveSpan(io.opentracing.ActiveSpan) EndOfFileException(org.jline.reader.EndOfFileException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) UserInterruptException(org.jline.reader.UserInterruptException) PatternSyntaxException(java.util.regex.PatternSyntaxException) FileNotFoundException(java.io.FileNotFoundException) BatfishException(org.batfish.common.BatfishException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

ActiveSpan (io.opentracing.ActiveSpan)24 BatfishException (org.batfish.common.BatfishException)12 SpanContext (io.opentracing.SpanContext)10 IOException (java.io.IOException)8 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 NoopActiveSpan (io.opentracing.NoopActiveSpanSource.NoopActiveSpan)6 ThreadLocalActiveSpan (io.opentracing.util.ThreadLocalActiveSpan)6 Path (java.nio.file.Path)6 CleanBatfishException (org.batfish.common.CleanBatfishException)6 JSONException (org.codehaus.jettison.json.JSONException)6 Test (org.junit.Test)6 ProcessingException (javax.ws.rs.ProcessingException)5 Answer (org.batfish.datamodel.answers.Answer)5 TreeMap (java.util.TreeMap)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Nullable (javax.annotation.Nullable)4 BatfishLogger (org.batfish.common.BatfishLogger)4 JSONArray (org.codehaus.jettison.json.JSONArray)4 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)3 LinkedHashSet (java.util.LinkedHashSet)3