001/*
002 * Copyright (c) 2016-2017 Chris K Wensel <chris@wensel.net>. All Rights Reserved.
003 * Copyright (c) 2007-2017 Xplenty, Inc. All Rights Reserved.
004 *
005 * Project and contact information: http://www.cascading.org/
006 *
007 * This file is part of the Cascading project.
008 *
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *     http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 */
021
022package cascading.flow;
023
024import java.util.Map;
025import java.util.Properties;
026
027import cascading.operation.AssertionLevel;
028import cascading.operation.DebugLevel;
029import cascading.property.Props;
030import cascading.scheme.Scheme;
031import cascading.tap.DecoratorTap;
032
033/**
034 * The class FlowConnectorProps is a fluent helper class for setting {@link FlowConnector} specific
035 * properties through the {@link FlowConnector} constructor.
036 *
037 * @see cascading.property.AppProps
038 * @see cascading.cascade.CascadeProps
039 * @see FlowProps
040 */
041public class FlowConnectorProps extends Props
042  {
043  public static final String ASSERTION_LEVEL = "cascading.flowconnector.assertionlevel";
044  public static final String DEBUG_LEVEL = "cascading.flowconnector.debuglevel";
045  public static final String INTERMEDIATE_SCHEME_CLASS = "cascading.flowconnector.intermediateschemeclass";
046  public static final String TEMPORARY_TAP_DECORATOR_CLASS = "cascading.flowconnector.temporary_tap.decorator.classname";
047  public static final String CHECKPOINT_TAP_DECORATOR_CLASS = "cascading.flowconnector.checkpoint_tap.decorator.classname";
048  public static final String ENABLE_DECORATE_ACCUMULATED_TAP = "cascading.flowconnector.accumulated_tap.decorator.enable";
049
050  AssertionLevel assertionLevel;
051  DebugLevel debugLevel;
052  String intermediateSchemeClassName;
053  String temporaryTapDecoratorClassName;
054  String checkpointTapDecoratorClassName;
055  Boolean enableDecorateAccumulatedTap;
056
057  /**
058   * Method setAssertionLevel sets the target planner {@link cascading.operation.AssertionLevel}.
059   *
060   * @param properties     of type Map
061   * @param assertionLevel of type AssertionLevel
062   */
063  public static void setAssertionLevel( Map<Object, Object> properties, AssertionLevel assertionLevel )
064    {
065    if( assertionLevel != null )
066      properties.put( ASSERTION_LEVEL, assertionLevel.toString() );
067    }
068
069  /**
070   * Method setDebugLevel sets the target planner {@link cascading.operation.DebugLevel}.
071   *
072   * @param properties of type Map
073   * @param debugLevel of type DebugLevel
074   */
075  public static void setDebugLevel( Map<Object, Object> properties, DebugLevel debugLevel )
076    {
077    if( debugLevel != null )
078      properties.put( DEBUG_LEVEL, debugLevel.toString() );
079    }
080
081  /**
082   * Method setIntermediateSchemeClass is used for debugging.
083   *
084   * @param properties              of type Map
085   * @param intermediateSchemeClass of type Class
086   */
087  public static void setIntermediateSchemeClass( Map<Object, Object> properties, Class<? extends Scheme> intermediateSchemeClass )
088    {
089    if( intermediateSchemeClass != null )
090      properties.put( INTERMEDIATE_SCHEME_CLASS, intermediateSchemeClass.getName() );
091    }
092
093  /**
094   * Method setIntermediateSchemeClass is used for debugging.
095   *
096   * @param properties                  of type Map
097   * @param intermediateSchemeClassName of type String
098   */
099  public static void setIntermediateSchemeClass( Map<Object, Object> properties, String intermediateSchemeClassName )
100    {
101    if( intermediateSchemeClassName != null )
102      properties.put( INTERMEDIATE_SCHEME_CLASS, intermediateSchemeClassName );
103    }
104
105  /**
106   * Method temporaryTapDecoratorClassName is used for wrapping a intermediate temporary Tap.
107   *
108   * @param properties                     of type Map
109   * @param temporaryTapDecoratorClassName of type String
110   */
111  public static void setTemporaryTapDecoratorClass( Map<Object, Object> properties, String temporaryTapDecoratorClassName )
112    {
113    if( temporaryTapDecoratorClassName != null )
114      properties.put( TEMPORARY_TAP_DECORATOR_CLASS, temporaryTapDecoratorClassName );
115    }
116
117  /**
118   * Method checkpointTapDecoratorClassName is used for wrapping a checkpoint Tap.
119   *
120   * @param properties                      of type Map
121   * @param checkpointTapDecoratorClassName of type String
122   */
123  public static void setCheckpointTapDecoratorClass( Map<Object, Object> properties, String checkpointTapDecoratorClassName )
124    {
125    if( checkpointTapDecoratorClassName != null )
126      properties.put( CHECKPOINT_TAP_DECORATOR_CLASS, checkpointTapDecoratorClassName );
127    }
128
129  /**
130   * Creates a new FlowConnectorProps instance.
131   *
132   * @return FlowConnectorProps instance
133   */
134  public static FlowConnectorProps flowConnectorProps()
135    {
136    return new FlowConnectorProps();
137    }
138
139  public FlowConnectorProps()
140    {
141    }
142
143  public AssertionLevel getAssertionLevel()
144    {
145    return assertionLevel;
146    }
147
148  /**
149   * Method setAssertionLevel sets the target planner {@link cascading.operation.AssertionLevel}.
150   *
151   * @param assertionLevel of type AssertionLevel
152   * @return this instance
153   */
154  public FlowConnectorProps setAssertionLevel( AssertionLevel assertionLevel )
155    {
156    this.assertionLevel = assertionLevel;
157
158    return this;
159    }
160
161  public DebugLevel getDebugLevel()
162    {
163    return debugLevel;
164    }
165
166  /**
167   * Method setDebugLevel sets the target planner {@link cascading.operation.DebugLevel}.
168   *
169   * @param debugLevel of type DebugLevel
170   * @return this instance
171   */
172  public FlowConnectorProps setDebugLevel( DebugLevel debugLevel )
173    {
174    this.debugLevel = debugLevel;
175
176    return this;
177    }
178
179  public String getIntermediateSchemeClassName()
180    {
181    return intermediateSchemeClassName;
182    }
183
184  /**
185   * Method setIntermediateSchemeClassName is used for debugging.
186   *
187   * @param intermediateSchemeClassName of type String
188   * @return this instance
189   */
190  public FlowConnectorProps setIntermediateSchemeClassName( String intermediateSchemeClassName )
191    {
192    this.intermediateSchemeClassName = intermediateSchemeClassName;
193
194    return this;
195    }
196
197  /**
198   * Method setIntermediateSchemeClassName is used for debugging.
199   *
200   * @param intermediateSchemeClass of type Class
201   * @return this instance
202   */
203  public FlowConnectorProps setIntermediateSchemeClassName( Class<Scheme> intermediateSchemeClass )
204    {
205    if( intermediateSchemeClass != null )
206      this.intermediateSchemeClassName = intermediateSchemeClass.getName();
207
208    return this;
209    }
210
211  public String getTemporaryTapDecoratorClassName()
212    {
213    return temporaryTapDecoratorClassName;
214    }
215
216  /**
217   * Method setTemporaryTapDecoratorClassName sets the class of a {@link cascading.tap.DecoratorTap} to use to
218   * wrap an intermediate temporary Tap instance internal to the Flow.
219   *
220   * @param temporaryTapDecoratorClassName of type String
221   * @return this instance
222   */
223  public FlowConnectorProps setTemporaryTapDecoratorClassName( String temporaryTapDecoratorClassName )
224    {
225    this.temporaryTapDecoratorClassName = temporaryTapDecoratorClassName;
226
227    return this;
228    }
229
230  /**
231   * Method setTemporaryTapDecoratorClassName sets the class of a {@link cascading.tap.DecoratorTap} to use to
232   * wrap an intermediate temporary Tap instance internal to the Flow.
233   *
234   * @param temporaryTapDecoratorClass of type Class
235   * @return this instance
236   */
237  public FlowConnectorProps setTemporaryTapDecoratorClassName( Class<DecoratorTap> temporaryTapDecoratorClass )
238    {
239    if( temporaryTapDecoratorClass != null )
240      this.temporaryTapDecoratorClassName = temporaryTapDecoratorClass.getName();
241
242    return this;
243    }
244
245  public String getCheckpointTapDecoratorClassName()
246    {
247    return checkpointTapDecoratorClassName;
248    }
249
250  /**
251   * Method setCheckpointTapDecoratorClassName sets the class of a {@link cascading.tap.DecoratorTap} to use to
252   * wrap an Checkpoint Tap instance within the Flow.
253   *
254   * @param checkpointTapDecoratorClassName of type String
255   * @return this instance
256   */
257  public FlowConnectorProps setCheckpointTapDecoratorClassName( String checkpointTapDecoratorClassName )
258    {
259    this.checkpointTapDecoratorClassName = checkpointTapDecoratorClassName;
260
261    return this;
262    }
263
264  /**
265   * Method setCheckpointTapDecoratorClassName sets the class of a {@link cascading.tap.DecoratorTap} to use to
266   * wrap an Checkpoint Tap instance within the Flow.
267   *
268   * @param checkpointTapDecoratorClass of type Class
269   * @return this instance
270   */
271  public FlowConnectorProps setCheckpointTapDecoratorClassName( Class<DecoratorTap> checkpointTapDecoratorClass )
272    {
273    if( checkpointTapDecoratorClass != null )
274      this.checkpointTapDecoratorClassName = checkpointTapDecoratorClass.getName();
275
276    return this;
277    }
278
279  public Boolean getEnableDecorateAccumulatedTap()
280    {
281    return enableDecorateAccumulatedTap;
282    }
283
284  /**
285   * Method setEnableDecorateAccumulatedTap, when set to {@code false}, disables the use of a DistCacheTap decorator
286   * implementation during planning. It is enabled by default.
287   * <p>
288   * When enabled, any {@link cascading.tap.Tap} instance declared or planned via the planner (intermediate Tap or binding
289   * a {@link cascading.pipe.Checkpoint} pipe to a tap -- when applicable) will be wrapped by a platform specific
290   * implementation of a Tap that allows for data reads from the platform provided distributed caches or similiar
291   * service, if any.
292   *
293   * @param enableDecorateAccumulatedTap the enableDecorateAccumulatedTap of type boolean
294   * @return FlowConnectorProps
295   */
296  public FlowConnectorProps setEnableDecorateAccumulatedTap( boolean enableDecorateAccumulatedTap )
297    {
298    this.enableDecorateAccumulatedTap = enableDecorateAccumulatedTap;
299
300    return this;
301    }
302
303  @Override
304  protected void addPropertiesTo( Properties properties )
305    {
306    setAssertionLevel( properties, assertionLevel );
307    setDebugLevel( properties, debugLevel );
308    setIntermediateSchemeClass( properties, intermediateSchemeClassName );
309    setTemporaryTapDecoratorClass( properties, temporaryTapDecoratorClassName );
310    setCheckpointTapDecoratorClass( properties, checkpointTapDecoratorClassName );
311
312    if( enableDecorateAccumulatedTap != null )
313      properties.setProperty( ENABLE_DECORATE_ACCUMULATED_TAP, enableDecorateAccumulatedTap.toString() );
314    }
315  }