@Override public void writeHeader(final RecordSchema schema, final OutputStream out) throws IOException { final SchemaIdentifier identifier = schema.getIdentifier(); final Long id = identifier.getIdentifier().getAsLong(); // This encoding follows the pattern that is provided for serializing data by the Confluent Schema Registry serializer // as it is provided at: // http://docs.confluent.io/current/schema-registry/docs/serializer-formatter.html#wire-format // The format consists of the first byte always being 0, to indicate a 'magic byte' followed by 4 bytes // representing the schema id. final ByteBuffer bb = ByteBuffer.allocate(5); bb.put((byte) 0); bb.putInt(id.intValue()); out.write(bb.array()); }
@Override public void writeHeader(final RecordSchema schema, final OutputStream out) throws IOException { final SchemaIdentifier identifier = schema.getIdentifier(); final Long id = identifier.getIdentifier().getAsLong(); final Integer version = identifier.getVersion().getAsInt(); // This decoding follows the pattern that is provided for serializing data by the Hortonworks Schema Registry serializer // as it is provided at: // https://github.com/hortonworks/registry/blob/master/schema-registry/serdes/src/main/java/com/hortonworks/registries/schemaregistry/serdes/avro/AvroSnapshotSerializer.java final ByteBuffer bb = ByteBuffer.allocate(13); bb.put((byte) LATEST_PROTOCOL_VERSION); bb.putLong(id); bb.putInt(version); out.write(bb.array()); }
@Override public Map<String, String> getAttributes(final RecordSchema schema) { final Map<String, String> attributes = new HashMap<>(4); final SchemaIdentifier id = schema.getIdentifier(); final Long schemaId = id.getIdentifier().getAsLong(); final Integer schemaVersion = id.getVersion().getAsInt(); attributes.put(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_ID_ATTRIBUTE, String.valueOf(schemaId)); attributes.put(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_VERSION_ATTRIBUTE, String.valueOf(schemaVersion)); attributes.put(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_PROTOCOL_VERSION_ATTRIBUTE, String.valueOf(LATEST_PROTOCOL_VERSION)); if (id.getBranch().isPresent()) { attributes.put(SCHEMA_BRANCH_ATTRIBUTE, id.getBranch().get()); } return attributes; }
private RecordSchema retrieveSchemaById(final SchemaIdentifier schemaIdentifier) throws IOException, SchemaNotFoundException { final OptionalLong schemaId = schemaIdentifier.getIdentifier(); if (!schemaId.isPresent()) { throw new org.apache.nifi.schema.access.SchemaNotFoundException("Cannot retrieve schema because Schema Id is not present"); } final RecordSchema schema = client.getSchema((int) schemaId.getAsLong()); return schema; }
private RecordSchema retrieveSchemaByIdAndVersion(final SchemaIdentifier schemaIdentifier) throws IOException, SchemaNotFoundException { final OptionalLong schemaId = schemaIdentifier.getIdentifier(); if (!schemaId.isPresent()) { throw new org.apache.nifi.schema.access.SchemaNotFoundException("Cannot retrieve schema because Schema Id is not present"); } final OptionalInt version = schemaIdentifier.getVersion(); if (!version.isPresent()) { throw new org.apache.nifi.schema.access.SchemaNotFoundException("Cannot retrieve schema because Schema Version is not present"); } final Tuple<Long, Integer> tuple = new Tuple<>(schemaId.getAsLong(), version.getAsInt()); final RecordSchema schema = schemaIdVersionMap.get(tuple); return schema; }
@Override public RecordSchema retrieveSchema(final SchemaIdentifier schemaIdentifier) throws IOException, org.apache.nifi.schema.access.SchemaNotFoundException { if (schemaIdentifier.getIdentifier().isPresent()) { return retrieveSchemaByIdAndVersion(schemaIdentifier); } else { return retrieveSchemaByName(schemaIdentifier); } }
@Override public void validateSchema(final RecordSchema schema) throws SchemaNotFoundException { final SchemaIdentifier id = schema.getIdentifier(); if (!id.getIdentifier().isPresent()) { throw new SchemaNotFoundException("Cannot write Schema Reference as Attributes because it does not contain a Schema Identifier"); } if (!id.getVersion().isPresent()) { throw new SchemaNotFoundException("Cannot write Schema Reference as Attributes because it does not contain a Schema Version"); } }
@Override public void validateSchema(RecordSchema schema) throws SchemaNotFoundException { final SchemaIdentifier identifier = schema.getIdentifier(); final OptionalLong identifierOption = identifier.getIdentifier(); if (!identifierOption.isPresent()) { throw new SchemaNotFoundException("Cannot write Confluent Schema Registry Reference because the Schema Identifier is not known"); } final OptionalInt versionOption = identifier.getVersion(); if (!versionOption.isPresent()) { throw new SchemaNotFoundException("Cannot write Confluent Schema Registry Reference because the Schema Version is not known"); } }
@Override public void validateSchema(RecordSchema schema) throws SchemaNotFoundException { final SchemaIdentifier identifier = schema.getIdentifier(); final OptionalLong identifierOption = identifier.getIdentifier(); if (!identifierOption.isPresent()) { throw new SchemaNotFoundException("Cannot write Encoded Schema Reference because the Schema Identifier is not known"); } final OptionalInt versionOption = identifier.getVersion(); if (!versionOption.isPresent()) { throw new SchemaNotFoundException("Cannot write Encoded Schema Reference because the Schema Version is not known"); } }
@Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj == null) { return false; } if (!(obj instanceof SchemaIdentifier)) { return false; } final SchemaIdentifier other = (SchemaIdentifier) obj; return getName().equals(other.getName()) && getIdentifier().equals(other.getIdentifier()) && getVersion().equals(other.getVersion()) && getBranch().equals(other.getBranch()); }
final SchemaVersionInfo versionInfo; final OptionalLong schemaId = schemaIdentifier.getIdentifier(); if (!schemaId.isPresent()) { throw new org.apache.nifi.schema.access.SchemaNotFoundException("Cannot retrieve schema because Schema Id is not present");
@Override public void writeHeader(final RecordSchema schema, final OutputStream out) throws IOException { final SchemaIdentifier identifier = schema.getIdentifier(); final Long id = identifier.getIdentifier().getAsLong(); // This encoding follows the pattern that is provided for serializing data by the Confluent Schema Registry serializer // as it is provided at: // http://docs.confluent.io/current/schema-registry/docs/serializer-formatter.html#wire-format // The format consists of the first byte always being 0, to indicate a 'magic byte' followed by 4 bytes // representing the schema id. final ByteBuffer bb = ByteBuffer.allocate(5); bb.put((byte) 0); bb.putInt(id.intValue()); out.write(bb.array()); }
@Override public void writeHeader(final RecordSchema schema, final OutputStream out) throws IOException { final SchemaIdentifier identifier = schema.getIdentifier(); final Long id = identifier.getIdentifier().getAsLong(); final Integer version = identifier.getVersion().getAsInt(); // This decoding follows the pattern that is provided for serializing data by the Hortonworks Schema Registry serializer // as it is provided at: // https://github.com/hortonworks/registry/blob/master/schema-registry/serdes/src/main/java/com/hortonworks/registries/schemaregistry/serdes/avro/AvroSnapshotSerializer.java final ByteBuffer bb = ByteBuffer.allocate(13); bb.put((byte) LATEST_PROTOCOL_VERSION); bb.putLong(id); bb.putInt(version); out.write(bb.array()); }
@Override public Map<String, String> getAttributes(final RecordSchema schema) { final Map<String, String> attributes = new HashMap<>(4); final SchemaIdentifier id = schema.getIdentifier(); final Long schemaId = id.getIdentifier().getAsLong(); final Integer schemaVersion = id.getVersion().getAsInt(); attributes.put(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_ID_ATTRIBUTE, String.valueOf(schemaId)); attributes.put(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_VERSION_ATTRIBUTE, String.valueOf(schemaVersion)); attributes.put(HortonworksAttributeSchemaReferenceStrategy.SCHEMA_PROTOCOL_VERSION_ATTRIBUTE, String.valueOf(LATEST_PROTOCOL_VERSION)); if (id.getBranch().isPresent()) { attributes.put(SCHEMA_BRANCH_ATTRIBUTE, id.getBranch().get()); } return attributes; }
private RecordSchema retrieveSchemaById(final SchemaIdentifier schemaIdentifier) throws IOException, SchemaNotFoundException { final OptionalLong schemaId = schemaIdentifier.getIdentifier(); if (!schemaId.isPresent()) { throw new org.apache.nifi.schema.access.SchemaNotFoundException("Cannot retrieve schema because Schema Id is not present"); } final RecordSchema schema = client.getSchema((int) schemaId.getAsLong()); return schema; }
@Override public void validateSchema(RecordSchema schema) throws SchemaNotFoundException { final SchemaIdentifier identifier = schema.getIdentifier(); final OptionalLong identifierOption = identifier.getIdentifier(); if (!identifierOption.isPresent()) { throw new SchemaNotFoundException("Cannot write Encoded Schema Reference because the Schema Identifier is not known"); } final OptionalInt versionOption = identifier.getVersion(); if (!versionOption.isPresent()) { throw new SchemaNotFoundException("Cannot write Encoded Schema Reference because the Schema Version is not known"); } }
@Override public void validateSchema(RecordSchema schema) throws SchemaNotFoundException { final SchemaIdentifier identifier = schema.getIdentifier(); final OptionalLong identifierOption = identifier.getIdentifier(); if (!identifierOption.isPresent()) { throw new SchemaNotFoundException("Cannot write Confluent Schema Registry Reference because the Schema Identifier is not known"); } final OptionalInt versionOption = identifier.getVersion(); if (!versionOption.isPresent()) { throw new SchemaNotFoundException("Cannot write Confluent Schema Registry Reference because the Schema Version is not known"); } }
@Override public void validateSchema(final RecordSchema schema) throws SchemaNotFoundException { final SchemaIdentifier id = schema.getIdentifier(); if (!id.getIdentifier().isPresent()) { throw new SchemaNotFoundException("Cannot write Schema Reference as Attributes because it does not contain a Schema Identifier"); } if (!id.getVersion().isPresent()) { throw new SchemaNotFoundException("Cannot write Schema Reference as Attributes because it does not contain a Schema Version"); } }
@Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj == null) { return false; } if (!(obj instanceof SchemaIdentifier)) { return false; } final SchemaIdentifier other = (SchemaIdentifier) obj; return getName().equals(other.getName()) && getIdentifier().equals(other.getIdentifier()) && getVersion().equals(other.getVersion()) && getBranch().equals(other.getBranch()); }