protected synchronized SchemaRegistryClient getClient() { if (!initialized) { schemaRegistryClient = new SchemaRegistryClient(schemaRegistryConfig); initialized = true; } return schemaRegistryClient; }
@OnDisabled public void close() { if (schemaRegistryClient != null) { schemaRegistryClient.close(); } initialized = false; }
versionInfo = client.getLatestSchemaVersionInfo(schemaName); } else { versionInfo = client.getLatestSchemaVersionInfo(branchName, schemaName);
final SchemaMetadataInfo metadataInfo = client.getSchemaMetadataInfo(schemaName.get()); if (metadataInfo == null) { throw new org.apache.nifi.schema.access.SchemaNotFoundException("Could not find schema with name '" + schemaName + "'");
@Override public SchemaIdVersion addSchemaVersion(final String schemaName, final SchemaVersion schemaVersion) throws InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException, SchemaBranchNotFoundException { return addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaName, schemaVersion); }
private SchemaVersionInfo getSchemaVersionInfo(final SchemaRegistryClient client, final SchemaVersionKey key) throws org.apache.nifi.schema.access.SchemaNotFoundException { try { // Try to fetch the SchemaVersionInfo from the cache. final Tuple<SchemaVersionInfo, Long> timestampedVersionInfo = schemaVersionByKeyCache.get(key); // Determine if the timestampedVersionInfo is expired boolean fetch = false; if (timestampedVersionInfo == null) { fetch = true; } else { final long minTimestamp = System.nanoTime() - versionInfoCacheNanos; fetch = timestampedVersionInfo.getValue() < minTimestamp; } // If not expired, use what we got from the cache if (!fetch) { return timestampedVersionInfo.getKey(); } // schema version info was expired or not found in cache. Fetch from schema registry final SchemaVersionInfo versionInfo = client.getSchemaVersionInfo(key); if (versionInfo == null) { throw new org.apache.nifi.schema.access.SchemaNotFoundException("Could not find schema with name '" + key.getSchemaName() + "' and version " + key.getVersion()); } // Store new version in cache. final Tuple<SchemaVersionInfo, Long> tuple = new Tuple<>(versionInfo, System.nanoTime()); schemaVersionByKeyCache.put(key, tuple); return versionInfo; } catch (final SchemaNotFoundException e) { throw new org.apache.nifi.schema.access.SchemaNotFoundException(e); } }
@Override public SchemaMetadataInfo updateSchemaMetadata(String schemaName, SchemaMetadata schemaMetadata) { SchemaMetadataInfo schemaMetadataInfo = postEntity(currentSchemaRegistryTargets().schemasTarget.path(schemaName), schemaMetadata, SchemaMetadataInfo.class); if (schemaMetadataInfo != null) { schemaMetadataCache.put(SchemaMetadataCache.Key.of(schemaName), schemaMetadataInfo); } return schemaMetadataInfo; }
@Override public Long addSchemaMetadata(SchemaMetadata schemaMetadata) { SchemaMetadataInfo schemaMetadataInfo = schemaMetadataCache.getIfPresent(SchemaMetadataCache.Key.of(schemaMetadata .getName())); if (schemaMetadataInfo == null) { return doRegisterSchemaMetadata(schemaMetadata, currentSchemaRegistryTargets().schemasTarget); } return schemaMetadataInfo.getId(); }
@Override public SchemaMetadataInfo load(Key key) throws Exception { if (key.getName() != null) { return schemaMetadataFetcher.fetch(key.getName()); } else if (key.getId() != null) { return schemaMetadataFetcher.fetch(key.getId()); } else { throw new RegistryException("Key should have name or id as non null"); } } });
@Override public SchemaVersionLifecycleStateMachineInfo getSchemaVersionLifecycleStateMachineInfo() { return getEntity(currentSchemaRegistryTargets().schemaVersionsStatesMachineTarget, SchemaVersionLifecycleStateMachineInfo.class); }
@Override public SchemaVersionInfo retrieveSchemaVersion(SchemaIdVersion key) throws SchemaNotFoundException { return schemaRegistryClient.getSchemaVersionInfo(key); } };
/** * Creates {@link SchemaRegistryClient} instance with the given yaml config. * * @param confFile config file which contains the configuration entries. * * @throws IOException when any IOException occurs while reading the given confFile */ public SchemaRegistryClient(File confFile) throws IOException { this(buildConfFromFile(confFile)); }
@Override public void deleteSchemaVersion(Long schemaVersionId) throws SchemaNotFoundException, SchemaLifecycleException { transitionSchemaVersionState(schemaVersionId, "delete", null); }
@Override public CompatibilityResult checkCompatibility(String schemaName, String toSchemaText) throws SchemaNotFoundException, SchemaBranchNotFoundException { return checkCompatibility(SchemaBranch.MASTER_BRANCH, schemaName, toSchemaText); }
public static Key of(Long id) { return new Key(id); } }
public SampleSchemaRegistryClientApp(Map<String, Object> config) { this.config = config; schemaRegistryClient = new SchemaRegistryClient(config); }
final SchemaMetadataInfo info = client.getSchemaMetadataInfo(schemaId.getAsLong()); if (info == null) { throw new org.apache.nifi.schema.access.SchemaNotFoundException("Could not find schema with ID '" + schemaId + "' and version '" + version + "'");
@Override public SchemaIdVersion addSchemaVersion(SchemaMetadata schemaMetadata, SchemaVersion schemaVersion) throws InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException, SchemaBranchNotFoundException { return addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, schemaVersion); }