Examples of KafkaException


Examples of kafka.common.KafkaException

  @Override
  public RecordWriter<K, V> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException
  {
    Path outputPath = getOutputPath(context);
    if (outputPath == null)
      throw new KafkaException("no kafka output url specified");
    URI uri = URI.create(outputPath.toString());
    Configuration job = context.getConfiguration();

    Properties props = new Properties();
    String topic;

    props.putAll(kafkaConfigMap);                       // inject default configuration
    for (Map.Entry<String, String> m : job) {           // handle any overrides
      if (!m.getKey().startsWith(KAFKA_CONFIG_PREFIX))
        continue;
      if (m.getKey().equals(KAFKA_URL))
        continue;

      String kafkaKeyName = m.getKey().substring(KAFKA_CONFIG_PREFIX.length()+1);
      props.setProperty(kafkaKeyName, m.getValue());    // set Kafka producer property
    }

    // inject Kafka producer props back into jobconf for easier debugging
    for (Map.Entry<Object, Object> m : props.entrySet()) {
      job.set(KAFKA_CONFIG_PREFIX + "." + m.getKey().toString(), m.getValue().toString());
    }

    // KafkaOutputFormat specific parameters
    final int queueBytes = job.getInt(KAFKA_CONFIG_PREFIX + ".queue.bytes", KAFKA_QUEUE_BYTES);

    if (uri.getScheme().equals("kafka")) {
      // using the direct broker list
      // URL: kafka://<kafka host>/<topic>
      // e.g. kafka://kafka-server:9000,kafka-server2:9000/foobar
      String brokerList = uri.getAuthority();
      props.setProperty("metadata.broker.list", brokerList);
      job.set(KAFKA_CONFIG_PREFIX + ".metadata.broker.list", brokerList);

      if (uri.getPath() == null || uri.getPath().length() <= 1)
        throw new KafkaException("no topic specified in kafka uri");

      topic = uri.getPath().substring(1);               // ignore the initial '/' in the path
      job.set(KAFKA_CONFIG_PREFIX + ".topic", topic);
      log.info(String.format("using kafka broker %s (topic %s)", brokerList, topic));
    } else
      throw new KafkaException("missing scheme from kafka uri (must be kafka://)");

    Producer<Object, byte[]> producer = new Producer<Object, byte[]>(new ProducerConfig(props));
    return new KafkaRecordWriter<K, V>(producer, topic, queueBytes);
  }
View Full Code Here

Examples of kafka.common.KafkaException

   * @return props
   */
  @SuppressWarnings("unchecked")
  public static Props of(String... args) {
    if (args.length % 2 != 0)
      throw new KafkaException(
          "Must have an equal number of keys and values.");
    Map<String, String> vals = new HashMap<String, String>(args.length / 2);
    for (int i = 0; i < args.length; i += 2)
      vals.put(args[i], args[i + 1]);
    return new Props(vals);
View Full Code Here

Examples of kafka.common.KafkaException

           _limit = _props.getInt("kafka.request.limit", -1);
          
           /*get attemp id*/
           String taskId = _job.get("mapred.task.id");
           if (taskId == null) {
               throw new KafkaException("Configuration does not contain the property mapred.task.id");
           }
           String[] parts = taskId.split("_");
           if (    parts.length != 6 || !parts[0].equals("attempt")
                || (!"m".equals(parts[3]) && !"r".equals(parts[3]))) {
                   throw new KafkaException("TaskAttemptId string : " + taskId + " is not properly formed");
           }
          _attemptId = parts[4]+parts[3];
       }catch (Exception e) {
           throw new IOException (e);
       }
View Full Code Here

Examples of kafka.common.KafkaException

                    e instanceof SocketTimeoutException ||
                    e instanceof IOException ||
                    e instanceof UnresolvedAddressException
                    ) {
                LOG.warn("Network error when fetching messages:", e);
                throw new KafkaException("Network error when fetching messages: "+e.getMessage());
            } else {
                throw new RuntimeException(e);
            }
        }
        if(fetchResponse.hasError()) {
          short code = fetchResponse.errorCode(topic, partition);
//          if(code == ErrorMapping.OffsetOutOfRangeCode() && config.resetOffsetIfOutOfRange) {
//            long startOffset = getOffset(topic, partition, config.startOffsetTime);
//            offset = startOffset;
//          }
          throw new KafkaException("fetch data from kafka topic["+topic+"] partition["+partition+"] error:" + code);
        }else {
          ByteBufferMessageSet msgs =  fetchResponse.messageSet(topic, partition);
          return msgs;
        }
  }
View Full Code Here

Examples of org.apache.kafka.common.KafkaException

        Class<?> c = getClass(key);
        if (c == null)
            return null;
        Object o = Utils.newInstance(c);
        if (!t.isInstance(o))
            throw new KafkaException(c.getName() + " is not an instance of " + t.getName());
        if (o instanceof Configurable)
            ((Configurable) o).configure(this.originals);
        return t.cast(o);
    }
View Full Code Here

Examples of org.apache.kafka.common.KafkaException

            Class<?> c = getClass(klass);
            if (c == null)
                return null;
            Object o = Utils.newInstance(c);
            if (!t.isInstance(o))
                throw new KafkaException(c.getName() + " is not an instance of " + t.getName());
            if (o instanceof Configurable)
                ((Configurable) o).configure(this.originals);
            objects.add(t.cast(o));
        }
        return objects;
View Full Code Here

Examples of org.apache.kafka.common.KafkaException

                callback.onCompletion(null, e);
            this.errors.record();
            return new FutureFailure(e);
        } catch (InterruptedException e) {
            this.errors.record();
            throw new KafkaException(e);
        } catch (KafkaException e) {
            this.errors.record();
            throw e;
        }
    }
View Full Code Here

Examples of org.apache.kafka.common.KafkaException

        log.trace("Closing the Kafka producer.");
        this.sender.initiateClose();
        try {
            this.ioThread.join();
        } catch (InterruptedException e) {
            throw new KafkaException(e);
        }
        this.metrics.close();
        log.debug("The Kafka producer has closed.");
    }
View Full Code Here

Examples of org.apache.kafka.common.KafkaException

     */
    public Selector(Metrics metrics, Time time) {
        try {
            this.selector = java.nio.channels.Selector.open();
        } catch (IOException e) {
            throw new KafkaException(e);
        }
        this.time = time;
        this.keys = new HashMap<Integer, SelectionKey>();
        this.completedSends = new ArrayList<NetworkSend>();
        this.completedReceives = new ArrayList<NetworkReceive>();
View Full Code Here

Examples of org.apache.kafka.common.KafkaException

    public void close() {
        try {
            appendStream.close();
        } catch (IOException e) {
            throw new KafkaException(e);
        }

        if (type != CompressionType.NONE) {
            ByteBuffer buffer = bufferStream.buffer();
            int pos = buffer.position();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.