You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@fluo.apache.org by keith-turner <gi...@git.apache.org> on 2017/03/17 22:53:49 UTC
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
GitHub user keith-turner opened a pull request:
https://github.com/apache/incubator-fluo/pull/817
fixes #816 introduced better way to setup observers and deprecated old
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/keith-turner/fluo fluo-816
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-fluo/pull/817.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #817
----
commit 981f9ee80ce09977dad1fe4e50677c50c5d366ff
Author: Keith Turner <kt...@apache.org>
Date: 2017-03-17T22:51:08Z
fixes #816 introduced better way to setup observers and deprecated old
----
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by ctubbsii <gi...@git.apache.org>.
Github user ctubbsii commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107034326
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/ObserversFactory.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.api.observer;
+
+import java.util.function.BiConsumer;
+
+import org.apache.fluo.api.client.FluoClient;
+import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.config.SimpleConfiguration;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.metrics.MetricsReporter;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+/**
+ * Fluo Workers use this class to create {@link Observer}s to process notifications. Implementations
+ * of this class should emit zero or more {@link Observer}s.
+ *
+ * <p>
+ * When Fluo is initialized {@link #getObservedColumns(Context, BiConsumer)} is called. The columns
+ * it emits are stored in Zookeeper. Transactions will use the columns stored in Zookeeper to
+ * determine when to set notifications. When Workers call
+ * {@link #createObservers(ObserverConsumer, Context)}, the columns emitted must be the same as
+ * those emitted during initialization. If this is not the case, then the worker will fail to start.
+ *
+ * @see FluoConfiguration#setObserversFactory(String)
+ * @since 1.1.0
+ */
+public interface ObserversFactory {
--- End diff --
To me, `get` can have either connotation `retrieve existing` or `create and supply`. In any case, there's no requirement for instances of this interface to construct new instances.... they could be supplying pre-existing (provided by user's implementation). From an API perspective, we don't really care which is the case, and in my view, the semantics of `get` works with either.
Unless you wanted to make it a `Consumer<Context>` (see previous comment, not recommended) and force the use of the name `accept`, I think maybe `ObserverProvider` and `void provide(Context)` might be worth considering. "Provider" comes with less baggage than "Factory", allowing more flexibility to construct an API which doesn't necessarily fall directly into well-established patterns and conventions. It's also literally what an instance of the class would be doing: providing the observers to the framework.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by keith-turner <gi...@git.apache.org>.
Github user keith-turner commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107207572
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/ObserversFactory.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.api.observer;
+
+import java.util.function.BiConsumer;
+
+import org.apache.fluo.api.client.FluoClient;
+import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.config.SimpleConfiguration;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.metrics.MetricsReporter;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+/**
+ * Fluo Workers use this class to create {@link Observer}s to process notifications. Implementations
+ * of this class should emit zero or more {@link Observer}s.
+ *
+ * <p>
+ * When Fluo is initialized {@link #getObservedColumns(Context, BiConsumer)} is called. The columns
+ * it emits are stored in Zookeeper. Transactions will use the columns stored in Zookeeper to
+ * determine when to set notifications. When Workers call
+ * {@link #createObservers(ObserverConsumer, Context)}, the columns emitted must be the same as
+ * those emitted during initialization. If this is not the case, then the worker will fail to start.
+ *
+ * @see FluoConfiguration#setObserversFactory(String)
+ * @since 1.1.0
+ */
+public interface ObserversFactory {
--- End diff --
I really like `ObserverProvider` and `provide()`. I changed to that. I kinda like the idea of merging, Context and ObserverConsumer. However, I would like short method names on Context and can not think of any I like. I like the suggestion @mikewalch made to use the names `Registry` and `register()` instead of ObserverConsumer, so I switched to that.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107467396
--- Diff: modules/integration/src/test/java/org/apache/fluo/integration/impl/CollisionIT.java ---
@@ -81,27 +77,22 @@ public void load(TransactionBase tx, Context context) throws Exception {
}
}
- public static class TotalObserver extends AbstractObserver {
-
+ public static class CollisionObserverProvider implements ObserverProvider {
@Override
- public Observer.ObservedColumn getObservedColumn() {
- return new Observer.ObservedColumn(STAT_CHANGED, NotificationType.WEAK);
- }
-
- @Override
- public void process(TransactionBase tx, Bytes rowBytes, Column col) throws Exception {
- String row = rowBytes.toString();
- int total = Integer.parseInt(tx.gets(row, STAT_TOTAL));
- int processed = TestUtil.getOrDefault(tx, row, STAT_PROCESSED, 0);
-
- tx.set(row, STAT_PROCESSED, total + "");
- TestUtil.increment(tx, "all", STAT_TOTAL, total - processed);
+ public void provide(Registry consumer, Context ctx) {
--- End diff --
could look for `consumer` and replace with `registry`
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107483818
--- 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);
--- End diff --
should be `observer provider`
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107479937
--- Diff: modules/api/src/main/java/org/apache/fluo/api/config/FluoConfiguration.java ---
@@ -344,6 +362,37 @@ private int getNextObserverId() {
return max + 1;
}
+ /**
+ * Configure the observer factory that Fluo workers will use.
+ *
+ * @since 1.1.0
+ *
+ * @param className Name of a class that implements {@link ObserverProvider}. Must be non-null and
+ * non-empty.
+ */
+ public void setObserverProvider(String className) {
+ setNonEmptyString(OBSERVER_PROVIDER, className);
+ }
+
+ /**
+ * Calls {@link #setObserverProvider(String)} with the class name.
+ *
+ * @since 1.1.0
+ */
+ public void setObserverProvider(Class<? extends ObserverProvider> clazz) {
+ setObserverProvider(clazz.getName());
+ }
+
+ /**
+ * @return The configured {@link ObserverProvider} class name. If one was not configured, returns
+ * {@value #OBSERVERS_FACTORY_DEFAULT}
--- End diff --
should be provider
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107466714
--- Diff: modules/api/src/main/java/org/apache/fluo/api/config/FluoConfiguration.java ---
@@ -86,8 +88,19 @@
/** The properties below get loaded into/from Zookeeper */
// Observer
+ @Deprecated
public static final String OBSERVER_PREFIX = FLUO_PREFIX + ".observer.";
+ /**
+ * @since 1.1.0
+ */
+ public static final String OBSERVERS_FACTORY = FLUO_PREFIX + ".observers.factory";
--- End diff --
should use provider terminology
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by ctubbsii <gi...@git.apache.org>.
Github user ctubbsii commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107029175
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/StringObserver.java ---
@@ -0,0 +1,34 @@
+/*
+ * 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.api.observer;
+
+import org.apache.fluo.api.client.TransactionBase;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+
+/**
+ * @since 1.1.0
+ */
+@FunctionalInterface
+public interface StringObserver extends Observer {
+
+ @Override
+ default void process(TransactionBase tx, Bytes row, Column col) throws Exception {
+ process(tx, row.toString(), col);
--- End diff --
Yeah, the requiresNonNull wouldn't change the error. It's still going to be an NPE, but it's an opportunity to provide a better error message (if you think it needs it... I don't know for sure that it does) for an API method.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by ctubbsii <gi...@git.apache.org>.
Github user ctubbsii commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107008945
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/ObserversFactory.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.api.observer;
+
+import java.util.function.BiConsumer;
+
+import org.apache.fluo.api.client.FluoClient;
+import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.config.SimpleConfiguration;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.metrics.MetricsReporter;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+/**
+ * Fluo Workers use this class to create {@link Observer}s to process notifications. Implementations
+ * of this class should emit zero or more {@link Observer}s.
+ *
+ * <p>
+ * When Fluo is initialized {@link #getObservedColumns(Context, BiConsumer)} is called. The columns
+ * it emits are stored in Zookeeper. Transactions will use the columns stored in Zookeeper to
+ * determine when to set notifications. When Workers call
+ * {@link #createObservers(ObserverConsumer, Context)}, the columns emitted must be the same as
+ * those emitted during initialization. If this is not the case, then the worker will fail to start.
+ *
+ * @see FluoConfiguration#setObserversFactory(String)
+ * @since 1.1.0
+ */
+public interface ObserversFactory {
+
+ /**
+ * @since 1.1.0
+ */
+ interface Context {
+ /**
+ * @return A configuration object with application configuration like that returned by
+ * {@link FluoClient#getAppConfiguration()}
+ */
+ SimpleConfiguration getAppConfiguration();
+
+ /**
+ * @return A {@link MetricsReporter} to report application metrics from observers.
+ */
+ MetricsReporter getMetricsReporter();
+ }
+
+ /**
+ * Observers are emitted to the worker using this interface. This interface also allows
+ * {@link Observer}s to be related to the columns that trigger them.
+ *
+ * @since 1.1.0
+ */
+ interface ObserverConsumer {
+ void accept(Column observedColumn, NotificationType ntfyType, Observer observer);
+
+ /**
+ * This method was created to allow Observers written as lambda to be passed {@link String}
+ * instead of {@link Bytes}.
+ *
+ * <pre>
+ * <code>
+ * void createObservers(ObserverConsumer obsConsumer, Context ctx) {
+ * obsConsumer.accepts(someColumn, WEAK, (tx,row,col) -> {
+ * //row is of type String
+ * };
+ * }
+ * </code>
+ * </pre>
+ */
+ void accepts(Column observedColumn, NotificationType ntfyType, StringObserver observer);
+ }
+
+ /**
+ * This is method is called by Fluo Workers to create observers to process notifications.
+ *
+ * <p>
+ * Observers emitted may be called concurrently by multiple threads to process different
+ * notifications. Observers should be tolerant of this.
+ *
+ * @param obsConsumer Emit an applications observers to this consumer.
+ */
+ void createObservers(ObserverConsumer obsConsumer, Context ctx);
--- End diff --
Why not make this interface a `Function<Context,Stream<Observer>>` or maybe make the factory return a set of observers? That way, the user's code doesn't actually have to deal with the framework's observer consumer, which I think is an implementation detail they shouldn't have to interact with.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by keith-turner <gi...@git.apache.org>.
Github user keith-turner commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107011906
--- Diff: pom.xml ---
@@ -83,6 +83,11 @@
<version>1.32</version>
</dependency>
<dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.2.4</version>
--- End diff --
I changed it to 2.8.0 and successfully ran `mvn verify`
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r106999558
--- Diff: modules/core/src/main/java/org/apache/fluo/core/observer/v2/JsonObservers.java ---
@@ -0,0 +1,53 @@
+/*
+ * 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.List;
+import java.util.Map;
+
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+
+// this class created for json serialization
--- End diff --
will this work with javadoc? could use standard format.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107466983
--- Diff: modules/api/src/main/java/org/apache/fluo/api/config/FluoConfiguration.java ---
@@ -344,6 +362,37 @@ private int getNextObserverId() {
return max + 1;
}
+ /**
+ * Configure the observer factory that Fluo workers will use.
+ *
+ * @since 1.1.0
+ *
+ * @param className Name of a class that implements {@link ObserverProvider}. Must be non-null and
+ * non-empty.
+ */
+ public void setObserverProvider(String className) {
+ setNonEmptyString(OBSERVERS_FACTORY, className);
--- End diff --
should use provider terminlogy
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107483725
--- 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 "
--- 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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107480296
--- 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 obsFactoryClass = config.getObserverProvider();
+
+ ObserverProvider observerProvider = newObserverProvider(obsFactoryClass);
+
+ 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(obsFactoryClass, obsCols));
+ CuratorUtil.putData(curator, CONFIG_FLUO_OBSERVERS2, json.getBytes(UTF_8),
+ CuratorUtil.NodeExistsPolicy.OVERWRITE);
+
+ }
+
+ static ObserverProvider newObserverProvider(String obsFactoryClass) {
--- End diff --
should be provider
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by keith-turner <gi...@git.apache.org>.
Github user keith-turner commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107016744
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/StringObserver.java ---
@@ -0,0 +1,34 @@
+/*
+ * 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.api.observer;
+
+import org.apache.fluo.api.client.TransactionBase;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+
+/**
+ * @since 1.1.0
+ */
+@FunctionalInterface
+public interface StringObserver extends Observer {
+
+ @Override
+ default void process(TransactionBase tx, Bytes row, Column col) throws Exception {
+ process(tx, row.toString(), col);
--- End diff --
The reason I don't think the NPE check is needed, is because I think row.toString() is the only thing on that line that can cause an NPE.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by keith-turner <gi...@git.apache.org>.
Github user keith-turner commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107479688
--- Diff: modules/api/src/main/java/org/apache/fluo/api/config/FluoConfiguration.java ---
@@ -86,8 +88,19 @@
/** The properties below get loaded into/from Zookeeper */
// Observer
+ @Deprecated
public static final String OBSERVER_PREFIX = FLUO_PREFIX + ".observer.";
+ /**
+ * @since 1.1.0
+ */
+ public static final String OBSERVERS_FACTORY = FLUO_PREFIX + ".observers.factory";
--- End diff --
That is a good find. I also changed the default config file.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by keith-turner <gi...@git.apache.org>.
Github user keith-turner commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107008721
--- Diff: pom.xml ---
@@ -83,6 +83,11 @@
<version>1.32</version>
</dependency>
<dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.2.4</version>
--- End diff --
I think I did pull that version from Accumuo or Hadoop's pom. I will try upping it.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107000067
--- Diff: modules/accumulo/src/main/java/org/apache/fluo/accumulo/util/ZookeeperPath.java ---
@@ -25,7 +25,9 @@
public static final String CONFIG_ACCUMULO_INSTANCE_NAME = CONFIG + "/accumulo.instance.name";
public static final String CONFIG_ACCUMULO_INSTANCE_ID = CONFIG + "/accumulo.instance.id";
public static final String CONFIG_FLUO_APPLICATION_ID = CONFIG + "/fluo.application.id";
+ @Deprecated
public static final String CONFIG_FLUO_OBSERVERS = CONFIG + "/fluo.observers";
--- End diff --
Could make variable `CONFIG_FLUO_OBSERVERS1` to limit confusion.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r106992697
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/Observer.java ---
@@ -17,17 +17,19 @@
import org.apache.fluo.api.client.FluoClient;
import org.apache.fluo.api.client.TransactionBase;
+import org.apache.fluo.api.config.FluoConfiguration;
import org.apache.fluo.api.config.SimpleConfiguration;
import org.apache.fluo.api.data.Bytes;
import org.apache.fluo.api.data.Column;
import org.apache.fluo.api.metrics.MetricsReporter;
/**
* Implemented by users to a watch a {@link Column} and be notified of changes to the Column via the
- * {@link #process(TransactionBase, Bytes, Column)} method. An observer is created for each worker
- * thread and reused for the lifetime of a worker thread. Consider extending
- * {@link AbstractObserver} as it will let you optionally implement {@link #init(Context)} and
- * {@link #close()}. The abstract class will also shield you from the addition of interface methods.
+ * {@link #process(TransactionBase, Bytes, Column)} method.
+ *
+ * <p>
+ * In Fluo version 1.1.0 this was converted to a functional interface. This change along with the
--- End diff --
Could add `@FunctionalInterface` annotation to class
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r106992791
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/StringObserver.java ---
@@ -0,0 +1,33 @@
+/*
+ * 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.api.observer;
+
+import org.apache.fluo.api.client.TransactionBase;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+
+/**
+ * @since 1.1.0
+ */
+public interface StringObserver extends Observer {
--- End diff --
Could add `@FunctionalInterface` annotation to class
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by keith-turner <gi...@git.apache.org>.
Github user keith-turner commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107207929
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/ObserverFactory.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.api.observer;
+
+import java.util.function.BiConsumer;
+
+import org.apache.fluo.api.client.FluoClient;
+import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.config.SimpleConfiguration;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.metrics.MetricsReporter;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+/**
+ * Fluo Workers use this class to create {@link Observer}s to process notifications. Implementations
+ * of this class should emit zero or more {@link Observer}s.
+ *
+ * <p>
+ * When Fluo is initialized {@link #getObservedColumns(BiConsumer, Context)} is called. The columns
+ * it emits are stored in Zookeeper. Transactions will use the columns stored in Zookeeper to
+ * determine when to set notifications. When Workers call
+ * {@link #createObservers(ObserverConsumer, Context)}, the columns emitted must be the same as
+ * those emitted during initialization. If this is not the case, then the worker will fail to start.
+ *
+ * @see FluoConfiguration#setObserversFactory(String)
+ * @since 1.1.0
+ */
+public interface ObserverFactory {
+
+ /**
+ * @since 1.1.0
+ */
+ interface Context {
+ /**
+ * @return A configuration object with application configuration like that returned by
+ * {@link FluoClient#getAppConfiguration()}
+ */
+ SimpleConfiguration getAppConfiguration();
+
+ /**
+ * @return A {@link MetricsReporter} to report application metrics from observers.
+ */
+ MetricsReporter getMetricsReporter();
+ }
+
+ /**
+ * Observers are emitted to the worker using this interface. This interface also allows
+ * {@link Observer}s to be related to the columns that trigger them.
+ *
+ * @since 1.1.0
+ */
+ interface ObserverConsumer {
--- End diff --
I really like that name. I changed it to `Registry` instead of `ObserverRegistry`. I was thinking since its an inner interface it already has enough context.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107480429
--- Diff: modules/core/src/main/java/org/apache/fluo/core/observer/v2/ObserversV2.java ---
@@ -0,0 +1,113 @@
+/*
+ * 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.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import com.google.common.collect.Sets;
+import com.google.common.collect.Sets.SetView;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.exceptions.FluoException;
+import org.apache.fluo.api.observer.Observer;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+import org.apache.fluo.api.observer.ObserverProvider;
+import org.apache.fluo.api.observer.ObserverProvider.Registry;
+import org.apache.fluo.api.observer.StringObserver;
+import org.apache.fluo.core.impl.Environment;
+import org.apache.fluo.core.observer.Observers;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class ObserversV2 implements Observers {
+
+ private static final Logger log = LoggerFactory.getLogger(ObserversV2.class);
+
+ Map<Column, Observer> observers;
+
+ public ObserversV2(Environment env, JsonObservers jco, Set<Column> strongColumns,
+ Set<Column> weakColumns) {
+ observers = new HashMap<>();
+
+ ObserverProvider obsProvider =
+ ObserverStoreV2.newObserverProvider(jco.getObserverProviderClass());
+
+ ObserverProviderContextImpl ctx = new ObserverProviderContextImpl(env);
+
+ Registry or = new Registry() {
+
+ @Override
+ public void register(Column col, NotificationType nt, Observer obs) {
+ try {
+ Method closeMethod = obs.getClass().getMethod("close");
+ if (!closeMethod.getDeclaringClass().equals(Observer.class)) {
+ log.warn(
+ "Observer {} implements close(). Close is not called on Observers created using ObserverProvider."
+ + " Close is only called on Observers configured the old way.", obs.getClass()
+ .getName());
+ }
+ } catch (NoSuchMethodException | SecurityException e) {
+ throw new RuntimeException("Failed to check if close() is implemented", e);
+ }
+
+ if (nt == NotificationType.STRONG && !strongColumns.contains(col)) {
+ throw new IllegalArgumentException("Column " + col
+ + " not previously configured for strong notifications");
+ }
+
+ if (nt == NotificationType.WEAK && !weakColumns.contains(col)) {
+ throw new IllegalArgumentException("Column " + col
+ + " not previously configured for weak notifications");
+ }
+
+ if (observers.containsKey(col)) {
+ throw new IllegalArgumentException("Duplicate observed column " + col);
+ }
+
+ observers.put(col, obs);
+ }
+
+ @Override
+ public void registers(Column col, NotificationType nt, StringObserver obs) {
+ register(col, nt, obs);
+ }
+ };
+
+ obsProvider.provide(or, ctx);
+
+ // the following check ensures the observers factory provides observers for all previously
--- End diff --
should be provider
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107466485
--- Diff: docs/applications.md ---
@@ -114,25 +114,45 @@ To create an observer, follow these steps:
// invert row and value
tx.set(value, new Column("inv", "data"), row);
}
+ }
+ ```
+2. Create a class that implements [ObserverProvider] like the example below. The purpose of this
+ class is associate a set Observers with columns that trigger the observers. The class can
+ create multiple observers.
+ ```java
+ class AppObserverProvider implements ObserverProvider {
@Override
- public ObservedColumn getObservedColumn() {
- return new ObservedColumn(new Column("obs", "data"), NotificationType.STRONG);
+ public void provide(Registry or, Context ctx) {
+ //setup InvertObserver to be triggered when the column obs:data is modified
+ or.register(new Column("obs", "data"),
+ NotificationType.STRONG,
+ new InvertObserver());
+
+ //Observer is a Functional interface. So Obsevers can be written as lambdas.
+ or.register(new Column("new","data"),
+ NotificationType.WEAK,
+ (tx,row,col) -> {
+ Bytes combined = combineNewAndOld(tx,row);
+ tx.set(row, new Column("current","data"), combined);
+ });
}
}
```
-2. Build a jar containing this class and include this jar in the `lib/` directory of your Fluo
+
+3. Build a jar containing thses classes and include this jar in the `lib/` directory of your Fluo
application.
-3. Configure your Fluo instance to use this observer by modifying the Observer section of
+4. Configure your Fluo instance to use this observer factory by modifying the Observer section of
--- End diff --
should be `observer provider`
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r106999694
--- Diff: modules/core/src/main/java/org/apache/fluo/core/observer/v2/JsonObservedColumn.java ---
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+// this class created for json serialization
--- End diff --
will this work with javadoc? could use standard format.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by ctubbsii <gi...@git.apache.org>.
Github user ctubbsii commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107010658
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/ObserversFactory.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.api.observer;
+
+import java.util.function.BiConsumer;
+
+import org.apache.fluo.api.client.FluoClient;
+import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.config.SimpleConfiguration;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.metrics.MetricsReporter;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+/**
+ * Fluo Workers use this class to create {@link Observer}s to process notifications. Implementations
+ * of this class should emit zero or more {@link Observer}s.
+ *
+ * <p>
+ * When Fluo is initialized {@link #getObservedColumns(Context, BiConsumer)} is called. The columns
+ * it emits are stored in Zookeeper. Transactions will use the columns stored in Zookeeper to
+ * determine when to set notifications. When Workers call
+ * {@link #createObservers(ObserverConsumer, Context)}, the columns emitted must be the same as
+ * those emitted during initialization. If this is not the case, then the worker will fail to start.
+ *
+ * @see FluoConfiguration#setObserversFactory(String)
+ * @since 1.1.0
+ */
+public interface ObserversFactory {
--- End diff --
The pluralization of the name is a bit confusing. `ObserverFactory` vs. `ObserversFactory`. Also, I think this naming convention works best if there's a getter method which returns the object named by the part before the word "Factory". So, this name looks to me like it should have a `Observers get()` method, or a `Collection<Observer> get()` method. I'm not sure I have a better name, but perhaps if the "getter" looked like `Set<Observer> get(Context)`, it would be slightly more intuitive (in my mind, anyway). At the very least, I think it's weird to have a Factory interface which doesn't return anything.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107179559
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/ObserverFactory.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.api.observer;
+
+import java.util.function.BiConsumer;
+
+import org.apache.fluo.api.client.FluoClient;
+import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.config.SimpleConfiguration;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.metrics.MetricsReporter;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+/**
+ * Fluo Workers use this class to create {@link Observer}s to process notifications. Implementations
+ * of this class should emit zero or more {@link Observer}s.
+ *
+ * <p>
+ * When Fluo is initialized {@link #getObservedColumns(BiConsumer, Context)} is called. The columns
+ * it emits are stored in Zookeeper. Transactions will use the columns stored in Zookeeper to
+ * determine when to set notifications. When Workers call
+ * {@link #createObservers(ObserverConsumer, Context)}, the columns emitted must be the same as
+ * those emitted during initialization. If this is not the case, then the worker will fail to start.
+ *
+ * @see FluoConfiguration#setObserversFactory(String)
+ * @since 1.1.0
+ */
+public interface ObserverFactory {
+
+ /**
+ * @since 1.1.0
+ */
+ interface Context {
+ /**
+ * @return A configuration object with application configuration like that returned by
+ * {@link FluoClient#getAppConfiguration()}
+ */
+ SimpleConfiguration getAppConfiguration();
+
+ /**
+ * @return A {@link MetricsReporter} to report application metrics from observers.
+ */
+ MetricsReporter getMetricsReporter();
+ }
+
+ /**
+ * Observers are emitted to the worker using this interface. This interface also allows
+ * {@link Observer}s to be related to the columns that trigger them.
+ *
+ * @since 1.1.0
+ */
+ interface ObserverConsumer {
+ void accept(Column observedColumn, NotificationType ntfyType, Observer observer);
--- End diff --
This method could be `add` or `register`
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107180164
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/ObserverFactory.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.api.observer;
+
+import java.util.function.BiConsumer;
+
+import org.apache.fluo.api.client.FluoClient;
+import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.config.SimpleConfiguration;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.metrics.MetricsReporter;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+/**
+ * Fluo Workers use this class to create {@link Observer}s to process notifications. Implementations
+ * of this class should emit zero or more {@link Observer}s.
+ *
+ * <p>
+ * When Fluo is initialized {@link #getObservedColumns(BiConsumer, Context)} is called. The columns
+ * it emits are stored in Zookeeper. Transactions will use the columns stored in Zookeeper to
+ * determine when to set notifications. When Workers call
+ * {@link #createObservers(ObserverConsumer, Context)}, the columns emitted must be the same as
+ * those emitted during initialization. If this is not the case, then the worker will fail to start.
+ *
+ * @see FluoConfiguration#setObserversFactory(String)
+ * @since 1.1.0
+ */
+public interface ObserverFactory {
+
+ /**
+ * @since 1.1.0
+ */
+ interface Context {
+ /**
+ * @return A configuration object with application configuration like that returned by
+ * {@link FluoClient#getAppConfiguration()}
+ */
+ SimpleConfiguration getAppConfiguration();
+
+ /**
+ * @return A {@link MetricsReporter} to report application metrics from observers.
+ */
+ MetricsReporter getMetricsReporter();
+ }
+
+ /**
+ * Observers are emitted to the worker using this interface. This interface also allows
+ * {@link Observer}s to be related to the columns that trigger them.
+ *
+ * @since 1.1.0
+ */
+ interface ObserverConsumer {
+ void accept(Column observedColumn, NotificationType ntfyType, Observer observer);
+
+ /**
+ * This method was created to allow Observers written as lambda to be passed {@link String}
+ * instead of {@link Bytes}.
+ *
+ * <pre>
+ * <code>
+ * void createObservers(ObserverConsumer obsConsumer, Context ctx) {
+ * obsConsumer.accepts(someColumn, WEAK, (tx,row,col) -> {
+ * //row is of type String
+ * };
+ * }
+ * </code>
+ * </pre>
+ */
+ void accepts(Column observedColumn, NotificationType ntfyType, StringObserver observer);
+ }
+
+ /**
+ * This is method is called by Fluo Workers to create observers to process notifications.
+ *
+ * <p>
+ * Observers emitted may be called concurrently by multiple threads to process different
+ * notifications. Observers should be tolerant of this.
+ *
+ * @param obsConsumer Emit an applications observers to this consumer.
+ */
+ void createObservers(ObserverConsumer obsConsumer, Context ctx);
--- End diff --
this could be `registerObservers` or `setupObservers`
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107479866
--- Diff: modules/api/src/main/java/org/apache/fluo/api/config/FluoConfiguration.java ---
@@ -344,6 +362,37 @@ private int getNextObserverId() {
return max + 1;
}
+ /**
+ * Configure the observer factory that Fluo workers will use.
--- End diff --
should be provider
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by keith-turner <gi...@git.apache.org>.
Github user keith-turner commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107015060
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/ObserversFactory.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.api.observer;
+
+import java.util.function.BiConsumer;
+
+import org.apache.fluo.api.client.FluoClient;
+import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.config.SimpleConfiguration;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.metrics.MetricsReporter;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+/**
+ * Fluo Workers use this class to create {@link Observer}s to process notifications. Implementations
+ * of this class should emit zero or more {@link Observer}s.
+ *
+ * <p>
+ * When Fluo is initialized {@link #getObservedColumns(Context, BiConsumer)} is called. The columns
+ * it emits are stored in Zookeeper. Transactions will use the columns stored in Zookeeper to
+ * determine when to set notifications. When Workers call
+ * {@link #createObservers(ObserverConsumer, Context)}, the columns emitted must be the same as
+ * those emitted during initialization. If this is not the case, then the worker will fail to start.
+ *
+ * @see FluoConfiguration#setObserversFactory(String)
+ * @since 1.1.0
+ */
+public interface ObserversFactory {
+
+ /**
+ * @since 1.1.0
+ */
+ interface Context {
+ /**
+ * @return A configuration object with application configuration like that returned by
+ * {@link FluoClient#getAppConfiguration()}
+ */
+ SimpleConfiguration getAppConfiguration();
+
+ /**
+ * @return A {@link MetricsReporter} to report application metrics from observers.
+ */
+ MetricsReporter getMetricsReporter();
+ }
+
+ /**
+ * Observers are emitted to the worker using this interface. This interface also allows
+ * {@link Observer}s to be related to the columns that trigger them.
+ *
+ * @since 1.1.0
+ */
+ interface ObserverConsumer {
+ void accept(Column observedColumn, NotificationType ntfyType, Observer observer);
+
+ /**
+ * This method was created to allow Observers written as lambda to be passed {@link String}
+ * instead of {@link Bytes}.
+ *
+ * <pre>
+ * <code>
+ * void createObservers(ObserverConsumer obsConsumer, Context ctx) {
+ * obsConsumer.accepts(someColumn, WEAK, (tx,row,col) -> {
+ * //row is of type String
+ * };
+ * }
+ * </code>
+ * </pre>
+ */
+ void accepts(Column observedColumn, NotificationType ntfyType, StringObserver observer);
+ }
+
+ /**
+ * This is method is called by Fluo Workers to create observers to process notifications.
+ *
+ * <p>
+ * Observers emitted may be called concurrently by multiple threads to process different
+ * notifications. Observers should be tolerant of this.
+ *
+ * @param obsConsumer Emit an applications observers to this consumer.
+ */
+ void createObservers(ObserverConsumer obsConsumer, Context ctx);
--- End diff --
> Why not make this interface a `Function<Context,Stream<Observer>>`
Need to relate the observer to a column, so can't just return a stream of Observers.
> or maybe make the factory return a set of observers?
As for returning a set, I initially had something like that. But I changed it because if forced longer, boiler plate code.
For example, below is the case where the user has to return a Map.
```java
Map<ObservedColumn, Observer> createObservers(Context ctx) {
Map<ObservedColumn, Observer> observers = new HashMap<>(); //boilerplate code
observers.put(new ObservedColumn(col1,NotificationType.STRONG), (tx,row,col)->{...}); //this is longer than the observer consumer code
observers.put(new ObservedColumn(col2,NotificationType.STRONG), (tx,row,col)->{...});
return observers; //boilerplate code
}
```
Below is the same code with the observer consumer. Its shorter and lacks the boilerplate code.
```java
Map<ObservedColumn, Observer> createObservers(ObserverConsumer oc, Context ctx) {
oc.accept(col1,NotificationType.STRONG), (tx,row,col)->{...});
oc.accept(col2,NotificationType.STRONG), (tx,row,col)->{...});
}
```
Another nice thing I found with the ObserverConsumer, is its a standard thing that can be passed to other code. For example it can be passed to Fluo Recipes code that creates Observers.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by keith-turner <gi...@git.apache.org>.
Github user keith-turner commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107015681
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/ObserversFactory.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.api.observer;
+
+import java.util.function.BiConsumer;
+
+import org.apache.fluo.api.client.FluoClient;
+import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.config.SimpleConfiguration;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.metrics.MetricsReporter;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+/**
+ * Fluo Workers use this class to create {@link Observer}s to process notifications. Implementations
+ * of this class should emit zero or more {@link Observer}s.
+ *
+ * <p>
+ * When Fluo is initialized {@link #getObservedColumns(Context, BiConsumer)} is called. The columns
+ * it emits are stored in Zookeeper. Transactions will use the columns stored in Zookeeper to
+ * determine when to set notifications. When Workers call
+ * {@link #createObservers(ObserverConsumer, Context)}, the columns emitted must be the same as
+ * those emitted during initialization. If this is not the case, then the worker will fail to start.
+ *
+ * @see FluoConfiguration#setObserversFactory(String)
+ * @since 1.1.0
+ */
+public interface ObserversFactory {
--- End diff --
I think renaming it to `ObserverFactory` would make sense.
Let me know what you think about the method name `createObservers` after looking at the previous comment explaining why `ObserverConsumer` exist.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by ctubbsii <gi...@git.apache.org>.
Github user ctubbsii commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107011986
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/StringObserver.java ---
@@ -0,0 +1,34 @@
+/*
+ * 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.api.observer;
+
+import org.apache.fluo.api.client.TransactionBase;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+
+/**
+ * @since 1.1.0
+ */
+@FunctionalInterface
+public interface StringObserver extends Observer {
+
+ @Override
+ default void process(TransactionBase tx, Bytes row, Column col) throws Exception {
+ process(tx, row.toString(), col);
--- End diff --
Not sure it matters much, since it's API, you could have a helpful message here instead of a generic NPE:
you could do `Objects.requireNonNull(row, "message").toString()` instead of `row.toString()`
Also, I'm guessing `Bytes#toString()` assumes `UTF-8`? If not, this could have unpredictable results.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107467565
--- Diff: modules/integration/src/test/java/org/apache/fluo/integration/impl/FailureIT.java ---
@@ -54,29 +52,29 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import static org.apache.fluo.api.observer.Observer.NotificationType.STRONG;
import static org.apache.fluo.integration.BankUtil.BALANCE;
public class FailureIT extends ITBaseImpl {
@Rule
public ExpectedException exception = ExpectedException.none();
- public static class NullObserver extends AbstractObserver {
-
+ public static class NullObserver implements Observer {
@Override
public void process(TransactionBase tx, Bytes row, Column col) throws Exception {}
+ }
+ public static class FailuresObserverProvider implements ObserverProvider {
@Override
- public ObservedColumn getObservedColumn() {
- return new ObservedColumn(new Column("attr", "lastupdate"), NotificationType.STRONG);
+ public void provide(Registry consumer, Context ctx) {
--- End diff --
Replace `consumer` with `registry`
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r106990516
--- Diff: docs/applications.md ---
@@ -114,25 +114,45 @@ To create an observer, follow these steps:
// invert row and value
tx.set(value, new Column("inv", "data"), row);
}
+ }
+ ```
+2. Create a class that implements [ObserversFactory] like the example below. The purpose of this
+ class is associate a set Observers with columns that trigger the observers. The class can
+ create multiple observers.
+ ```java
+ class AppObserversFactory implements ObserversFactory {
@Override
- public ObservedColumn getObservedColumn() {
- return new ObservedColumn(new Column("obs", "data"), NotificationType.STRONG);
+ public void createObservers(ObserverConsumer obsConsumer, Context ctx) {
+ //setup InvertObserver to be triggered when the column obs:data is modified
+ obsConsumer.accept(new Column("obs", "data"),
+ NotificationType.STRONG,
+ new InvertObserver());
+
+ //Observer is a Functional interface. So Obsevers can be written as lambdas.
+ obsConcumer.accept(new Column("new","data"),
+ NotificationType.WEAK,
+ (tx,row,col) -> {
--- End diff --
Very nice to have a functional interface now
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by keith-turner <gi...@git.apache.org>.
Github user keith-turner commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107016522
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/StringObserver.java ---
@@ -0,0 +1,34 @@
+/*
+ * 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.api.observer;
+
+import org.apache.fluo.api.client.TransactionBase;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+
+/**
+ * @since 1.1.0
+ */
+@FunctionalInterface
+public interface StringObserver extends Observer {
+
+ @Override
+ default void process(TransactionBase tx, Bytes row, Column col) throws Exception {
+ process(tx, row.toString(), col);
--- End diff --
I don't think its really needed, but it would not hurt to add the NPE check.
Yeah, Bytes.toString() uses UTF-8.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107479787
--- Diff: modules/api/src/main/java/org/apache/fluo/api/config/FluoConfiguration.java ---
@@ -86,8 +88,19 @@
/** The properties below get loaded into/from Zookeeper */
// Observer
+ @Deprecated
public static final String OBSERVER_PREFIX = FLUO_PREFIX + ".observer.";
+ /**
+ * @since 1.1.0
+ */
+ public static final String OBSERVER_PROVIDER = FLUO_PREFIX + ".observer.provider";
+
+ /**
+ * @since 1.1.0
+ */
+ public static final String OBSERVERS_FACTORY_DEFAULT = "";
--- End diff --
Should be provider
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by keith-turner <gi...@git.apache.org>.
Github user keith-turner closed the pull request at:
https://github.com/apache/incubator-fluo/pull/817
---
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.
---
[GitHub] incubator-fluo issue #817: fixes #816 introduced better way to setup observe...
Posted by keith-turner <gi...@git.apache.org>.
Github user keith-turner commented on the issue:
https://github.com/apache/incubator-fluo/pull/817
Squash merged in commit d6af386bfacd795350f0bdb79da751748c09cfdc
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107480187
--- 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 obsFactoryClass = config.getObserverProvider();
--- End diff --
should be provider
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by keith-turner <gi...@git.apache.org>.
Github user keith-turner commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107021693
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/ObserversFactory.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.api.observer;
+
+import java.util.function.BiConsumer;
+
+import org.apache.fluo.api.client.FluoClient;
+import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.config.SimpleConfiguration;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.metrics.MetricsReporter;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+/**
+ * Fluo Workers use this class to create {@link Observer}s to process notifications. Implementations
+ * of this class should emit zero or more {@link Observer}s.
+ *
+ * <p>
+ * When Fluo is initialized {@link #getObservedColumns(Context, BiConsumer)} is called. The columns
+ * it emits are stored in Zookeeper. Transactions will use the columns stored in Zookeeper to
+ * determine when to set notifications. When Workers call
+ * {@link #createObservers(ObserverConsumer, Context)}, the columns emitted must be the same as
+ * those emitted during initialization. If this is not the case, then the worker will fail to start.
+ *
+ * @see FluoConfiguration#setObserversFactory(String)
+ * @since 1.1.0
+ */
+public interface ObserversFactory {
--- End diff --
I am not too happy with the `createObservers` method name. But I do like it better than `get`, which to me implies retrieving something that already exists. I was looking at the design patterns write up for factories and the word `make` was used. But `make` is not something I can recall seeing in java code. I like `create`, `new`, and `make` better than `get`.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107179300
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/ObserverFactory.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.api.observer;
+
+import java.util.function.BiConsumer;
+
+import org.apache.fluo.api.client.FluoClient;
+import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.config.SimpleConfiguration;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.metrics.MetricsReporter;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+/**
+ * Fluo Workers use this class to create {@link Observer}s to process notifications. Implementations
+ * of this class should emit zero or more {@link Observer}s.
+ *
+ * <p>
+ * When Fluo is initialized {@link #getObservedColumns(BiConsumer, Context)} is called. The columns
+ * it emits are stored in Zookeeper. Transactions will use the columns stored in Zookeeper to
+ * determine when to set notifications. When Workers call
+ * {@link #createObservers(ObserverConsumer, Context)}, the columns emitted must be the same as
+ * those emitted during initialization. If this is not the case, then the worker will fail to start.
+ *
+ * @see FluoConfiguration#setObserversFactory(String)
+ * @since 1.1.0
+ */
+public interface ObserverFactory {
+
+ /**
+ * @since 1.1.0
+ */
+ interface Context {
+ /**
+ * @return A configuration object with application configuration like that returned by
+ * {@link FluoClient#getAppConfiguration()}
+ */
+ SimpleConfiguration getAppConfiguration();
+
+ /**
+ * @return A {@link MetricsReporter} to report application metrics from observers.
+ */
+ MetricsReporter getMetricsReporter();
+ }
+
+ /**
+ * Observers are emitted to the worker using this interface. This interface also allows
+ * {@link Observer}s to be related to the columns that trigger them.
+ *
+ * @since 1.1.0
+ */
+ interface ObserverConsumer {
--- End diff --
this should be called `ObserverRegistry`
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by ctubbsii <gi...@git.apache.org>.
Github user ctubbsii commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107032718
--- Diff: modules/api/src/main/java/org/apache/fluo/api/observer/ObserversFactory.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.api.observer;
+
+import java.util.function.BiConsumer;
+
+import org.apache.fluo.api.client.FluoClient;
+import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.config.SimpleConfiguration;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.metrics.MetricsReporter;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+/**
+ * Fluo Workers use this class to create {@link Observer}s to process notifications. Implementations
+ * of this class should emit zero or more {@link Observer}s.
+ *
+ * <p>
+ * When Fluo is initialized {@link #getObservedColumns(Context, BiConsumer)} is called. The columns
+ * it emits are stored in Zookeeper. Transactions will use the columns stored in Zookeeper to
+ * determine when to set notifications. When Workers call
+ * {@link #createObservers(ObserverConsumer, Context)}, the columns emitted must be the same as
+ * those emitted during initialization. If this is not the case, then the worker will fail to start.
+ *
+ * @see FluoConfiguration#setObserversFactory(String)
+ * @since 1.1.0
+ */
+public interface ObserversFactory {
+
+ /**
+ * @since 1.1.0
+ */
+ interface Context {
+ /**
+ * @return A configuration object with application configuration like that returned by
+ * {@link FluoClient#getAppConfiguration()}
+ */
+ SimpleConfiguration getAppConfiguration();
+
+ /**
+ * @return A {@link MetricsReporter} to report application metrics from observers.
+ */
+ MetricsReporter getMetricsReporter();
+ }
+
+ /**
+ * Observers are emitted to the worker using this interface. This interface also allows
+ * {@link Observer}s to be related to the columns that trigger them.
+ *
+ * @since 1.1.0
+ */
+ interface ObserverConsumer {
+ void accept(Column observedColumn, NotificationType ntfyType, Observer observer);
+
+ /**
+ * This method was created to allow Observers written as lambda to be passed {@link String}
+ * instead of {@link Bytes}.
+ *
+ * <pre>
+ * <code>
+ * void createObservers(ObserverConsumer obsConsumer, Context ctx) {
+ * obsConsumer.accepts(someColumn, WEAK, (tx,row,col) -> {
+ * //row is of type String
+ * };
+ * }
+ * </code>
+ * </pre>
+ */
+ void accepts(Column observedColumn, NotificationType ntfyType, StringObserver observer);
+ }
+
+ /**
+ * This is method is called by Fluo Workers to create observers to process notifications.
+ *
+ * <p>
+ * Observers emitted may be called concurrently by multiple threads to process different
+ * notifications. Observers should be tolerant of this.
+ *
+ * @param obsConsumer Emit an applications observers to this consumer.
+ */
+ void createObservers(ObserverConsumer obsConsumer, Context ctx);
--- End diff --
I'm not sure what you mean about it not being able to return a stream, since it's essentially the same as returning a set. Perhaps you thought I meant a stream of unpaired observers, when really I just meant a stream of whatever ObserverConsumer is consuming.
In any case, I agree with you on the boilerplate reduction, and returning a stream would be just as bad, if not significantly worse, than returning a set or a map.
Perhaps instead, the context itself can become an instance of ObserverConsumer? This simplifies the API a bit, and matches what MapReduce does for things like counters.
(And, if you wished, you could make ObserversFactory a `Consumer<Context>`, but that'd force a confusing method of `void accept(Context)` so I wouldn't recommend it).
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r106993321
--- Diff: modules/core/src/main/java/org/apache/fluo/core/observer/v2/ObserversV2.java ---
@@ -0,0 +1,152 @@
+/*
+ * 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.ObserversFactory;
+import org.apache.fluo.core.impl.Environment;
+import org.apache.fluo.core.observer.ConfiguredObservers;
+import org.apache.fluo.core.observer.ObserverProvider;
+import org.apache.fluo.core.observer.Observers;
+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 ObserversV2 implements Observers {
+
+ @Override
+ public boolean handles(FluoConfiguration config) {
+ return !config.getObserversFactory().isEmpty();
+ }
+
+ @Override
+ public void update(CuratorFramework curator, FluoConfiguration config) throws Exception {
+ String obsFactoryClass = config.getObserversFactory();
+
+ ObserversFactory observerFactory = newObserversFactory(obsFactoryClass);
+
+ 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);
+ };
+
+ observerFactory.getObservedColumns(
+ new ObserverFactoryContextImpl(config.getAppConfiguration()), obsColConsumer);
+
+ // TODO does core depend on GSon? If not, do we want to add dep?
--- End diff --
should remove this comment as you added it as a dependency
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by keith-turner <gi...@git.apache.org>.
Github user keith-turner commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107480219
--- Diff: modules/integration/src/test/java/org/apache/fluo/integration/impl/CollisionIT.java ---
@@ -81,27 +77,22 @@ public void load(TransactionBase tx, Context context) throws Exception {
}
}
- public static class TotalObserver extends AbstractObserver {
-
+ public static class CollisionObserverProvider implements ObserverProvider {
@Override
- public Observer.ObservedColumn getObservedColumn() {
- return new Observer.ObservedColumn(STAT_CHANGED, NotificationType.WEAK);
- }
-
- @Override
- public void process(TransactionBase tx, Bytes rowBytes, Column col) throws Exception {
- String row = rowBytes.toString();
- int total = Integer.parseInt(tx.gets(row, STAT_TOTAL));
- int processed = TestUtil.getOrDefault(tx, row, STAT_PROCESSED, 0);
-
- tx.set(row, STAT_PROCESSED, total + "");
- TestUtil.increment(tx, "all", STAT_TOTAL, total - processed);
+ public void provide(Registry consumer, Context ctx) {
--- End diff --
I switched everything to use `or` as a short for observer registry. Its probably too short though. Still trying to think of a shorter variable name for this. `observerRegistry` is too long. May just go with `registry` as you suggested.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107001150
--- Diff: pom.xml ---
@@ -83,6 +83,11 @@
<version>1.32</version>
</dependency>
<dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.2.4</version>
--- End diff --
Are you using `2.2.4` due to Hadoop using that version? Could add comment if Hadoop restricts use of latest version.
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107180790
--- Diff: modules/core/src/main/java/org/apache/fluo/core/observer/ConfiguredObservers.java ---
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+import java.util.Set;
+
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.observer.Observer;
+import org.apache.fluo.core.impl.Environment;
+
+public interface ConfiguredObservers {
--- End diff --
If you go by register terminology, this could be `RegisteredObservers`
---
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.
---
[GitHub] incubator-fluo pull request #817: fixes #816 introduced better way to setup ...
Posted by mikewalch <gi...@git.apache.org>.
Github user mikewalch commented on a diff in the pull request:
https://github.com/apache/incubator-fluo/pull/817#discussion_r107480083
--- Diff: modules/core/src/main/java/org/apache/fluo/core/observer/v2/JsonObservers.java ---
@@ -0,0 +1,55 @@
+/*
+ * 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.List;
+import java.util.Map;
+
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.observer.Observer.NotificationType;
+
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+
+/**
+ * this class created for json serialization
+ */
+class JsonObservers {
+ String obsProviderClass;
+ List<JsonObservedColumn> observedColumns;
+
+ JsonObservers(String obsFactoryClass, Map<Column, NotificationType> columns) {
--- End diff --
should be provider
---
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.
---