Search in sources :

Example 6 with AttributeValue

use of com.google.devtools.cloudtrace.v2.AttributeValue in project j2objc by google.

the class DNParser method parse.

/**
     * Parses DN
     *
     * @return a list of Relative Distinguished Names(RDN),
     *         each RDN is represented as a list of AttributeTypeAndValue objects
     */
public List<List<AttributeTypeAndValue>> parse() throws IOException {
    List<List<AttributeTypeAndValue>> list = new ArrayList<List<AttributeTypeAndValue>>();
    String attType = nextAT();
    if (attType == null) {
        //empty list of RDNs
        return list;
    }
    ObjectIdentifier oid = AttributeTypeAndValue.getObjectIdentifier(attType);
    List<AttributeTypeAndValue> atav = new ArrayList<AttributeTypeAndValue>();
    while (true) {
        if (pos == chars.length) {
            //empty Attribute Value
            atav.add(new AttributeTypeAndValue(oid, new AttributeValue("", false, oid)));
            list.add(0, atav);
            return list;
        }
        switch(chars[pos]) {
            case '"':
                atav.add(new AttributeTypeAndValue(oid, new AttributeValue(quotedAV(), hasQE, oid)));
                break;
            case '#':
                atav.add(new AttributeTypeAndValue(oid, new AttributeValue(hexAV(), encoded)));
                break;
            case '+':
            case ',':
            case // compatibility with RFC 1779: semicolon can separate RDNs
            ';':
                //empty attribute value
                atav.add(new AttributeTypeAndValue(oid, new AttributeValue("", false, oid)));
                break;
            default:
                atav.add(new AttributeTypeAndValue(oid, new AttributeValue(escapedAV(), hasQE, oid)));
        }
        if (pos >= chars.length) {
            list.add(0, atav);
            return list;
        }
        if (chars[pos] == ',' || chars[pos] == ';') {
            list.add(0, atav);
            atav = new ArrayList<AttributeTypeAndValue>();
        } else if (chars[pos] != '+') {
            throw new IOException("Invalid distinguished name string");
        }
        pos++;
        attType = nextAT();
        if (attType == null) {
            throw new IOException("Invalid distinguished name string");
        }
        oid = AttributeTypeAndValue.getObjectIdentifier(attType);
    }
}
Also used : AttributeValue(org.apache.harmony.security.x501.AttributeValue) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AttributeTypeAndValue(org.apache.harmony.security.x501.AttributeTypeAndValue) ObjectIdentifier(org.apache.harmony.security.utils.ObjectIdentifier)

Example 7 with AttributeValue

use of com.google.devtools.cloudtrace.v2.AttributeValue in project instrumentation-java by census-instrumentation.

the class StackdriverV2ExporterHandlerProtoTest method generateSpan_WithResourceLabels.

@Test
public void generateSpan_WithResourceLabels() {
    SpanData spanData = SpanData.create(spanContext, parentSpanId, /* hasRemoteParent= */
    true, SPAN_NAME, null, startTimestamp, attributes, annotations, messageEvents, links, CHILD_SPAN_COUNT, status, endTimestamp);
    Span span = handler.generateSpan(spanData, EXPECTED_RESOURCE_ATTRIBUTES, Collections.<String, AttributeValue>emptyMap());
    Map<String, AttributeValue> attributeMap = span.getAttributes().getAttributeMapMap();
    assertThat(attributeMap.entrySet()).containsAtLeastElementsIn(EXPECTED_RESOURCE_ATTRIBUTES.entrySet());
}
Also used : AttributeValue(com.google.devtools.cloudtrace.v2.AttributeValue) SpanData(io.opencensus.trace.export.SpanData) TruncatableString(com.google.devtools.cloudtrace.v2.TruncatableString) Span(com.google.devtools.cloudtrace.v2.Span) Test(org.junit.Test)

Example 8 with AttributeValue

use of com.google.devtools.cloudtrace.v2.AttributeValue in project instrumentation-java by census-instrumentation.

the class StackdriverV2ExporterHandlerProtoTest method addFixedAttributes.

@Test
public void addFixedAttributes() {
    final ImmutableMap<String, AttributeValue> fixedAttributes = ImmutableMap.of("string_attr_key", toStringAttributeValueProto("my-project"), "long_attr_key", AttributeValue.newBuilder().setIntValue(1234).build(), "bool_attr_key", AttributeValue.newBuilder().setBoolValue(true).build());
    SpanData spanData = SpanData.create(spanContext, parentSpanId, /* hasRemoteParent= */
    true, "Sent." + SPAN_NAME, Kind.CLIENT, startTimestamp, attributes, annotations, messageEvents, links, CHILD_SPAN_COUNT, status, endTimestamp);
    Span span = handler.generateSpan(spanData, EMPTY_RESOURCE_LABELS, fixedAttributes);
    Map<String, AttributeValue> attributeMap = span.getAttributes().getAttributeMapMap();
    assertThat(attributeMap.entrySet()).containsAtLeastElementsIn(fixedAttributes.entrySet());
}
Also used : AttributeValue(com.google.devtools.cloudtrace.v2.AttributeValue) SpanData(io.opencensus.trace.export.SpanData) TruncatableString(com.google.devtools.cloudtrace.v2.TruncatableString) Span(com.google.devtools.cloudtrace.v2.Span) Test(org.junit.Test)

Aggregations

Span (com.google.devtools.cloudtrace.v2.Span)5 TruncatableString (com.google.devtools.cloudtrace.v2.TruncatableString)4 SpanData (io.opencensus.trace.export.SpanData)4 Test (org.junit.Test)4 AttributeValue (com.google.devtools.cloudtrace.v2.AttributeValue)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 AttributeTypeAndValue (org.apache.harmony.security.x501.AttributeTypeAndValue)3 AttributeValue (org.apache.harmony.security.x501.AttributeValue)3 ObjectIdentifier (org.apache.harmony.security.utils.ObjectIdentifier)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 TimeEvent (com.google.devtools.cloudtrace.v2.Span.TimeEvent)1 SpanName (com.google.devtools.cloudtrace.v2.SpanName)1 Timestamp (io.opencensus.common.Timestamp)1 SpanContext (io.opencensus.trace.SpanContext)1 HashMap (java.util.HashMap)1