use of org.apache.ignite.internal.binary.BinaryMetadata in project ignite by apache.
the class ClientUtils method binaryMetadata.
/**
* Serialize binary type metadata to stream.
*/
void binaryMetadata(BinaryMetadata meta, BinaryOutputStream out) {
try (BinaryRawWriterEx w = new BinaryWriterExImpl(marsh.context(), out, null, null)) {
w.writeInt(meta.typeId());
w.writeString(meta.typeName());
w.writeString(meta.affinityKeyFieldName());
collection(meta.fieldsMap().entrySet(), out, (unused, e) -> {
w.writeString(e.getKey());
w.writeInt(e.getValue().typeId());
w.writeInt(e.getValue().fieldId());
});
w.writeBoolean(meta.isEnum());
if (meta.isEnum())
collection(meta.enumMap().entrySet(), out, (unused, e) -> {
w.writeString(e.getKey());
w.writeInt(e.getValue());
});
collection(meta.schemas(), out, (unused, s) -> {
w.writeInt(s.schemaId());
collection(Arrays.stream(s.fieldIds()).boxed().collect(Collectors.toList()), out, (unused2, i) -> w.writeInt(i));
});
}
}
use of org.apache.ignite.internal.binary.BinaryMetadata in project ignite by apache.
the class ClientUtils method binaryMetadata.
/**
* Deserialize binary type metadata from stream.
*/
BinaryMetadata binaryMetadata(BinaryInputStream in) throws IOException {
try (BinaryReaderExImpl reader = createBinaryReader(in)) {
int typeId = reader.readInt();
String typeName = reader.readString();
String affKeyFieldName = reader.readString();
Map<String, BinaryFieldMetadata> fields = ClientUtils.map(in, unused -> reader.readString(), unused2 -> new BinaryFieldMetadata(reader.readInt(), reader.readInt()));
boolean isEnum = reader.readBoolean();
Map<String, Integer> enumValues = isEnum ? ClientUtils.map(in, unsed -> reader.readString(), unsed2 -> reader.readInt()) : null;
Collection<BinarySchema> schemas = ClientUtils.collection(in, unused -> new BinarySchema(reader.readInt(), new ArrayList<>(ClientUtils.collection(in, unused2 -> reader.readInt()))));
return new BinaryMetadata(typeId, typeName, fields, affKeyFieldName, schemas, isEnum, enumValues);
}
}
use of org.apache.ignite.internal.binary.BinaryMetadata in project ignite by apache.
the class MetadataDetailsCommand method printResult.
/**
* {@inheritDoc}
*/
@Override
protected void printResult(MetadataListResult res, Logger log) {
if (res.metadata() == null) {
log.info("Type not found");
return;
}
assert res.metadata().size() == 1 : "Unexpected metadata results: " + res.metadata();
BinaryMetadata m = F.first(res.metadata());
log.info("typeId=" + printInt(m.typeId()));
log.info("typeName=" + m.typeName());
log.info("Fields:");
final Map<Integer, String> fldMap = new HashMap<>();
m.fieldsMap().forEach((name, fldMeta) -> {
log.info(INDENT + "name=" + name + ", type=" + BinaryUtils.fieldTypeName(fldMeta.typeId()) + ", fieldId=" + printInt(fldMeta.fieldId()));
fldMap.put(fldMeta.fieldId(), name);
});
log.info("Schemas:");
m.schemas().forEach(s -> log.info(INDENT + "schemaId=" + printInt(s.schemaId()) + ", fields=" + Arrays.stream(s.fieldIds()).mapToObj(fldMap::get).collect(Collectors.toList())));
}
use of org.apache.ignite.internal.binary.BinaryMetadata in project ignite by apache.
the class MetadataUpdateCommand method printResult.
/**
* {@inheritDoc}
*/
@Override
protected void printResult(MetadataMarshalled res, Logger log) {
if (res.metadata() == null) {
log.info("Type not found");
return;
}
BinaryMetadata m = res.metadata();
log.info("Metadata updated for the type: '" + m.typeName() + '\'');
}
use of org.apache.ignite.internal.binary.BinaryMetadata in project ignite by apache.
the class MetadataRemoveCommand method printResult.
/**
* {@inheritDoc}
*/
@Override
protected void printResult(MetadataMarshalled res, Logger log) {
if (res.metadata() == null)
throw new IllegalArgumentException("Failed to remove binary type, type not found: " + arg());
BinaryMetadata m = res.metadata();
if (outFile == null)
outFile = FS.getPath(m.typeId() + ".bin");
try (OutputStream os = Files.newOutputStream(outFile)) {
os.write(res.metadataMarshalled());
} catch (IOException e) {
log.severe("Cannot store removed type '" + m.typeName() + "' to: " + outFile);
log.severe(CommandLogger.errorMessage(e));
return;
}
log.info("Type '" + m.typeName() + "' is removed. Metadata is stored at: " + outFile);
}
Aggregations