Ejemplo n.º 1
0
def convert_to_avro_from_mysql(
    schema_repo,
    new_create_table_stmt,
    old_create_table_stmt=None,
    alter_table_stmt=None
):
    if bool(old_create_table_stmt) ^ bool(alter_table_stmt):
        raise exceptions_v1.invalid_request_exception(
            'Both old_create_table_stmt and alter_table_stmt must be provided.'
        )

    try:
        mysql_statements = [
            old_create_table_stmt, alter_table_stmt, new_create_table_stmt
        ]
        sql_table = sql_handler.create_sql_table_from_sql_stmts(
            mysql_statements,
            sql_handler_base.SQLDialect.MySQL
        )
        return schema_repo.convert_schema(
            models.SchemaKindEnum.MySQL,
            models.SchemaKindEnum.Avro,
            sql_table
        )
    except (sql_handler_base.SQLHandlerException,
            converter_base.SchemaConversionException) as e:
        log.exception('{0}'.format(get_current_func_arg_name_values()))
        raise exceptions_v1.invalid_schema_exception(e.message)
Ejemplo n.º 2
0
def register_schema(request):
    try:
        req = requests_v1.RegisterSchemaRequest(**request.json_body)
        validate_names([req.namespace, req.source])
        docs_required = (
            req.namespace not in get_config().namespace_no_doc_required
        )

        return _register_avro_schema(
            schema_json=req.schema_json,
            namespace=req.namespace,
            source=req.source,
            source_owner_email=req.source_owner_email,
            contains_pii=req.contains_pii,
            cluster_type=req.cluster_type,
            base_schema_id=req.base_schema_id,
            docs_required=docs_required
        )
    except simplejson.JSONDecodeError as e:
        log.exception("Failed to construct RegisterSchemaRequest. {}"
                      .format(request.json_body))
        raise exceptions_v1.invalid_schema_exception(
            'Error "{error}" encountered decoding JSON: "{schema}"'.format(
                error=str(e),
                schema=request.json_body['schema']
            )
        )
Ejemplo n.º 3
0
def _register_avro_schema(
    schema_json,
    namespace,
    source,
    source_owner_email,
    contains_pii,
    cluster_type,
    base_schema_id=None,
    docs_required=True
):
    try:
        validate_names([namespace, source])
        avro_schema = schema_repository.register_avro_schema_from_avro_json(
            avro_schema_json=schema_json,
            namespace_name=namespace,
            source_name=source,
            source_owner_email=source_owner_email,
            contains_pii=contains_pii,
            cluster_type=cluster_type,
            base_schema_id=base_schema_id,
            docs_required=docs_required
        )
        return responses_v1.get_schema_response_from_avro_schema(avro_schema)
    except ValueError as e:
        log.exception('{0}'.format(get_current_func_arg_name_values()))
        raise exceptions_v1.invalid_schema_exception(e.message)
Ejemplo n.º 4
0
def _is_schema_compatible(schema_json, namespace, source):
    try:
        return schema_repo.is_schema_compatible(
            schema_json,
            namespace,
            source
        )
    except schema.AvroException as e:
        log.exception('{0}'.format(get_current_func_arg_name_values()))
        raise exceptions_v1.invalid_schema_exception(e.message)
Ejemplo n.º 5
0
def is_avro_schema_compatible(request):
    try:
        req = requests_v1.AvroSchemaCompatibilityRequest(**request.json_body)
        return _is_schema_compatible(req.schema_json, req.namespace,
                                     req.source)
    except simplejson.JSONDecodeError as e:
        log.exception(
            "Failed to construct AvroSchemaCompatibilityRequest. {}".format(
                request.json_body))
        raise exceptions_v1.invalid_schema_exception(
            'Error "{error}" encountered decoding JSON: "{schema}"'.format(
                error=str(e), schema=request.json_body['schema']))
Ejemplo n.º 6
0
def get_schema_migration(request):
    new_schema_json = request.json_body.get('new_schema')
    old_schema_json = request.json_body.get('old_schema')
    target_schema_type = request.json_body.get('target_schema_type')

    _get_migration = SCHEMA_MIGRATION_STRATEGY_MAP.get(target_schema_type)
    if _get_migration is None:
        raise exceptions_v1.unsupported_target_schema_exception()

    try:
        return _get_migration(new_avro_schema=json.loads(new_schema_json),
                              old_avro_schema=json.loads(old_schema_json)
                              if old_schema_json else {})
    except json.JSONDecodeError:
        raise exceptions_v1.invalid_schema_exception()
Ejemplo n.º 7
0
def get_schema_migration(request):
    new_schema_json = request.json_body.get('new_schema')
    old_schema_json = request.json_body.get('old_schema')
    target_schema_type = request.json_body.get('target_schema_type')

    _get_migration = SCHEMA_MIGRATION_STRATEGY_MAP.get(target_schema_type)
    if _get_migration is None:
        raise exceptions_v1.unsupported_target_schema_exception()

    try:
        return _get_migration(
            new_avro_schema=json.loads(new_schema_json),
            old_avro_schema=json.loads(old_schema_json)
            if old_schema_json else {}
        )
    except json.JSONDecodeError:
        raise exceptions_v1.invalid_schema_exception()
Ejemplo n.º 8
0
def is_avro_schema_compatible(request):
    try:
        req = requests_v1.AvroSchemaCompatibilityRequest(**request.json_body)
        return _is_schema_compatible(
            req.schema_json,
            req.namespace,
            req.source
        )
    except simplejson.JSONDecodeError as e:
        log.exception("Failed to construct AvroSchemaCompatibilityRequest. {}"
                      .format(request.json_body))
        raise exceptions_v1.invalid_schema_exception(
            'Error "{error}" encountered decoding JSON: "{schema}"'.format(
                error=str(e),
                schema=request.json_body['schema']
            )
        )
Ejemplo n.º 9
0
def register_schema(request):
    try:
        req = requests_v1.RegisterSchemaRequest(**request.json_body)
        validate_names([req.namespace, req.source])
        docs_required = (req.namespace
                         not in get_config().namespace_no_doc_required)

        return _register_avro_schema(schema_json=req.schema_json,
                                     namespace=req.namespace,
                                     source=req.source,
                                     source_owner_email=req.source_owner_email,
                                     contains_pii=req.contains_pii,
                                     cluster_type=req.cluster_type,
                                     base_schema_id=req.base_schema_id,
                                     docs_required=docs_required)
    except simplejson.JSONDecodeError as e:
        log.exception("Failed to construct RegisterSchemaRequest. {}".format(
            request.json_body))
        raise exceptions_v1.invalid_schema_exception(
            'Error "{error}" encountered decoding JSON: "{schema}"'.format(
                error=str(e), schema=request.json_body['schema']))
Ejemplo n.º 10
0
def _register_avro_schema(schema_json,
                          namespace,
                          source,
                          source_owner_email,
                          contains_pii,
                          cluster_type,
                          base_schema_id=None,
                          docs_required=True):
    try:
        validate_names([namespace, source])
        avro_schema = schema_repository.register_avro_schema_from_avro_json(
            avro_schema_json=schema_json,
            namespace_name=namespace,
            source_name=source,
            source_owner_email=source_owner_email,
            contains_pii=contains_pii,
            cluster_type=cluster_type,
            base_schema_id=base_schema_id,
            docs_required=docs_required)
        return responses_v1.get_schema_response_from_avro_schema(avro_schema)
    except ValueError as e:
        log.exception('{0}'.format(get_current_func_arg_name_values()))
        raise exceptions_v1.invalid_schema_exception(e.message)
Ejemplo n.º 11
0
def _is_schema_compatible(schema_json, namespace, source):
    try:
        return schema_repo.is_schema_compatible(schema_json, namespace, source)
    except schema.AvroException as e:
        log.exception('{0}'.format(get_current_func_arg_name_values()))
        raise exceptions_v1.invalid_schema_exception(e.message)