Add custom class object to Apache Storm Config

I have created my own class called Configuration.java and I want to put it in my Config object in my storm topology. When I try to use my topology, I get the error:

java.lang.IllegalArgumentException: Topology conf is not json-serializable

      

Here is my code trying to put the Configuration object in Config

public static Config loadConf(String resource) {

        Configuration _epconf = null;
        Yaml yaml = new Yaml();

        Config conf = new Config();
        conf.registerSerialization(Configuration.class);  //register the Configuration class 

        try {

           //load the yaml file into the Configuration pojo
           _epconf = (Configuration)yaml.loadAs(new InputStreamReader(new FileInputStream(resource)), Configuration.class);

        } catch (FileNotFoundException e) {
            Log.error("Configuration file does not exist : " + resource);
            System.err.println("Conf file does not exist : " + resource);
            System.exit(-1);
        } catch (YAMLException e ) {
            Log.error("Error parsing YAML file for configuration : " + resource + "\n" + e.getMessage());
            System.err.println("Error parsing YAML file for configuration : " + resource);
            System.exit(-1);
        }

        //verify object is not empty
        if (_epconf == null) {
            Log.error("Empty configuration object created from : " + resource );
            System.err.println("Empty configuration object created from : " + resource);
            System.exit(-1);
        }

        conf.put("epconf", _epconf);  //add the Configuration to the Config object

        return conf;
    }

      

I believe the problem is that I am not registering my class for serialization correctly. I suspect conf.registerSerialization (Configuration.class) is not entirely correct, but I cannot follow what the documentation asks for in the storm page other than this.

+3


source to share





All Articles