Beispiel #1
0
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)
Beispiel #2
0
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
Beispiel #3
0
def _entity_references(dss_resource_name: str,
                       utm_client: infrastructure.DSSTestSession,
                       area: s2sphere.LatLngRect,
                       start_time: datetime.datetime,
                       end_time: datetime.datetime,
                       alt_min_m: float = 0,
                       alt_max_m: float = 3048) -> FetchedEntityReferences:
    # Query DSS for Entities in 4D volume of interest
    request_body = {
        'area_of_interest':
        scd.make_vol4(start_time,
                      end_time,
                      alt_min_m,
                      alt_max_m,
                      polygon=scd.make_polygon(latlngrect=area))
    }
    url = '/dss/v1/{}/query'.format(dss_resource_name)
    entity_references = FetchedEntityReferences(
        fetch.query_and_describe(utm_client,
                                 'POST',
                                 url,
                                 json=request_body,
                                 scope=scd.SCOPE_SC))
    entity_references['entity_type'] = dss_resource_name
    return entity_references
Beispiel #4
0
def delete_subscription(utm_client: infrastructure.DSSTestSession,
                        subscription_id: str) -> MutatedSubscription:
  url = '/dss/v1/subscriptions/{}'.format(subscription_id)
  result = MutatedSubscription(fetch.query_and_describe(
    utm_client, 'DELETE', url, scope=scd.SCOPE_SC))
  result['mutation'] = 'delete'
  return result
Beispiel #5
0
def subscription(utm_client: infrastructure.DSSTestSession,
                 subscription_id: str) -> FetchedSubscription:
    url = '/dss/v1/subscriptions/{}'.format(subscription_id)
    result = fetch.query_and_describe(utm_client,
                                      'GET',
                                      url,
                                      scope=scd.SCOPE_SC)
    return FetchedSubscription(result)
Beispiel #6
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))
Beispiel #7
0
def _full_entity(uss_resource_name: str,
                 uss_base_url: str,
                 entity_id: str,
                 utm_client: infrastructure.DSSTestSession):
  uss_entity_url = uss_base_url + '/uss/v1/{}s/{}'.format(uss_resource_name, entity_id)

  # Query the USS for Entity details
  entity = FetchedEntity(fetch.query_and_describe(
    utm_client, 'GET', uss_entity_url, scope=scd.SCOPE_SC))
  entity['id_requested'] = entity_id
  entity['entity_type'] = uss_resource_name
  return entity
Beispiel #8
0
def delete_isa(utm_client: infrastructure.DSSTestSession,
               entity_id: str,
               isa_version: str) -> MutatedISA:
  url = '/v1/dss/identification_service_areas/{}/{}'.format(entity_id, isa_version)
  dss_response = MutatedISAResponse(fetch.query_and_describe(
    utm_client, 'DELETE', url, scope=rid.SCOPE_WRITE))
  dss_response['mutation'] = 'delete'

  # Notify subscribers
  notifications: Dict[str, fetch.Query] = {}
  try:
    subscribers = dss_response.subscribers
  except ValueError:
    subscribers = []
  for subscriber in subscribers:
    body = {
      'subscriptions': subscriber.subscriptions
    }
    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)
Beispiel #9
0
def flight_details(utm_client: infrastructure.DSSTestSession,
                   flights_url: str,
                   id: str,
                   enhanced_details: bool = False) -> FetchedUSSFlightDetails:
    suffix = '?enhanced=true' if enhanced_details else ''
    scope = ' '.join([rid.SCOPE_READ, rid.UPP2_SCOPE_ENHANCED_DETAILS
                      ]) if enhanced_details else rid.SCOPE_READ
    result = FetchedUSSFlightDetails(
        fetch.query_and_describe(utm_client,
                                 'GET',
                                 flights_url +
                                 '/{}/details{}'.format(id, suffix),
                                 scope=scope))
    result['requested_id'] = id
    return result
Beispiel #10
0
def flights(utm_client: infrastructure.DSSTestSession, flights_url: str,
            area: s2sphere.LatLngRect,
            include_recent_positions: bool) -> FetchedUSSFlights:
    result = fetch.query_and_describe(
        utm_client,
        'GET',
        flights_url,
        params={
            'view':
            '{},{},{},{}'.format(
                area.lat_lo().degrees,
                area.lng_lo().degrees,
                area.lat_hi().degrees,
                area.lng_hi().degrees,
            ),
            'include_recent_positions':
            'true' if include_recent_positions else 'false',
        },
        scope=rid.SCOPE_READ)
    return FetchedUSSFlights(result)
Beispiel #11
0
def put_subscription(utm_client: infrastructure.DSSTestSession,
                     area: s2sphere.LatLngRect,
                     start_time: datetime.datetime,
                     end_time: datetime.datetime,
                     base_url: str,
                     subscription_id: str,
                     min_alt_m: float=0,
                     max_alt_m: float=3048,
                     old_version: int=0) -> MutatedSubscription:
  body = {
    'extents': scd.make_vol4(
      start_time, end_time, min_alt_m, max_alt_m,
      polygon=scd.make_polygon(latlngrect=area)),
    'old_version': old_version,
    'uss_base_url': base_url,
    'notify_for_operations': True,
    'notify_for_constraints': True,
  }
  url = '/dss/v1/subscriptions/{}'.format(subscription_id)
  result = MutatedSubscription(fetch.query_and_describe(
    utm_client, 'PUT', url, json=body, scope=scd.SCOPE_SC))
  result['mutation'] = 'create' if old_version == 0 else 'update'
  return result