def test_cmd_save(self):
     self.inter.execute_string("save(" + self.tmp_save_file + ")")
     self.inter.execute_string("load(" + self.tmp_save_file + ")")
     self.inter.execute_string("A = IPTablesSource")
     self.inter.execute_string("save()")
     expected = const.get_default_base_config()
     expected[const.SOURCES]["src1"] = ipt_src.IPTablesSource.\
         get_default_config()
     expected[const.CONNECTIONS]["src1"] = []
     with open(self.tmp_save_file) as f:
         saved_config = json.loads(f.read())
     self.assertEqual(expected, saved_config)
     pass
Exemplo n.º 2
0
 def test_cmd_save(self):
     self.inter.execute_string("save(" + self.tmp_save_file + ")")
     self.inter.execute_string("load(" + self.tmp_save_file + ")")
     self.inter.execute_string("A = IPTablesSource")
     self.inter.execute_string("save()")
     expected = const.get_default_base_config()
     expected[const.SOURCES]["src1"] = ipt_src.IPTablesSource.\
         get_default_config()
     expected[const.CONNECTIONS]["src1"] = []
     with open(self.tmp_save_file) as f:
         saved_config = json.loads(f.read())
     self.assertEqual(expected, saved_config)
     pass
Exemplo n.º 3
0
    def __init__(self, config_file_path=None):
        """Constructor with an optional configuration file path

        If the configuration file is provided, it will be loaded at
        MonanasDLS creation time.
        If no configuration file path is provided, the default base
        configuration defined in config.const will be used.

        :type config_file_path: str
        :param config_file_path: path to the file containing the configuration
                                 that will be loaded at MonansDSL creation
        """
        if config_file_path:
            self.load_configuration(config_file_path)
        else:
            self._config = const.get_default_base_config()
            self._init_ids_dictionary()
Exemplo n.º 4
0
    def __init__(self, config_file_path=None):
        """Constructor with an optional configuration file path

        If the configuration file is provided, it will be loaded at
        MonanasDLS creation time.
        If no configuration file path is provided, the default base
        configuration defined in config.const will be used.

        :type config_file_path: str
        :param config_file_path: path to the file containing the configuration
                                 that will be loaded at MonansDSL creation
        """
        if config_file_path:
            self.load_configuration(config_file_path)
        else:
            self._config = const.get_default_base_config()
            self._init_ids_dictionary()
def eval_ast(ast_root, type_table, driver):
    """
    Evaluate the provided AST by instantiating
    the appropriate components and connecting them
    together using the Driver interface.
    :type ast_root: ast.BananaFile
    :param ast_root: AST to evaluate.
    :type type_table: monasca_analytics.banana.typeck.type_table.TypeTable
    :param type_table: the TypeTable (used to create configurations)
    :type driver: monasca_analytics.spark.driver.DriverExecutor
    :param driver: Driver that will manage the created
        components and connect them together.
    """
    logger.debug("Creating the config dictionary from the AST...")
    _config = conf_const.get_default_base_config()

    try:
        logger.debug("Creating components according to banana config...")
        components = eval_create_components(ast_root.statements, type_table)
        convert_connections(ast_root.connections, _config)
        logger.debug("Done creating components. Creating link data...")
        # Pre-process to convert to old style components
        components_old_style = into.into_old_conf_dict(components)
        links = connection.connect_components(components_old_style, _config)
        logger.debug("Done connecting components. Successful instantiation")
    except Exception as ex:
        logger.error("Failed to instantiate components")
        logger.error("Reason : " + str(ex))
        return

    # Restart Spark using the new config
    logger.debug("Stop pipeline")
    driver.stop_pipeline()
    logger.debug("Set new links")
    driver.set_links(links)
    logger.debug("Start pipeline")
    driver.start_pipeline()
Exemplo n.º 6
0
def eval_ast(ast_root, type_table, driver):
    """
    Evaluate the provided AST by instantiating
    the appropriate components and connecting them
    together using the Driver interface.
    :type ast_root: ast.BananaFile
    :param ast_root: AST to evaluate.
    :type type_table: monasca_analytics.banana.typeck.type_table.TypeTable
    :param type_table: the TypeTable (used to create configurations)
    :type driver: monasca_analytics.spark.driver.DriverExecutor
    :param driver: Driver that will manage the created
        components and connect them together.
    """
    logger.debug("Creating the config dictionary from the AST...")
    _config = conf_const.get_default_base_config()

    try:
        logger.debug("Creating components according to banana config...")
        components = eval_create_components(ast_root.statements, type_table)
        convert_connections(ast_root.connections, _config)
        logger.debug("Done creating components. Creating link data...")
        # Pre-process to convert to old style components
        components_old_style = into.into_old_conf_dict(components)
        links = connection.connect_components(components_old_style, _config)
        logger.debug("Done connecting components. Successful instantiation")
    except Exception as ex:
        logger.error("Failed to instantiate components")
        logger.error("Reason : " + str(ex))
        return

    # Restart Spark using the new config
    logger.debug("Stop pipeline")
    driver.stop_pipeline()
    logger.debug("Set new links")
    driver.set_links(links)
    logger.debug("Start pipeline")
    driver.start_pipeline()
 def test_cmd_save_as(self):
     self.inter.execute_string("save(" + self.tmp_save_file + ")")
     with open(self.tmp_save_file) as f:
         saved_config = json.loads(f.read())
     self.assertEqual(const.get_default_base_config(), saved_config)
Exemplo n.º 8
0
 def test_cmd_save_as(self):
     self.inter.execute_string("save(" + self.tmp_save_file + ")")
     with open(self.tmp_save_file) as f:
         saved_config = json.loads(f.read())
     self.assertEqual(const.get_default_base_config(), saved_config)