本文整理汇总了Java中com.hortonworks.registries.schemaregistry.SchemaVersionKey类的典型用法代码示例。如果您正苦于以下问题:Java SchemaVersionKey类的具体用法?Java SchemaVersionKey怎么用?Java SchemaVersionKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SchemaVersionKey类属于com.hortonworks.registries.schemaregistry包,在下文中一共展示了SchemaVersionKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleSchemaIdVersionResponse
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
private SchemaIdVersion handleSchemaIdVersionResponse(SchemaMetadataInfo schemaMetadataInfo,
Response response) throws IncompatibleSchemaException, InvalidSchemaException {
int status = response.getStatus();
String msg = response.readEntity(String.class);
if (status == Response.Status.BAD_REQUEST.getStatusCode() || status == Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()) {
CatalogResponse catalogResponse = readCatalogResponse(msg);
if (CatalogResponse.ResponseMessage.INCOMPATIBLE_SCHEMA.getCode() == catalogResponse.getResponseCode()) {
throw new IncompatibleSchemaException(catalogResponse.getResponseMessage());
} else if (CatalogResponse.ResponseMessage.INVALID_SCHEMA.getCode() == catalogResponse.getResponseCode()) {
throw new InvalidSchemaException(catalogResponse.getResponseMessage());
} else {
throw new RuntimeException(catalogResponse.getResponseMessage());
}
}
Integer version = readEntity(msg, Integer.class);
SchemaVersionInfo schemaVersionInfo = doGetSchemaVersionInfo(new SchemaVersionKey(schemaMetadataInfo.getSchemaMetadata()
.getName(), version));
return new SchemaIdVersion(schemaMetadataInfo.getId(), version, schemaVersionInfo.getId());
}
示例2: doGetSchemaVersionInfo
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
private SchemaVersionInfo doGetSchemaVersionInfo(SchemaIdVersion schemaIdVersion) throws SchemaNotFoundException {
if (schemaIdVersion.getSchemaVersionId() != null) {
LOG.info("Getting schema version from target registry for [{}]", schemaIdVersion.getSchemaVersionId());
return getEntity(currentSchemaRegistryTargets()
.schemaVersionsByIdTarget
.path(schemaIdVersion.getSchemaVersionId().toString()),
SchemaVersionInfo.class);
} else if (schemaIdVersion.getSchemaMetadataId() != null) {
SchemaMetadataInfo schemaMetadataInfo = getSchemaMetadataInfo(schemaIdVersion.getSchemaMetadataId());
SchemaVersionKey schemaVersionKey = new SchemaVersionKey(schemaMetadataInfo.getSchemaMetadata()
.getName(), schemaIdVersion.getVersion());
LOG.info("Getting schema version from target registry for key [{}]", schemaVersionKey);
return doGetSchemaVersionInfo(schemaVersionKey);
}
throw new IllegalArgumentException("Given argument not valid: " + schemaIdVersion);
}
示例3: buildDeserializedObject
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
/**
* Builds the deserialized object from the given {@code payloadInputStream} and applying writer and reader schemas
* from the respective given versions.
*
* @param protocolId protocol id
* @param payloadInputStream payload
* @param schemaMetadata metadata about schema
* @param writerSchemaVersion schema version of the writer
* @param readerSchemaVersion schema version to be applied for reading or projection
* @return the deserialized object
* @throws SerDesException when any ser/des error occurs
*/
protected Object buildDeserializedObject(byte protocolId,
InputStream payloadInputStream,
SchemaMetadata schemaMetadata,
Integer writerSchemaVersion,
Integer readerSchemaVersion) throws SerDesException {
Object deserializedObj;
String schemaName = schemaMetadata.getName();
SchemaVersionKey writerSchemaVersionKey = new SchemaVersionKey(schemaName, writerSchemaVersion);
LOG.debug("SchemaKey: [{}] for the received payload", writerSchemaVersionKey);
Schema writerSchema = getSchema(writerSchemaVersionKey);
if (writerSchema == null) {
throw new RegistryException("No schema exists with metadata-key: " + schemaMetadata + " and writerSchemaVersion: " + writerSchemaVersion);
}
Schema readerSchema = readerSchemaVersion != null ? getSchema(new SchemaVersionKey(schemaName, readerSchemaVersion)) : null;
deserializedObj = deserializePayloadForProtocol(protocolId, payloadInputStream, writerSchema, readerSchema);
return deserializedObj;
}
示例4: traverseIncludedSchemaTypes
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
private Map<String, Schema> traverseIncludedSchemaTypes(String schemaText,
Map<String, SchemaParsingState> schemaParsingStates)
throws InvalidSchemaException, SchemaNotFoundException {
List<SchemaVersionKey> includedSchemaVersions = getIncludedSchemaVersions(schemaText);
if (includedSchemaVersions == null || includedSchemaVersions.isEmpty()) {
return Collections.emptyMap();
}
Map<String, Schema> schemaTypes = new HashMap<>();
for (SchemaVersionKey schemaVersionKey : includedSchemaVersions) {
Map<String, Schema> collectedSchemas = collectSchemaTypes(schemaVersionKey, schemaParsingStates);
if (collectedSchemas != null) {
schemaTypes.putAll(collectedSchemas);
}
}
return schemaTypes;
}
示例5: getIncludedSchemaVersions
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
private List<SchemaVersionKey> getIncludedSchemaVersions(String schemaText) throws InvalidSchemaException {
JsonNode jsonNode = null;
try {
jsonNode = new ObjectMapper().readTree(schemaText);
} catch (IOException e) {
throw new InvalidSchemaException(e);
}
JsonNode includeSchemaNodes = jsonNode.get("includeSchemas");
List<SchemaVersionKey> includedSchemaVersions = new ArrayList<>();
if (includeSchemaNodes != null) {
if (!includeSchemaNodes.isArray()) {
throw new InvalidSchemaException("includeSchemas should be an array of strings");
}
for (JsonNode includeSchema : includeSchemaNodes) {
String name = includeSchema.get("name").asText();
JsonNode versionNode = includeSchema.get("version");
int version = versionNode != null ? versionNode.asInt() : SchemaVersionKey.LATEST_VERSION;
includedSchemaVersions.add(new SchemaVersionKey(name, version));
}
}
return includedSchemaVersions;
}
示例6: findSchemasByFields
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
@GET
@Path("/search/schemas/fields")
@ApiOperation(value = "Search for schemas containing the given field names",
notes = "Search the schemas for given field names and return a list of schemas that contain the field.",
response = SchemaVersionKey.class, responseContainer = "List", tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response findSchemasByFields(@Context UriInfo uriInfo) {
MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
try {
Collection<SchemaVersionKey> schemaVersionKeys = schemaRegistry.findSchemasByFields(buildSchemaFieldQuery(queryParameters));
return WSUtils.respondEntities(schemaVersionKeys, Response.Status.OK);
} catch (Exception ex) {
LOG.error("Encountered error while finding schemas for given fields [{}]", queryParameters, ex);
return WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage());
}
}
示例7: serialize
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
@Override
public byte[] serialize(String topic, StreamlineEvent streamlineEvent) {
SchemaMetadata schemaMetadata = getSchemaKey(topic, false);
SchemaVersionInfo schemaVersionInfo;
try {
schemaMetadata = schemaRegistryClient.getSchemaMetadataInfo(schemaMetadata.getName()).getSchemaMetadata();
if (writerSchemaVersion != null) {
schemaVersionInfo = schemaRegistryClient.getSchemaVersionInfo(new SchemaVersionKey(schemaMetadata.getName(), writerSchemaVersion));
} else {
schemaVersionInfo = schemaRegistryClient.getLatestSchemaVersionInfo(schemaMetadata.getName());
}
} catch (SchemaNotFoundException e) {
LOG.error("Exception occured while getting SchemaVersionInfo for " + schemaMetadata, e);
throw new RuntimeException(e);
}
if (streamlineEvent == null || streamlineEvent.isEmpty()) {
return null;
} else {
return avroSnapshotSerializer.serialize(getAvroRecord(streamlineEvent, new Schema.Parser().parse(schemaVersionInfo.getSchemaText())),
schemaMetadata);
}
}
示例8: deleteSchemaVersion
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
@Override
public void deleteSchemaVersion(SchemaVersionKey schemaVersionKey) throws SchemaNotFoundException, SchemaLifecycleException {
schemaVersionInfoCache.invalidateSchema(new SchemaVersionInfoCache.Key(schemaVersionKey));
WebTarget target = currentSchemaRegistryTargets().schemasTarget.path(String.format("%s/versions/%s", schemaVersionKey
.getSchemaName(), schemaVersionKey.getVersion()));
Response response = Subject.doAs(subject, new PrivilegedAction<Response>() {
@Override
public Response run() {
return target.request(MediaType.APPLICATION_JSON_TYPE).delete(Response.class);
}
});
handleDeleteSchemaResponse(response);
}
示例9: findSchemasByFields
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
@Override
public Collection<SchemaVersionKey> findSchemasByFields(SchemaFieldQuery schemaFieldQuery) {
WebTarget target = currentSchemaRegistryTargets().searchFieldsTarget;
for (Map.Entry<String, String> entry : schemaFieldQuery.toQueryMap().entrySet()) {
target = target.queryParam(entry.getKey(), entry.getValue());
}
return getEntities(target, SchemaVersionKey.class);
}
示例10: doInit
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
protected void doInit(Map<String, ?> config) {
schemaCache = CacheBuilder.newBuilder()
.maximumSize(getCacheMaxSize(config))
.expireAfterAccess(getCacheExpiryInSecs(config), TimeUnit.SECONDS)
.build(new CacheLoader<SchemaVersionKey, S>() {
@Override
public S load(SchemaVersionKey schemaVersionKey) {
try {
return getParsedSchema(schemaVersionKey);
} catch (SchemaNotFoundException | InvalidSchemaException e) {
throw new RegistryException(e);
}
}
});
}
示例11: getSchema
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
/**
* Returns Schema for the given {@code schemaVersionKey} from loadable cache.
* @param schemaVersionKey schema version key
*/
protected S getSchema(SchemaVersionKey schemaVersionKey) {
try {
return schemaCache.get(schemaVersionKey);
} catch (ExecutionException e) {
if (e.getCause() instanceof RegistryException) {
throw (RegistryException) e.getCause();
} else {
throw new RegistryException(e);
}
}
}
示例12: _testSerDes
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
private void _testSerDes(Long id, Number serdesProtocolVersion) throws Exception {
SchemaMetadata schemaMetadata =
new SchemaMetadata.Builder("random-" + System.currentTimeMillis())
.schemaGroup("custom")
.type(AvroSchemaProvider.TYPE)
.compatibility(SchemaCompatibility.BACKWARD)
.build();
SchemaIdVersion schemaIdVersion = new SchemaIdVersion(1L, 1, id);
Device input = new Device(1L, "device", 1, System.currentTimeMillis());
SchemaVersionInfo schemaVersionInfo = new SchemaVersionInfo(id, input.getName().toString(), schemaIdVersion.getVersion(),
input.getSchema().toString(),
System.currentTimeMillis(),
"some device");
new Expectations() {
{
mockSchemaRegistryClient.getSchemaMetadataInfo(anyString);
result = new SchemaMetadataInfo(schemaMetadata); minTimes=0; maxTimes=1;
mockSchemaRegistryClient.addSchemaVersion(withInstanceOf(SchemaMetadata.class), withInstanceOf(SchemaVersion.class));
result = schemaIdVersion; minTimes=0; maxTimes=1;
mockSchemaRegistryClient.getSchemaVersionInfo(withInstanceOf(SchemaVersionKey.class));
result = schemaVersionInfo; minTimes=0; maxTimes=1;
}
};
AvroSnapshotSerializer serializer = new AvroSnapshotSerializer();
serializer.init(Collections.singletonMap(SERDES_PROTOCOL_VERSION, serdesProtocolVersion));
AvroSnapshotDeserializer deserializer = new AvroSnapshotDeserializer();
deserializer.init(Collections.emptyMap());
byte[] serializedData = serializer.serialize(input, schemaMetadata);
Object deserializedObj = deserializer.deserialize(new ByteArrayInputStream(serializedData), null);
Assert.assertTrue(SpecificData.get().compare(input, deserializedObj, input.getSchema()) == 0);
}
示例13: collectSchemaTypes
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
private Map<String, Schema> collectSchemaTypes(SchemaVersionKey schemaVersionKey,
Map<String, SchemaParsingState> schemaParsingStates)
throws SchemaNotFoundException, InvalidSchemaException {
String schemaName = schemaVersionKey.getSchemaName();
SchemaParsingState schemaParsingState = schemaParsingStates.putIfAbsent(schemaName, SchemaParsingState.PARSING);
// if it is already parsed then the respective schema types would have been already collected.
if (SchemaParsingState.PARSED == schemaParsingState) {
return null;
}
// if it is in parsing state earlier and it is visted again then ther eis circular dependency!!
if (SchemaParsingState.PARSING == schemaParsingState) {
throw new CyclicSchemaDependencyException("Cyclic dependency of schema imports with schema [" + schemaName + "]");
}
// this schema is not yet parsed till now
if (schemaParsingState == null) {
Schema.Parser parser = new Schema.Parser();
Schema schema = parser.parse(getResultantSchema(schemaVersionKey, schemaParsingStates));
Map<String, Schema> complexTypes = new HashMap<>();
collectComplexTypes(schema, complexTypes);
schemaParsingStates.put(schemaName, SchemaParsingState.PARSED);
return complexTypes;
}
throw new IllegalStateException("Schema parsing with schema version " + schemaVersionKey + " is in invalid state!!");
}
示例14: addAndDeleteSchemaVersion
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
private SchemaVersionKey addAndDeleteSchemaVersion(String schemaName) throws InvalidSchemaException, IncompatibleSchemaException, SchemaNotFoundException, IOException, SchemaBranchNotFoundException, SchemaLifecycleException {
SchemaMetadata schemaMetadata = createSchemaMetadata(schemaName, SchemaCompatibility.BOTH);
SchemaIdVersion schemaIdVersion = SCHEMA_REGISTRY_CLIENT.addSchemaVersion(schemaMetadata, new SchemaVersion(AvroSchemaRegistryClientUtil
.getSchema("/device.avsc"), "Initial version of the schema"));
SchemaVersionKey schemaVersionKey = new SchemaVersionKey(schemaMetadata.getName(), schemaIdVersion.getVersion());
SCHEMA_REGISTRY_CLIENT.deleteSchemaVersion(schemaVersionKey);
return schemaVersionKey;
}
示例15: testDeletingNonExistingSchema
import com.hortonworks.registries.schemaregistry.SchemaVersionKey; //导入依赖的package包/类
@Test(expected = SchemaNotFoundException.class)
public void testDeletingNonExistingSchema() throws Exception {
SchemaVersionKey schemaVersionKey = addAndDeleteSchemaVersion(TEST_NAME_RULE.getMethodName());
// deleting again should return SchemaNotFoundException
SCHEMA_REGISTRY_CLIENT.deleteSchemaVersion(schemaVersionKey);
}