forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#31 [euphoria-core] Implementation of accumulator API + integration w…
…ith Flink executor
- Loading branch information
Showing
74 changed files
with
1,352 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
.../euphoria-core/src/main/java/cz/seznam/euphoria/core/client/accumulators/Accumulator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright 2016-2017 Seznam.cz, a.s. | ||
* | ||
* Licensed 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 cz.seznam.euphoria.core.client.accumulators; | ||
|
||
/** | ||
* Accumulators collect values from user functions. | ||
* Accumulators allow user to calculate statistics during the flow execution. | ||
* <p> | ||
* Accumulators are inspired by the Hadoop/MapReduce counters. | ||
*/ | ||
public interface Accumulator { | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
...a-core/src/main/java/cz/seznam/euphoria/core/client/accumulators/AccumulatorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright 2016-2017 Seznam.cz, a.s. | ||
* | ||
* Licensed 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 cz.seznam.euphoria.core.client.accumulators; | ||
|
||
import cz.seznam.euphoria.core.util.Settings; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Provides access to an accumulator backend service. It is intended to be | ||
* implemented by third party to support different type of services. | ||
*/ | ||
public interface AccumulatorProvider { | ||
|
||
/** | ||
* Get an existing instance of a counter or create a new one. | ||
* | ||
* @param name Unique name of the counter. | ||
* @return Instance of a counter. | ||
*/ | ||
Counter getCounter(String name); | ||
|
||
/** | ||
* Get an existing instance of a histogram or create a new one. | ||
* | ||
* @param name Unique name of the histogram. | ||
* @return Instance of a histogram. | ||
*/ | ||
Histogram getHistogram(String name); | ||
|
||
/** | ||
* Get an existing instance of a timer or create a new one. | ||
* | ||
* @param name Unique name of the timer. | ||
* @return Instance of a timer. | ||
*/ | ||
Timer getTimer(String name); | ||
|
||
/** | ||
* Creates a new instance of {@link AccumulatorProvider} | ||
* initialized by given settings. | ||
* <p> | ||
* It is required this factory is thread-safe. | ||
*/ | ||
@FunctionalInterface | ||
interface Factory extends Serializable { | ||
AccumulatorProvider create(Settings settings); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...oria/euphoria-core/src/main/java/cz/seznam/euphoria/core/client/accumulators/Counter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright 2016-2017 Seznam.cz, a.s. | ||
* | ||
* Licensed 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 cz.seznam.euphoria.core.client.accumulators; | ||
|
||
/** | ||
* Counter is a type of accumulator making a sum from integral numbers. | ||
*/ | ||
public interface Counter extends Accumulator { | ||
|
||
/** | ||
* Increment counter by given value. | ||
* @param value Value to be added to the counter. | ||
*/ | ||
void increment(long value); | ||
|
||
/** | ||
* Increment counter by one. | ||
*/ | ||
void increment(); | ||
} |
35 changes: 35 additions & 0 deletions
35
...ia/euphoria-core/src/main/java/cz/seznam/euphoria/core/client/accumulators/Histogram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright 2016-2017 Seznam.cz, a.s. | ||
* | ||
* Licensed 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 cz.seznam.euphoria.core.client.accumulators; | ||
|
||
/** | ||
* Histogram is a type of accumulator recording a distribution of different values. | ||
*/ | ||
public interface Histogram extends Accumulator { | ||
|
||
/** | ||
* Add specified value. | ||
* @param value Value to be added. | ||
*/ | ||
void add(long value); | ||
|
||
/** | ||
* Add specified value multiple times. | ||
* @param value Value to be added. | ||
* @param times Number of occurrences to add. | ||
*/ | ||
void add(long value, long times); | ||
} |
41 changes: 41 additions & 0 deletions
41
...phoria/euphoria-core/src/main/java/cz/seznam/euphoria/core/client/accumulators/Timer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright 2016-2017 Seznam.cz, a.s. | ||
* | ||
* Licensed 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 cz.seznam.euphoria.core.client.accumulators; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Timer provides convenience API very similar to {@link Histogram} | ||
* but extended by time unit support. | ||
*/ | ||
public interface Timer extends Accumulator { | ||
|
||
/** | ||
* Add specific duration. | ||
* @param duration Duration to be added. | ||
*/ | ||
void add(Duration duration); | ||
|
||
/** | ||
* Add specific duration with given time unit | ||
* @param duration Duration to be added. | ||
* @param unit Time unit. | ||
*/ | ||
default void add(long duration, TimeUnit unit) { | ||
add(Duration.ofMillis(unit.toMillis(duration))); | ||
} | ||
} |
125 changes: 125 additions & 0 deletions
125
...re/src/main/java/cz/seznam/euphoria/core/client/accumulators/VoidAccumulatorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/** | ||
* Copyright 2016-2017 Seznam.cz, a.s. | ||
* | ||
* Licensed 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 cz.seznam.euphoria.core.client.accumulators; | ||
|
||
import cz.seznam.euphoria.core.util.Settings; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.time.Duration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Placeholder implementation of {@link AccumulatorProvider} that | ||
* may be used in executors as a default. | ||
*/ | ||
public class VoidAccumulatorProvider implements AccumulatorProvider { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(VoidAccumulatorProvider.class); | ||
|
||
private final Map<String, Accumulator> accumulators = new HashMap<>(); | ||
|
||
private VoidAccumulatorProvider() {} | ||
|
||
@Override | ||
public Counter getCounter(String name) { | ||
return getAccumulator(name, VoidCounter.class); | ||
} | ||
|
||
@Override | ||
public Histogram getHistogram(String name) { | ||
return getAccumulator(name, VoidHistogram.class); | ||
} | ||
|
||
@Override | ||
public Timer getTimer(String name) { | ||
return getAccumulator(name, VoidTimer.class); | ||
} | ||
|
||
private <ACC extends Accumulator> ACC getAccumulator(String name, Class<ACC> clz) { | ||
try { | ||
ACC acc = clz.getConstructor().newInstance(); | ||
if (accumulators.putIfAbsent(name, acc) == null) { | ||
LOG.warn("Using accumulators with VoidAccumulatorProvider will have no effect"); | ||
} | ||
return acc; | ||
} catch (Exception e) { | ||
throw new RuntimeException("Exception during accumulator initialization: " + clz, e); | ||
} | ||
} | ||
|
||
public static Factory getFactory() { | ||
return Factory.get(); | ||
} | ||
|
||
// ------------------------ | ||
|
||
public static class Factory implements AccumulatorProvider.Factory { | ||
|
||
private static final Factory INSTANCE = new Factory(); | ||
|
||
private static final AccumulatorProvider PROVIDER = | ||
new VoidAccumulatorProvider(); | ||
|
||
private Factory() {} | ||
|
||
@Override | ||
public AccumulatorProvider create(Settings settings) { | ||
return PROVIDER; | ||
} | ||
|
||
public static Factory get() { | ||
return INSTANCE; | ||
} | ||
} | ||
|
||
// ------------------------ | ||
|
||
public static class VoidCounter implements Counter { | ||
|
||
@Override | ||
public void increment(long value) { | ||
// NOOP | ||
} | ||
|
||
@Override | ||
public void increment() { | ||
// NOOP | ||
} | ||
} | ||
|
||
public static class VoidHistogram implements Histogram { | ||
|
||
@Override | ||
public void add(long value) { | ||
// NOOP | ||
} | ||
|
||
@Override | ||
public void add(long value, long times) { | ||
// NOOP | ||
} | ||
} | ||
|
||
public static class VoidTimer implements Timer { | ||
|
||
@Override | ||
public void add(Duration duration) { | ||
// NOOP | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.