Example #1
0
def cache_get_or_create_with_config(
    connection: 'Connection', cache_props: dict, query_id=None,
) -> 'APIResult':
    """
    Creates cache with provided configuration. Does nothing if the name
    is already in use.

    :param connection: connection to Ignite server,
    :param cache_props: cache configuration properties to create cache with
     in form of dictionary {property code: python value}.
     You must supply at least name (PROP_NAME),
    :param query_id: (optional) a value generated by client and returned as-is
     in response.query_id. When the parameter is omitted, a random value
     is generated,
    :return: API result data object. Contains zero status if cache was created,
     non-zero status and an error description otherwise.
    """

    prop_types = {}
    prop_values = {}
    for i, prop_item in enumerate(cache_props.items()):
        prop_code, prop_value = prop_item
        prop_name = 'property_{}'.format(i)
        prop_types[prop_name] = prop_map(prop_code)
        prop_values[prop_name] = prop_value
    prop_values['param_count'] = len(cache_props)

    query_struct = ConfigQuery(
        OP_CACHE_GET_OR_CREATE_WITH_CONFIGURATION,
        [
            ('param_count', Short),
        ] + list(prop_types.items()),
        query_id=query_id,
    )
    return query_struct.perform(connection, query_params=prop_values)
Example #2
0
def __cache_create_with_config(op_code, connection, cache_props, query_id):
    prop_types, prop_values = {}, {}
    for i, prop_item in enumerate(cache_props.items()):
        prop_code, prop_value = prop_item
        prop_name = 'property_{}'.format(i)
        prop_types[prop_name] = prop_map(prop_code)
        prop_values[prop_name] = prop_value
    prop_values['param_count'] = len(cache_props)

    following = [('param_count', Short)] + list(prop_types.items())
    query_struct = ConfigQuery(op_code, following, query_id=query_id)
    return query_perform(query_struct, connection, query_params=prop_values)
Example #3
0
def __cache_create_with_config(op_code, connection, cache_props, query_id):
    prop_types, prop_values = {}, {}
    is_expiry_policy_supported = connection.protocol_context.is_expiry_policy_supported()
    for i, prop_item in enumerate(cache_props.items()):
        prop_code, prop_value = prop_item
        if prop_code == PROP_EXPIRY_POLICY and not is_expiry_policy_supported:
            raise NotSupportedByClusterError("'ExpiryPolicy' API is not supported by the cluster")

        prop_name = 'property_{}'.format(i)
        prop_types[prop_name] = prop_map(prop_code)
        prop_values[prop_name] = prop_value
    prop_values['param_count'] = len(cache_props)

    following = [('param_count', Short)] + list(prop_types.items())
    query_struct = ConfigQuery(op_code, following, query_id=query_id)
    return query_perform(query_struct, connection, query_params=prop_values)