Search in sources :

Example 1 with ICredentialsListener

use of org.apache.storm.ICredentialsListener in project storm by apache.

the class BoltExecutor method init.

public void init(ArrayList<Task> idToTask, int idToTaskBase) throws InterruptedException {
    executorTransfer.initLocalRecvQueues();
    workerReady.await();
    while (!stormActive.get()) {
        // Topology may be deployed in deactivated mode, wait for activation
        Utils.sleepNoSimulation(100);
    }
    LOG.info("Preparing bolt {}:{}", componentId, getTaskIds());
    for (Task taskData : idToTask) {
        if (taskData == null) {
            // This happens if the min id is too small
            continue;
        }
        IBolt boltObject = (IBolt) taskData.getTaskObject();
        TopologyContext userContext = taskData.getUserContext();
        if (boltObject instanceof ICredentialsListener) {
            ((ICredentialsListener) boltObject).setCredentials(credentials);
        }
        if (Constants.SYSTEM_COMPONENT_ID.equals(componentId)) {
            BuiltinMetricsUtil.registerIconnectionServerMetric(workerData.getReceiver(), topoConf, userContext);
            // add any autocredential expiry metrics from the worker
            if (workerData.getAutoCredentials() != null) {
                for (IAutoCredentials autoCredential : workerData.getAutoCredentials()) {
                    if (autoCredential instanceof IMetricsRegistrant) {
                        IMetricsRegistrant registrant = (IMetricsRegistrant) autoCredential;
                        registrant.registerMetrics(userContext, topoConf);
                    }
                }
            }
        }
        this.outputCollector = new BoltOutputCollectorImpl(this, taskData, rand, hasEventLoggers, ackingEnabled, isDebug);
        boltObject.prepare(topoConf, userContext, new OutputCollector(outputCollector));
    }
    openOrPrepareWasCalled.set(true);
    LOG.info("Prepared bolt {}:{}", componentId, taskIds);
    setupTicks(false);
    setupMetrics();
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) Task(org.apache.storm.daemon.Task) ICredentialsListener(org.apache.storm.ICredentialsListener) IAutoCredentials(org.apache.storm.security.auth.IAutoCredentials) IMetricsRegistrant(org.apache.storm.metric.api.IMetricsRegistrant) IBolt(org.apache.storm.task.IBolt) TopologyContext(org.apache.storm.task.TopologyContext)

Example 2 with ICredentialsListener

use of org.apache.storm.ICredentialsListener in project storm by apache.

the class SpoutExecutor method init.

public void init(final ArrayList<Task> idToTask, int idToTaskBase) throws InterruptedException {
    this.threadId = Thread.currentThread().getId();
    executorTransfer.initLocalRecvQueues();
    workerReady.await();
    while (!stormActive.get()) {
        // Topology may be deployed in deactivated mode, wait for activation
        Utils.sleepNoSimulation(100);
    }
    LOG.info("Opening spout {}:{}", componentId, taskIds);
    this.idToTask = idToTask;
    this.maxSpoutPending = ObjectReader.getInt(topoConf.get(Config.TOPOLOGY_MAX_SPOUT_PENDING), 0) * idToTask.size();
    this.spouts = new ArrayList<>();
    for (Task task : idToTask) {
        if (task != null) {
            this.spouts.add((ISpout) task.getTaskObject());
        }
    }
    this.pending = new RotatingMap<>(2, new RotatingMap.ExpiredCallback<Long, TupleInfo>() {

        @Override
        public void expire(Long key, TupleInfo tupleInfo) {
            Long timeDelta = null;
            if (tupleInfo.getTimestamp() != 0) {
                timeDelta = Time.deltaMs(tupleInfo.getTimestamp());
            }
            failSpoutMsg(SpoutExecutor.this, idToTask.get(tupleInfo.getTaskId() - idToTaskBase), timeDelta, tupleInfo, "TIMEOUT");
        }
    });
    this.outputCollectors = new ArrayList<>();
    for (int i = 0; i < idToTask.size(); ++i) {
        Task taskData = idToTask.get(i);
        if (taskData == null) {
            continue;
        }
        ISpout spoutObject = (ISpout) taskData.getTaskObject();
        spoutOutputCollector = new SpoutOutputCollectorImpl(spoutObject, this, taskData, emittedCount, hasAckers, rand, hasEventLoggers, isDebug, pending);
        SpoutOutputCollector outputCollector = new SpoutOutputCollector(spoutOutputCollector);
        this.outputCollectors.add(outputCollector);
        if (spoutObject instanceof ICredentialsListener) {
            ((ICredentialsListener) spoutObject).setCredentials(credentials);
        }
        spoutObject.open(topoConf, taskData.getUserContext(), outputCollector);
    }
    openOrPrepareWasCalled.set(true);
    LOG.info("Opened spout {}:{}", componentId, taskIds);
    setupTicks(true);
    setupMetrics();
}
Also used : Task(org.apache.storm.daemon.Task) ICredentialsListener(org.apache.storm.ICredentialsListener) TupleInfo(org.apache.storm.executor.TupleInfo) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) MutableLong(org.apache.storm.utils.MutableLong) ISpout(org.apache.storm.spout.ISpout)

Example 3 with ICredentialsListener

use of org.apache.storm.ICredentialsListener in project storm by apache.

the class BoltExecutor method init.

public void init(Map<Integer, Task> idToTask) {
    while (!stormActive.get()) {
        Utils.sleep(100);
    }
    LOG.info("Preparing bolt {}:{}", componentId, idToTask.keySet());
    for (Map.Entry<Integer, Task> entry : idToTask.entrySet()) {
        Task taskData = entry.getValue();
        IBolt boltObject = (IBolt) taskData.getTaskObject();
        TopologyContext userContext = taskData.getUserContext();
        taskData.getBuiltInMetrics().registerAll(stormConf, userContext);
        if (boltObject instanceof ICredentialsListener) {
            ((ICredentialsListener) boltObject).setCredentials(credentials);
        }
        if (Constants.SYSTEM_COMPONENT_ID.equals(componentId)) {
            Map<String, DisruptorQueue> map = ImmutableMap.of("sendqueue", transferQueue, "receive", receiveQueue, "transfer", workerData.getTransferQueue());
            BuiltinMetricsUtil.registerQueueMetrics(map, stormConf, userContext);
            Map cachedNodePortToSocket = (Map) workerData.getCachedNodeToPortSocket().get();
            BuiltinMetricsUtil.registerIconnectionClientMetrics(cachedNodePortToSocket, stormConf, userContext);
            BuiltinMetricsUtil.registerIconnectionServerMetric(workerData.getReceiver(), stormConf, userContext);
        } else {
            Map<String, DisruptorQueue> map = ImmutableMap.of("sendqueue", transferQueue, "receive", receiveQueue);
            BuiltinMetricsUtil.registerQueueMetrics(map, stormConf, userContext);
        }
        IOutputCollector outputCollector = new BoltOutputCollectorImpl(this, taskData, entry.getKey(), rand, hasEventLoggers, isDebug);
        boltObject.prepare(stormConf, userContext, new OutputCollector(outputCollector));
    }
    openOrPrepareWasCalled.set(true);
    LOG.info("Prepared bolt {}:{}", componentId, idToTask.keySet());
    setupMetrics();
}
Also used : IOutputCollector(org.apache.storm.task.IOutputCollector) OutputCollector(org.apache.storm.task.OutputCollector) Task(org.apache.storm.daemon.Task) ICredentialsListener(org.apache.storm.ICredentialsListener) IOutputCollector(org.apache.storm.task.IOutputCollector) DisruptorQueue(org.apache.storm.utils.DisruptorQueue) IBolt(org.apache.storm.task.IBolt) TopologyContext(org.apache.storm.task.TopologyContext) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 4 with ICredentialsListener

use of org.apache.storm.ICredentialsListener in project storm by apache.

the class SpoutExecutor method init.

public void init(final Map<Integer, Task> idToTask) {
    while (!stormActive.get()) {
        Utils.sleep(100);
    }
    LOG.info("Opening spout {}:{}", componentId, idToTask.keySet());
    this.idToTask = idToTask;
    this.maxSpoutPending = Utils.getInt(stormConf.get(Config.TOPOLOGY_MAX_SPOUT_PENDING), 0) * idToTask.size();
    this.spouts = new ArrayList<>();
    for (Task task : idToTask.values()) {
        this.spouts.add((ISpout) task.getTaskObject());
    }
    this.pending = new RotatingMap<>(2, new RotatingMap.ExpiredCallback<Long, TupleInfo>() {

        @Override
        public void expire(Long key, TupleInfo tupleInfo) {
            Long timeDelta = null;
            if (tupleInfo.getTimestamp() != 0) {
                timeDelta = Time.deltaMs(tupleInfo.getTimestamp());
            }
            failSpoutMsg(SpoutExecutor.this, idToTask.get(tupleInfo.getTaskId()), timeDelta, tupleInfo, "TIMEOUT");
        }
    });
    this.spoutThrottlingMetrics.registerAll(stormConf, idToTask.values().iterator().next().getUserContext());
    this.outputCollectors = new ArrayList<>();
    for (Map.Entry<Integer, Task> entry : idToTask.entrySet()) {
        Task taskData = entry.getValue();
        ISpout spoutObject = (ISpout) taskData.getTaskObject();
        SpoutOutputCollectorImpl spoutOutputCollector = new SpoutOutputCollectorImpl(spoutObject, this, taskData, entry.getKey(), emittedCount, hasAckers, rand, hasEventLoggers, isDebug, pending);
        SpoutOutputCollector outputCollector = new SpoutOutputCollector(spoutOutputCollector);
        this.outputCollectors.add(outputCollector);
        taskData.getBuiltInMetrics().registerAll(stormConf, taskData.getUserContext());
        Map<String, DisruptorQueue> map = ImmutableMap.of("sendqueue", transferQueue, "receive", receiveQueue);
        BuiltinMetricsUtil.registerQueueMetrics(map, stormConf, taskData.getUserContext());
        if (spoutObject instanceof ICredentialsListener) {
            ((ICredentialsListener) spoutObject).setCredentials(credentials);
        }
        spoutObject.open(stormConf, taskData.getUserContext(), outputCollector);
    }
    openOrPrepareWasCalled.set(true);
    LOG.info("Opened spout {}:{}", componentId, idToTask.keySet());
    setupMetrics();
}
Also used : Task(org.apache.storm.daemon.Task) ICredentialsListener(org.apache.storm.ICredentialsListener) TupleInfo(org.apache.storm.executor.TupleInfo) DisruptorQueue(org.apache.storm.utils.DisruptorQueue) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) MutableLong(org.apache.storm.utils.MutableLong) RotatingMap(org.apache.storm.utils.RotatingMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ISpout(org.apache.storm.spout.ISpout)

Example 5 with ICredentialsListener

use of org.apache.storm.ICredentialsListener in project storm by apache.

the class Executor method updateExecCredsIfRequired.

protected void updateExecCredsIfRequired() {
    if (this.needToRefreshCreds.get()) {
        this.needToRefreshCreds.set(false);
        LOG.info("The credentials are being updated {}.", executorId);
        Credentials creds = this.workerData.getCredentials();
        idToTask.stream().map(Task::getTaskObject).filter(taskObject -> taskObject instanceof ICredentialsListener).forEach(taskObject -> {
            ((ICredentialsListener) taskObject).setCredentials(creds == null ? null : creds.get_creds());
        });
    }
}
Also used : Acker(org.apache.storm.daemon.Acker) GrouperFactory(org.apache.storm.daemon.GrouperFactory) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) BooleanSupplier(java.util.function.BooleanSupplier) JCQueue(org.apache.storm.utils.JCQueue) IMetricsConsumer(org.apache.storm.metric.api.IMetricsConsumer) WorkerTopologyContext(org.apache.storm.task.WorkerTopologyContext) DaemonType(org.apache.storm.cluster.DaemonType) Map(java.util.Map) Counter(com.codahale.metrics.Counter) Metered(com.codahale.metrics.Metered) ReportError(org.apache.storm.executor.error.ReportError) AddressedTuple(org.apache.storm.tuple.AddressedTuple) DebugOptions(org.apache.storm.generated.DebugOptions) Lists(org.apache.storm.shade.com.google.common.collect.Lists) PerReporterGauge(org.apache.storm.metrics2.PerReporterGauge) Task(org.apache.storm.daemon.Task) ReportErrorAndDie(org.apache.storm.executor.error.ReportErrorAndDie) ClientStatsUtil(org.apache.storm.stats.ClientStatsUtil) ParseException(org.apache.storm.shade.org.json.simple.parser.ParseException) Fields(org.apache.storm.tuple.Fields) Collectors(java.util.stream.Collectors) Snapshot(com.codahale.metrics.Snapshot) Credentials(org.apache.storm.generated.Credentials) Objects(java.util.Objects) Time(org.apache.storm.utils.Time) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ConfigUtils(org.apache.storm.utils.ConfigUtils) JSONValue(org.apache.storm.shade.org.json.simple.JSONValue) TupleImpl(org.apache.storm.tuple.TupleImpl) SpoutSpec(org.apache.storm.generated.SpoutSpec) LoadMapping(org.apache.storm.grouping.LoadMapping) IMetric(org.apache.storm.metric.api.IMetric) Timer(com.codahale.metrics.Timer) Config(org.apache.storm.Config) Gauge(com.codahale.metrics.Gauge) Queue(java.util.Queue) StormCommon(org.apache.storm.daemon.StormCommon) ClusterUtils(org.apache.storm.cluster.ClusterUtils) Histogram(com.codahale.metrics.Histogram) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) LoadAwareCustomStreamGrouping(org.apache.storm.grouping.LoadAwareCustomStreamGrouping) SpoutExecutor(org.apache.storm.executor.spout.SpoutExecutor) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Bolt(org.apache.storm.generated.Bolt) Meter(com.codahale.metrics.Meter) Values(org.apache.storm.tuple.Values) VisibleForTesting(org.apache.storm.shade.com.google.common.annotations.VisibleForTesting) StormTopology(org.apache.storm.generated.StormTopology) ClusterStateContext(org.apache.storm.cluster.ClusterStateContext) ICredentialsListener(org.apache.storm.ICredentialsListener) Logger(org.slf4j.Logger) BoltExecutor(org.apache.storm.executor.bolt.BoltExecutor) Grouping(org.apache.storm.generated.Grouping) CommonStats(org.apache.storm.stats.CommonStats) IOException(java.io.IOException) Field(java.lang.reflect.Field) IStormClusterState(org.apache.storm.cluster.IStormClusterState) WorkerState(org.apache.storm.daemon.worker.WorkerState) Utils(org.apache.storm.utils.Utils) UnknownHostException(java.net.UnknownHostException) TimeUnit(java.util.concurrent.TimeUnit) StormTimer(org.apache.storm.StormTimer) ObjectReader(org.apache.storm.utils.ObjectReader) Constants(org.apache.storm.Constants) IReportError(org.apache.storm.executor.error.IReportError) RateCounter(org.apache.storm.metrics2.RateCounter) Collections(java.util.Collections) MpscChunkedArrayQueue(org.apache.storm.shade.org.jctools.queues.MpscChunkedArrayQueue) Task(org.apache.storm.daemon.Task) ICredentialsListener(org.apache.storm.ICredentialsListener) Credentials(org.apache.storm.generated.Credentials)

Aggregations

ICredentialsListener (org.apache.storm.ICredentialsListener)5 Task (org.apache.storm.daemon.Task)5 Map (java.util.Map)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 DisruptorQueue (org.apache.storm.utils.DisruptorQueue)2 Counter (com.codahale.metrics.Counter)1 Gauge (com.codahale.metrics.Gauge)1 Histogram (com.codahale.metrics.Histogram)1 Meter (com.codahale.metrics.Meter)1 Metered (com.codahale.metrics.Metered)1 Snapshot (com.codahale.metrics.Snapshot)1 Timer (com.codahale.metrics.Timer)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Objects (java.util.Objects)1