streams-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From steveblackmon <...@git.apache.org>
Subject [GitHub] incubator-streams pull request: updater implementation
Date Thu, 07 Aug 2014 15:39:50 GMT
Github user steveblackmon commented on a diff in the pull request:

    https://github.com/apache/incubator-streams/pull/63#discussion_r15943453
  
    --- Diff: streams-contrib/streams-persist-elasticsearch/src/main/java/org/apache/streams/elasticsearch/ElasticsearchPersistDeleter.java
---
    @@ -0,0 +1,102 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package org.apache.streams.elasticsearch;
    +
    +import com.fasterxml.jackson.core.JsonProcessingException;
    +import com.google.common.base.Optional;
    +import com.google.common.base.Preconditions;
    +import org.apache.streams.core.StreamsDatum;
    +import org.apache.streams.core.StreamsPersistWriter;
    +import org.elasticsearch.action.delete.DeleteRequest;
    +import org.elasticsearch.action.update.UpdateRequest;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +public class ElasticsearchPersistDeleter extends ElasticsearchPersistWriter implements
StreamsPersistWriter {
    +
    +    private final static Logger LOGGER = LoggerFactory.getLogger(ElasticsearchPersistDeleter.class);
    +
    +    public ElasticsearchPersistDeleter() {
    +        super();
    +    }
    +
    +    public ElasticsearchPersistDeleter(ElasticsearchWriterConfiguration config) {
    +        super(config);
    +    }
    +
    +    @Override
    +    public void write(StreamsDatum streamsDatum) {
    +
    +        Preconditions.checkNotNull(streamsDatum);
    +        Preconditions.checkNotNull(streamsDatum.getDocument());
    +        Preconditions.checkNotNull(streamsDatum.getMetadata());
    +        Preconditions.checkNotNull(streamsDatum.getMetadata().get("id"));
    +
    +        String index;
    +        String type;
    +        String id;
    +
    +        index = Optional.fromNullable(
    +                (String) streamsDatum.getMetadata().get("index"))
    +                .or(config.getIndex());
    +        type = Optional.fromNullable(
    +                (String) streamsDatum.getMetadata().get("type"))
    +                .or(config.getType());
    +        id = (String) streamsDatum.getMetadata().get("id");
    +
    +        delete(index, type, id);
    +
    +    }
    +
    +    public void delete(String index, String type, String id) {
    +        DeleteRequest deleteRequest;
    +
    +        Preconditions.checkNotNull(index);
    +        Preconditions.checkNotNull(id);
    +        Preconditions.checkNotNull(type);
    +
    +        // They didn't specify an ID, so we will create one for them.
    +        deleteRequest = new DeleteRequest()
    +                .index(index)
    +                .type(type)
    +                .id(id);
    +
    +        add(deleteRequest);
    +
    +    }
    +
    +    public void add(DeleteRequest request) {
    --- End diff --
    
    i see what you are getting at, but consider:
    a) they aren't exactly the same. the relevant field(s) for flush threshold tracking differ
between types
    b) there common parent class of IndexRequest, UpdateRequest, and DeleteRequest is ShardReplicationOperationRequest
which is templated on the type we are using.  IMO the code will get less rather than more
comprehensible if we do this.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message