/** * It fetches latest version of the schema. * @param schemaName Fully qualified schema name * @param schemaVersion schema version * @return Avro schema */ public Schema getSchema(@NotEmpty final String schemaName, final int schemaVersion) { try { final HDFSSchemaServiceConfiguration conf = new HDFSSchemaServiceConfiguration(this.conf); Path schemaPath = new Path(conf.getPath(), String.format(AVRO_SCHEMA_FILE_PATTERN, schemaName, schemaVersion)); return getSchemaFromPath(schemaPath); } catch (IOException e) { throw new JobRuntimeException("Unable to load schema", e); } }
public HDFSSchemaServiceConfiguration(@NonNull final Configuration conf) { ConfigUtil.checkMandatoryProperties(conf, getMandatoryProperties()); this.conf = conf; }
@Override public HDFSSchemaServiceWriter getWriter(@NotEmpty final String schemaName, final int schemaVersion) { HDFSSchemaServiceWriter writer; try { final HDFSSchemaServiceConfiguration conf = new HDFSSchemaServiceConfiguration(this.conf); Path schemaPath = new Path(conf.getPath(), String.format(AVRO_SCHEMA_FILE_PATTERN, schemaName, schemaVersion)); writer = new HDFSSchemaServiceWriter(getSchemaFromPath(schemaPath)); } catch (IOException e) { throw new JobRuntimeException("Unable to load schema", e); } return writer; }
@Override public HDFSSchemaServiceReader getReader(@NotEmpty final String schemaName, final int schemaVersion) { HDFSSchemaServiceReader reader; try { final HDFSSchemaServiceConfiguration conf = new HDFSSchemaServiceConfiguration(this.conf); Path schemaPath = new Path(conf.getPath(), String.format(AVRO_SCHEMA_FILE_PATTERN, schemaName, schemaVersion)); reader = new HDFSSchemaServiceReader(getSchemaFromPath(schemaPath)); } catch (IOException e) { throw new JobRuntimeException("Unable to load schema", e); } return reader; }
@Override public Schema getSchema(@NotEmpty final String schemaName) { final HadoopConfiguration hadoopConfiguration = new HadoopConfiguration(this.conf); final HDFSSchemaServiceConfiguration conf = new HDFSSchemaServiceConfiguration(this.conf); try { LocatedFileStatus resultSchemaFile = null; final FileSystem fileSystem = FileSystem.get(hadoopConfiguration.getHadoopConf()); final RemoteIterator<LocatedFileStatus> fileIterator = fileSystem.listFiles(conf.getPath(), false); while (fileIterator.hasNext()) { final LocatedFileStatus f = fileIterator.next(); String.format("Unable to find schema %s in %s", schemaName, conf.getPath())); } else { return getSchemaFromFile(resultSchemaFile);