示例#1
0
def create2(node_id=None,
            bus_id=None,
            existing_node=None,
            policy_engine=True,
            datasources=True,
            api=True):
    """Get Congress up.

    Creates a DseNode if one is not provided and adds policy_engine,
    datasources, api to that node.

    :param node_id is node_id of DseNode to be created
    :param bus_id is partition_id of DseNode to be created
    :param existing_node is a DseNode (optional; in lieu of previous 2 params)
    :param policy_engine controls whether policy_engine is included
    :param datasources controls whether datasources are included
    :param api controls whether API is included
    :returns DseNode
    """
    # create DseNode if existing_node not given
    if existing_node is None:
        assert (not (node_id is None or bus_id is None)),\
            'params node_id and bus_id required.'
        node = dse_node.DseNode(cfg.CONF, node_id, [], partition_id=bus_id)
    else:
        assert (node_id is None and bus_id is None),\
            'params node_id and bus_id must be None when existing_node given.'
        node = existing_node

    # create services as required
    services = {}

    if datasources:
        LOG.info("Registering congress datasource services on node %s",
                 node.node_id)
        services['datasources'] = create_datasources(node)
        services['ds_manager'] = ds_manager.DSManagerService(
            api_base.DS_MANAGER_SERVICE_ID)
        node.register_service(services['ds_manager'])

    if policy_engine:
        LOG.info("Registering congress PolicyEngine service on node %s",
                 node.node_id)
        engine = create_policy_engine()
        services[api_base.ENGINE_SERVICE_ID] = engine
        node.register_service(engine)
        initialize_policy_engine(engine)

    if api:
        LOG.info("Registering congress API service on node %s", node.node_id)
        services['api'], services['api_service'] = create_api()
        node.register_service(services['api_service'])

    return services
    def test_ds_manager_endpoints_add_ds(self):
        ds_manager_service = ds_manager.DSManagerService('test_mgr')
        node_mock = mock.MagicMock()
        ds_manager_service.add_datasource = mock.MagicMock()
        ds_manager_service.add_datasource.return_value = 'add_datasource'
        ds_manager_service.node = node_mock
        endpoints = ds_manager.DSManagerEndpoints(ds_manager_service)

        expect_ret = 'add_datasource'
        self.assertEqual(expect_ret, endpoints.add_datasource('context', {}))

        ds_manager_service.add_datasource.assert_called_with({})
示例#3
0
def create2(node_id=None, bus_id=None, existing_node=None,
            policy_engine=True, datasources=True, api=True):
    """Get Congress up.

    Creates a DseNode if one is not provided and adds policy_engine,
    datasources, api to that node.

    :param: node_id is node_id of DseNode to be created
    :param: bus_id is partition_id of DseNode to be created
    :param: existing_node is a DseNode (optional; in lieu of previous 2 params)
    :param: policy_engine controls whether policy_engine is included
    :param: datasources controls whether datasources are included
    :param: api controls whether API is included
    :returns: DseNode
    """
    # create DseNode if existing_node not given
    if existing_node is None:
        assert (not (node_id is None or bus_id is None)),\
            'params node_id and bus_id required.'
        node = dse_node.DseNode(cfg.CONF, node_id, [], partition_id=bus_id)
    else:
        assert (node_id is None and bus_id is None),\
            'params node_id and bus_id must be None when existing_node given.'
        node = existing_node

    # create services as required
    services = {}

    # Load all configured drivers
    dse_node.DseNode.load_drivers()

    if datasources:
        LOG.info("Registering congress datasource services on node %s",
                 node.node_id)
        services['datasources'] = create_datasources(node)
        services['ds_manager'] = ds_manager.DSManagerService(
            api_base.DS_MANAGER_SERVICE_ID)
        node.register_service(services['ds_manager'])

    if policy_engine:
        LOG.info("Registering congress PolicyEngine service on node %s",
                 node.node_id)
        engine = create_policy_engine()
        services[api_base.ENGINE_SERVICE_ID] = engine
        node.register_service(engine)
        initialize_policy_engine(engine)

        # NOTE(ekcs): library service does not depend on policy engine,
        # it is placed on the same nodes as policy engine for convenience only
        LOG.info("Registering congress policy library service on node %s",
                 node.node_id)
        library = create_policy_library_service()
        services[api_base.LIBRARY_SERVICE_ID] = library
        node.register_service(library)

    if api:
        LOG.info("Registering congress API service on node %s", node.node_id)
        services['api'], services['api_service'] = create_api()
        node.register_service(services['api_service'])

    return services