def update_with_results(self, batch_propagation): uuid = batch_propagation.get_uuid() response = AdamObjects._get_json(self, uuid) if response is None: raise RuntimeError("Could not retrieve results for " + uuid) batch_propagation.set_summary(response.get('summary'))
def get_children(self, uuid): child_response_list = AdamObjects._get_children_json(self, uuid) children = [] for childJson, child_runnable_state, child_type in child_response_list: # All child types should be SinglePropagation, but ignore those # that aren't just in case. if not child_type == 'SinglePropagation': print('Skipping child of unexpected type ' + child_type) continue # Values in [] are guaranteed to be present. Values in .get() may be missing. childOpmParams = OpmParams.fromJsonResponse( childJson['propagationParameters']['opm']) childPropParams = PropagationParams.fromJsonResponse( childJson['propagationParameters'], childJson.get('description')) childProp = SinglePropagation(childPropParams, childOpmParams) childProp.set_uuid(childJson['uuid']) childProp.set_runnable_state(child_runnable_state) childProp.set_ephemeris(childJson.get('ephemeris')) childProp.set_final_state_vector(childJson.get('finalStateVector')) children.append(childProp) return children
def insert(self, targeted_propagation, project_uuid): data = self._build_targeted_propagation_creation_data( targeted_propagation.get_propagation_params(), targeted_propagation.get_opm_params(), targeted_propagation.get_targeting_params(), project_uuid ) targeted_propagation.set_uuid(AdamObjects._insert(self, data))
def test_get_in_project_json(self): rest = _RestProxyForTest() adam_objects = AdamObjects(rest, 'MyType') rest.expect_get("/adam_object/by_project/MyType/project_uuid", 200, {'items': []}) json = adam_objects._get_in_project_json('project_uuid') self.assertEqual(0, len(json)) rest.expect_get( "/adam_object/by_project/MyType/project_uuid", 200, {'items': [{ 'anyKey': 'anyVal' }, { 'anyKey': 'anyOtherVal' }]}) json = adam_objects._get_in_project_json('project_uuid') self.assertEqual(2, len(json)) self.assertEqual({'anyKey': 'anyVal'}, json[0]) self.assertEqual({'anyKey': 'anyOtherVal'}, json[1]) rest.expect_get("/adam_object/by_project/MyType/project_uuid", 404, {}) json = adam_objects._get_in_project_json('project_uuid') self.assertEqual(json, []) rest.expect_get("/adam_object/by_project/MyType/project_uuid", 403, {}) with self.assertRaises(RuntimeError): adam_objects._get_in_project_json('project_uuid')
def test_insert(self): rest = _RestProxyForTest() adam_objects = AdamObjects(rest, 'MyType') expected_data = {} def check_input(data_dict): self.assertEqual(expected_data, data_dict) return True expected_data = {'anyKey': 'anyVal'} rest.expect_post("/adam_object/single/MyType", check_input, 200, {'uuid': 'uuid1'}) uuid = adam_objects._insert({'anyKey': 'anyVal'}) self.assertEqual('uuid1', uuid) rest.expect_post("/adam_object/single/MyType", check_input, 404, {}) with self.assertRaises(RuntimeError): adam_objects._insert({'anyKey': 'anyVal'})
def test_get_children_json(self): rest = _RestProxyForTest() adam_objects = AdamObjects(rest, 'MyType') rest.expect_get("/adam_object/by_parent/MyType/uuid1", 200, { 'childTypes': ['ChildType'], 'childUuids': ['childUuid1'] }) rest.expect_get("/adam_object/single/ChildType/childUuid1", 200, {'anyJson': 5}) rest.expect_get( "/adam_object/runnable_state/single/ChildType/childUuid1", 200, { 'uuid': 'childUuid1', 'calculationState': 'COMPLETED' }) children_json = adam_objects._get_children_json('uuid1') self.assertEqual(1, len(children_json)) child_json, child_runnable_state, child_type = children_json[0] self.assertEqual({'anyJson': 5}, child_json) self.assertEqual('childUuid1', child_runnable_state.get_uuid()) self.assertEqual('COMPLETED', child_runnable_state.get_calc_state()) self.assertIsNone(child_runnable_state.get_error()) self.assertEqual('ChildType', child_type) rest.expect_get("/adam_object/by_parent/MyType/uuid1", 404, {}) json = adam_objects._get_children_json('uuid1') self.assertEqual([], json) rest.expect_get("/adam_object/by_parent/MyType/uuid1", 403, {}) with self.assertRaises(RuntimeError): adam_objects._get_children_json('uuid1')
def update_with_results(self, targeted_propagation): uuid = targeted_propagation.get_uuid() response = AdamObjects._get_json(self, uuid) if response is None: raise RuntimeError("Could not retrieve results for " + uuid) ephemeris = response.get('ephemeris') maneuver = None if 'maneuverX' in response: maneuver = [response['maneuverX'], response['maneuverY'], response['maneuverZ']] targeted_propagation.set_ephemeris(ephemeris) targeted_propagation.set_maneuver(maneuver)
def test_delete(self): rest = _RestProxyForTest() adam_objects = AdamObjects(rest, 'MyType') rest.expect_delete("/adam_object/single/MyType/uuid1", 204) adam_objects.delete('uuid1') # 200 isn't a valid return value for delete calls right now rest.expect_delete("/adam_object/single/MyType/uuid1", 200) with self.assertRaises(RuntimeError): adam_objects.delete('uuid1') rest.expect_delete("/adam_object/single/MyType/uuid1", 404) with self.assertRaises(RuntimeError): adam_objects.delete('uuid1')
def get(self, uuid): response = AdamObjects._get_json(self, uuid) if response is None: return None # Values in [] are guaranteed to be present. Values in .get() may be missing. opmParams = OpmParams.fromJsonResponse( response['templatePropagationParameters']['opm']) propParams = PropagationParams.fromJsonResponse( response['templatePropagationParameters'], response.get('description')) batch_propagation = BatchPropagation(propParams, opmParams) batch_propagation.set_uuid(response['uuid']) batch_propagation.set_summary(response.get('summary')) return batch_propagation
def test_get_runnable_states(self): rest = _RestProxyForTest() adam_objects = AdamObjects(rest, 'MyType') # Empty return value rest.expect_get( "/adam_object/runnable_state/by_project/MyType/project_uuid", 200, {'items': []}) runnable_states = adam_objects.get_runnable_states('project_uuid') self.assertEqual(0, len(runnable_states)) rest.expect_get( "/adam_object/runnable_state/by_project/MyType/project_uuid", 200, { 'items': [{ 'uuid': 'uuid1', 'calculationState': 'PENDING', }, { 'uuid': 'uuid2', 'calculationState': 'FAILED', 'error': 'some error' }] }) runnable_states = adam_objects.get_runnable_states('project_uuid') self.assertEqual(2, len(runnable_states)) self.assertEqual('uuid1', runnable_states[0].get_uuid()) self.assertEqual('PENDING', runnable_states[0].get_calc_state()) self.assertIsNone(runnable_states[0].get_error()) self.assertEqual('uuid2', runnable_states[1].get_uuid()) self.assertEqual('FAILED', runnable_states[1].get_calc_state()) self.assertEqual('some error', runnable_states[1].get_error()) rest.expect_get( "/adam_object/runnable_state/by_project/MyType/project_uuid", 404, {}) runnable_states = adam_objects.get_runnable_states('project_uuid') self.assertEqual(runnable_states, []) rest.expect_get( "/adam_object/runnable_state/by_project/MyType/project_uuid", 403, {}) with self.assertRaises(RuntimeError): adam_objects.get_runnable_states('project_uuid')
def test_get_json(self): rest = _RestProxyForTest() adam_objects = AdamObjects(rest, 'MyType') rest.expect_get("/adam_object/single/MyType/uuid1", 200, {'anyKey': 'anyVal'}) json = adam_objects._get_json('uuid1') self.assertEqual({'anyKey': 'anyVal'}, json) rest.expect_get("/adam_object/single/MyType/uuid1", 404, {}) json = adam_objects._get_json('uuid1') self.assertEqual(json, None) rest.expect_get("/adam_object/single/MyType/uuid1", 403, {}) with self.assertRaises(RuntimeError): adam_objects._get_json('uuid1')
def get(self, uuid): response = AdamObjects._get_json(self, uuid) if response is None: return None opmParams = OpmParams.fromJsonResponse( response['initialPropagationParameters']['opm']) propParams = PropagationParams.fromJsonResponse( response['initialPropagationParameters'], response.get('description')) targetingParams = TargetingParams.fromJsonResponse( response['targetingParameters']) targeted_propagation = TargetedPropagation( propParams, opmParams, targetingParams) uuid = response['uuid'] ephemeris = response.get('ephemeris') maneuver = None if 'maneuverX' in response: maneuver = [response['maneuverX'], response['maneuverY'], response['maneuverZ']] targeted_propagation.set_uuid(uuid) targeted_propagation.set_ephemeris(ephemeris) targeted_propagation.set_maneuver(maneuver) return targeted_propagation
def test_get_runnable_state(self): rest = _RestProxyForTest() adam_objects = AdamObjects(rest, 'MyType') rest.expect_get("/adam_object/runnable_state/single/MyType/uuid1", 200, { 'uuid': 'uuid1', 'calculationState': 'PENDING', }) runnable_state = adam_objects.get_runnable_state('uuid1') self.assertEqual('uuid1', runnable_state.get_uuid()) self.assertEqual('PENDING', runnable_state.get_calc_state()) self.assertIsNone(runnable_state.get_error()) rest.expect_get("/adam_object/runnable_state/single/MyType/uuid1", 404, {}) runnable_state = adam_objects.get_runnable_state('uuid1') self.assertEqual(runnable_state, None) rest.expect_get("/adam_object/runnable_state/single/MyType/uuid1", 403, {}) with self.assertRaises(RuntimeError): adam_objects.get_runnable_state('uuid1')
def __init__(self, rest): AdamObjects.__init__(self, rest, 'TargetedPropagation')
def insert(self, batch_propagation, project_uuid): data = self._build_batch_propagation_creation_data( batch_propagation.get_propagation_params(), batch_propagation.get_opm_params(), project_uuid) batch_propagation.set_uuid(AdamObjects._insert(self, data))
def __init__(self, rest): AdamObjects.__init__(self, rest, 'BatchPropagation')