Search in sources :

Example 1 with BytesSchemaVersion

use of org.apache.pulsar.common.protocol.schema.BytesSchemaVersion in project pulsar by apache.

the class LookupProxyHandler method handleGetSchema.

public void handleGetSchema(CommandGetSchema commandGetSchema) {
    GET_SCHEMA_REQUESTS.inc();
    if (log.isDebugEnabled()) {
        log.debug("[{}] Received GetSchema {}", clientAddress, commandGetSchema);
    }
    final long clientRequestId = commandGetSchema.getRequestId();
    String serviceUrl = getBrokerServiceUrl(clientRequestId);
    String topic = commandGetSchema.getTopic();
    Optional<SchemaVersion> schemaVersion;
    if (commandGetSchema.hasSchemaVersion()) {
        schemaVersion = Optional.of(commandGetSchema.getSchemaVersion()).map(BytesSchemaVersion::of);
    } else {
        schemaVersion = Optional.empty();
    }
    if (!StringUtils.isNotBlank(serviceUrl)) {
        return;
    }
    InetSocketAddress addr = getAddr(serviceUrl, clientRequestId);
    if (addr == null) {
        return;
    }
    if (log.isDebugEnabled()) {
        log.debug("Getting connections to '{}' for getting schema of topic '{}' with clientReq Id '{}'", addr, topic, clientRequestId);
    }
    proxyConnection.getConnectionPool().getConnection(addr).thenAccept(clientCnx -> {
        // Connected to backend broker
        long requestId = proxyConnection.newRequestId();
        ByteBuf command;
        command = Commands.newGetSchema(requestId, topic, schemaVersion);
        clientCnx.sendGetRawSchema(command, requestId).whenComplete((r, t) -> {
            if (t != null) {
                log.warn("[{}] Failed to get schema {}: {}", clientAddress, topic, t);
                proxyConnection.ctx().writeAndFlush(Commands.newError(clientRequestId, ServerError.ServiceNotReady, t.getMessage()));
            } else {
                proxyConnection.ctx().writeAndFlush(Commands.newGetSchemaResponse(clientRequestId, r));
            }
            proxyConnection.getConnectionPool().releaseConnection(clientCnx);
        });
    }).exceptionally(ex -> {
        // Failed to connect to backend broker
        proxyConnection.ctx().writeAndFlush(Commands.newError(clientRequestId, ServerError.ServiceNotReady, ex.getMessage()));
        return null;
    });
}
Also used : CommandLookupTopic(org.apache.pulsar.common.api.proto.CommandLookupTopic) TopicName(org.apache.pulsar.common.naming.TopicName) Logger(org.slf4j.Logger) SocketAddress(java.net.SocketAddress) Semaphore(java.util.concurrent.Semaphore) URISyntaxException(java.net.URISyntaxException) CommandGetTopicsOfNamespace(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace) ServerError(org.apache.pulsar.common.api.proto.ServerError) LoggerFactory(org.slf4j.LoggerFactory) SchemaVersion(org.apache.pulsar.common.protocol.schema.SchemaVersion) ServiceLookupData(org.apache.pulsar.policies.data.loadbalancer.ServiceLookupData) Counter(io.prometheus.client.Counter) InetSocketAddress(java.net.InetSocketAddress) StringUtils(org.apache.commons.lang3.StringUtils) Commands(org.apache.pulsar.common.protocol.Commands) ByteBuf(io.netty.buffer.ByteBuf) CommandGetSchema(org.apache.pulsar.common.api.proto.CommandGetSchema) CommandPartitionedTopicMetadata(org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadata) BytesSchemaVersion(org.apache.pulsar.common.protocol.schema.BytesSchemaVersion) Optional(java.util.Optional) URI(java.net.URI) LookupType(org.apache.pulsar.common.api.proto.CommandLookupTopicResponse.LookupType) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) SchemaVersion(org.apache.pulsar.common.protocol.schema.SchemaVersion) BytesSchemaVersion(org.apache.pulsar.common.protocol.schema.BytesSchemaVersion) InetSocketAddress(java.net.InetSocketAddress) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with BytesSchemaVersion

use of org.apache.pulsar.common.protocol.schema.BytesSchemaVersion in project pulsar by yahoo.

the class LookupProxyHandler method handleGetSchema.

public void handleGetSchema(CommandGetSchema commandGetSchema) {
    GET_SCHEMA_REQUESTS.inc();
    if (log.isDebugEnabled()) {
        log.debug("[{}] Received GetSchema {}", clientAddress, commandGetSchema);
    }
    final long clientRequestId = commandGetSchema.getRequestId();
    String serviceUrl = getBrokerServiceUrl(clientRequestId);
    String topic = commandGetSchema.getTopic();
    Optional<SchemaVersion> schemaVersion;
    if (commandGetSchema.hasSchemaVersion()) {
        schemaVersion = Optional.of(commandGetSchema.getSchemaVersion()).map(BytesSchemaVersion::of);
    } else {
        schemaVersion = Optional.empty();
    }
    if (!StringUtils.isNotBlank(serviceUrl)) {
        return;
    }
    InetSocketAddress addr = getAddr(serviceUrl, clientRequestId);
    if (addr == null) {
        return;
    }
    if (log.isDebugEnabled()) {
        log.debug("Getting connections to '{}' for getting schema of topic '{}' with clientReq Id '{}'", addr, topic, clientRequestId);
    }
    proxyConnection.getConnectionPool().getConnection(addr).thenAccept(clientCnx -> {
        // Connected to backend broker
        long requestId = proxyConnection.newRequestId();
        ByteBuf command;
        command = Commands.newGetSchema(requestId, topic, schemaVersion);
        clientCnx.sendGetRawSchema(command, requestId).whenComplete((r, t) -> {
            if (t != null) {
                log.warn("[{}] Failed to get schema {}: {}", clientAddress, topic, t);
                proxyConnection.ctx().writeAndFlush(Commands.newError(clientRequestId, ServerError.ServiceNotReady, t.getMessage()));
            } else {
                proxyConnection.ctx().writeAndFlush(Commands.newGetSchemaResponse(clientRequestId, r));
            }
            proxyConnection.getConnectionPool().releaseConnection(clientCnx);
        });
    }).exceptionally(ex -> {
        // Failed to connect to backend broker
        proxyConnection.ctx().writeAndFlush(Commands.newError(clientRequestId, ServerError.ServiceNotReady, ex.getMessage()));
        return null;
    });
}
Also used : CommandLookupTopic(org.apache.pulsar.common.api.proto.CommandLookupTopic) TopicName(org.apache.pulsar.common.naming.TopicName) Logger(org.slf4j.Logger) SocketAddress(java.net.SocketAddress) Semaphore(java.util.concurrent.Semaphore) URISyntaxException(java.net.URISyntaxException) CommandGetTopicsOfNamespace(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace) ServerError(org.apache.pulsar.common.api.proto.ServerError) LoggerFactory(org.slf4j.LoggerFactory) SchemaVersion(org.apache.pulsar.common.protocol.schema.SchemaVersion) ServiceLookupData(org.apache.pulsar.policies.data.loadbalancer.ServiceLookupData) Counter(io.prometheus.client.Counter) InetSocketAddress(java.net.InetSocketAddress) StringUtils(org.apache.commons.lang3.StringUtils) Commands(org.apache.pulsar.common.protocol.Commands) ByteBuf(io.netty.buffer.ByteBuf) CommandGetSchema(org.apache.pulsar.common.api.proto.CommandGetSchema) CommandPartitionedTopicMetadata(org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadata) BytesSchemaVersion(org.apache.pulsar.common.protocol.schema.BytesSchemaVersion) Optional(java.util.Optional) URI(java.net.URI) LookupType(org.apache.pulsar.common.api.proto.CommandLookupTopicResponse.LookupType) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) SchemaVersion(org.apache.pulsar.common.protocol.schema.SchemaVersion) BytesSchemaVersion(org.apache.pulsar.common.protocol.schema.BytesSchemaVersion) InetSocketAddress(java.net.InetSocketAddress) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with BytesSchemaVersion

use of org.apache.pulsar.common.protocol.schema.BytesSchemaVersion in project incubator-pulsar by apache.

the class LookupProxyHandler method handleGetSchema.

public void handleGetSchema(CommandGetSchema commandGetSchema) {
    GET_SCHEMA_REQUESTS.inc();
    if (log.isDebugEnabled()) {
        log.debug("[{}] Received GetSchema {}", clientAddress, commandGetSchema);
    }
    final long clientRequestId = commandGetSchema.getRequestId();
    String serviceUrl = getBrokerServiceUrl(clientRequestId);
    String topic = commandGetSchema.getTopic();
    Optional<SchemaVersion> schemaVersion;
    if (commandGetSchema.hasSchemaVersion()) {
        schemaVersion = Optional.of(commandGetSchema.getSchemaVersion()).map(BytesSchemaVersion::of);
    } else {
        schemaVersion = Optional.empty();
    }
    if (!StringUtils.isNotBlank(serviceUrl)) {
        return;
    }
    InetSocketAddress addr = getAddr(serviceUrl, clientRequestId);
    if (addr == null) {
        return;
    }
    if (log.isDebugEnabled()) {
        log.debug("Getting connections to '{}' for getting schema of topic '{}' with clientReq Id '{}'", addr, topic, clientRequestId);
    }
    proxyConnection.getConnectionPool().getConnection(addr).thenAccept(clientCnx -> {
        // Connected to backend broker
        long requestId = proxyConnection.newRequestId();
        ByteBuf command;
        command = Commands.newGetSchema(requestId, topic, schemaVersion);
        clientCnx.sendGetRawSchema(command, requestId).whenComplete((r, t) -> {
            if (t != null) {
                log.warn("[{}] Failed to get schema {}: {}", clientAddress, topic, t);
                proxyConnection.ctx().writeAndFlush(Commands.newError(clientRequestId, ServerError.ServiceNotReady, t.getMessage()));
            } else {
                proxyConnection.ctx().writeAndFlush(Commands.newGetSchemaResponse(clientRequestId, r));
            }
            proxyConnection.getConnectionPool().releaseConnection(clientCnx);
        });
    }).exceptionally(ex -> {
        // Failed to connect to backend broker
        proxyConnection.ctx().writeAndFlush(Commands.newError(clientRequestId, ServerError.ServiceNotReady, ex.getMessage()));
        return null;
    });
}
Also used : CommandLookupTopic(org.apache.pulsar.common.api.proto.CommandLookupTopic) TopicName(org.apache.pulsar.common.naming.TopicName) Logger(org.slf4j.Logger) SocketAddress(java.net.SocketAddress) Semaphore(java.util.concurrent.Semaphore) URISyntaxException(java.net.URISyntaxException) CommandGetTopicsOfNamespace(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace) ServerError(org.apache.pulsar.common.api.proto.ServerError) LoggerFactory(org.slf4j.LoggerFactory) SchemaVersion(org.apache.pulsar.common.protocol.schema.SchemaVersion) ServiceLookupData(org.apache.pulsar.policies.data.loadbalancer.ServiceLookupData) Counter(io.prometheus.client.Counter) InetSocketAddress(java.net.InetSocketAddress) StringUtils(org.apache.commons.lang3.StringUtils) Commands(org.apache.pulsar.common.protocol.Commands) ByteBuf(io.netty.buffer.ByteBuf) CommandGetSchema(org.apache.pulsar.common.api.proto.CommandGetSchema) CommandPartitionedTopicMetadata(org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadata) BytesSchemaVersion(org.apache.pulsar.common.protocol.schema.BytesSchemaVersion) Optional(java.util.Optional) URI(java.net.URI) LookupType(org.apache.pulsar.common.api.proto.CommandLookupTopicResponse.LookupType) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) SchemaVersion(org.apache.pulsar.common.protocol.schema.SchemaVersion) BytesSchemaVersion(org.apache.pulsar.common.protocol.schema.BytesSchemaVersion) InetSocketAddress(java.net.InetSocketAddress) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)3 Counter (io.prometheus.client.Counter)3 InetSocketAddress (java.net.InetSocketAddress)3 SocketAddress (java.net.SocketAddress)3 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 Optional (java.util.Optional)3 Semaphore (java.util.concurrent.Semaphore)3 StringUtils (org.apache.commons.lang3.StringUtils)3 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)3 CommandGetSchema (org.apache.pulsar.common.api.proto.CommandGetSchema)3 CommandGetTopicsOfNamespace (org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace)3 CommandLookupTopic (org.apache.pulsar.common.api.proto.CommandLookupTopic)3 LookupType (org.apache.pulsar.common.api.proto.CommandLookupTopicResponse.LookupType)3 CommandPartitionedTopicMetadata (org.apache.pulsar.common.api.proto.CommandPartitionedTopicMetadata)3 ServerError (org.apache.pulsar.common.api.proto.ServerError)3 TopicName (org.apache.pulsar.common.naming.TopicName)3 Commands (org.apache.pulsar.common.protocol.Commands)3 BytesSchemaVersion (org.apache.pulsar.common.protocol.schema.BytesSchemaVersion)3 SchemaVersion (org.apache.pulsar.common.protocol.schema.SchemaVersion)3