Exemplo n.º 1
0
Arquivo: rid.py Projeto: interuss/dss
def put_subscription(utm_client: infrastructure.DSSTestSession,
                     area: s2sphere.LatLngRect,
                     start_time: datetime.datetime,
                     end_time: datetime.datetime,
                     callback_url: str,
                     subscription_id: str,
                     subscription_version: Optional[str]=None) -> MutatedSubscription:
  body = {
    'extents': {
      'spatial_volume': {
        'footprint': {
          'vertices': rid.vertices_from_latlng_rect(area)
        },
        'altitude_lo': 0,
        'altitude_hi': 3048,
      },
      'time_start': start_time.strftime(rid.DATE_FORMAT),
      'time_end': end_time.strftime(rid.DATE_FORMAT),
    },
    'callbacks': {
      'identification_service_area_url': callback_url
    },
  }
  if subscription_version is None:
    url = '/v1/dss/subscriptions/{}'.format(subscription_id)
  else:
    url = '/v1/dss/subscriptions/{}/{}'.format(subscription_id, subscription_version)
  result = MutatedSubscription(fetch.query_and_describe(
    utm_client, 'PUT', url, json=body, scope=rid.SCOPE_READ))
  result['mutation'] = 'create' if subscription_version is None else 'update'
  return result
Exemplo n.º 2
0
def _subscribe_rid(resources: ResourceSet, callback_url: str) -> None:
    _clear_existing_rid_subscription(resources, 'old')

    body = {
        'extents': {
            'spatial_volume': {
                'footprint': {
                    'vertices': rid.vertices_from_latlng_rect(resources.area)
                },
                'altitude_lo': 0,
                'altitude_hi': 3048,
            },
            'time_start': resources.start_time.strftime(rid.DATE_FORMAT),
            'time_end': resources.end_time.strftime(rid.DATE_FORMAT),
        },
        'callbacks': {
            'identification_service_area_url': callback_url
        },
    }
    resp = resources.dss_client.put(_rid_subscription_url(),
                                    json=body,
                                    scope=rid.SCOPE_READ)
    if resp.status_code != 200:
        msg = 'Failed to create RID Subscription'
        msg += ' -> ' + resources.logger.log_new('ridsubscription',
                                                 _describe_response(resp, msg))
        raise SubscriptionManagementError(msg)

    msg = 'Created RID Subscription successfully'
    resources.logger.log_new('ridsubscription', _describe_response(resp, msg))
Exemplo n.º 3
0
def isas(utm_client: infrastructure.DSSTestSession, box: s2sphere.LatLngRect,
         start_time: datetime.datetime,
         end_time: datetime.datetime) -> FetchedISAs:
    area = rid.geo_polygon_string(rid.vertices_from_latlng_rect(box))
    url = '/v1/dss/identification_service_areas?area={}&earliest_time={}&latest_time={}'.format(
        area, start_time.strftime(rid.DATE_FORMAT),
        end_time.strftime(rid.DATE_FORMAT))
    return FetchedISAs(
        fetch.query_and_describe(utm_client, 'GET', url, scope=rid.SCOPE_READ))
Exemplo n.º 4
0
def poll_rid_isas(resources: ResourceSet,
                  box: s2sphere.LatLngRect) -> PollResult:
    # Query DSS for ISAs in 2D+time area of interest
    area = rid.geo_polygon_string(rid.vertices_from_latlng_rect(box))
    url = '/v1/dss/identification_service_areas?area={}&earliest_time={}&latest_time={}'.format(
        area, resources.start_time.strftime(rid.DATE_FORMAT),
        resources.end_time.strftime(rid.DATE_FORMAT))
    t0 = datetime.datetime.utcnow()
    resp = resources.dss_client.get(url, scope=rid.SCOPE_READ)
    t1 = datetime.datetime.utcnow()

    # Handle overall errors
    if resp.status_code != 200:
        return PollResult(t0,
                          t1,
                          error=PollError(resp,
                                          'Failed to search ISAs in DSS'))
    try:
        json = resp.json()
    except ValueError:
        return PollResult(
            t0,
            t1,
            error=PollError(resp,
                            'DSS response to search ISAs was not valid JSON'))

    # Extract ISAs from response
    isa_list = json.get('service_areas', [])
    isas = {}
    for isa in isa_list:
        if 'id' not in isa:
            return PollResult(
                t0,
                t1,
                error=PollError(
                    resp,
                    'DSS response to search ISAs included ISA without id'))
        if 'owner' not in isa:
            return PollResult(
                t0,
                t1,
                error=PollError(
                    resp,
                    'DSS response to search ISAs included ISA without owner'))
        isa_id = '{} ({})'.format(isa['id'], isa['owner'])
        del isa['id']
        del isa['owner']
        isas[isa_id] = isa
    return PollResult(t0, t1, success=PollSuccess(isas))
Exemplo n.º 5
0
Arquivo: rid.py Projeto: interuss/dss
def put_isa(utm_client: infrastructure.DSSTestSession,
            area: s2sphere.LatLngRect,
            start_time: datetime.datetime,
            end_time: datetime.datetime,
            flights_url: str,
            entity_id: str,
            isa_version: Optional[str]=None) -> MutatedISA:
  extents = {
    'spatial_volume': {
      'footprint': {
        'vertices': rid.vertices_from_latlng_rect(area)
      },
      'altitude_lo': 0,
      'altitude_hi': 3048,
    },
    'time_start': start_time.strftime(rid.DATE_FORMAT),
    'time_end': end_time.strftime(rid.DATE_FORMAT),
  }
  body = {
    'extents': extents,
    'flights_url': flights_url,
  }
  if isa_version is None:
    url = '/v1/dss/identification_service_areas/{}'.format(entity_id)
  else:
    url = '/v1/dss/identification_service_areas/{}/{}'.format(entity_id, isa_version)
  dss_response = MutatedISAResponse(fetch.query_and_describe(
    utm_client, 'PUT', url, json=body, scope=rid.SCOPE_WRITE))
  dss_response['mutation'] = 'create' if isa_version is None else 'update'

  # Notify subscribers
  notifications: Dict[str, fetch.Query] = {}
  try:
    subscribers = dss_response.subscribers
    isa = dss_response.isa
  except ValueError:
    subscribers = []
    isa = None
  for subscriber in subscribers:
    body = {
      'service_area': isa,
      'subscriptions': subscriber.subscriptions,
      'extents': extents
    }
    url = '{}/{}'.format(subscriber.url, entity_id)
    notifications[subscriber.url] = fetch.query_and_describe(
      utm_client, 'POST', url, json=body, scope=rid.SCOPE_WRITE)

  return MutatedISA(dss_response=dss_response, notifications=notifications)