def _query_subscription_query(self, filters): query = SubscriptionDao.query.order_by(desc(SubscriptionDao.updated)) for f in filters: query = self._filter_service.apply_filter(f, query, SubscriptionDao, [subscription_schema()]) return query
def update_subscription_name(subscription, name): """ :type subscription: dart.model.subscription.Subscription """ source_subscription = subscription.copy() subscription = default_and_validate(subscription, subscription_schema()) subscription.data.name = name return patch_difference(SubscriptionDao, source_subscription, subscription)
def subgraph_definition_schema(trigger_schemas, action_schemas, datastore_schema): return base_schema({ 'type': 'object', 'properties': { 'name': {'type': 'string'}, 'description': {'type': 'string'}, 'engine_name': {'type': 'string'}, 'related_type': {'type': 'string', 'maxLength': 50}, 'related_is_a': {'type': 'string', 'maxLength': 50}, 'actions': { 'x-schema-form': {'type': 'tabarray', 'title': "{{ value.name }}"}, 'type': 'array', 'items': {'anyOf': action_schemas}, 'default': [] }, 'datastores': { 'x-schema-form': {'type': 'tabarray', 'title': "{{ value.name }}"}, 'type': 'array', 'items': datastore_schema, 'default': [] }, 'datasets': { 'x-schema-form': {'type': 'tabarray', 'title': "{{ value.name }}"}, 'type': 'array', 'items': dataset_schema(), 'default': [] }, 'events': { 'x-schema-form': {'type': 'tabarray', 'title': "{{ value.name }}"}, 'type': 'array', 'items': event_schema(), 'default': [] }, 'subscriptions': { 'x-schema-form': {'type': 'tabarray', 'title': "{{ value.name }}"}, 'type': 'array', 'items': subscription_schema(), 'default': [] }, 'triggers': { 'x-schema-form': {'type': 'tabarray', 'title': "{{ value.name }}"}, 'type': 'array', 'items': {'anyOf': trigger_schemas}, 'default': [] }, 'workflows': { 'x-schema-form': {'type': 'tabarray', 'title': "{{ value.name }}"}, 'type': 'array', 'items': workflow_schema(), 'default': [] }, 'icon': {'type': ['string', 'null']}, 'md_icon': {'type': ['string', 'null']}, }, 'additionalProperties': False, 'required': ['name', 'engine_name', 'related_type', 'related_is_a'] })
def test_subscription_schema(self): start = 's3://my-test-bucket/impala/impala' end = 's3://my-test-bucket/impala/install' regex = '.*\\.rpm' state = None sub = Subscription(data=SubscriptionData('test-subscription', 'ABC123', start, end, regex, state=state)) obj_before = sub.to_dict() sub = default_and_validate(sub, subscription_schema()) # state should be defaulted to INACTIVE self.assertNotEqual(obj_before, sub.to_dict())
def test_subscription_schema(self): start = 's3://my-test-bucket/impala/impala' end = 's3://my-test-bucket/impala/install' regex = '.*\\.rpm' state = None sub = Subscription(data=SubscriptionData( 'test-subscription', 'ABC123', start, end, regex, state=state)) obj_before = sub.to_dict() sub = default_and_validate(sub, subscription_schema()) # state should be defaulted to INACTIVE self.assertNotEqual(obj_before, sub.to_dict())
def test_subscription_schema_invalid(self): with self.assertRaises(DartValidationException) as context: start = 's3://my-test-bucket/impala/impala' end = 's3://my-test-bucket/impala/install' regex = '.*\\.rpm' name = None sub = Subscription(data=SubscriptionData(name, 'ABC123', start, end, regex)) # should fail because the name is missing default_and_validate(sub, subscription_schema()) self.assertTrue(isinstance(context.exception, DartValidationException))
def test_subscription_schema_invalid(self): with self.assertRaises(DartValidationException) as context: start = 's3://my-test-bucket/impala/impala' end = 's3://my-test-bucket/impala/install' regex = '.*\\.rpm' name = None sub = Subscription( data=SubscriptionData(name, 'ABC123', start, end, regex)) # should fail because the name is missing default_and_validate(sub, subscription_schema()) self.assertTrue(isinstance(context.exception, DartValidationException))
def save_subscription(self, subscription, commit_and_generate=True, flush=False): """ :type subscription: dart.model.subscription.Subscription """ subscription = default_and_validate(subscription, subscription_schema()) subscription_dao = SubscriptionDao() subscription_dao.id = random_id() subscription.data.state = SubscriptionState.ACTIVE subscription_dao.data = subscription.data.to_dict() db.session.add(subscription_dao) if flush: db.session.flush() subscription = subscription_dao.to_model() if commit_and_generate: db.session.commit() subscription = subscription_dao.to_model() return subscription
def save_subscription(self, subscription, commit_and_generate=True, flush=False): """ :type subscription: dart.model.subscription.Subscription """ subscription = default_and_validate(subscription, subscription_schema()) subscription_dao = SubscriptionDao() subscription_dao.id = random_id() subscription.data.state = SubscriptionState.ACTIVE subscription_dao.data = subscription.data.to_dict() db.session.add(subscription_dao) if flush: db.session.flush() subscription = subscription_dao.to_model() if commit_and_generate: db.session.commit() subscription = subscription_dao.to_model() return subscription
def save_subscription(self, subscription, commit_and_generate=True, flush=False): """ :type subscription: dart.model.subscription.Subscription """ subscription = default_and_validate(subscription, subscription_schema()) subscription_dao = SubscriptionDao() subscription_dao.id = random_id() subscription.data.state = SubscriptionState.QUEUED subscription.data.queued_time = datetime.now() subscription_dao.data = subscription.data.to_dict() db.session.add(subscription_dao) if flush: db.session.flush() subscription = subscription_dao.to_model() if commit_and_generate: db.session.commit() subscription = subscription_dao.to_model() self._subscription_proxy.generate_subscription_elements(subscription) return subscription
def save_subscription(self, subscription, commit_and_generate=True, flush=False): """ :type subscription: dart.model.subscription.Subscription """ subscription = default_and_validate(subscription, subscription_schema()) subscription_dao = SubscriptionDao() subscription_dao.id = random_id() subscription.data.state = SubscriptionState.QUEUED subscription.data.queued_time = datetime.now() subscription_dao.data = subscription.data.to_dict() db.session.add(subscription_dao) if flush: db.session.flush() subscription = subscription_dao.to_model() if commit_and_generate: db.session.commit() subscription = subscription_dao.to_model() self._subscription_proxy.generate_subscription_elements( subscription) return subscription
def main(): data = { 'definitions': { 'Action': action_schema(None), 'ActionContext': action_context_schema(), 'ActionResult': action_result_schema(), 'Dataset': dataset_schema(), 'Datastore': datastore_schema(None), 'Engine': engine_schema(), 'ErrorResult': error_result_schema(), 'Event': event_schema(), 'Filter': filter_schema(), 'GraphEntityIdentifier': graph_entity_identifier_schema(), 'GraphEntity': graph_entity_schema(), 'JSONPatch': json_patch_schema(), 'JSONSchema': json_schema_schema(), 'OKResult': ok_result_schema(), 'OrderBy': order_by_schema(), 'SubGraph': sub_graph_schema(), 'SubGraphDefinition': { 'type': 'object' }, #subgraph_definition_schema([{'type': 'object'}], [{'type': 'object'}], {'type': 'object'}), 'Subscription': subscription_schema(), 'Trigger': trigger_schema({'type': 'object'}), 'TriggerType': trigger_type_schema(), 'Workflow': workflow_schema(), 'WorkflowInstance': workflow_instance_schema() } } fix_up(data, data, [None]) print dump(data, Dumper=Dumper, default_style=None, default_flow_style=False, explicit_start=False, explicit_end=False) return 0
def get_subscription_json_schema(): return {'results': subscription_schema()}
def default_and_validate_subscription(subscription): return default_and_validate(subscription, subscription_schema())
def _query_subscription_query(self, filters): query = SubscriptionDao.query.order_by(desc(SubscriptionDao.updated)) for f in filters: query = self._filter_service.apply_filter(f, query, SubscriptionDao, [subscription_schema()]) return query
def default_and_validate_subscription(subscription): return default_and_validate(subscription, subscription_schema())
def export_swagger_definitions(out): data = { 'definitions': { 'Action': action_schema({'type': 'object', 'x-nullable': True}), 'ActionResponse': object_response_schema('Action'), 'ActionsResponse': array_response_schema('Action'), 'PagedActionsResponse': paged_response_schema('Action'), 'ActionContext': action_context_schema(), 'ActionContextResponse': object_response_schema('ActionContext'), 'ActionResult': action_result_schema(), 'Dataset': dataset_schema(), 'DatasetResponse': object_response_schema('Dataset'), 'PagedDatasetsResponse': paged_response_schema('Dataset'), 'Datastore': datastore_schema({'type': 'object', 'x-nullable': True}), 'DatastoreResponse': object_response_schema('Datastore'), 'PagedDatastoresResponse': paged_response_schema('Datastore'), 'Engine': engine_schema(), 'EngineResponse': object_response_schema('Engine'), 'PagedEnginesResponse': paged_response_schema('Engine'), 'ErrorResponse': error_response_schema(), 'Event': event_schema(), 'EventResponse': object_response_schema('Event'), 'PagedEventsResponse': paged_response_schema('Event'), 'Filter': filter_schema(), 'GraphEntityIdentifier': graph_entity_identifier_schema(), 'GraphEntityIdentifierResponse': object_response_schema('GraphEntityIdentifier'), 'GraphEntityIdentifiersResponse': array_response_schema('GraphEntityIdentifier'), 'GraphEntity': graph_entity_schema(), 'GraphEntityResponse': object_response_schema('GraphEntity'), 'JSONPatch': json_patch_schema(), 'JSONSchema': json_schema_schema(), 'JSONSchemaResponse': object_response_schema('JSONSchema'), 'ObjectResponse': object_response_schema('object'), 'ObjectsResponse': array_response_schema('object'), 'PagedObjectsResponse': paged_response_schema('object'), 'OKResponse': ok_response_schema(), 'OrderBy': order_by_schema(), 'Subgraph': sub_graph_schema(), 'SubgraphResponse': object_response_schema('Subgraph'), 'SubgraphDefinition': {'type': 'object'}, #subgraph_definition_schema([{'type': 'object'}], [{'type': 'object'}], {'type': 'object'}), 'SubgraphDefinitionResponse': object_response_schema('SubgraphDefinition'), 'Subscription': subscription_schema(), 'SubscriptionResponse': object_response_schema('Subscription'), 'PagedSubscriptionsResponse': paged_response_schema('Subscription'), 'SubscriptionElement': subscription_element_schema(), 'PagedSubscriptionElementsResponse': paged_response_schema('SubscriptionElement'), 'Trigger': trigger_schema({'type': 'object'}), 'TriggerResponse': object_response_schema('Trigger'), 'PagedTriggersResponse': paged_response_schema('Trigger'), 'TriggerType': trigger_type_schema(), 'PagedTriggerTypesResponse': paged_response_schema('TriggerType'), 'Workflow': workflow_schema(), 'WorkflowResponse': object_response_schema('Workflow'), 'PagedWorkflowsResponse': paged_response_schema('Workflow'), 'WorkflowInstance': workflow_instance_schema(), 'WorkflowInstanceResponse': object_response_schema('WorkflowInstance'), 'PagedWorkflowInstancesResponse': paged_response_schema('WorkflowInstance') } } fix_up(data, data, [None]) dump(data, out, Dumper=Dumper, default_style=None, default_flow_style=False, explicit_start=False, explicit_end=False)
def get_subscription_json_schema(): return {'results': subscription_schema()}
def export_swagger_definitions(out): data = { 'definitions': { 'Action': action_schema({ 'type': 'object', 'x-nullable': True }), 'ActionResponse': object_response_schema('Action'), 'ActionsResponse': array_response_schema('Action'), 'PagedActionsResponse': paged_response_schema('Action'), 'ActionContext': action_context_schema(), 'ActionContextResponse': object_response_schema('ActionContext'), 'ActionResult': action_result_schema(), 'Dataset': dataset_schema(), 'DatasetResponse': object_response_schema('Dataset'), 'PagedDatasetsResponse': paged_response_schema('Dataset'), 'Datastore': datastore_schema({ 'type': 'object', 'x-nullable': True }), 'DatastoreResponse': object_response_schema('Datastore'), 'PagedDatastoresResponse': paged_response_schema('Datastore'), 'Engine': engine_schema(), 'EngineResponse': object_response_schema('Engine'), 'PagedEnginesResponse': paged_response_schema('Engine'), 'ErrorResponse': error_response_schema(), 'Event': event_schema(), 'EventResponse': object_response_schema('Event'), 'PagedEventsResponse': paged_response_schema('Event'), 'Filter': filter_schema(), 'GraphEntityIdentifier': graph_entity_identifier_schema(), 'GraphEntityIdentifierResponse': object_response_schema('GraphEntityIdentifier'), 'GraphEntityIdentifiersResponse': array_response_schema('GraphEntityIdentifier'), 'GraphEntity': graph_entity_schema(), 'GraphEntityResponse': object_response_schema('GraphEntity'), 'JSONPatch': json_patch_schema(), 'JSONSchema': json_schema_schema(), 'JSONSchemaResponse': object_response_schema('JSONSchema'), 'ObjectResponse': object_response_schema('object'), 'ObjectsResponse': array_response_schema('object'), 'PagedObjectsResponse': paged_response_schema('object'), 'OKResponse': ok_response_schema(), 'OrderBy': order_by_schema(), 'Subgraph': sub_graph_schema(), 'SubgraphResponse': object_response_schema('Subgraph'), 'SubgraphDefinition': { 'type': 'object' }, #subgraph_definition_schema([{'type': 'object'}], [{'type': 'object'}], {'type': 'object'}), 'SubgraphDefinitionResponse': object_response_schema('SubgraphDefinition'), 'Subscription': subscription_schema(), 'SubscriptionResponse': object_response_schema('Subscription'), 'PagedSubscriptionsResponse': paged_response_schema('Subscription'), 'SubscriptionElement': subscription_element_schema(), 'PagedSubscriptionElementsResponse': paged_response_schema('SubscriptionElement'), 'Trigger': trigger_schema({'type': 'object'}), 'TriggerResponse': object_response_schema('Trigger'), 'PagedTriggersResponse': paged_response_schema('Trigger'), 'TriggerType': trigger_type_schema(), 'PagedTriggerTypesResponse': paged_response_schema('TriggerType'), 'Workflow': workflow_schema(), 'WorkflowResponse': object_response_schema('Workflow'), 'PagedWorkflowsResponse': paged_response_schema('Workflow'), 'WorkflowInstance': workflow_instance_schema(), 'WorkflowInstanceResponse': object_response_schema('WorkflowInstance'), 'PagedWorkflowInstancesResponse': paged_response_schema('WorkflowInstance') } } fix_up(data, data, [None]) dump(data, out, Dumper=Dumper, default_style=None, default_flow_style=False, explicit_start=False, explicit_end=False)