Class SchemaRegistryClientImpl

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCodecType​(java.lang.String groupId, io.pravega.schemaregistry.contract.data.CodecType codecType)
      Add new codec type to be used in encoding in the group.
      boolean addGroup​(java.lang.String groupId, io.pravega.schemaregistry.contract.data.GroupProperties groupProperties)
      Adds a new group.
      io.pravega.schemaregistry.contract.data.VersionInfo addSchema​(java.lang.String groupId, io.pravega.schemaregistry.contract.data.SchemaInfo schemaInfo)
      Registers schema to the group.
      boolean canReadUsing​(java.lang.String groupId, io.pravega.schemaregistry.contract.data.SchemaInfo schemaInfo)
      Checks whether given schema can be used to read by validating it for reads against one or more existing schemas in the group subject to current GroupProperties.getCompatibility() policy.
      void close()  
      void deleteSchemaVersion​(java.lang.String groupId, io.pravega.schemaregistry.contract.data.VersionInfo versionInfo)
      Deletes the schema associated to the given version.
      java.util.List<io.pravega.schemaregistry.contract.data.CodecType> getCodecTypes​(java.lang.String groupId)
      List of codec types used for encoding in the group.
      io.pravega.schemaregistry.contract.data.EncodingId getEncodingId​(java.lang.String groupId, io.pravega.schemaregistry.contract.data.VersionInfo versionInfo, java.lang.String codecType)
      Gets an encoding id that uniquely identifies a combination of Schema version and codec type.
      io.pravega.schemaregistry.contract.data.EncodingInfo getEncodingInfo​(java.lang.String groupId, io.pravega.schemaregistry.contract.data.EncodingId encodingId)
      Gets encoding info against the requested encoding Id.
      java.util.List<io.pravega.schemaregistry.contract.data.GroupHistoryRecord> getGroupHistory​(java.lang.String groupId)
      Gets complete schema evolution history of the group with schemas, versions, compatibility policy and time when the schema was added to the group.
      io.pravega.schemaregistry.contract.data.GroupProperties getGroupProperties​(java.lang.String groupId)
      Get group properties for the group identified by the group id.
      io.pravega.schemaregistry.contract.data.SchemaWithVersion getLatestSchemaVersion​(java.lang.String groupId, java.lang.String schemaType)
      Gets latest schema and version for the group (or type, if specified).
      java.lang.String getNamespace()
      The Namespace which is used for making all client requests to registry service.
      io.pravega.schemaregistry.contract.data.SchemaInfo getSchemaForVersion​(java.lang.String groupId, io.pravega.schemaregistry.contract.data.VersionInfo versionInfo)
      Gets schema corresponding to the version.
      java.util.Map<java.lang.String,​io.pravega.schemaregistry.contract.data.VersionInfo> getSchemaReferences​(io.pravega.schemaregistry.contract.data.SchemaInfo schemaInfo)
      Finds all groups and corresponding version info for the groups where the supplied schema has been registered.
      java.util.List<io.pravega.schemaregistry.contract.data.SchemaWithVersion> getSchemas​(java.lang.String groupId)
      Gets list of latest schemas for each object types registered under the group.
      java.util.List<io.pravega.schemaregistry.contract.data.SchemaWithVersion> getSchemaVersions​(java.lang.String groupId, java.lang.String schemaType)
      Gets all schemas with corresponding versions for the group (or type, if specified).
      io.pravega.schemaregistry.contract.data.VersionInfo getVersionForSchema​(java.lang.String groupId, io.pravega.schemaregistry.contract.data.SchemaInfo schema)
      Gets version corresponding to the schema.
      java.util.Iterator<java.util.Map.Entry<java.lang.String,​io.pravega.schemaregistry.contract.data.GroupProperties>> listGroups()
      List all groups that the user is authorized on.
      void removeGroup​(java.lang.String groupId)
      Removes a group identified by the groupId.
      boolean updateCompatibility​(java.lang.String groupId, io.pravega.schemaregistry.contract.data.Compatibility compatibility, io.pravega.schemaregistry.contract.data.Compatibility previous)
      Update group's schema validation policy.
      boolean validateSchema​(java.lang.String groupId, io.pravega.schemaregistry.contract.data.SchemaInfo schemaInfo)
      Checks whether given schema is valid by applying compatibility policy against previous schemas in the group subject to current GroupProperties.getCompatibility() policy.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • addGroup

        public boolean addGroup​(java.lang.String groupId,
                                io.pravega.schemaregistry.contract.data.GroupProperties groupProperties)
        Description copied from interface: SchemaRegistryClient
        Adds a new group. A group refers to the name under which the schemas are registered. A group is identified by a unique id and has an associated set of group metadata GroupProperties and a list of codec types and a versioned history of schemas that were registered under the group. Add group is idempotent. If the group by the same id already exists the api will return false.
        Specified by:
        addGroup in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group that uniquely identifies the group.
        groupProperties - groupProperties Group properties for the group. These include serialization format, compatibility policy, and flag to declare whether multiple schemas representing distinct object types can be registered with the group. Type identify objects of same type. Schema compatibility checks are always performed for schemas that share same SchemaInfo.getType(). Additionally, a user defined map of properties can be supplied.
        Returns:
        True indicates if the group was added successfully, false if it exists.
      • removeGroup

        public void removeGroup​(java.lang.String groupId)
        Description copied from interface: SchemaRegistryClient
        Removes a group identified by the groupId. This will remove all the codec types and schemas registered under the group. Remove group is idempotent.
        Specified by:
        removeGroup in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group that uniquely identifies the group.
      • listGroups

        public java.util.Iterator<java.util.Map.Entry<java.lang.String,​io.pravega.schemaregistry.contract.data.GroupProperties>> listGroups()
        Description copied from interface: SchemaRegistryClient
        List all groups that the user is authorized on. This returns an iterator where each element is a pair of group name and group properties. The list group is a non atomic call. The implementation is not necessarily consistent as it uses paginated iteration using Continuation Token. This could mean that as the list is being iterated over, the state on the server may be updated (some groups added or removed). For example, if a group that has been iterated over is deleted and recereated, the iterator may deliver a group with identical name twice. Similarly, If a group that has not yet been iterated over is deleted, the client may or may not see the group as it is iterating over the response depending on whether the client had received the deleted group from service before it was deleted or not. This iterator can be used to iterate over each element until all elements are exhausted and gives a weak guarantee that all groups added before the iterator Iterator.hasNext() = false can be iterated over.
        Specified by:
        listGroups in interface SchemaRegistryClient
        Returns:
        map of names of groups with corresponding group properties for all groups.
      • getGroupProperties

        public io.pravega.schemaregistry.contract.data.GroupProperties getGroupProperties​(java.lang.String groupId)
        Description copied from interface: SchemaRegistryClient
        Get group properties for the group identified by the group id. GroupProperties.serializationFormat which identifies the serialization format is used to describe the schema. GroupProperties.getCompatibility() sets the schema validation policy that needs to be enforced for evolving schemas. GroupProperties.isAllowMultipleTypes() that specifies if multiple schemas are allowed to be registered in the group. Schemas are validated against existing schema versions that have the same SchemaInfo.getType(). GroupProperties.properties describes generic properties for a group.
        Specified by:
        getGroupProperties in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        Returns:
        Group properties which includes property like Serialization format and compatibility policy.
      • updateCompatibility

        public boolean updateCompatibility​(java.lang.String groupId,
                                           io.pravega.schemaregistry.contract.data.Compatibility compatibility,
                                           @Nullable
                                           io.pravega.schemaregistry.contract.data.Compatibility previous)
        Description copied from interface: SchemaRegistryClient
        Update group's schema validation policy. If previous compatibility policy are not supplied, then the update to the policy will be performed unconditionally. However, if previous compatibility policy are supplied, then the update will be performed if and only if existing GroupProperties.getCompatibility() match previous compatibility policy.
        Specified by:
        updateCompatibility in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        compatibility - New Compatibility for the group.
        previous - Previous compatibility.
        Returns:
        true if the update was accepted by the service, false if it was rejected because of precondition failure. Precondition failure can occur if previous compatibility policy were specified and they do not match the policy set on the group.
      • getSchemas

        public java.util.List<io.pravega.schemaregistry.contract.data.SchemaWithVersion> getSchemas​(java.lang.String groupId)
        Description copied from interface: SchemaRegistryClient
        Gets list of latest schemas for each object types registered under the group. Objects are identified by SchemaInfo.getType(). Schema registry provides consistency guarantees. So all schemas added before this call will be returned by this call. However, the service side implementation is not guaranteed to be atomic. So if schemas are being added concurrently, the schemas returned by this api may or may not include those.
        Specified by:
        getSchemas in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        Returns:
        Unordered list of different objects within the group.
      • addSchema

        public io.pravega.schemaregistry.contract.data.VersionInfo addSchema​(java.lang.String groupId,
                                                                             io.pravega.schemaregistry.contract.data.SchemaInfo schemaInfo)
        Description copied from interface: SchemaRegistryClient
        Registers schema to the group. Schemas are validated against existing schemas in the group that share the same SchemaInfo.getType(). If group is configured with GroupProperties.isAllowMultipleTypes() then multiple schemas with distinct type SchemaInfo.getType() could be registered. All schemas with same type are assigned monotonically increasing version numbers. Implementation of this method is expected to be idempotent. The behaviour of Add Schema API on the schema registry service is idempotent. The service assigns and returns a new version info object to identify the given schema. If a schema was already registered, the existing version info is returned by the service.
        Specified by:
        addSchema in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        schemaInfo - Schema to add.
        Returns:
        versionInfo which uniquely identifies where the schema is added in the group. If schema is already registered, then the existing version info is returned.
      • getSchemaForVersion

        public io.pravega.schemaregistry.contract.data.SchemaInfo getSchemaForVersion​(java.lang.String groupId,
                                                                                      io.pravega.schemaregistry.contract.data.VersionInfo versionInfo)
        Description copied from interface: SchemaRegistryClient
        Gets schema corresponding to the version.
        Specified by:
        getSchemaForVersion in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        versionInfo - Version which uniquely identifies schema within a group.
        Returns:
        Schema info corresponding to the version info.
      • getEncodingInfo

        public io.pravega.schemaregistry.contract.data.EncodingInfo getEncodingInfo​(java.lang.String groupId,
                                                                                    io.pravega.schemaregistry.contract.data.EncodingId encodingId)
        Description copied from interface: SchemaRegistryClient
        Gets encoding info against the requested encoding Id. The purpose of encoding info is to uniquely identify the encoding used on the data at rest. The encoding covers two parts - 1. Schema that defines the structure of the data and is used for serialization. A specific schema version registered with registry service is uniquely identified by the corresponding VersionInfo object. 2. CodecType that is used to encode the serialized data. This would typically be some compression. The codecType and schema should both be registered with the service and service will generate a unique identifier for each such pair. Encoding Info uniquely identifies a combination of a versionInfo and codecType. EncodingInfo also includes the SchemaInfo identified by the VersionInfo.
        Specified by:
        getEncodingInfo in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        encodingId - Encoding id that uniquely identifies a schema within a group.
        Returns:
        Encoding info corresponding to the encoding id.
      • getEncodingId

        public io.pravega.schemaregistry.contract.data.EncodingId getEncodingId​(java.lang.String groupId,
                                                                                io.pravega.schemaregistry.contract.data.VersionInfo versionInfo,
                                                                                java.lang.String codecType)
        Description copied from interface: SchemaRegistryClient
        Gets an encoding id that uniquely identifies a combination of Schema version and codec type. This encoding id is a 4 byte integer and it can be used to tag the data which is serialized and encoded using the schema version and codecType identified by this encoding id. The implementation of this method is expected to be idempotent. The corresponding GetEncodingId API on schema registry service is idempotent and will generate a new encoding id for each unique version and codecType pair only once. Subsequent requests to get the encoding id for the codecType and version will return the previously generated id. If the schema identified by the version is deleted using SchemaRegistryClient.deleteSchemaVersion(java.lang.String, io.pravega.schemaregistry.contract.data.VersionInfo) api, then if the encoding id was already generated for the pair of schema version and codec, then it will be returned. However, if no encoding id for the versioninfo and codec pair was generated and the schema version was deleted, then any call to getEncodingId using the deleted versionInfo will throw ResourceNotFoundException.
        Specified by:
        getEncodingId in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        versionInfo - version of schema
        codecType - codec type
        Returns:
        Encoding id for the pair of version and codec type.
      • getLatestSchemaVersion

        public io.pravega.schemaregistry.contract.data.SchemaWithVersion getLatestSchemaVersion​(java.lang.String groupId,
                                                                                                @Nullable
                                                                                                java.lang.String schemaType)
        Description copied from interface: SchemaRegistryClient
        Gets latest schema and version for the group (or type, if specified). To get latest schema version for a specific type identified by SchemaInfo.getType(), provide the type. Otherwise if the group is configured to allow multiple schemas GroupProperties.isAllowMultipleTypes(), then and type is not specified, then last schema added to the group across all types will be returned.
        Specified by:
        getLatestSchemaVersion in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        schemaType - Type of object identified by SchemaInfo.getType().
        Returns:
        Schema with version for the last schema that was added to the group (or type).
      • getSchemaVersions

        public java.util.List<io.pravega.schemaregistry.contract.data.SchemaWithVersion> getSchemaVersions​(java.lang.String groupId,
                                                                                                           @Nullable
                                                                                                           java.lang.String schemaType)
        Description copied from interface: SchemaRegistryClient
        Gets all schemas with corresponding versions for the group (or type, if specified). For groups configured with GroupProperties.isAllowMultipleTypes(), the type SchemaInfo.getType() should be supplied to view schemas specific to a type. if type is null, all schemas in the group are returned. The order in the list matches the order in which schemas were evolved within the group.
        Specified by:
        getSchemaVersions in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        schemaType - type of object identified by SchemaInfo.getType().
        Returns:
        Ordered list of schemas with versions and compatibility policy for all schemas in the group.
      • getGroupHistory

        public java.util.List<io.pravega.schemaregistry.contract.data.GroupHistoryRecord> getGroupHistory​(java.lang.String groupId)
        Description copied from interface: SchemaRegistryClient
        Gets complete schema evolution history of the group with schemas, versions, compatibility policy and time when the schema was added to the group. The order in the list matches the order in which schemas were evolved within the group. This call will get a consistent view at the time when the request is processed on the service. So all schemas that were added before this call are returned and all schemas that were deleted before this call are excluded. The execution of this API is non-atomic and if concurrent requests to add or delete schemas are invoked, it may or may not include those schemas in the response.
        Specified by:
        getGroupHistory in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        Returns:
        Ordered list of schemas with versions and compatibility policy for all schemas in the group.
      • getSchemaReferences

        public java.util.Map<java.lang.String,​io.pravega.schemaregistry.contract.data.VersionInfo> getSchemaReferences​(io.pravega.schemaregistry.contract.data.SchemaInfo schemaInfo)
                                                                                                                      throws RegistryExceptions.ResourceNotFoundException,
                                                                                                                             RegistryExceptions.UnauthorizedException
        Description copied from interface: SchemaRegistryClient
        Finds all groups and corresponding version info for the groups where the supplied schema has been registered. It is important to note that the same schema type could be part of multiple group, however in each group it may have gone through a separate evolution. Invocation of this method lists all groups where the specific schema (type, format and binary) is used along with versions that identifies this schema in those groups. The user defined SchemaInfo.properties is not used for comparison.
        Specified by:
        getSchemaReferences in interface SchemaRegistryClient
        Parameters:
        schemaInfo - Schema info to find references for.
        Returns:
        Map of group Id to versionInfo identifier for the schema in that group.
        Throws:
        RegistryExceptions.ResourceNotFoundException - if schema is not found.
        RegistryExceptions.UnauthorizedException - if the user is unauthorized.
      • getVersionForSchema

        public io.pravega.schemaregistry.contract.data.VersionInfo getVersionForSchema​(java.lang.String groupId,
                                                                                       io.pravega.schemaregistry.contract.data.SchemaInfo schema)
        Description copied from interface: SchemaRegistryClient
        Gets version corresponding to the schema. For each schema type SchemaInfo.getType() and SchemaInfo.serializationFormat a versionInfo object uniquely identifies each distinct SchemaInfo.schemaData.
        Specified by:
        getVersionForSchema in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        schema - SchemaInfo that describes format and structure.
        Returns:
        VersionInfo corresponding to schema.
      • validateSchema

        public boolean validateSchema​(java.lang.String groupId,
                                      io.pravega.schemaregistry.contract.data.SchemaInfo schemaInfo)
        Description copied from interface: SchemaRegistryClient
        Checks whether given schema is valid by applying compatibility policy against previous schemas in the group subject to current GroupProperties.getCompatibility() policy. The invocation of this method will perform exactly the same validations as SchemaRegistryClient.addSchema(String, SchemaInfo) but without registering the schema. This is primarily intended to be used during schema development phase to validate that the changes to schema are in compliance with compatibility policy for the group.
        Specified by:
        validateSchema in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        schemaInfo - Schema to check for validity.
        Returns:
        A schema is valid if it passes all the GroupProperties.getCompatibility(). The rule supported are allow any, deny all or a combination of BackwardAndForward. If desired compatibility is satisfied by the schema then this method returns true, false otherwise.
      • canReadUsing

        public boolean canReadUsing​(java.lang.String groupId,
                                    io.pravega.schemaregistry.contract.data.SchemaInfo schemaInfo)
        Description copied from interface: SchemaRegistryClient
        Checks whether given schema can be used to read by validating it for reads against one or more existing schemas in the group subject to current GroupProperties.getCompatibility() policy.
        Specified by:
        canReadUsing in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        schemaInfo - Schema to check to be used for reads.
        Returns:
        True if it can be used to read, false otherwise.
      • getCodecTypes

        public java.util.List<io.pravega.schemaregistry.contract.data.CodecType> getCodecTypes​(java.lang.String groupId)
        Description copied from interface: SchemaRegistryClient
        List of codec types used for encoding in the group.
        Specified by:
        getCodecTypes in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        Returns:
        List of codec types used for encoding in the group.
      • addCodecType

        public void addCodecType​(java.lang.String groupId,
                                 io.pravega.schemaregistry.contract.data.CodecType codecType)
        Description copied from interface: SchemaRegistryClient
        Add new codec type to be used in encoding in the group. Adding a new codectype is backward incompatible. Make sure all readers are upgraded to use the new codec before any writers use the codec to encode the data.
        Specified by:
        addCodecType in interface SchemaRegistryClient
        Parameters:
        groupId - Id for the group.
        codecType - codec type.
      • close

        public void close()
                   throws java.lang.Exception
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.lang.Exception
      • getNamespace

        public java.lang.String getNamespace()
        Description copied from interface: SchemaRegistryClient
        The Namespace which is used for making all client requests to registry service.
        Specified by:
        getNamespace in interface SchemaRegistryClient
        Returns:
        Namespace used for the client.