Search in sources :

Example 16 with BinaryMetadata

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));
        });
    }
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) BinaryObject(org.apache.ignite.binary.BinaryObject) PlatformExpiryPolicy.convertDuration(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy.convertDuration) Arrays(java.util.Arrays) Array(java.lang.reflect.Array) CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) MutableSingletonList(org.apache.ignite.internal.util.MutableSingletonList) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) BinaryOutputStream(org.apache.ignite.internal.binary.streams.BinaryOutputStream) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) BinaryRawWriter(org.apache.ignite.binary.BinaryRawWriter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BinaryUtils(org.apache.ignite.internal.binary.BinaryUtils) Map(java.util.Map) QueryEntity(org.apache.ignite.cache.QueryEntity) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) BinaryFieldMetadata(org.apache.ignite.internal.binary.BinaryFieldMetadata) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) BinaryObjectImpl(org.apache.ignite.internal.binary.BinaryObjectImpl) BinarySchema(org.apache.ignite.internal.binary.BinarySchema) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl) Function(java.util.function.Function) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) PartitionLossPolicy(org.apache.ignite.cache.PartitionLossPolicy) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) BiConsumer(java.util.function.BiConsumer) LinkedList(java.util.LinkedList) SimpleEntry(java.util.AbstractMap.SimpleEntry) EXPIRY_POLICY(org.apache.ignite.internal.client.thin.ProtocolVersionFeature.EXPIRY_POLICY) LinkedHashSet(java.util.LinkedHashSet) BinaryThreadLocalContext(org.apache.ignite.internal.binary.BinaryThreadLocalContext) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) QueryIndexType(org.apache.ignite.cache.QueryIndexType) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) IOException(java.io.IOException) BinaryReaderHandles(org.apache.ignite.internal.binary.BinaryReaderHandles) Consumer(java.util.function.Consumer) QUERY_ENTITY_PRECISION_AND_SCALE(org.apache.ignite.internal.client.thin.ProtocolVersionFeature.QUERY_ENTITY_PRECISION_AND_SCALE) QueryIndex(org.apache.ignite.cache.QueryIndex) CacheMode(org.apache.ignite.cache.CacheMode) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx)

Example 17 with BinaryMetadata

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);
    }
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) BinaryObject(org.apache.ignite.binary.BinaryObject) PlatformExpiryPolicy.convertDuration(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy.convertDuration) Arrays(java.util.Arrays) Array(java.lang.reflect.Array) CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) MutableSingletonList(org.apache.ignite.internal.util.MutableSingletonList) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) BinaryOutputStream(org.apache.ignite.internal.binary.streams.BinaryOutputStream) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) BinaryRawWriter(org.apache.ignite.binary.BinaryRawWriter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BinaryUtils(org.apache.ignite.internal.binary.BinaryUtils) Map(java.util.Map) QueryEntity(org.apache.ignite.cache.QueryEntity) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) BinaryFieldMetadata(org.apache.ignite.internal.binary.BinaryFieldMetadata) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) BinaryObjectImpl(org.apache.ignite.internal.binary.BinaryObjectImpl) BinarySchema(org.apache.ignite.internal.binary.BinarySchema) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl) Function(java.util.function.Function) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) PartitionLossPolicy(org.apache.ignite.cache.PartitionLossPolicy) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) BiConsumer(java.util.function.BiConsumer) LinkedList(java.util.LinkedList) SimpleEntry(java.util.AbstractMap.SimpleEntry) EXPIRY_POLICY(org.apache.ignite.internal.client.thin.ProtocolVersionFeature.EXPIRY_POLICY) LinkedHashSet(java.util.LinkedHashSet) BinaryThreadLocalContext(org.apache.ignite.internal.binary.BinaryThreadLocalContext) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) QueryIndexType(org.apache.ignite.cache.QueryIndexType) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) IOException(java.io.IOException) BinaryReaderHandles(org.apache.ignite.internal.binary.BinaryReaderHandles) Consumer(java.util.function.Consumer) QUERY_ENTITY_PRECISION_AND_SCALE(org.apache.ignite.internal.client.thin.ProtocolVersionFeature.QUERY_ENTITY_PRECISION_AND_SCALE) QueryIndex(org.apache.ignite.cache.QueryIndex) CacheMode(org.apache.ignite.cache.CacheMode) BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) ArrayList(java.util.ArrayList) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BinaryFieldMetadata(org.apache.ignite.internal.binary.BinaryFieldMetadata) BinarySchema(org.apache.ignite.internal.binary.BinarySchema)

Example 18 with BinaryMetadata

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())));
}
Also used : HashMap(java.util.HashMap) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata)

Example 19 with BinaryMetadata

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() + '\'');
}
Also used : BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata)

Example 20 with BinaryMetadata

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);
}
Also used : OutputStream(java.io.OutputStream) IOException(java.io.IOException) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata)

Aggregations

BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)32 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)11 HashMap (java.util.HashMap)9 BinaryTypeImpl (org.apache.ignite.internal.binary.BinaryTypeImpl)9 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)7 IOException (java.io.IOException)6 Map (java.util.Map)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 BinaryObject (org.apache.ignite.binary.BinaryObject)6 LinkedHashMap (java.util.LinkedHashMap)4 BinaryType (org.apache.ignite.binary.BinaryType)4 ArrayList (java.util.ArrayList)3 LinkedHashSet (java.util.LinkedHashSet)3 IgniteException (org.apache.ignite.IgniteException)3 BinaryFieldMetadata (org.apache.ignite.internal.binary.BinaryFieldMetadata)3 Array (java.lang.reflect.Array)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2