Review Board 1.7.22


FLUME-1745: FlumeConfiguration Eats Exceptions

Review Request #8281 - Created Nov. 29, 2012 and submitted

Brock Noland
trunk
FLUME-1745
Reviewers
Flume
flume-git
1) Gives Exception thrown in ComponentConfigurationFactory a better error message
2) FlumeConfiguration.validate* now logs exceptions as opposed to opaque error message
Unit tests pass and adds regression test for FLUME-1743.
flume-ng-configuration/src/main/java/org/apache/flume/conf/ComponentConfigurationFactory.java
Revision 6c151dc New Change
[20] 14 lines
[+20]
15
 * the License.
15
 * the License.
16
 */
16
 */
17
package org.apache.flume.conf;
17
package org.apache.flume.conf;
18

    
   
18

   
19
import org.apache.flume.conf.ComponentConfiguration.ComponentType;
19
import org.apache.flume.conf.ComponentConfiguration.ComponentType;
20
import org.apache.flume.conf.source.SourceConfiguration.SourceConfigurationType;
20
import org.apache.flume.conf.channel.ChannelConfiguration.ChannelConfigurationType;
21
import org.apache.flume.conf.sink.SinkGroupConfiguration;
21
import org.apache.flume.conf.channel.ChannelSelectorConfiguration.ChannelSelectorConfigurationType;
22
import org.apache.flume.conf.sink.SinkConfiguration.SinkConfigurationType;
22
import org.apache.flume.conf.sink.SinkConfiguration.SinkConfigurationType;

    
   
23
import org.apache.flume.conf.sink.SinkGroupConfiguration;
23
import org.apache.flume.conf.sink.SinkProcessorConfiguration.SinkProcessorConfigurationType;
24
import org.apache.flume.conf.sink.SinkProcessorConfiguration.SinkProcessorConfigurationType;
24
import org.apache.flume.conf.channel.ChannelSelectorConfiguration.ChannelSelectorConfigurationType;
25
import org.apache.flume.conf.source.SourceConfiguration.SourceConfigurationType;
25
import org.apache.flume.conf.channel.ChannelConfiguration.ChannelConfigurationType;

   
26

    
   
26

   
27
public class ComponentConfigurationFactory {
27
public class ComponentConfigurationFactory {
28
  @SuppressWarnings("unchecked")
28
  @SuppressWarnings("unchecked")
29
  public static ComponentConfiguration
29
  public static ComponentConfiguration
30
  create(String name, String type, ComponentType component)
30
  create(String name, String type, ComponentType component)
[+20] [20] 5 lines
[+20] public class ComponentConfigurationFactory {
36
          "Cannot create component without knowing its type!");
36
          "Cannot create component without knowing its type!");
37
    }
37
    }
38
    try {
38
    try {
39
      confType = (Class<? extends ComponentConfiguration>) Class.forName(type);
39
      confType = (Class<? extends ComponentConfiguration>) Class.forName(type);
40
      return confType.getConstructor(String.class).newInstance(type);
40
      return confType.getConstructor(String.class).newInstance(type);
41
    } catch (Exception e) {
41
    } catch (Exception ignored) {
42
      try {
42
      try {
43
        type = type.toUpperCase();
43
        type = type.toUpperCase();
44
        switch(component){
44
        switch(component){
45
          case SOURCE:
45
          case SOURCE:
46
            return SourceConfigurationType.valueOf(type.toUpperCase())
46
            return SourceConfigurationType.valueOf(type.toUpperCase())
[+20] [20] 15 lines
[+20] public class ComponentConfigurationFactory {
62
          default:
62
          default:
63
            throw new ConfigurationException(
63
            throw new ConfigurationException(
64
                "Cannot create configuration. Unknown Type specified: " +
64
                "Cannot create configuration. Unknown Type specified: " +
65
                    type);
65
                    type);
66
        }
66
        }
67
      } catch (Exception e2) {
67
      } catch (ConfigurationException e) {
68
        throw new ConfigurationException("Could not create configuration!", e);
68
        throw e;

    
   
69
      } catch (Exception e) {

    
   
70
        throw new ConfigurationException("Could not create configuration! " +

    
   
71
            " Due to " + e.getClass().getSimpleName() + ": " + e.getMessage(),

    
   
72
            e);
69
      }
73
      }
70
    }
74
    }
71
  }
75
  }
72
}
76
}
flume-ng-configuration/src/main/java/org/apache/flume/conf/FlumeConfiguration.java
Revision 9b209e8 New Change
 
flume-ng-configuration/src/test/java/com/apache/flume/conf/TestFlumeConfiguration.java
New File
 
  1. flume-ng-configuration/src/main/java/org/apache/flume/conf/ComponentConfigurationFactory.java: Loading...
  2. flume-ng-configuration/src/main/java/org/apache/flume/conf/FlumeConfiguration.java: Loading...
  3. flume-ng-configuration/src/test/java/com/apache/flume/conf/TestFlumeConfiguration.java: Loading...