Search in sources :

Example 1 with Annotation

use of org.sbolstandard.core2.Annotation in project brave by openzipkin.

the class MutableSpanMapTest method reportOrphanedSpans_afterGC.

/**
 * This is the key feature. Spans orphaned via GC are reported to zipkin on the next action.
 *
 * <p>This is a customized version of https://github.com/raphw/weak-lock-free/blob/master/src/test/java/com/blogspot/mydailyjava/weaklockfree/WeakConcurrentMapTest.java
 */
@Test
public void reportOrphanedSpans_afterGC() {
    TraceContext context1 = context.toBuilder().spanId(1).build();
    map.getOrCreate(context1);
    TraceContext context2 = context.toBuilder().spanId(2).build();
    map.getOrCreate(context2);
    TraceContext context3 = context.toBuilder().spanId(3).build();
    map.getOrCreate(context3);
    TraceContext context4 = context.toBuilder().spanId(4).build();
    map.getOrCreate(context4);
    // By clearing strong references in this test, we are left with the weak ones in the map
    context1 = context2 = null;
    blockOnGC();
    // After GC, we expect that the weak references of context1 and context2 to be cleared
    assertThat(map.delegate.keySet()).extracting(o -> ((Reference) o).get()).containsExactlyInAnyOrder(null, null, context3, context4);
    map.reportOrphanedSpans();
    // After reporting, we expect no the weak references of null
    assertThat(map.delegate.keySet()).extracting(o -> ((Reference) o).get()).containsExactlyInAnyOrder(context3, context4);
    // We also expect the spans to have been reported
    assertThat(spans).flatExtracting(Span::annotations).extracting(Annotation::value).containsExactly("brave.flush", "brave.flush");
}
Also used : Tracing(brave.Tracing) PowerMockito.mockStatic(org.powermock.api.mockito.PowerMockito.mockStatic) PowerMockito.when(org.powermock.api.mockito.PowerMockito.when) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Span(zipkin2.Span) Test(org.junit.Test) TraceContext(brave.propagation.TraceContext) ArrayList(java.util.ArrayList) Reference(java.lang.ref.Reference) List(java.util.List) Annotation(zipkin2.Annotation) Platform(brave.internal.Platform) Endpoint(zipkin2.Endpoint) After(org.junit.After) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) PowerMockIgnore(org.powermock.core.classloader.annotations.PowerMockIgnore) Reference(java.lang.ref.Reference) TraceContext(brave.propagation.TraceContext) Span(zipkin2.Span) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with Annotation

use of org.sbolstandard.core2.Annotation in project spring-cloud-gcp by spring-cloud.

the class LabelExtractor method extract.

/**
 * Extracts the Stackdriver span labels that are equivalent to the Zipkin Span
 * annotations.
 *
 * @param zipkinSpan The Zipkin Span
 * @return A map of the Stackdriver span labels equivalent to the Zipkin annotations.
 */
public Map<String, String> extract(Span zipkinSpan) {
    Map<String, String> result = new LinkedHashMap<>();
    for (Map.Entry<String, String> tag : zipkinSpan.tags().entrySet()) {
        result.put(label(tag.getKey()), tag.getValue());
    }
    // trace might not show the final destination.
    if (zipkinSpan.localEndpoint() != null && zipkinSpan.kind() == Span.Kind.SERVER) {
        if (zipkinSpan.localEndpoint().ipv4() != null) {
            result.put(label("endpoint.ipv4"), zipkinSpan.localEndpoint().ipv4());
        }
        if (zipkinSpan.localEndpoint().ipv6() != null) {
            result.put(label("endpoint.ipv6"), zipkinSpan.localEndpoint().ipv6());
        }
    }
    for (Annotation annotation : zipkinSpan.annotations()) {
        result.put(label(annotation.value()), formatTimestamp(annotation.timestamp()));
    }
    if (zipkinSpan.localEndpoint() != null && !zipkinSpan.localEndpoint().serviceName().isEmpty()) {
        result.put("/component", zipkinSpan.localEndpoint().serviceName());
    }
    if (zipkinSpan.parentId() == null) {
        String agentName = System.getProperty("stackdriver.trace.zipkin.agent", "spring-cloud-gcp-trace");
        result.put("/agent", agentName);
    }
    return result;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap) Annotation(zipkin2.Annotation) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with Annotation

use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.

the class Provenance_SpecifyBuildOperations method specifyAmplifyOperation.

/**
 * specifies the amplify operation, which amplifies a linear DNA construct using
 * 5' and 3' primers
 *
 * @throws Exception
 */
public static void specifyAmplifyOperation() throws Exception {
    // instantiate a document
    SBOLDocument document = new SBOLDocument();
    document.setDefaultURIprefix(BUILD_PREFIX);
    // the linear DNA construct
    ComponentDefinition dnaConstruct = document.createComponentDefinition("dna_construct", LINEAR_SINGLE_STRANDED_DNA);
    dnaConstruct.setName("dna_construct");
    // the 5' primer for amplification
    ComponentDefinition fivePrimer = document.createComponentDefinition("five_primer", FORWARD_PRIMER);
    fivePrimer.setName("five_primer");
    // the 3' primer for amplification
    ComponentDefinition threePrimer = document.createComponentDefinition("three_primer", REVERSE_PRIMER);
    threePrimer.setName("three_primer");
    // Create the generic top level entity for the amplify operation
    Activity amplifyOperation = document.createActivity("amplify_" + dnaConstruct.getName() + "_with_" + fivePrimer.getName() + "_and_" + threePrimer.getName());
    amplifyOperation.setName("amplify(" + dnaConstruct.getName() + ", " + fivePrimer.getName() + ", " + threePrimer.getName() + ")");
    // create the qualifiedUsage annotation to describe the inputs of the amplification operation
    // -- the amplicon
    Usage usageDNAConstruct = amplifyOperation.createUsage("dna_construct", dnaConstruct.getIdentity());
    usageDNAConstruct.addRole(URI.create("http://sbols.org/v2#source"));
    usageDNAConstruct.addRole(PCR_PRODUCT);
    // -- the forward primer
    Usage usageFwdPrimer = amplifyOperation.createUsage("forward_primer", fivePrimer.getIdentity());
    usageFwdPrimer.addRole(FORWARD_PRIMER);
    usageFwdPrimer.addRole(FORWARD_PRIMER);
    // -- the reverse primer
    Usage usageRevPrimer = amplifyOperation.createUsage("reverse_primer", threePrimer.getIdentity());
    usageRevPrimer.addRole(REVERSE_PRIMER);
    usageRevPrimer.addRole(REVERSE_PRIMER);
    // the result of the amplification operation
    ComponentDefinition amplified_construct = document.createComponentDefinition("my_amplified_dna", AMPLIFIED_CONSTRUCT);
    amplified_construct.setName("my_amplified_dna");
    amplified_construct.addWasGeneratedBy(amplifyOperation.getIdentity());
    // serialize the document to a file
    SBOLWriter.write(document, System.out);
}
Also used : Usage(org.sbolstandard.core2.Usage) SBOLDocument(org.sbolstandard.core2.SBOLDocument) Activity(org.sbolstandard.core2.Activity) ComponentDefinition(org.sbolstandard.core2.ComponentDefinition)

Example 4 with Annotation

use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.

the class Provenance_StrainDerivation method main.

public static void main(String[] args) throws Exception {
    NamespaceBinding myAppNs = NamespaceBinding("http://myapp.com/", "myapp");
    SBOLDocument document = new SBOLDocument();
    document.addNamespace(URI.create(myAppNs.getNamespaceURI()), myAppNs.getPrefix());
    document.setDefaultURIprefix(myAppNs.getNamespaceURI());
    ComponentDefinition b168 = getCds(document, "bsubtilis168", "Bacillus subtilis 168");
    ComponentDefinition b3610 = getCds(document, "bsubtilisncimb3610", "Bacillus subtilis NCIMB 3610");
    b168.addWasDerivedFrom(b3610.getIdentity());
    // Create the agent definition to represent X-ray
    Agent agent = document.createAgent("x_ray");
    agent.setName("X-ray");
    // Create the generic top level entity for the X-ray mutagenesis activity
    Activity activity = document.createActivity("xraymutagenesis");
    activity.setName("X-ray mutagenesis");
    // Create the qualifiedUsage annotation to describe the use of the parent strain
    activity.createUsage("usage", b3610.getIdentity()).addRole(URI.create("http://sbols.org/v2#source"));
    // Create the qualifiedAssociation annotation to describe the use of the agent used in the activity
    activity.createAssociation("association", agent.getIdentity()).addRole(myAppNs.namespacedUri("mutagen"));
    b168.addWasGeneratedBy(activity.getIdentity());
    SBOLWriter.write(document, System.out);
}
Also used : Agent(org.sbolstandard.core2.Agent) SBOLDocument(org.sbolstandard.core2.SBOLDocument) Activity(org.sbolstandard.core2.Activity) NamespaceBinding(org.sbolstandard.core.datatree.Datatree.NamespaceBinding) NamespaceBinding(org.sbolstandard.core.datatree.NamespaceBinding) ComponentDefinition(org.sbolstandard.core2.ComponentDefinition)

Example 5 with Annotation

use of org.sbolstandard.core2.Annotation in project libSBOLj by SynBioDex.

the class Provenance_CodonOptimization method main.

public static void main(String[] args) throws Exception {
    NamespaceBinding myAppNs = NamespaceBinding("http://myapp.com/", "myapp");
    SBOLDocument document = new SBOLDocument();
    document.addNamespace(URI.create(myAppNs.getNamespaceURI()), myAppNs.getPrefix());
    document.setDefaultURIprefix(myAppNs.getNamespaceURI());
    ComponentDefinition optimizedCds = getCds(document, "codon_optimized", "Codon optimised CDS");
    ComponentDefinition sourceCds = getCds(document, "non_codon_optimized", "Non Codon optimised CDS");
    optimizedCds.addWasDerivedFrom(sourceCds.getIdentity());
    // Create the agent definition for the codon optimization software
    Agent agent = document.createAgent("codon_optimization_software");
    agent.setName("Codon Optimization Software");
    // Create the generic top level entity for the codon optimization activity
    Activity activity = document.createActivity("codon_optimization_activity");
    activity.setName("Codon Optimization Activity");
    // Create the qualifiedUsage annotation to describe the use of the non codon optimized CDS component
    activity.createUsage("usage", sourceCds.getIdentity()).addRole(URI.create("http://sbols.org/v2#source"));
    // Create the qualifiedAssociation annotation to describe the use of the software agent used in the activity
    activity.createAssociation("association", agent.getIdentity()).addRole(myAppNs.namespacedUri("codonoptimiser"));
    optimizedCds.addWasGeneratedBy(activity.getIdentity());
    SBOLWriter.write(document, System.out);
}
Also used : Agent(org.sbolstandard.core2.Agent) SBOLDocument(org.sbolstandard.core2.SBOLDocument) Activity(org.sbolstandard.core2.Activity) NamespaceBinding(org.sbolstandard.core.datatree.Datatree.NamespaceBinding) NamespaceBinding(org.sbolstandard.core.datatree.NamespaceBinding) ComponentDefinition(org.sbolstandard.core2.ComponentDefinition)

Aggregations

URI (java.net.URI)33 QName (javax.xml.namespace.QName)33 ArrayList (java.util.ArrayList)31 HashSet (java.util.HashSet)31 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)31 Literal (org.sbolstandard.core.datatree.Literal)30 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)30 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)17 NestedDocument (org.sbolstandard.core.datatree.NestedDocument)13 Annotation (zipkin2.Annotation)11 Map (java.util.Map)8 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)7 SBOLDocument (org.sbolstandard.core2.SBOLDocument)5 Endpoint (zipkin2.Endpoint)5 Activity (org.sbolstandard.core2.Activity)4 LinkedHashMap (java.util.LinkedHashMap)3 Test (org.junit.Test)3 Annotation (org.sbolstandard.core2.Annotation)3 Span (zipkin2.Span)3 JsonToken (com.fasterxml.jackson.core.JsonToken)2