Exemplo n.º 1
0
def compute_regions(args):
    """
    method computing the region the journey has to be computed on
    The complexity comes from the fact that the regions in jormungandr can overlap.

    return the kraken instance keys

    rules are easy:
    we fetch the different regions the user can use for 'origin' and 'destination'
    we do the intersection and sort the list
    """
    from_regions = set()
    to_regions = set()
    if args['origin']:
        from_regions = set(i_manager.get_instances(object_id=args['origin']))
        # Note: if get_regions does not find any region, it raises a RegionNotFoundException

    if args['destination']:
        to_regions = set(i_manager.get_instances(object_id=args['destination']))

    if not from_regions:
        # we didn't get any origin, the region is in the destination's list
        possible_regions = to_regions
    elif not to_regions:
        # we didn't get any origin, the region is in the destination's list
        possible_regions = from_regions
    else:
        # we need the intersection set
        possible_regions = from_regions.intersection(to_regions)
        logging.getLogger(__name__).debug(
            "orig region = {o}, dest region = {d} => set = {p}".format(
                o=from_regions, d=to_regions, p=possible_regions
            )
        )

    if not possible_regions:
        raise RegionNotFound(
            custom_msg="cannot find a region with {o} and {d} in the same time".format(
                o=args['origin'], d=args['destination']
            )
        )

    sorted_regions = list(possible_regions)

    regions = sorted(sorted_regions, key=cmp_to_key(instances_comparator))

    return [r.name for r in regions]
Exemplo n.º 2
0
def compute_regions(args):
    """
    Method computing the possible regions on which the journey can be queried
    The complexity comes from the fact that the regions in Jormungandr can overlap.

    Rules are :
    - Fetch the different regions that can be used for 'origin' and 'destination'
    - Intersect both lists and sort it

    :return: Kraken instance keys
    """
    from_regions = set()
    to_regions = set()
    if args['origin']:
        from_regions = set(i_manager.get_instances(object_id=args['origin']))
        # Note: if get_regions does not find any region, it raises a RegionNotFoundException

    if args['destination']:
        to_regions = set(i_manager.get_instances(object_id=args['destination']))

    if not from_regions:
        # we didn't get any origin, the region is in the destination's list
        possible_regions = to_regions
    elif not to_regions:
        # we didn't get any origin, the region is in the destination's list
        possible_regions = from_regions
    else:
        # we need the intersection set
        possible_regions = from_regions.intersection(to_regions)
        logging.getLogger(__name__).debug(
            "orig region = {o}, dest region = {d} => set = {p}".format(
                o=from_regions, d=to_regions, p=possible_regions
            )
        )

    if not possible_regions:
        raise RegionNotFound(
            custom_msg="cannot find a region with {o} and {d} in the same time".format(
                o=args['origin'], d=args['destination']
            )
        )

    sorted_regions = list(possible_regions)

    regions = sort_regions(sorted_regions)

    return [r.name for r in regions]
Exemplo n.º 3
0
 def get(self, region):
     instance = i_manager.get_instances(region)[0]
     return {'geo_status': instance.autocomplete.geo_status(instance)}, 200