Exemplo n.º 1
0
def add(name=None):
    """
    Deploy configuration for a connector onto a cluster.

    E.g.: 'presto-admin connector add tpch'
    deploys a configuration file for the tpch connector.  The configuration is
    defined by tpch.properties in /etc/opt/prestoadmin/connectors directory.

    If no connector name is specified, then  configurations for all connectors
    in the connectors directory will be deployed

    Parameters:
        name - Name of the connector to be added
    """
    if name:
        filename = name + '.properties'
        config_path = os.path.join(constants.CONNECTORS_DIR, filename)
        if not os.path.isfile(config_path):
            raise ConfigFileNotFoundError(
                config_path=config_path,
                message='Configuration for connector ' + name + ' not found')
        filenames = [filename]
    elif not os.path.isdir(constants.CONNECTORS_DIR):
        message = (
            'Cannot add connectors because directory %s does not exist' %
            constants.CONNECTORS_DIR)
        raise ConfigFileNotFoundError(config_path=constants.CONNECTORS_DIR,
                                      message=message)
    else:
        try:
            filenames = os.listdir(constants.CONNECTORS_DIR)
        except OSError as e:
            fabric.utils.error(e.strerror)
            return
        if not filenames:
            fabric.utils.warn(
                'Directory %s is empty. No connectors will be deployed' %
                constants.CONNECTORS_DIR)
            return

    if not validate(filenames):
        return
    filenames.sort()
    _LOGGER.info('Adding connector configurations: ' + str(filenames))
    print('Deploying %s connector configurations on: %s ' %
          (', '.join(filenames), env.host))

    deploy_files(filenames, constants.CONNECTORS_DIR,
                 constants.REMOTE_CATALOG_DIR, PRESTO_STANDALONE_USER_GROUP)
Exemplo n.º 2
0
    def test_can_pickle_ConfigFileNotFound(self):
        config_path = '/usa/georgia/macon'
        message = 'I woke up this morning, I had them Statesboro Blues'
        e = ConfigFileNotFoundError(config_path=config_path, message=message)

        ps = pickle.dumps(e, pickle.HIGHEST_PROTOCOL)
        a = pickle.loads(ps)

        self.assertEquals(message, a.message)
        self.assertEquals(config_path, a.config_path)
Exemplo n.º 3
0
def get_conf_from_json_file(path):
    try:
        with open(path, 'r') as conf_file:
            if os.path.getsize(conf_file.name) == 0:
                return {}
            return json.load(conf_file)
    except IOError:
        raise ConfigFileNotFoundError("Missing configuration file at " +
                                      repr(path))
    except ValueError as e:
        raise ConfigurationError(e)
 def test_get_config_load_interactive(self, set_env_mock, store_conf_mock,
                                      file_conf_mock,
                                      interactive_conf_mock):
     file_conf_mock.side_effect = ConfigFileNotFoundError(
         message='oops', config_path='/asdf')
     config = StandaloneConfig()
     config.get_config()
     self.assertTrue(file_conf_mock.called)
     self.assertTrue(interactive_conf_mock.called)
     self.assertTrue(set_env_mock.called)
     self.assertTrue(store_conf_mock.called)
     self.assertTrue(config.is_config_loaded())
Exemplo n.º 5
0
    def test_load_topology_not_exists(self, get_conf_mock):
        e = ConfigFileNotFoundError()

        get_conf_mock.side_effect = e
        main.load_topology()
        self.assertEqual(main.state.env.roledefs, {
            'coordinator': [],
            'worker': [],
            'all': []
        })
        self.assertEqual(main.state.env.port, '22')
        self.assertNotEqual(main.state.env.user, 'user')
        self.assertEqual(main.state.env.topology_config_not_found, e)
Exemplo n.º 6
0
    def test_update_config(self, mock_open, mock_fdopen, mock_makedir,
                           mock_path_exists, mock_config, mock_connector):
        e = ConfigFileNotFoundError(
            message='problems', config_path='config_path')
        mock_connector.add.side_effect = e
        mock_path_exists.side_effect = [False, False]

        server.update_configs()

        mock_config.assert_called_with()
        mock_makedir.assert_called_with(constants.CONNECTORS_DIR)
        mock_open.assert_called_with(os.path.join(constants.CONNECTORS_DIR,
                                                  'tpch.properties'),
                                     os.O_CREAT | os.O_EXCL | os.O_WRONLY)
        file_manager = mock_fdopen.return_value.__enter__.return_value
        file_manager.write.assert_called_with("connector.name=tpch")
Exemplo n.º 7
0
 def required(*args, **kwargs):
     if 'topology_config_not_found' in env \
             and env.topology_config_not_found:
         raise ConfigFileNotFoundError('Missing topology configuration ' +
                                       'in ' + constants.CONFIG_PATH + '.')
     return func(*args, **kwargs)