Search in sources :

Example 1 with PulsarDriverUnsupportedOpException

use of io.nosqlbench.driver.pulsar.exception.PulsarDriverUnsupportedOpException in project nosqlbench by nosqlbench.

the class ReadyPulsarOp method resolve.

private LongFunction<PulsarOp> resolve() {
    String stmtOpType = lookupStaticParameter("optype", true, null);
    if (cmdTpl.containsKey("topic_url")) {
        throw new PulsarDriverParamException("[resolve()] \"topic_url\" parameter is not valid. Perhaps you mean \"topic_uri\"?");
    }
    // Doc-level parameter: topic_uri
    LongFunction<String> topicUriFunc = lookupParameterFunc(PulsarActivityUtil.DOC_LEVEL_PARAMS.TOPIC_URI.label);
    logger.info("topic_uri: {}", topicUriFunc.apply(0));
    // Doc-level parameter: async_api
    boolean useAsyncApi = BooleanUtils.toBoolean(lookupStaticParameter(PulsarActivityUtil.DOC_LEVEL_PARAMS.ASYNC_API.label, false, "false"));
    LongFunction<Boolean> asyncApiFunc = (l) -> useAsyncApi;
    logger.info("async_api: {}", useAsyncApi);
    // Doc-level parameter: use_transaction
    boolean useTransaction = BooleanUtils.toBoolean(lookupStaticParameter(PulsarActivityUtil.DOC_LEVEL_PARAMS.USE_TRANSACTION.label, false, "false"));
    LongFunction<Boolean> useTransactionFunc = (l) -> useTransaction;
    logger.info("use_transaction: {}", useTransaction);
    // Doc-level parameter: admin_delop
    boolean adminDelOp = BooleanUtils.toBoolean(lookupStaticParameter(PulsarActivityUtil.DOC_LEVEL_PARAMS.ADMIN_DELOP.label, false, "false"));
    LongFunction<Boolean> adminDelOpFunc = (l) -> adminDelOp;
    logger.info("admin_delop: {}", adminDelOp);
    // Doc-level parameter: seq_tracking
    boolean seqTracking = BooleanUtils.toBoolean(lookupStaticParameter(PulsarActivityUtil.DOC_LEVEL_PARAMS.SEQ_TRACKING.label, false, "false"));
    LongFunction<Boolean> seqTrackingFunc = (l) -> seqTracking;
    logger.info("seq_tracking: {}", seqTracking);
    // TODO: Collapse this pattern into a simple version and flatten out all call sites
    LongFunction<String> payloadRttFieldFunc = lookupParameterFunc(RTT_TRACKING_FIELD, false, "");
    logger.info("payload_rtt_field_func: {}", payloadRttFieldFunc.apply(0));
    // Admin operation: create/delete tenant
    if (StringUtils.equalsIgnoreCase(stmtOpType, PulsarActivityUtil.OP_TYPES.ADMIN_TENANT.label)) {
        return resolveAdminTenant(clientSpace, asyncApiFunc, adminDelOpFunc);
    } else // Admin operation: create/delete namespace
    if (StringUtils.equalsIgnoreCase(stmtOpType, PulsarActivityUtil.OP_TYPES.ADMIN_NAMESPACE.label)) {
        return resolveAdminNamespace(clientSpace, asyncApiFunc, adminDelOpFunc);
    } else // Admin operation: create/delete topic
    if (StringUtils.equalsIgnoreCase(stmtOpType, PulsarActivityUtil.OP_TYPES.ADMIN_TOPIC.label)) {
        return resolveAdminTopic(clientSpace, topicUriFunc, asyncApiFunc, adminDelOpFunc);
    } else // Regular/non-admin operation: single message sending (producer)
    if (StringUtils.equalsIgnoreCase(stmtOpType, PulsarActivityUtil.OP_TYPES.MSG_SEND.label)) {
        return resolveMsgSend(clientSpace, topicUriFunc, asyncApiFunc, useTransactionFunc, seqTrackingFunc);
    } else // Regular/non-admin operation: single message consuming from a single topic (consumer)
    if (StringUtils.equalsIgnoreCase(stmtOpType, PulsarActivityUtil.OP_TYPES.MSG_CONSUME.label)) {
        return resolveMsgConsume(clientSpace, topicUriFunc, asyncApiFunc, useTransactionFunc, seqTrackingFunc, parseEndToEndStartingTimeSourceParameter(EndToEndStartingTimeSource.NONE), payloadRttFieldFunc);
    } else // Regular/non-admin operation: single message consuming from multiple-topics (consumer)
    if (StringUtils.equalsIgnoreCase(stmtOpType, PulsarActivityUtil.OP_TYPES.MSG_MULTI_CONSUME.label)) {
        return resolveMultiTopicMsgConsume(clientSpace, topicUriFunc, asyncApiFunc, useTransactionFunc, seqTrackingFunc, payloadRttFieldFunc);
    } else // Regular/non-admin operation: single message consuming a single topic (reader)
    if (StringUtils.equalsIgnoreCase(stmtOpType, PulsarActivityUtil.OP_TYPES.MSG_READ.label)) {
        return resolveMsgRead(clientSpace, topicUriFunc, asyncApiFunc);
    } else // Regular/non-admin operation: batch message processing - batch start
    if (StringUtils.equalsIgnoreCase(stmtOpType, PulsarActivityUtil.OP_TYPES.BATCH_MSG_SEND_START.label)) {
        return resolveMsgBatchSendStart(clientSpace, topicUriFunc, asyncApiFunc);
    } else // Regular/non-admin operation: batch message processing - message sending (producer)
    if (StringUtils.equalsIgnoreCase(stmtOpType, PulsarActivityUtil.OP_TYPES.BATCH_MSG_SEND.label)) {
        return resolveMsgBatchSend(clientSpace, asyncApiFunc);
    } else // Regular/non-admin operation: batch message processing - batch send
    if (StringUtils.equalsIgnoreCase(stmtOpType, PulsarActivityUtil.OP_TYPES.BATCH_MSG_SEND_END.label)) {
        return resolveMsgBatchSendEnd(clientSpace, asyncApiFunc);
    } else // Regular/non-admin operation: end-to-end message processing - sending message
    if (StringUtils.equalsIgnoreCase(stmtOpType, PulsarActivityUtil.OP_TYPES.E2E_MSG_PROC_SEND.label)) {
        return resolveMsgSend(clientSpace, topicUriFunc, asyncApiFunc, useTransactionFunc, seqTrackingFunc);
    } else // Regular/non-admin operation: end-to-end message processing - consuming message
    if (StringUtils.equalsIgnoreCase(stmtOpType, PulsarActivityUtil.OP_TYPES.E2E_MSG_PROC_CONSUME.label)) {
        return resolveMsgConsume(clientSpace, topicUriFunc, asyncApiFunc, useTransactionFunc, seqTrackingFunc, parseEndToEndStartingTimeSourceParameter(EndToEndStartingTimeSource.MESSAGE_PUBLISH_TIME), payloadRttFieldFunc);
    } else // Invalid operation type
    {
        throw new PulsarDriverUnsupportedOpException();
    }
}
Also used : PulsarDriverUnsupportedOpException(io.nosqlbench.driver.pulsar.exception.PulsarDriverUnsupportedOpException) java.util(java.util) PulsarSpaceCache(io.nosqlbench.driver.pulsar.PulsarSpaceCache) BaseOpDispenser(io.nosqlbench.engine.api.activityimpl.BaseOpDispenser) LongFunction(java.util.function.LongFunction) Producer(org.apache.pulsar.client.api.Producer) Reader(org.apache.pulsar.client.api.Reader) BooleanUtils(org.apache.commons.lang3.BooleanUtils) PulsarActivity(io.nosqlbench.driver.pulsar.PulsarActivity) StringUtils(org.apache.commons.lang3.StringUtils) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) Transaction(org.apache.pulsar.client.api.transaction.Transaction) CommandTemplate(io.nosqlbench.engine.api.templating.CommandTemplate) PulsarSpace(io.nosqlbench.driver.pulsar.PulsarSpace) PulsarDriverParamException(io.nosqlbench.driver.pulsar.exception.PulsarDriverParamException) Consumer(org.apache.pulsar.client.api.Consumer) Logger(org.apache.logging.log4j.Logger) PulsarActivityUtil(io.nosqlbench.driver.pulsar.util.PulsarActivityUtil) OpTemplate(io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate) LogManager(org.apache.logging.log4j.LogManager) PulsarDriverParamException(io.nosqlbench.driver.pulsar.exception.PulsarDriverParamException) PulsarDriverUnsupportedOpException(io.nosqlbench.driver.pulsar.exception.PulsarDriverUnsupportedOpException)

Aggregations

PulsarActivity (io.nosqlbench.driver.pulsar.PulsarActivity)1 PulsarSpace (io.nosqlbench.driver.pulsar.PulsarSpace)1 PulsarSpaceCache (io.nosqlbench.driver.pulsar.PulsarSpaceCache)1 PulsarDriverParamException (io.nosqlbench.driver.pulsar.exception.PulsarDriverParamException)1 PulsarDriverUnsupportedOpException (io.nosqlbench.driver.pulsar.exception.PulsarDriverUnsupportedOpException)1 PulsarActivityUtil (io.nosqlbench.driver.pulsar.util.PulsarActivityUtil)1 OpTemplate (io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate)1 BaseOpDispenser (io.nosqlbench.engine.api.activityimpl.BaseOpDispenser)1 CommandTemplate (io.nosqlbench.engine.api.templating.CommandTemplate)1 java.util (java.util)1 LongFunction (java.util.function.LongFunction)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 BooleanUtils (org.apache.commons.lang3.BooleanUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Consumer (org.apache.pulsar.client.api.Consumer)1 Producer (org.apache.pulsar.client.api.Producer)1 Reader (org.apache.pulsar.client.api.Reader)1