if (versionInfo == null || versionInfo.getVersion() == null) { final String message = createErrorMessage("Could not find schema", schemaName, schemaBranchName, schemaVersion); throw new org.apache.nifi.schema.access.SchemaNotFoundException(message); .name(schemaName.get()) .branch(schemaBranchName.orElse(null)) .version(versionInfo.getVersion()) .build();
private void updateCacheInvalidationEntries(SchemaVersionInfo schemaVersionInfo) { // need to support this as SchemaIdVersion supports multiple ways to construct for backward compatible APIs // this would have been simple without that. SchemaVersionKey schemaVersionKey = new SchemaVersionKey(schemaVersionInfo.getName(), schemaVersionInfo.getVersion()); SchemaIdVersion key1 = new SchemaIdVersion(schemaVersionInfo.getId()); idWithNameVersion.putIfAbsent(key1, schemaVersionKey); Long schemaMetadataId = schemaVersionInfo.getSchemaMetadataId(); // schemaMetadataId can be null from earlier registry instances. if (schemaMetadataId != null) { SchemaIdVersion key2 = new SchemaIdVersion(schemaMetadataId, schemaVersionInfo.getVersion()); nameVersionWithIds.putIfAbsent(schemaVersionKey, Lists.newArrayList(key1, key2)); idWithNameVersion.putIfAbsent(key2, schemaVersionKey); } else { nameVersionWithIds.putIfAbsent(schemaVersionKey, Collections.singletonList(key1)); } }
private Response doGetAllSchemaVersionForBranch(String schemaName, String branchName) { try { LOG.info("Get all versions for schema : {}", schemaName); Collection<SchemaVersionInfo> schemaVersionInfos = schemaRegistryClient.getAllVersions(effectiveBranchName(branchName), schemaName); LOG.debug("Received schema versions [{}] from schema registry for schema: {}", schemaVersionInfos, schemaName); if (schemaVersionInfos != null && !schemaVersionInfos.isEmpty()) { List<String> schemaVersions = schemaVersionInfos.stream().map(x -> x.getVersion().toString()).collect(Collectors.toList()); return WSUtils.respondEntities(schemaVersions, OK); } else { return WSUtils.respondEntity(Collections.EMPTY_LIST, NOT_FOUND); } } catch (SchemaNotFoundException e) { LOG.error("Schema not found: [{}]", schemaName, e); throw EntityNotFoundException.byName(schemaName); } catch (Exception e) { throw new RuntimeException(e); } }
private void updateCacheInvalidationEntries(SchemaVersionInfo schemaVersionInfo) { // need to support this as SchemaIdVersion supports multiple ways to construct for backward compatible APIs // this would have been simple without that. SchemaVersionKey schemaVersionKey = new SchemaVersionKey(schemaVersionInfo.getName(), schemaVersionInfo.getVersion()); SchemaIdVersion key1 = new SchemaIdVersion(schemaVersionInfo.getId()); idWithNameVersion.putIfAbsent(key1, schemaVersionKey); Long schemaMetadataId = schemaVersionInfo.getSchemaMetadataId(); // schemaMetadataId can be null from earlier registry instances. if (schemaMetadataId != null) { SchemaIdVersion key2 = new SchemaIdVersion(schemaMetadataId, schemaVersionInfo.getVersion()); nameVersionWithIds.putIfAbsent(schemaVersionKey, Lists.newArrayList(key1, key2)); idWithNameVersion.putIfAbsent(key2, schemaVersionKey); } else { nameVersionWithIds.putIfAbsent(schemaVersionKey, Collections.singletonList(key1)); } }
private Set<SchemaIdVersion> transformToSchemaIdVersions(Collection<SchemaVersionInfo> versionInfos) { return versionInfos.stream().map(versionInfo -> new SchemaIdVersion(versionInfo.getSchemaMetadataId(), versionInfo.getVersion(), versionInfo.getId())) .collect(Collectors.toSet()); }
map(mappping -> schemaBranchCache.get(SchemaBranchCache.Key.of(mappping.getSchemaBranchId())).getName()). collect(Collectors.toList()); schemaVersionTiedToOtherBranch.put(schemaVersionInfo.getVersion(), forkedBranchName); } else { schemaVersionsToBeDeleted.add(schemaVersionId);
@POST @Path("/subjects/{subject}") @ApiOperation(value = "Get schema information for the given schema subject and schema text", response = Schema.class, tags = OPERATION_GROUP_CONFLUENT_SR) @Timed @UnitOfWork public Response lookupSubjectVersion(@ApiParam(value = "Schema subject", required = true) @PathParam("subject") String subject, @ApiParam(value = "The schema ", required = true) String schema) { Response response; try { SchemaVersionInfo schemaVersionInfo = schemaRegistry.getSchemaVersionInfo(subject, schemaStringFromJson(schema).getSchema()); if (schemaVersionInfo != null) { response = WSUtils.respondEntity(new Schema(schemaVersionInfo.getName(), schemaVersionInfo.getVersion(), schemaVersionInfo.getId(), schemaVersionInfo.getSchemaText()), Response.Status.OK); } else { response = WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, subject); } } catch (InvalidSchemaException ex) { LOG.error("Given schema is invalid", ex); response = invalidSchemaError(); } catch (SchemaNotFoundException ex) { LOG.error("No schema found with subject [{}]", subject, ex); response = subjectNotFoundError(); } catch (Exception ex) { LOG.error("Encountered error while retrieving schema version with subject: [{}]", subject, ex); response = serverError(); } return response; }
@POST @Path("/subjects/{subject}") @ApiOperation(value = "Get schema information for the given schema subject and schema text", response = Schema.class, tags = OPERATION_GROUP_CONFLUENT_SR) @Timed @UnitOfWork public Response lookupSubjectVersion(@ApiParam(value = "Schema subject", required = true) @PathParam("subject") String subject, @ApiParam(value = "The schema ", required = true) String schema) { Response response; try { SchemaVersionInfo schemaVersionInfo = schemaRegistry.getSchemaVersionInfo(subject, schemaStringFromJson(schema).getSchema()); if (schemaVersionInfo != null) { response = WSUtils.respondEntity(new Schema(schemaVersionInfo.getName(), schemaVersionInfo.getVersion(), schemaVersionInfo.getId(), schemaVersionInfo.getSchemaText()), Response.Status.OK); } else { response = WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, subject); } } catch (InvalidSchemaException ex) { LOG.error("Given schema is invalid", ex); response = invalidSchemaError(); } catch (SchemaNotFoundException ex) { LOG.error("No schema found with subject [{}]", subject, ex); response = subjectNotFoundError(); } catch (Exception ex) { LOG.error("Encountered error while retrieving schema version with subject: [{}]", subject, ex); response = serverError(); } return response; }
int schemaVersion = schemaVersionInfo.getVersion(); String schemaText = schemaVersionInfo.getSchemaText(); List<SchemaVersionInfo> allEnabledSchemaVersions = if (validationLevel.equals(SchemaValidationLevel.ALL)) { for (SchemaVersionInfo curSchemaVersionInfo : allEnabledSchemaVersions) { int curVersion = curSchemaVersionInfo.getVersion(); if (curVersion < schemaVersion) { checkCompatibility(schemaVersionService, int i = 0; int size = sortedSchemaVersionInfos.size(); for (; i < size && sortedSchemaVersionInfos.get(i).getVersion() < schemaVersion; i++) { String fromSchemaText = sortedSchemaVersionInfos.get(i).getSchemaText(); checkCompatibility(schemaVersionService, schemaMetadata, schemaText, fromSchemaText); for (; i < size && sortedSchemaVersionInfos.get(i).getVersion() > schemaVersion; i++) { String toSchemaText = sortedSchemaVersionInfos.get(i).getSchemaText(); checkCompatibility(schemaVersionService, schemaMetadata, toSchemaText, schemaText);
int schemaVersion = schemaVersionInfo.getVersion(); String schemaText = schemaVersionInfo.getSchemaText(); List<SchemaVersionInfo> allEnabledSchemaVersions = if (validationLevel.equals(SchemaValidationLevel.ALL)) { for (SchemaVersionInfo curSchemaVersionInfo : allEnabledSchemaVersions) { int curVersion = curSchemaVersionInfo.getVersion(); if (curVersion < schemaVersion) { checkCompatibility(schemaVersionService, int i = 0; int size = sortedSchemaVersionInfos.size(); for (; i < size && sortedSchemaVersionInfos.get(i).getVersion() < schemaVersion; i++) { String fromSchemaText = sortedSchemaVersionInfos.get(i).getSchemaText(); checkCompatibility(schemaVersionService, schemaMetadata, schemaText, fromSchemaText); for (; i < size && sortedSchemaVersionInfos.get(i).getVersion() > schemaVersion; i++) { String toSchemaText = sortedSchemaVersionInfos.get(i).getSchemaText(); checkCompatibility(schemaVersionService, schemaMetadata, toSchemaText, schemaText);
} else { Schema schema = new Schema(schemaVersionInfo.getName(), schemaVersionInfo.getVersion(), schemaVersionInfo.getId(), schemaVersionInfo.getSchemaText());
} else { Schema schema = new Schema(schemaVersionInfo.getName(), schemaVersionInfo.getVersion(), schemaVersionInfo.getId(), schemaVersionInfo.getSchemaText());
return new SchemaIdVersion(schemaMetadataId, schemaVersionInfo.getVersion(), schemaVersionInfo.getId());
if (existingSchemaVersionInfo != null) { String mergeMessage = String.format("Given version %d is already merged to master with version %d", schemaVersionId, existingSchemaVersionInfo.getVersion()); LOG.info(mergeMessage); return new SchemaVersionMergeResult(new SchemaIdVersion(schemaMetadataInfo.getId(), existingSchemaVersionInfo.getVersion(), existingSchemaVersionInfo.getId()), mergeMessage); schemaVersionId, createdSchemaVersionInfo.getVersion()); LOG.info(mergeMessage); return new SchemaVersionMergeResult(new SchemaIdVersion(schemaMetadataInfo.getId(), createdSchemaVersionInfo.getVersion(), createdSchemaVersionInfo.getId()), mergeMessage);
@Override public Object deserialize(MessageAndMetadata context, Integer readerSchemaVersion) throws SerDesException { byte protocolId = retrieveProtocolId(context); SchemaIdVersion schemaIdVersion = retrieveSchemaIdVersion(protocolId, context); SchemaMetadata schemaMetadata; SchemaVersionInfo schemaVersionInfo; try { schemaVersionInfo = schemaRegistryClient.getSchemaVersionInfo(schemaIdVersion); schemaMetadata = schemaRegistryClient.getSchemaMetadataInfo(schemaVersionInfo.getName()).getSchemaMetadata(); } catch (Exception e) { throw new RegistryException(e); } return doDeserialize(context, protocolId, schemaMetadata, schemaVersionInfo.getVersion(), readerSchemaVersion); }
if (!compatibilityResult.isCompatible()) { LOG.info("Received schema is not compatible with the latest schema versions [{}] with schema name [{}]", latestSchemaVersionInfo.getVersion(), schemaName); if (!compatibilityResult.isCompatible()) { LOG.info("Received schema is not compatible with one of the schema versions [{}] with schema name [{}]", schemaVersionInfo.getVersion(), schemaName); break;
@Override public O deserialize(I input, Integer readerSchemaVersion) throws SerDesException { ensureInitialized(); // it can be enhanced to have respective protocol handlers for different versions byte protocolId = retrieveProtocolId(input); SchemaIdVersion schemaIdVersion = retrieveSchemaIdVersion(protocolId, input); SchemaVersionInfo schemaVersionInfo; SchemaMetadata schemaMetadata; try { schemaVersionInfo = schemaRegistryClient.getSchemaVersionInfo(schemaIdVersion); schemaMetadata = schemaRegistryClient.getSchemaMetadataInfo(schemaVersionInfo.getName()).getSchemaMetadata(); } catch (Exception e) { throw new RegistryException(e); } return doDeserialize(input, protocolId, schemaMetadata, schemaVersionInfo.getVersion(), readerSchemaVersion); }
public SchemaIdVersion addSchemaVersion(String schemaBranchName, SchemaMetadataInfo schemaMetadataInfo, SchemaVersion schemaVersion) throws SchemaNotFoundException, IncompatibleSchemaException, InvalidSchemaException, SchemaBranchNotFoundException { Preconditions.checkNotNull(schemaBranchName, "Schema branch name can't be null"); checkSchemaText(schemaVersion.getSchemaText()); SchemaVersionInfo schemaVersionInfo; // check whether there exists schema-metadata for schema-metadata-key SchemaMetadata schemaMetadata = schemaMetadataInfo.getSchemaMetadata(); // check whether the same schema text exists schemaVersionInfo = findSchemaVersion(schemaBranchName, schemaMetadata.getType(), schemaVersion.getSchemaText(), schemaMetadataInfo .getSchemaMetadata().getName()); if (schemaVersionInfo == null) { schemaVersionInfo = createSchemaVersion(schemaBranchName, schemaMetadata, schemaMetadataInfo.getId(), schemaVersion); } return new SchemaIdVersion(schemaMetadataInfo.getId(), schemaVersionInfo.getVersion(), schemaVersionInfo.getId()); }
version = latestSchemaVersionInfo.getVersion();
Assert.assertEquals(schemaMetadata, schemaMetadataInfo.getSchemaMetadata()); Integer schemaVersion = schemaRegistry.getSchemaVersionInfo(schemaName, schema1).getVersion(); Assert.assertEquals(v1, schemaVersion);