fluo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikewalch <...@git.apache.org>
Subject [GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Date Wed, 22 Mar 2017 17:44:48 GMT
Github user mikewalch commented on a diff in the pull request:

    https://github.com/apache/incubator-fluo/pull/817#discussion_r107483906
  
    --- Diff: modules/core/src/main/java/org/apache/fluo/core/observer/v2/ObserverStoreV2.java
---
    @@ -0,0 +1,151 @@
    +/*
    + * 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 with the License. You may
obtain a
    + * copy of the License at
    + * 
    + * 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.fluo.core.observer.v2;
    +
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.Map;
    +import java.util.Map.Entry;
    +import java.util.Objects;
    +import java.util.Set;
    +import java.util.function.BiConsumer;
    +
    +import com.google.common.base.Preconditions;
    +import com.google.gson.Gson;
    +import org.apache.curator.framework.CuratorFramework;
    +import org.apache.fluo.api.config.FluoConfiguration;
    +import org.apache.fluo.api.data.Column;
    +import org.apache.fluo.api.exceptions.FluoException;
    +import org.apache.fluo.api.observer.Observer.NotificationType;
    +import org.apache.fluo.api.observer.ObserverProvider;
    +import org.apache.fluo.core.impl.Environment;
    +import org.apache.fluo.core.observer.RegisteredObservers;
    +import org.apache.fluo.core.observer.Observers;
    +import org.apache.fluo.core.observer.ObserverStore;
    +import org.apache.fluo.core.util.CuratorUtil;
    +import org.apache.zookeeper.KeeperException.NoNodeException;
    +
    +import static java.nio.charset.StandardCharsets.UTF_8;
    +import static org.apache.fluo.accumulo.util.ZookeeperPath.CONFIG_FLUO_OBSERVERS2;
    +
    +/*
    + * Support for observers configured the new way.
    + */
    +public class ObserverStoreV2 implements ObserverStore {
    +
    +  @Override
    +  public boolean handles(FluoConfiguration config) {
    +    return !config.getObserverProvider().isEmpty();
    +  }
    +
    +  @Override
    +  public void update(CuratorFramework curator, FluoConfiguration config) throws Exception
{
    +    String obsProviderClass = config.getObserverProvider();
    +
    +    ObserverProvider observerProvider = newObserverProvider(obsProviderClass);
    +
    +    Map<Column, NotificationType> obsCols = new HashMap<>();
    +    BiConsumer<Column, NotificationType> obsColConsumer = (col, nt) -> {
    +      Objects.requireNonNull(col, "Observed column must be non-null");
    +      Objects.requireNonNull(nt, "Notification type must be non-null");
    +      Preconditions.checkArgument(!obsCols.containsKey(col), "Duplicate observed column
%s", col);
    +      obsCols.put(col, nt);
    +    };
    +
    +    observerProvider.provideColumns(obsColConsumer,
    +        new ObserverProviderContextImpl(config.getAppConfiguration()));
    +
    +    Gson gson = new Gson();
    +    String json = gson.toJson(new JsonObservers(obsProviderClass, obsCols));
    +    CuratorUtil.putData(curator, CONFIG_FLUO_OBSERVERS2, json.getBytes(UTF_8),
    +        CuratorUtil.NodeExistsPolicy.OVERWRITE);
    +
    +  }
    +
    +  static ObserverProvider newObserverProvider(String obsProviderClass) {
    +    ObserverProvider observerProvider;
    +    try {
    +      observerProvider =
    +          Class.forName(obsProviderClass).asSubclass(ObserverProvider.class).newInstance();
    +    } catch (ClassNotFoundException e1) {
    +      throw new FluoException("ObserverFactory class '" + obsProviderClass + "' was not
"
    +          + "found.  Check for class name misspellings or failure to include "
    +          + "the observer factory jar.", e1);
    +    } catch (InstantiationException | IllegalAccessException e2) {
    +      throw new FluoException("ObserverFactory class '" + obsProviderClass
    --- End diff --
    
    should be `observerProvider`


---
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