示例#1
0
    def get(self):
        response = {
            "jormungandr_version": __version__,
            "regions": []
        }
        regions = i_manager.get_regions()
        for key_region in regions:
            req = request_pb2.Request()

            req.requested_api = type_pb2.STATUS
            try:
                resp = i_manager.instances[key_region].send_and_receive(req,
                                                                        timeout=1000)

                raw_resp_dict = protobuf_to_dict(resp, use_enum_labels=True)

                resp_dict = marshal(raw_resp_dict['status'],
                                    fields.instance_status)
            except DeadSocketException:
                resp_dict = {
                    "status": "dead",
                    "error": {
                        "code": "dead_socket",
                        "value": "The region {} is dead".format(key_region)
                    }
                }
            resp_dict['region_id'] = key_region
            response['regions'].append(resp_dict)

        return response
示例#2
0
    def get(self):
        response = {
            "jormungandr_version": __version__,
            "regions": [],
            "bss_providers": [provider.status() for provider in bss_provider_manager.get_providers()],
        }
        regions = i_manager.get_regions()
        for key_region in regions:
            req = request_pb2.Request()
            instance = i_manager.instances[key_region]
            req.requested_api = type_pb2.STATUS
            try:
                resp = instance.send_and_receive(req, timeout=1000)

                raw_resp_dict = protobuf_to_dict(resp, use_enum_labels=True)
                add_common_status(raw_resp_dict, instance)

                if USE_SERPY:
                    resp_dict = CommonStatusSerializer(raw_resp_dict['status']).data
                else:
                    resp_dict = marshal(raw_resp_dict['status'], instance_status)
            except DeadSocketException:
                resp_dict = {
                    "status": "dead",
                    "realtime_proxies": [],
                    "error": {"code": "dead_socket", "value": "The region {} is dead".format(key_region)},
                }
            resp_dict['region_id'] = key_region
            response['regions'].append(resp_dict)

        return response
示例#3
0
 def regions(self, region=None, lon=None, lat=None):
     response = {'regions': []}
     regions = []
     if region or lon or lat:
         regions.append(self.get_region(region_str=region, lon=lon,
                                        lat=lat))
     else:
         regions = self.instances.keys()
     for key_region in regions:
         req = request_pb2.Request()
         req.requested_api = type_pb2.METADATAS
         try:
             resp = self.instances[key_region].send_and_receive(req,
                                                            timeout=1000)
             resp_dict = protobuf_to_dict(resp.metadatas)
         except DeadSocketException:
             resp_dict = {
                 "status": "dead",
                 "error" : {
                     "code": "dead_socket",
                     "value": "The region %s is dead".format(key_region)
                 }
             }
         resp_dict['region_id'] = key_region
         response['regions'].append(resp_dict)
     return response
示例#4
0
    def get(self):
        response = {
            "jormungandr_version": __version__,
            "regions": [],
            "bss_providers": [provider.status() for provider in bss_provider_manager.get_providers()],
        }

        regions = i_manager.get_regions()
        for key_region in regions:
            req = request_pb2.Request()
            instance = i_manager.instances[key_region]
            req.requested_api = type_pb2.STATUS
            try:
                resp = instance.send_and_receive(req, timeout=1000)

                raw_resp_dict = protobuf_to_dict(resp, use_enum_labels=True)
                add_common_status(raw_resp_dict, instance)
                resp_dict = CommonStatusSerializer(raw_resp_dict['status']).data
            except DeadSocketException:
                resp_dict = {
                    "status": "dead",
                    "realtime_proxies": [],
                    "error": {"code": "dead_socket", "value": "The region {} is dead".format(key_region)},
                }
            resp_dict['region_id'] = key_region
            response['regions'].append(resp_dict)

        # if we use our implementation of redisCache display the status
        cache_status_op = getattr(cache.cache, "status", None)
        if callable(cache_status_op):
            response['redis'] = cache_status_op()

        return response
示例#5
0
 def get(self, region):
     response = protobuf_to_dict(i_manager.dispatch({},
                                                    "status",
                                                    instance_name=region),
                                 use_enum_labels=True)
     instance = i_manager.instances[region]
     response['status']['parameters'] = instance
     return response, 200
示例#6
0
        def wrapper(*args, **kwargs):
            objects = f(*args, **kwargs)
            if has_invalid_reponse_code(objects) or journeys_absent(objects):
                return objects

            for j in objects[0]['journeys']:
                if "sections" not in j:
                    continue
                for s in j['sections']:
                    # For a section with type = on_demand_transport
                    if s.get('type') == 'on_demand_transport':
                        # get network uri from the link
                        network_id = next(
                            (link['id'] for link in s.get('links', []) if link['type'] == "network"), None
                        )
                        if not network_id:
                            continue

                        region = kwargs.get('region')
                        if region is None:
                            continue

                        # Get the Network details and verify if it contains codes with type = "app_code"
                        instance = i_manager.instances.get(region)
                        network_details = instance.ptref.get_objs(
                            type_pb2.NETWORK, 'network.uri={}'.format(network_id)
                        )
                        network_dict = protobuf_to_dict(next(network_details))
                        app_value = next(
                            (
                                code['value']
                                for code in network_dict.get('codes', [])
                                if code.get('type') == "app_code"
                            ),
                            None,
                        )
                        if not app_value:
                            continue

                        # Prepare parameters for the deeplink of external service
                        from_embedded_type = s.get('from').get('embedded_type')
                        to_embedded_type = s.get('to').get('embedded_type')
                        from_coord = s.get('from').get(from_embedded_type).get('coord')
                        to_coord = s.get('to').get(to_embedded_type).get('coord')
                        args = dict()
                        date_utc = local_str_date_to_utc(s.get('departure_date_time'), instance.timezone)
                        args['departure_latitude'] = from_coord.get('lat')
                        args['departure_longitude'] = from_coord.get('lon')
                        args['destination_latitude'] = to_coord.get('lat')
                        args['destination_longitude'] = to_coord.get('lon')
                        args['requested_departure_time'] = dt_to_str(date_utc, _format=UTC_DATETIME_FORMAT)
                        url = "{}://home?".format(app_value)
                        tad_link = make_external_service_link(
                            url=url, rel="tad_dynamic_link", _type="tad_dynamic_link", **args
                        )
                        s['links'].append(tad_link)

            return objects
示例#7
0
def render_from_protobuf(pb_resp, format, callback, status=200):
    if pb_resp.status_code:
        status = pb_resp.status_code
        pb_resp.ClearField("status_code")
    if format == 'pb':
        return Response(pb_resp.SerializeToString(),
                        mimetype='application/octet-stream',
                        status=status)
    else:
        return render(protobuf_to_dict(pb_resp, use_enum_labels=True), format,
                      callback, status)
示例#8
0
 def get(self, region=None):
     args = self.parsers["get"].parse_args()
     if region is None:
         region = i_manager.key_of_id(args["origin"])
     response = i_manager.dispatch(args, "isochrone", instance_name=region)
     if response.journeys:
         (before, after) = extremes(response, request)
         if before and after:
             response.prev = before
             response.next = after
     return protobuf_to_dict(response, use_enum_labels=True), 200
示例#9
0
 def get(self, region=None, lon=None, lat=None):
     region_str = i_manager.get_region(region, lon, lat)
     response = protobuf_to_dict(
         i_manager.dispatch({}, "status", instance_name=region_str), use_enum_labels=True
     )
     instance = i_manager.instances[region_str]
     add_common_status(response, instance)
     response['status']['parameters'] = instance
     response['status']['traveler_profiles'] = travelers_profile.TravelerProfile.get_profiles_by_coverage(
         region_str
     )
     return response, 200
示例#10
0
文件: Status.py 项目: linvan/navitia
 def get(self, region):
     response = protobuf_to_dict(i_manager.dispatch({},
                                                    "status",
                                                    instance_name=region),
                                 use_enum_labels=True)
     instance = i_manager.instances[region]
     response['status']["is_open_data"] = instance.is_free
     response['status']['parameters'] = instance
     response['status'][
         'traveler_profiles'] = travelers_profile.TravelerProfile.get_profiles_by_coverage(
             region)
     return response, 200
示例#11
0
文件: Status.py 项目: xlqian/navitia
    def get(self, region=None, lon=None, lat=None):
        region_str = i_manager.get_region(region, lon, lat)
        response = protobuf_to_dict(i_manager.dispatch(
            {}, "status", instance_name=region_str),
                                    use_enum_labels=True)
        instance = i_manager.instances[region_str]
        add_common_status(response, instance)
        response['status']['parameters'] = instance
        response['status'][
            'traveler_profiles'] = travelers_profile.TravelerProfile.get_profiles_by_coverage(
                region_str)
        logging.getLogger(__name__).info("status reponse: %s", response)
        response['status']['configuration_database'] = (
            'connected' if can_connect_to_database() else 'no_SQL_connection')

        return response, 200
示例#12
0
    def get(self):
        response = {
            "jormungandr_version":
            __version__,
            "regions": [],
            "bss_providers": [
                provider.status()
                for provider in bss_provider_manager.bss_providers
            ]
        }
        regions = i_manager.get_regions()
        for key_region in regions:
            req = request_pb2.Request()

            req.requested_api = type_pb2.STATUS
            try:
                resp = i_manager.instances[key_region].send_and_receive(
                    req, timeout=1000)

                raw_resp_dict = protobuf_to_dict(resp, use_enum_labels=True)
                raw_resp_dict['status'][
                    "is_open_service"] = i_manager.instances[
                        key_region].is_free
                raw_resp_dict['status']["is_open_data"] = i_manager.instances[
                    key_region].is_open_data
                raw_resp_dict['status']['realtime_proxies'] = []
                for realtime_proxy in i_manager.instances[
                        key_region].realtime_proxy_manager.realtime_proxies.values(
                        ):
                    raw_resp_dict['status']['realtime_proxies'].append(
                        realtime_proxy.status())

                resp_dict = marshal(raw_resp_dict['status'],
                                    fields.instance_status)
            except DeadSocketException:
                resp_dict = {
                    "status": "dead",
                    "error": {
                        "code": "dead_socket",
                        "value": "The region {} is dead".format(key_region)
                    }
                }
            resp_dict['region_id'] = key_region
            response['regions'].append(resp_dict)

        return response
示例#13
0
 def get(self, region):
     response = protobuf_to_dict(i_manager.dispatch({},
                                                    "status",
                                                    instance_name=region),
                                 use_enum_labels=True)
     instance = i_manager.instances[region]
     is_open_data = True
     if not app.config['DISABLE_DATABASE']:
         if instance and instance.name:
             instance_db = models.Instance.get_by_name(instance.name)
             if instance_db:
                 is_open_data = instance_db.is_free
     response['status']["is_open_data"] = is_open_data
     response['status']['parameters'] = instance
     response['status'][
         'traveler_profiles'] = travelers_profile.TravelerProfile.get_profiles_by_coverage(
             region)
     return response, 200
示例#14
0
    def get(self, region=None):
        args = self.parsers["get"].parse_args()

        #default value for compatibility with v1
        args["min_nb_journeys"] = None
        args["max_nb_journeys"] = None
        args["show_codes"] = False

        if region is None:
            region = i_manager.key_of_id(args["origin"])
        response = i_manager.dispatch(args, "journeys", instance_name=region)
        if response.journeys:
            (before, after) = extremes(response, request)
            if before and after:
                response.prev = before
                response.next = after

        return protobuf_to_dict(response, use_enum_labels=True), 200
示例#15
0
 def get(self, region):
     response = protobuf_to_dict(i_manager.dispatch({},
                                                    "status",
                                                    instance_name=region),
                                 use_enum_labels=True)
     instance = i_manager.instances[region]
     response['status']["is_open_data"] = instance.is_open_data
     response['status']["is_open_service"] = instance.is_free
     response['status']['parameters'] = instance
     response['status'][
         'traveler_profiles'] = travelers_profile.TravelerProfile.get_profiles_by_coverage(
             region)
     response['status']['realtime_proxies'] = []
     for realtime_proxy in instance.realtime_proxy_manager.realtime_proxies.values(
     ):
         response['status']['realtime_proxies'].append(
             realtime_proxy.status())
     return response, 200
示例#16
0
 def get(self, region):
     args = self.parsers["get"].parse_args()
     args["interface_version"] = 0
     response = i_manager.dispatch(args, self.api, instance_name=region)
     return protobuf_to_dict(response, use_enum_labels=True), 200
示例#17
0
 def get(self, region):
     args = self.parsers["get"].parse_args()
     response = i_manager.dispatch(args,
                                   self.resource_type,
                                   instance_name=region)
     return protobuf_to_dict(response, use_enum_labels=True), 200
示例#18
0
文件: Places.py 项目: skywave/navitia
 def get(self, region):
     args = self.parsers["get"].parse_args()
     if len(args['q']) == 0:
         abort(400, message="Search word absent")
     response = i_manager.dispatch(args, "places", instance_name=region)
     return protobuf_to_dict(response, use_enum_labels=True), 200
示例#19
0
文件: Status.py 项目: skywave/navitia
 def get(self, region):
     response = i_manager.dispatch([], "status", instance_name=region)
     return protobuf_to_dict(response, use_enum_labels=True), 200