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