Package org.apache.flume

Examples of org.apache.flume.FlumeException


        " not setup correctly!";
      LogLog.error(errorMsg);
      if (unsafeMode) {
        return;
      }
      throw new FlumeException(errorMsg);
    }

    if(!rpcClient.isActive()){
      reconnect();
    }

    //Client created first time append is called.
    Map<String, String> hdrs = new HashMap<String, String>();
    hdrs.put(Log4jAvroHeaders.LOGGER_NAME.toString(), event.getLoggerName());
    hdrs.put(Log4jAvroHeaders.TIMESTAMP.toString(),
        String.valueOf(event.timeStamp));

    //To get the level back simply use
    //LoggerEvent.toLevel(hdrs.get(Integer.parseInt(
    //Log4jAvroHeaders.LOG_LEVEL.toString()))
    hdrs.put(Log4jAvroHeaders.LOG_LEVEL.toString(),
        String.valueOf(event.getLevel().toInt()));

    Event flumeEvent;
    Object message = event.getMessage();
    if (message instanceof GenericRecord) {
      GenericRecord record = (GenericRecord) message;
      populateAvroHeaders(hdrs, record.getSchema(), message);
      flumeEvent = EventBuilder.withBody(serialize(record, record.getSchema()), hdrs);
    } else if (message instanceof SpecificRecord || avroReflectionEnabled) {
      Schema schema = ReflectData.get().getSchema(message.getClass());
      populateAvroHeaders(hdrs, schema, message);
      flumeEvent = EventBuilder.withBody(serialize(message, schema), hdrs);
    } else {
      hdrs.put(Log4jAvroHeaders.MESSAGE_ENCODING.toString(), "UTF8");
      String msg = layout != null ? layout.format(event) : message.toString();
      flumeEvent = EventBuilder.withBody(msg, Charset.forName("UTF8"), hdrs);
    }

    try {
      rpcClient.append(flumeEvent);
    } catch (EventDeliveryException e) {
      String msg = "Flume append() failed.";
      LogLog.error(msg);
      if (unsafeMode) {
        return;
      }
      throw new FlumeException(msg + " Exception follows.", e);
    }
  }
View Full Code Here


    try {
      writer.write(datum, encoder);
      encoder.flush();
      return out.toByteArray();
    } catch (IOException e) {
      throw new FlumeException(e);
    }
  }
View Full Code Here

      String errorMsg = "Flume log4jappender already closed!";
      LogLog.error(errorMsg);
      if(unsafeMode) {
        return;
      }
      throw new FlumeException(errorMsg);
    }
  }
View Full Code Here

    } catch (Exception e) {
      lifecycleState = LifecycleState.ERROR;
      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
      } else {
        throw new FlumeException(e);
      }
    }
    lifecycleState = LifecycleState.START;
  }
View Full Code Here

      } else {
        connection = connectionFactory.createConnection();
      }
      connection.start();
    } catch (JMSException e) {
      throw new FlumeException("Could not create connection to broker", e);
    }

    try {
      session = connection.createSession(true, Session.SESSION_TRANSACTED);
    } catch (JMSException e) {
      throw new FlumeException("Could not create session", e);
    }

  try {
    if (destinationLocator.equals(JMSDestinationLocator.CDI)) {
      switch (destinationType) {
        case QUEUE:
          destination = session.createQueue(destinationName);
          break;
        case TOPIC:
          destination = session.createTopic(destinationName);
          break;
        default:
          throw new IllegalStateException(String.valueOf(destinationType));
      }
    } else {
      destination = (Destination) initialContext.lookup(destinationName);
    }
  } catch (JMSException e) {
    throw new FlumeException("Could not create destination " + destinationName, e);
  } catch (NamingException e) {
    throw new FlumeException("Could not find destination " + destinationName, e);
  }

  try {
      messageConsumer = session.createConsumer(destination,
          messageSelector.isEmpty() ? null: messageSelector);
    } catch (JMSException e) {
      throw new FlumeException("Could not create consumer", e);
    }
    String startupMsg = String.format("Connected to '%s' of type '%s' with " +
        "user '%s', batch size '%d', selector '%s' ", destinationName,
        destinationType, userName.isPresent() ? userName.get() : "null",
            batchSize, messageSelector.isEmpty() ? null : messageSelector);
View Full Code Here

    } else {
      try {
        password = Optional.of(Files.toString(new File(passwordFile),
            Charsets.UTF_8).trim());
      } catch (IOException e) {
        throw new FlumeException(String.format(
            "Could not read password file %s", passwordFile), e);
      }
    }

    String converterClassName = context.getString(
        JMSSourceConfiguration.CONVERTER_TYPE,
        JMSSourceConfiguration.CONVERTER_TYPE_DEFAULT)
        .trim();
    if(JMSSourceConfiguration.CONVERTER_TYPE_DEFAULT.
        equalsIgnoreCase(converterClassName)) {
      converterClassName = DefaultJMSMessageConverter.Builder.class.getName();
    }
    Context converterContext = new Context(context.
        getSubProperties(JMSSourceConfiguration.CONVERTER + "."));
    try {
      @SuppressWarnings("rawtypes")
      Class clazz = Class.forName(converterClassName);
      boolean isBuilder = JMSMessageConverter.Builder.class
          .isAssignableFrom(clazz);
      if(isBuilder) {
        JMSMessageConverter.Builder builder = (JMSMessageConverter.Builder)
            clazz.newInstance();
        converter = builder.build(converterContext);
      } else {
        Preconditions.checkState(JMSMessageConverter.class.
            isAssignableFrom(clazz), String.
            format("Class %s is not a subclass of JMSMessageConverter",
                clazz.getName()));
        converter = (JMSMessageConverter)clazz.newInstance();
        boolean configured = Configurables.configure(converter,
            converterContext);
        if(logger.isDebugEnabled()) {
          logger.debug(String.
              format("Attempted configuration of %s, result = %s",
                  converterClassName, String.valueOf(configured)));
        }
      }
    } catch(Exception e) {
      throw new FlumeException(String.format(
          "Unable to create instance of converter %s", converterClassName), e);
    }

    String connectionFactoryName = context.getString(JMSSourceConfiguration.
        CONNECTION_FACTORY, JMSSourceConfiguration.CONNECTION_FACTORY_DEFAULT)
        .trim();

    assertNotEmpty(initialContextFactoryName, String.format(
        "Initial Context Factory is empty. This is specified by %s",
        JMSSourceConfiguration.INITIAL_CONTEXT_FACTORY));

    assertNotEmpty(providerUrl, String.format(
        "Provider URL is empty. This is specified by %s",
        JMSSourceConfiguration.PROVIDER_URL));

    assertNotEmpty(destinationName, String.format(
        "Destination Name is empty. This is specified by %s",
        JMSSourceConfiguration.DESTINATION_NAME));

    assertNotEmpty(destinationTypeName, String.format(
        "Destination Type is empty. This is specified by %s",
        JMSSourceConfiguration.DESTINATION_TYPE));

    try {
      destinationType = JMSDestinationType.valueOf(destinationTypeName);
    } catch (IllegalArgumentException e) {
      throw new FlumeException(String.format("Destination type '%s' is " +
          "invalid.", destinationTypeName), e);
    }

    try {
      destinationLocator = JMSDestinationLocator.valueOf(destinationLocatorName);
    } catch (IllegalArgumentException e) {
      throw new FlumeException(String.format("Destination locator '%s' is " +
          "invalid.", destinationLocatorName), e);
    }

    Preconditions.checkArgument(batchSize > 0, "Batch size must be greater " +
        "than 0");

    try {
      Properties contextProperties = new Properties();
      contextProperties.setProperty(
          javax.naming.Context.INITIAL_CONTEXT_FACTORY,
          initialContextFactoryName);
      contextProperties.setProperty(
          javax.naming.Context.PROVIDER_URL, providerUrl);
      initialContext = initialContextFactory.create(contextProperties);
    } catch (NamingException e) {
      throw new FlumeException(String.format(
          "Could not create initial context %s provider %s",
          initialContextFactoryName, providerUrl), e);
    }

    try {
      connectionFactory = (ConnectionFactory) initialContext.
          lookup(connectionFactoryName);
    } catch (NamingException e) {
      throw new FlumeException("Could not lookup ConnectionFactory", e);
    }
  }
View Full Code Here

    try {
      consumer = createConsumer();
      jmsExceptionCounter = 0;
      sourceCounter.start();
    } catch (JMSException e) {
      throw new FlumeException("Unable to create consumer", e);
    }
  }
View Full Code Here

    checkAllowed(ALLOWED_CHANNELS, properties.get(CHANNEL_TYPE));
    checkRequired(properties, SINKS);
    String sinkNames = properties.get(SINKS);
    for(String sink : sinkNames.split("\\s+")) {
      if(DISALLOWED_SINK_NAMES.contains(sink.toLowerCase(Locale.ENGLISH))) {
        throw new FlumeException("Sink name " + sink + " is one of the" +
            " disallowed sink names: " + DISALLOWED_SINK_NAMES);
      }
      String key = join(sink, TYPE);
      checkRequired(properties, key);
      checkAllowed(ALLOWED_SINKS, properties.get(key));
View Full Code Here

        // agent.sinkgroups.sinkgroup.processor.*
        result.put(join(name, BasicConfigurationConstants.CONFIG_SINKGROUPS,
                sinkGroupName, key), value);
      } else {
        // XXX should we simply ignore this?
        throw new FlumeException("Unknown configuration " + key);
      }
    }
    return result;
  }
View Full Code Here

        isAllowed = true;
        break;
      }
    }
    if(!isAllowed) {
      throw new FlumeException("Component type of " + type + " is not in " +
          "allowed types of " + Arrays.toString(allowedTypes));
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.flume.FlumeException

Copyright © 2018 www.massapicom. 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.