Search in sources :

Example 36 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project codebunker by gazampa.

the class BinaryTree method printPaths.

// if the tree was very large, this list would grow very large, the array method limits it
public void printPaths(LinkedList<Node> path) {
    if (path.isEmpty())
        path.addLast(root);
    Node node = path.peekLast();
    if (node.getLeft() == null && node.getRight() == null) {
        System.out.println(path.toString());
    } else {
        if (node.getLeft() != null) {
            path.addLast(node.getLeft());
            printPaths(path);
        }
        if (node.getRight() != null) {
            path.addLast(node.getRight());
            printPaths(path);
        }
    }
    path.removeLast();
}
Also used : Node(datastructures.nodes.ver1.Node)

Example 37 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project grpc-java by grpc.

the class CsdsServiceTest method verifyClientConfigNode.

/**
 * Assuming {@link io.grpc.xds.EnvoyProtoDataTest#convertNode} passes, perform a minimal check,
 * just verify the node itself is the one we expect.
 */
private static void verifyClientConfigNode(ClientConfig clientConfig) {
    Node node = clientConfig.getNode();
    assertThat(node.getId()).isEqualTo(NODE_ID);
    assertThat(node).isEqualTo(BOOTSTRAP_NODE.toEnvoyProtoNode());
}
Also used : Node(io.envoyproxy.envoy.config.core.v3.Node)

Example 38 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project instrumentation-java by census-instrumentation.

the class OcAgentTraceExporterIntegrationTest method testExportSpans.

@Test
public void testExportSpans() throws InterruptedException, IOException {
    // Mock a real-life scenario in production, where Agent is not enabled at first, then enabled
    // after an outage. Users should be able to see traces shortly after Agent is up.
    // Configure to be always-sampled.
    TraceConfig traceConfig = Tracing.getTraceConfig();
    TraceParams activeTraceParams = traceConfig.getActiveTraceParams();
    traceConfig.updateActiveTraceParams(activeTraceParams.toBuilder().setSampler(Samplers.alwaysSample()).build());
    // Register the OcAgent Exporter first.
    // Agent is not yet up and running so Exporter will just retry connection.
    OcAgentTraceExporter.createAndRegister(OcAgentTraceExporterConfiguration.builder().setServiceName(SERVICE_NAME).setUseInsecure(true).setEnableConfig(false).build());
    // Create one root span and 5 children.
    try (Scope scope = tracer.spanBuilder("root").startScopedSpan()) {
        for (int i = 0; i < 5; i++) {
            // Fake work
            doWork("first-iteration-child-" + i, i);
        }
    }
    // Wait 5s so that SpanExporter exports exports all spans.
    Thread.sleep(5000);
    // No interaction with Agent so far.
    assertThat(fakeOcAgentTraceServiceGrpc.getExportTraceServiceRequests()).isEmpty();
    // Image an outage happened, now start Agent. Exporter should be able to connect to Agent
    // when the next batch of SpanData arrives.
    agent.start();
    // Create one root span and 8 children.
    try (Scope scope = tracer.spanBuilder("root2").startScopedSpan()) {
        for (int i = 0; i < 8; i++) {
            // Fake work
            doWork("second-iteration-child-" + i, i);
        }
    }
    // Wait 5s so that SpanExporter exports exports all spans.
    Thread.sleep(5000);
    List<ExportTraceServiceRequest> exportRequests = fakeOcAgentTraceServiceGrpc.getExportTraceServiceRequests();
    assertThat(exportRequests.size()).isAtLeast(2);
    ExportTraceServiceRequest firstRequest = exportRequests.get(0);
    Node expectedNode = OcAgentNodeUtils.getNodeInfo(SERVICE_NAME);
    Node actualNode = firstRequest.getNode();
    assertThat(actualNode.getIdentifier().getHostName()).isEqualTo(expectedNode.getIdentifier().getHostName());
    assertThat(actualNode.getIdentifier().getPid()).isEqualTo(expectedNode.getIdentifier().getPid());
    assertThat(actualNode.getLibraryInfo()).isEqualTo(expectedNode.getLibraryInfo());
    assertThat(actualNode.getServiceInfo()).isEqualTo(expectedNode.getServiceInfo());
    List<io.opencensus.proto.trace.v1.Span> spanProtos = new ArrayList<>();
    for (int i = 1; i < exportRequests.size(); i++) {
        spanProtos.addAll(exportRequests.get(i).getSpansList());
    }
    // On some platforms (e.g Windows) SpanData will never be dropped, so spans from the first batch
    // may also be exported after Agent is up.
    assertThat(spanProtos.size()).isAtLeast(9);
    Set<String> exportedSpanNames = new HashSet<>();
    for (io.opencensus.proto.trace.v1.Span spanProto : spanProtos) {
        if ("root2".equals(spanProto.getName().getValue())) {
            assertThat(spanProto.getChildSpanCount().getValue()).isEqualTo(8);
            assertThat(spanProto.getParentSpanId()).isEqualTo(ByteString.EMPTY);
        } else if ("root".equals(spanProto.getName().getValue())) {
            // This won't happen on Linux but does happen on Windows.
            assertThat(spanProto.getChildSpanCount().getValue()).isEqualTo(5);
            assertThat(spanProto.getParentSpanId()).isEqualTo(ByteString.EMPTY);
        }
        exportedSpanNames.add(spanProto.getName().getValue());
    }
    // The second batch of spans should be exported no matter what.
    assertThat(exportedSpanNames).contains("root2");
    for (int i = 0; i < 8; i++) {
        assertThat(exportedSpanNames).contains("second-iteration-child-" + i);
    }
}
Also used : ExportTraceServiceRequest(io.opencensus.proto.agent.trace.v1.ExportTraceServiceRequest) Node(io.opencensus.proto.agent.common.v1.Node) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) TraceParams(io.opencensus.trace.config.TraceParams) Span(io.opencensus.trace.Span) Scope(io.opencensus.common.Scope) TraceConfig(io.opencensus.trace.config.TraceConfig) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 39 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project instrumentation-java by census-instrumentation.

the class OcAgentMetricsExporterIntegrationTest method testExportMetrics.

@Test
public void testExportMetrics() throws InterruptedException, IOException {
    // Mock a real-life scenario in production, where Agent is not enabled at first, then enabled
    // after an outage. Users should be able to see metrics shortly after Agent is up.
    registerAllViews();
    LongGauge gauge = registerGauge();
    // Register the OcAgent Exporter first.
    // Agent is not yet up and running so Exporter will just retry connection.
    OcAgentMetricsExporter.createAndRegister(OcAgentMetricsExporterConfiguration.builder().setServiceName(SERVICE_NAME).setUseInsecure(true).setRetryInterval(RETRY_INTERVAL).setExportInterval(EXPORT_INTERVAL).build());
    doWork(5, gauge.getOrCreateTimeSeries(Collections.singletonList(LabelValue.create("First work"))));
    // Wait 3s so that all metrics get exported.
    Thread.sleep(3000);
    // No interaction with Agent so far.
    assertThat(fakeOcAgentMetricsServiceGrpc.getExportMetricsServiceRequests()).isEmpty();
    // Imagine that an outage happened, now start Agent. Exporter should be able to connect to Agent
    // after the next retry interval.
    agent.start();
    // Wait 3s for Exporter to start another attempt to connect to Agent.
    Thread.sleep(3000);
    doWork(8, gauge.getOrCreateTimeSeries(Collections.singletonList(LabelValue.create("Second work"))));
    // Wait 3s so that all metrics get exported.
    Thread.sleep(3000);
    List<ExportMetricsServiceRequest> exportRequests = fakeOcAgentMetricsServiceGrpc.getExportMetricsServiceRequests();
    assertThat(exportRequests.size()).isAtLeast(2);
    ExportMetricsServiceRequest firstRequest = exportRequests.get(0);
    Node expectedNode = OcAgentNodeUtils.getNodeInfo(SERVICE_NAME);
    Node actualNode = firstRequest.getNode();
    assertThat(actualNode.getIdentifier().getHostName()).isEqualTo(expectedNode.getIdentifier().getHostName());
    assertThat(actualNode.getIdentifier().getPid()).isEqualTo(expectedNode.getIdentifier().getPid());
    assertThat(actualNode.getLibraryInfo()).isEqualTo(expectedNode.getLibraryInfo());
    assertThat(actualNode.getServiceInfo()).isEqualTo(expectedNode.getServiceInfo());
    List<Metric> metricProtos = new ArrayList<>();
    for (int i = 1; i < exportRequests.size(); i++) {
        metricProtos.addAll(exportRequests.get(i).getMetricsList());
    }
    // There should be at least one metric exported for each view and gauge (4 + 1).
    assertThat(metricProtos.size()).isAtLeast(5);
    Set<String> expectedMetrics = new HashSet<>();
    expectedMetrics.add("jobs");
    for (View view : VIEWS) {
        expectedMetrics.add(view.getName().asString());
    }
    Set<String> actualMetrics = new HashSet<>();
    for (Metric metricProto : metricProtos) {
        actualMetrics.add(metricProto.getMetricDescriptor().getName());
    }
    assertThat(actualMetrics).containsAtLeastElementsIn(expectedMetrics);
}
Also used : LongGauge(io.opencensus.metrics.LongGauge) Node(io.opencensus.proto.agent.common.v1.Node) ArrayList(java.util.ArrayList) Metric(io.opencensus.proto.metrics.v1.Metric) View(io.opencensus.stats.View) LongPoint(io.opencensus.metrics.LongGauge.LongPoint) ExportMetricsServiceRequest(io.opencensus.proto.agent.metrics.v1.ExportMetricsServiceRequest) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project atlas by osmlab.

the class OsmPbfCounter method process.

@Override
public void process(final EntityContainer entityContainer) {
    final Entity rawEntity = entityContainer.getEntity();
    if (OsmPbfReader.shouldProcessEntity(this.loadingOption, rawEntity)) {
        // store all node locations for calculating way geometry
        if (rawEntity instanceof Node) {
            final Node node = (Node) rawEntity;
            final Location nodeLocation = new Location(Latitude.degrees(node.getLatitude()), Longitude.degrees(node.getLongitude()));
            this.nodeIdentifierToLocation.put(rawEntity.getId(), nodeLocation);
        }
        if (shouldLoadOsmNode(rawEntity)) {
            // This node is within the boundary, bring it in
            this.nodeIdentifiersToInclude.add(rawEntity.getId());
        } else if (shouldLoadOsmWay(rawEntity)) {
            final Way way = (Way) rawEntity;
            if (wayIntersectsBoundary(way)) {
                // This way contains at least one shape-point within the given bounding box.
                // Bring it and all of its nodes in to the atlas.
                addWayNodes(this.nodeIdentifiersBroughtInByWaysOrRelations, way);
                this.wayIdentifiersToInclude.add(way.getId());
            } else {
                // This way doesn't have any shape-points within the given boundary. Mark it as
                // a way to exclude so it can be revisited during relation processing
                this.waysToExclude.put(way.getId(), way);
            }
        } else if (shouldLoadOsmRelation(rawEntity)) {
            final Relation relation = (Relation) rawEntity;
            if (relationContainsMemberWithinBoundary(relation)) {
                // Shallow check showed that this relation has a member that is inside our
                // boundary, mark all members and relation as inside
                markRelationAndMembersInsideBoundary(relation);
            } else {
                // Stage the relation - it might be added later
                this.stagedRelations.add(relation);
            }
        } else if (rawEntity instanceof Bound) {
            logger.trace("Encountered PBF Bound {}, skipping over it.", rawEntity.getId());
        }
    }
}
Also used : Entity(org.openstreetmap.osmosis.core.domain.v0_6.Entity) Relation(org.openstreetmap.osmosis.core.domain.v0_6.Relation) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way) Location(org.openstreetmap.atlas.geography.Location)

Aggregations

Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)52 Test (org.junit.Test)27 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)26 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)21 Date (java.util.Date)18 NodeContainer (org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)17 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)16 Node (org.flyte.api.v1.Node)15 Test (org.junit.jupiter.api.Test)15 ArrayList (java.util.ArrayList)14 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)14 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)13 TaskNode (org.flyte.api.v1.TaskNode)10 Bound (org.openstreetmap.osmosis.core.domain.v0_6.Bound)10 List (java.util.List)9 Map (java.util.Map)9 Node (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node)9 Node (org.openhab.binding.mqtt.homie.internal.homie300.Node)9 EntityContainer (org.openstreetmap.osmosis.core.container.v0_6.EntityContainer)9 Node (ch.ethz.globis.phtree.v16.Node)8