Search in sources :

Example 1 with Node

use of org.openstreetmap.osmosis.core.domain.v0_6.Node in project voltdb by VoltDB.

the class VoltDBOsmSink method process.

public void process(NodeContainer nodeContainer) {
    Node node;
    node = nodeContainer.getEntity();
    double lat = node.getLatitude();
    double lng = node.getLongitude();
    String pointText = "POINT(" + lng + " " + lat + ")";
    // keep track of the nodes so we can build polygons later
    if (enableBboxBuilder || enableLinestringBuilder) {
        wayGeometryBuilder.addNodeLocation(node);
    }
    try {
        client.callProcedure(new InsertCallback(), INS_NODE_PROC, node.getId(), node.getVersion(), node.getUser().getId(), new TimestampType(node.getTimestamp().getTime()), node.getChangesetId(), pointText);
    } catch (NoConnectionsException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Collection<Tag> tags = node.getTags();
    for (Tag tag : tags) {
        // System.out.println(INS_NODE_TAG_PROC+","+node.getId()+","+tag.getKey()+","+tag.getValue());
        try {
            client.callProcedure(new InsertCallback(), INS_NODE_TAG_PROC, node.getId(), tag.getKey(), tag.getValue());
        } catch (NoConnectionsException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : NoConnectionsException(org.voltdb.client.NoConnectionsException) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) TimestampType(org.voltdb.types.TimestampType) LineString(org.postgis.LineString) IOException(java.io.IOException) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 2 with Node

use of org.openstreetmap.osmosis.core.domain.v0_6.Node in project GeoGig by boundlessgeo.

the class OSMUnmapOp method unmapNode.

private void unmapNode(SimpleFeature feature, FeatureMapFlusher mapFlusher) {
    boolean modified = false;
    String id = feature.getID();
    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(OSMUtils.nodeType());
    Optional<RevFeature> rawFeature = command(RevObjectParse.class).setRefSpec("WORK_HEAD:" + OSMUtils.NODE_TYPE_NAME + "/" + id).call(RevFeature.class);
    Map<String, String> tagsMap = Maps.newHashMap();
    long timestamp = System.currentTimeMillis();
    int version = 1;
    long changeset = -1;
    String user = UNKNOWN_USER;
    Collection<Tag> tags = Lists.newArrayList();
    if (rawFeature.isPresent()) {
        ImmutableList<Optional<Object>> values = rawFeature.get().getValues();
        tags = OSMUtils.buildTagsCollectionFromString(values.get(NODE_TAGS_FIELD_INDEX).get().toString());
        for (Tag tag : tags) {
            tagsMap.put(tag.getKey(), tag.getValue());
        }
        Optional<Object> timestampOpt = values.get(NODE_TIMESTAMP_FIELD_INDEX);
        if (timestampOpt.isPresent()) {
            timestamp = ((Long) timestampOpt.get()).longValue();
        }
        Optional<Object> versionOpt = values.get(NODE_VERSION_FIELD_INDEX);
        if (versionOpt.isPresent()) {
            version = ((Integer) versionOpt.get()).intValue();
        }
        Optional<Object> changesetOpt = values.get(NODE_CHANGESET_FIELD_INDEX);
        if (changesetOpt.isPresent()) {
            changeset = ((Long) changesetOpt.get()).longValue();
        }
        Optional<Object> userOpt = values.get(NODE_USER_FIELD_INDEX);
        if (userOpt.isPresent()) {
            user = (String) userOpt.get();
        }
    }
    Map<String, String> unaliased = Maps.newHashMap();
    Collection<Property> properties = feature.getProperties();
    for (Property property : properties) {
        String name = property.getName().getLocalPart();
        if (name.equals("id") || Geometry.class.isAssignableFrom(property.getDescriptor().getType().getBinding())) {
            continue;
        }
        Object value = property.getValue();
        if (value != null) {
            String tagName = name;
            if (mapping != null) {
                if (unaliased.containsKey(name)) {
                    tagName = unaliased.get(name);
                } else {
                    tagName = mapping.getTagNameFromAlias(path, tagName);
                    unaliased.put(name, tagName);
                }
            }
            if (!DefaultField.isDefaultField(tagName)) {
                if (tagsMap.containsKey(tagName)) {
                    if (!modified) {
                        String oldValue = tagsMap.get(tagName);
                        modified = !value.equals(oldValue);
                    }
                } else {
                    modified = true;
                }
                tagsMap.put(tagName, value.toString());
            }
        }
    }
    if (!modified && rawFeature.isPresent()) {
        // no changes after unmapping tags, so there's nothing else to do
        return;
    }
    Collection<Tag> newTags = Lists.newArrayList();
    Set<Entry<String, String>> entries = tagsMap.entrySet();
    for (Entry<String, String> entry : entries) {
        newTags.add(new Tag(entry.getKey(), entry.getValue()));
    }
    featureBuilder.set("tags", OSMUtils.buildTagsString(newTags));
    featureBuilder.set("location", feature.getDefaultGeometry());
    featureBuilder.set("changeset", changeset);
    featureBuilder.set("timestamp", timestamp);
    featureBuilder.set("version", version);
    featureBuilder.set("user", user);
    featureBuilder.set("visible", true);
    if (rawFeature.isPresent()) {
        // the feature has changed, so we cannot reuse some attributes.
        // We reconstruct the feature and insert it
        featureBuilder.set("timestamp", System.currentTimeMillis());
        featureBuilder.set("changeset", null);
        featureBuilder.set("version", null);
        featureBuilder.set("visible", true);
        mapFlusher.put("node", featureBuilder.buildFeature(id));
    } else {
        // The feature didn't exist, so we have to add it
        mapFlusher.put("node", featureBuilder.buildFeature(id));
    }
}
Also used : Optional(com.google.common.base.Optional) LineString(com.vividsolutions.jts.geom.LineString) Point(com.vividsolutions.jts.geom.Point) Geometry(com.vividsolutions.jts.geom.Geometry) ReadOSMMappingLogEntry(org.locationtech.geogig.osm.internal.log.ReadOSMMappingLogEntry) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Entry(java.util.Map.Entry) OSMMappingLogEntry(org.locationtech.geogig.osm.internal.log.OSMMappingLogEntry) RevFeature(org.locationtech.geogig.api.RevFeature) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) Property(org.opengis.feature.Property) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 3 with Node

use of org.openstreetmap.osmosis.core.domain.v0_6.Node in project GeoGig by boundlessgeo.

the class OSMExport method getFeatures.

private Iterator<EntityContainer> getFeatures(String ref) {
    Optional<ObjectId> id = geogig.command(RevParse.class).setRefSpec(ref).call();
    if (!id.isPresent()) {
        return Iterators.emptyIterator();
    }
    LsTreeOp op = geogig.command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).setReference(ref);
    if (bbox != null) {
        final Envelope env;
        try {
            env = new Envelope(Double.parseDouble(bbox.get(0)), Double.parseDouble(bbox.get(2)), Double.parseDouble(bbox.get(1)), Double.parseDouble(bbox.get(3)));
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Wrong bbox definition");
        }
        Predicate<Bounded> filter = new Predicate<Bounded>() {

            @Override
            public boolean apply(final Bounded bounded) {
                boolean intersects = bounded.intersects(env);
                return intersects;
            }
        };
        op.setBoundsFilter(filter);
    }
    Iterator<NodeRef> iterator = op.call();
    final EntityConverter converter = new EntityConverter();
    Function<NodeRef, EntityContainer> function = new Function<NodeRef, EntityContainer>() {

        @Override
        @Nullable
        public EntityContainer apply(@Nullable NodeRef ref) {
            RevFeature revFeature = geogig.command(RevObjectParse.class).setObjectId(ref.objectId()).call(RevFeature.class).get();
            SimpleFeatureType featureType;
            if (ref.path().startsWith(OSMUtils.NODE_TYPE_NAME)) {
                featureType = OSMUtils.nodeType();
            } else {
                featureType = OSMUtils.wayType();
            }
            SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
            RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType);
            List<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
            ImmutableList<Optional<Object>> values = revFeature.getValues();
            for (int i = 0; i < descriptors.size(); i++) {
                PropertyDescriptor descriptor = descriptors.get(i);
                Optional<Object> value = values.get(i);
                featureBuilder.set(descriptor.getName(), value.orNull());
            }
            SimpleFeature feature = featureBuilder.buildFeature(ref.name());
            Entity entity = converter.toEntity(feature, null);
            EntityContainer container;
            if (entity instanceof Node) {
                container = new NodeContainer((Node) entity);
            } else {
                container = new WayContainer((Way) entity);
            }
            return container;
        }
    };
    return Iterators.transform(iterator, function);
}
Also used : EntityConverter(org.locationtech.geogig.osm.internal.EntityConverter) Entity(org.openstreetmap.osmosis.core.domain.v0_6.Entity) WayContainer(org.openstreetmap.osmosis.core.container.v0_6.WayContainer) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) Envelope(com.vividsolutions.jts.geom.Envelope) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way) Predicate(com.google.common.base.Predicate) NodeRef(org.locationtech.geogig.api.NodeRef) Function(com.google.common.base.Function) Bounded(org.locationtech.geogig.api.Bounded) RevFeature(org.locationtech.geogig.api.RevFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) SimpleFeature(org.opengis.feature.simple.SimpleFeature) LsTreeOp(org.locationtech.geogig.api.plumbing.LsTreeOp) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) Nullable(javax.annotation.Nullable) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 4 with Node

use of org.openstreetmap.osmosis.core.domain.v0_6.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 5 with Node

use of org.openstreetmap.osmosis.core.domain.v0_6.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)

Aggregations

Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)6 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)6 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)6 IOException (java.io.IOException)5 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)5 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)4 Optional (com.google.common.base.Optional)3 Test (org.junit.Test)3 RevFeature (org.locationtech.geogig.api.RevFeature)3 Function (com.google.common.base.Function)2 Point (com.vividsolutions.jts.geom.Point)2 Node (io.opencensus.proto.agent.common.v1.Node)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Nullable (javax.annotation.Nullable)2 ParseException (org.apache.commons.cli.ParseException)2 OSMTagEntityFilter (org.bboxdb.tools.converter.osm.filter.OSMTagEntityFilter)2 Polygon (org.bboxdb.tools.converter.osm.util.Polygon)2 SerializableNode (org.bboxdb.tools.converter.osm.util.SerializableNode)2 NodeRef (org.locationtech.geogig.api.NodeRef)2