private static void checkMongoClient(
      Configuration configuration, Class<?> mappedClass, String clientName, String dbName) {
    Configuration mongodbClientConfiguration =
        getMongoClientConfiguration(configuration, clientName);

    if (mongodbClientConfiguration.isEmpty()) {
      throw SeedException.createNew(MongoDbErrorCodes.UNKNOWN_CLIENT_SPECIFIED)
          .put("aggregate", mappedClass.getName())
          .put("clientName", clientName)
          .put("dbName", dbName);
    }

    boolean async = mongodbClientConfiguration.getBoolean("async", false);
    if (async) {
      throw SeedException.createNew(MorphiaErrorCodes.ERROR_ASYNC_CLIENT)
          .put("aggregate", mappedClass.getName())
          .put("clientName", clientName)
          .put("dbName", dbName);
    }

    String[] dbNames = mongodbClientConfiguration.getStringArray("databases");
    boolean found = false;
    for (String nameToCheck : dbNames) {
      if (nameToCheck.equals(resolveDatabaseAlias(mongodbClientConfiguration, dbName))) {
        found = true;
        break;
      }
    }
    if (!found) {
      throw SeedException.createNew(MorphiaErrorCodes.UNKNOW_DATABASE_NAME)
          .put("aggregate", mappedClass.getName())
          .put("clientName", clientName)
          .put("dbName", dbName);
    }
  }
Example #2
0
  /**
   * Configuration parameters for NeuralNetEvaluator are:
   *
   * <ul>
   *   <li><code>train-data: complex</code> Train data set used in individuals evaluation.
   *       <ul>
   *         <li><code>train-data[@file-name] String </code> File name of train data
   *       </ul>
   *   <li><code>test-data: complex</code> Test data set used in individuals evaluation.
   *       <ul>
   *         <li><code>test-data[@file-name] String </code> File name of test data
   *       </ul>
   *   <li><code>[@normalize-data]: boolean (default = false)</code> If this parameter is set to
   *       <code>true</code> data sets values are normalizated after reading their contents
   *   <li><code>[input-interval] (complex)</code> Input interval of normalization.
   *   <li><code>[output-interval] (complex)</code> Output interval of normalization.
   * </ul>
   *
   * <p>
   *
   * @param settings Configuration object from which the properties are read
   */
  public void configure(Configuration settings) {

    // Set trainData
    unscaledTrainData = new DoubleTransposedDataSet();
    unscaledTrainData.configure(settings.subset("train-data"));

    // Set testData
    unscaledTestData = new DoubleTransposedDataSet();
    unscaledTestData.configure(settings.subset("test-data"));

    // Set normalizer
    normalizer = new Normalizer();

    // Set dataNormalized
    dataNormalized = settings.getBoolean("[@normalize-data]", false);

    // Set dataNormalized
    logTransformation = settings.getBoolean("[@log-input-data]", false);

    if (dataNormalized) {
      // Normalization Input Interval
      Interval interval = new Interval();
      // Configure interval
      interval.configure(settings.subset("input-interval"));
      // Set interval
      setInputInterval(interval);
      // Normalization Output Interval
      interval = new Interval();
      // Configure range
      interval.configure(settings.subset("output-interval"));
      // Set interval
      setOutputInterval(interval);
    }
  }
Example #3
0
  public Backend(Configuration storageConfig) {
    this.storageConfig = storageConfig;

    storeManager = getStorageManager(storageConfig);
    indexes = getIndexes(storageConfig);
    storeFeatures = storeManager.getFeatures();

    basicMetrics = storageConfig.getBoolean(BASIC_METRICS, BASIC_METRICS_DEFAULT);
    mergeBasicMetrics =
        storageConfig.getBoolean(MERGE_BASIC_METRICS_KEY, MERGE_BASIC_METRICS_DEFAULT);

    int bufferSizeTmp = storageConfig.getInt(BUFFER_SIZE_KEY, BUFFER_SIZE_DEFAULT);
    Preconditions.checkArgument(
        bufferSizeTmp >= 0, "Buffer size must be non-negative (use 0 to disable)");
    if (!storeFeatures.supportsBatchMutation()) {
      bufferSize = 0;
      log.debug("Buffering disabled because backend does not support batch mutations");
    } else bufferSize = bufferSizeTmp;

    writeAttempts = storageConfig.getInt(WRITE_ATTEMPTS_KEY, WRITE_ATTEMPTS_DEFAULT);
    Preconditions.checkArgument(writeAttempts > 0, "Write attempts must be positive");
    readAttempts = storageConfig.getInt(READ_ATTEMPTS_KEY, READ_ATTEMPTS_DEFAULT);
    Preconditions.checkArgument(readAttempts > 0, "Read attempts must be positive");
    persistAttemptWaittime =
        storageConfig.getInt(STORAGE_ATTEMPT_WAITTIME_KEY, STORAGE_ATTEMPT_WAITTIME_DEFAULT);
    Preconditions.checkArgument(
        persistAttemptWaittime > 0, "Persistence attempt retry wait time must be non-negative");

    // If lock prefix is unspecified, specify it now
    storageConfig.setProperty(
        ExpectedValueCheckingStore.LOCAL_LOCK_MEDIATOR_PREFIX_KEY,
        storageConfig.getString(
            ExpectedValueCheckingStore.LOCAL_LOCK_MEDIATOR_PREFIX_KEY, storeManager.getName()));

    final String lockBackendName =
        storageConfig.getString(
            GraphDatabaseConfiguration.LOCK_BACKEND,
            GraphDatabaseConfiguration.LOCK_BACKEND_DEFAULT);
    if (REGISTERED_LOCKERS.containsKey(lockBackendName)) {
      lockerCreator = REGISTERED_LOCKERS.get(lockBackendName);
    } else {
      throw new TitanConfigurationException(
          "Unknown lock backend \""
              + lockBackendName
              + "\".  Known lock backends: "
              + Joiner.on(", ").join(REGISTERED_LOCKERS.keySet())
              + ".");
    }
    // Never used for backends that have innate transaction support, but we
    // want to maintain the non-null invariant regardless; it will default
    // to connsistentkey impl if none is specified
    Preconditions.checkNotNull(lockerCreator);

    if (storeFeatures.isDistributed() && storeFeatures.isKeyOrdered()) {
      log.debug("Wrapping index store with HashPrefix");
      hashPrefixIndex = true;
    } else {
      hashPrefixIndex = false;
    }
  }
Example #4
0
  /**
   * Check the frequency of retrieving new ids from the database. If the frequency is high then we
   * increase the amount (i.e. quantity column) of ids retrieved on each access. Tries to alter
   * number of keys grabbed so that IDBroker retrieves a new set of ID's prior to their being
   * needed.
   *
   * @param tableName The name of the table for which we want an id.
   */
  private void checkTiming(String tableName) {
    // Check if quantity changing is switched on.
    // If prefetch is turned off, changing quantity does not make sense
    if (!configuration.getBoolean(DB_IDBROKER_CLEVERQUANTITY, true)
        || !configuration.getBoolean(DB_IDBROKER_PREFETCH, true)) {
      return;
    }

    // Get the last id request for this table.
    java.util.Date lastTime = (java.util.Date) lastQueryTime.get(tableName);
    java.util.Date now = new java.util.Date();

    if (lastTime != null) {
      long thenLong = lastTime.getTime();
      long nowLong = now.getTime();
      int timeLapse = (int) (nowLong - thenLong);
      if (timeLapse < SLEEP_PERIOD && timeLapse > 0) {
        if (log.isDebugEnabled()) {
          log.debug("Unscheduled retrieval of more ids for table: " + tableName);
        }
        // Increase quantity, so that hopefully this does not
        // happen again.
        float rate = getQuantity(tableName, null).floatValue() / (float) timeLapse;
        quantityStore.put(
            tableName, new BigDecimal(Math.ceil(SLEEP_PERIOD * rate * SAFETY_MARGIN)));
      }
    }
    lastQueryTime.put(tableName, now);
  }
  public void restoreCustomProperties(Configuration pConfig) {
    centerPanel.setMenuVisible(pConfig.getBoolean(getPropertyPrefix() + ".menu.visible", true));
    try {
      jAlwaysOnTopBox.setSelected(pConfig.getBoolean(getPropertyPrefix() + ".alwaysOnTop"));
    } catch (Exception e) {
    }

    setAlwaysOnTop(jAlwaysOnTopBox.isSelected());
  }
    /**
     * Reads properties from the provided {@link Configuration} object.<br>
     * <br>
     * Known properties:
     *
     * <ul>
     *   <li>api.adwords.clientCustomerId
     *   <li>api.adwords.userAgent
     *   <li>api.adwords.developerToken
     *   <li>api.adwords.isPartialFailure
     *   <li>api.adwords.endpoint
     *   <li>api.adwords.reportMoneyInMicros
     * </ul>
     *
     * @param config
     * @return Builder populated from the Configuration
     */
    public Builder from(Configuration config) {
      this.clientCustomerId = config.getString("api.adwords.clientCustomerId", null);
      this.userAgent = config.getString("api.adwords.userAgent", null);
      this.developerToken = config.getString("api.adwords.developerToken", null);
      this.isPartialFailure = config.getBoolean("api.adwords.isPartialFailure", null);
      this.endpoint = config.getString("api.adwords.endpoint", null);
      this.isReportMoneyInMicros = config.getBoolean("api.adwords.reportMoneyInMicros", null);

      return this;
    }
Example #7
0
  /**
   * @param configuration Object carrying all configurable properties from file.
   * @throws UnRetriableException
   * @link configure method supplies the configuration object carrying all the properties parsed
   *     from the external properties file.
   */
  public void configure(Configuration configuration) throws UnRetriableException {
    log.info(" configure : setting up our configurations.");

    int tcpPort =
        configuration.getInt(
            CONFIGURATION_SERVER_MQTT_TCP_PORT, CONFIGURATION_VALUE_DEFAULT_SERVER_MQTT_TCP_PORT);
    setTcpPort(tcpPort);

    int sslPort =
        configuration.getInt(
            CONFIGURATION_SERVER_MQTT_SSL_PORT, CONFIGURATION_VALUE_DEFAULT_SERVER_MQTT_SSL_PORT);
    setSslPort(sslPort);

    boolean sslEnabled =
        configuration.getBoolean(
            CONFIGURATION_SERVER_MQTT_SSL_IS_ENABLED,
            CONFIGURATION_VALUE_DEFAULT_SERVER_MQTT_SSL_IS_ENABLED);
    setSslEnabled(sslEnabled);

    if (isSslEnabled()) {

      setSslHandler(new SSLHandler(configuration));
    }

    int connectionTimeout =
        configuration.getInt(
            CONFIGURATION_SERVER_MQTT_CONNECTION_TIMEOUT,
            CONFIGURATION_VALUE_DEFAULT_SERVER_MQTT_CONNECTION_TIMEOUT);
    setConnectionTimeout(connectionTimeout);
  }
Example #8
0
  public static void main(String[] args) throws Exception {

    Configuration jobConfiguration = new PropertiesConfiguration("configFilePath");

    /**
     * xodel nranq voronq vor trvats en conf ov
     *
     * <p>connecting hbase get from hbase user and create user.job(); get from hbase photo and
     * create photo.job(); get from hbase enets and create events.job();
     *
     * <p>connecting mongo recreate collection insert statuses close mongo
     */
    try {

      JavaSparkContext jsc = SparkTool.getJSC(null);
      User user = new User(jsc, Constants.USERSCAN);
      Photo photo = new Photo(jsc, Constants.PHOTOSCAN);
      Events events = new Events(jsc, Constants.EVENTSCAN);

      MongoTool.connect();

      if (jobConfiguration.getBoolean("dropDB", true)) {
        MongoTool.recreateCollection();

        user.job(jobConfiguration);
        photo.job(jobConfiguration);
        events.job(jobConfiguration);

        MongoTool.disconnect();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public UberdustCoapServerBackend(String pathPrefix, Configuration config) throws Exception {
   super(pathPrefix, "", 0, config.getBoolean("coap.enableVirtualHttpServer", false));
   this.pathPrefix = pathPrefix;
   this.config = config;
   log.debug("Prefix Uberdust: " + getPrefix());
   new Thread(new FakeRegistrationMessageSender(config)).start();
 }
Example #10
0
  /**
   * @param configuration The configuration object for the Abstract query strategy. The XML labels
   *     supported are:
   *     <ul>
   *       <li><b>maximal= boolean</b>
   *       <li><b>wrapper-classifier type= class</b>
   *           <p>Package: net.sf.jclal.classifier
   *           <p>Class: All
   *     </ul>
   */
  @Override
  public void configure(Configuration configuration) {

    // Set max iteration
    boolean maximalT = configuration.getBoolean("maximal", isMaximal());
    setMaximal(maximalT);

    String wrapperError = "wrapper-classifier type= ";
    try {
      // classifier classname
      String classifierClassname = configuration.getString("wrapper-classifier[@type]");

      wrapperError += classifierClassname;
      // classifier class
      Class<? extends IClassifier> classifierClass =
          (Class<? extends IClassifier>) Class.forName(classifierClassname);
      // classifier instance
      IClassifier classifierTemp = classifierClass.newInstance();
      // Configure classifier (if necessary)
      if (classifierTemp instanceof IConfigure) {
        ((IConfigure) classifierTemp).configure(configuration.subset("wrapper-classifier"));
      }
      // Add this classifier to the query strategy
      setClassifier(classifierTemp);
    } catch (ClassNotFoundException e) {
      throw new ConfigurationRuntimeException("Illegal classifier classname: " + wrapperError, e);
    } catch (InstantiationException e) {
      throw new ConfigurationRuntimeException("Illegal classifier classname: " + wrapperError, e);
    } catch (IllegalAccessException e) {
      throw new ConfigurationRuntimeException("Illegal classifier classname: " + wrapperError, e);
    }
  }
 public void loadFrom(Configuration conf) {
   this.setEnabled(conf.getBoolean("pscans." + getClass().getCanonicalName() + ".enabled", true));
   this.setLevel(
       AlertThreshold.valueOf(
           conf.getString(
               "pscans." + getClass().getCanonicalName() + ".level",
               AlertThreshold.DEFAULT.name())));
 }
 public static Object[] prepareConfiguration(String pages, boolean turnOff) {
   Configuration conf = EasyMock.createMock(Configuration.class);
   EasyMock.expect(conf.getString("generatePdfMaxRange")).andReturn(pages).anyTimes();
   EasyMock.expect(conf.getBoolean("turnOffPdfCheck")).andReturn(turnOff).anyTimes();
   KConfiguration kConfiguration = EasyMock.createMock(KConfiguration.class);
   EasyMock.expect(kConfiguration.getConfiguration()).andReturn(conf).anyTimes();
   return new Object[] {conf, kConfiguration};
 }
Example #13
0
  /**
   * Constructor. Provided as long as both Constructors, IDBroker(DatabaseInfo) and
   * IDBroker(TableMap), are around.
   *
   * @param databaseName the name of the database for which this IdBroker provides Ids.
   */
  private IDBroker(String databaseName) {
    this.databaseName = databaseName;
    configuration = Torque.getConfiguration();

    // Start the housekeeper thread only if prefetch has not been disabled
    if (configuration.getBoolean(DB_IDBROKER_PREFETCH, true)) {
      houseKeeperThread = new Thread(this);
      // Indicate that this is a system thread. JVM will quit only when
      // there are no more active user threads. Settings threads spawned
      // internally by Torque as daemons allows commandline applications
      // using Torque terminate in an orderly manner.
      houseKeeperThread.setDaemon(true);
      houseKeeperThread.setName("Torque - ID Broker thread");
      houseKeeperThread.start();
    }

    // Check for Transaction support.  Give warning message if
    // IDBroker is being used with a database that does not
    // support transactions.
    Connection dbCon = null;
    try {
      dbCon = Torque.getConnection(databaseName);
    } catch (Throwable t) {
      log.error("Could not open a connection to the database " + databaseName, t);
      transactionsSupported = false;
    }
    try {
      transactionsSupported = dbCon.getMetaData().supportsTransactions();
    } catch (Exception e) {
      log.warn(
          "Could not read from connection Metadata"
              + " whether transactions are supported for the database "
              + databaseName,
          e);
      transactionsSupported = false;
    } finally {
      try {
        // Return the connection to the pool.
        dbCon.close();
      } catch (Exception e) {
        log.warn(
            "Could not close the connection which was used "
                + "for testing whether transactions are supported",
            e);
      }
    }
    if (!transactionsSupported) {
      log.warn(
          "IDBroker is being used with db '"
              + databaseName
              + "', which does not support transactions. IDBroker "
              + "attempts to use transactions to limit the possibility "
              + "of duplicate key generation.  Without transactions, "
              + "duplicate key generation is possible if multiple JVMs "
              + "are used or other means are used to write to the "
              + "database.");
    }
  }
  public ZooKeeperBenchmark(Configuration conf) throws IOException {
    LinkedList<String> serverList = new LinkedList<String>();
    Iterator<String> serverNames = conf.getKeys("server");

    while (serverNames.hasNext()) {
      String serverName = serverNames.next();
      String address = conf.getString(serverName);
      serverList.add(address);
    }

    if (serverList.size() == 0) {
      throw new IllegalArgumentException("ZooKeeper server addresses required");
    }

    _interval = conf.getInt("interval");
    _totalOps = conf.getInt("totalOperations");
    _lowerbound = conf.getInt("lowerbound");
    int totaltime = conf.getInt("totalTime");
    _totalTimeSeconds = Math.round((double) totaltime / 1000.0);
    boolean sync = conf.getBoolean("sync");

    _running = new HashMap<Integer, Thread>();
    _clients = new BenchmarkClient[serverList.size()];
    _barrier = new CyclicBarrier(_clients.length + 1);
    _deadline = totaltime / _interval;

    LOG.info(
        "benchmark set with: interval: "
            + _interval
            + " total number: "
            + _totalOps
            + " threshold: "
            + _lowerbound
            + " time: "
            + totaltime
            + " sync: "
            + (sync ? "SYNC" : "ASYNC"));

    _data = "";

    for (int i = 0; i < 20; i++) { // 100 bytes of important data
      _data += "!!!!!";
    }

    int avgOps = _totalOps / serverList.size();

    for (int i = 0; i < serverList.size(); i++) {
      if (sync) {
        _clients[i] = new SyncBenchmarkClient(this, serverList.get(i), "/zkTest", avgOps, i);
      } else {
        _clients[i] = new AsyncBenchmarkClient(this, serverList.get(i), "/zkTest", avgOps, i);
      }
    }
  }
Example #15
0
  /**
   * This method allows you to get the number of ids that are to be cached in memory. This is either
   * stored in quantityStore or read from the db. (ie the value in ID_TABLE.QUANTITY). Though this
   * method returns a BigDecimal for the quantity, it is unlikey the system could withstand whatever
   * conditions would lead to really needing a large quantity, it is retrieved as a BigDecimal only
   * because it is going to be added to another BigDecimal.
   *
   * @param tableName The name of the table we want to query.
   * @param connection a Connection
   * @return An int with the number of ids cached in memory.
   */
  private BigDecimal getQuantity(String tableName, Connection connection) {
    BigDecimal quantity = null;

    // If prefetch is turned off we simply return 1
    if (!configuration.getBoolean(DB_IDBROKER_PREFETCH, true)) {
      quantity = new BigDecimal((double) 1);
    }
    // Initialize quantity, if necessary.
    else if (quantityStore.containsKey(tableName)) {
      quantity = (BigDecimal) quantityStore.get(tableName);
    } else {
      Connection dbCon = null;
      try {
        if (connection == null || configuration.getBoolean(DB_IDBROKER_USENEWCONNECTION, true)) {
          // Get a connection to the db
          dbCon = Torque.getConnection(databaseName);
        }

        // Read the row from the ID_TABLE.
        BigDecimal[] results = selectRow(dbCon, tableName);

        // QUANTITY column.
        quantity = results[1];
        quantityStore.put(tableName, quantity);
      } catch (Exception e) {
        quantity = new BigDecimal((double) 10);
      } finally {
        // Return the connection to the pool.
        try {
          dbCon.close();
        } catch (Exception e) {
          log.error("Release of connection failed.", e);
        }
      }
    }
    return quantity;
  }
Example #16
0
  /**
   * Writes the asset includes out as production references. These includes will refer to the
   * optimized, concatenated version of each configured asset.
   *
   * @throws IOException
   */
  private void writeProduction() throws IOException {

    boolean bustCache = _configuration.getBoolean(ConfigKey.BUST_CACHE.getKey(), true);

    File file = new File(_assetsDir + "/" + _name + "." + _type);
    if (file.exists()) {
      String relativePath = file.getAbsolutePath().substring(_webrootDir.length());
      if (bustCache) {
        String cacheBustSuffix = "?" + file.lastModified();
        relativePath += cacheBustSuffix;
      }
      String html =
          _type.equals(CSS_TYPE) ? getCssInclude(relativePath) : getJsInclude(relativePath);
      getJspContext().getOut().write(html + "\n");
    }
  }
 private static void runSetupIfRequired(Configuration configuration) throws SetupException {
   boolean shouldRunSetup = configuration.getBoolean(ATLAS_SERVER_RUN_SETUP_KEY, false);
   if (shouldRunSetup) {
     LOG.warn("Running setup per configuration {}.", ATLAS_SERVER_RUN_SETUP_KEY);
     AtlasSetup atlasSetup = new AtlasSetup();
     try {
       atlasSetup.run();
     } catch (SetupException se) {
       LOG.error("Failed running setup. Will not start the server.");
       throw se;
     }
     LOG.warn("Finished running setup.");
   } else {
     LOG.info("Not running setup per configuration {}.", ATLAS_SERVER_RUN_SETUP_KEY);
   }
 }
  @Override
  public void execute(CommandLineArguments arguments) {
    logger.info("AddNodesCommand local execute.");
    if (isArgumentsCountFalse(arguments)) {
      return;
    }

    Scanner scanner = arguments.asScanner();

    int numberOfNodes = scanner.nextInt();
    int numberOfCpusPerNode = scanner.nextInt();
    final Configuration configuration = getNodeManager().getConfiguration();

    Collection<File> artifactsToPreload =
        DependencyConfigurationUtil.getConfiguredDependencies(configuration);

    String jvmOptions =
        configuration.getString(
            ConfigurationKeys.JVM_OPTIONS_NODE, ConfigurationKeys.DEFAULT_JVM_OPTIONS_NODE);

    String nodeLogLevel =
        configuration.getString(
            ConfigurationKeys.LOGGING_NODE_LEVEL, ConfigurationKeys.DEFAULT_LOGGING_NODE_LEVEL);

    boolean nodeRemoteLogging =
        configuration.getBoolean(
            ConfigurationKeys.LOGGING_NODE_REMOTE, ConfigurationKeys.DEFAULT_LOGGING_NODE_REMOTE);

    int nodeRemoteLoggingPort =
        configuration.getInt(
            ConfigurationKeys.LOGGING_NODE_REMOTE_PORT,
            ConfigurationKeys.DEFAULT_LOGGING_NODE_REMOTE_PORT);

    final LocalNodeConfiguration nodeConfiguration =
        LocalNodeConfiguration.configurationFor(
            artifactsToPreload,
            jvmOptions,
            nodeLogLevel,
            nodeRemoteLogging,
            nodeRemoteLoggingPort,
            numberOfCpusPerNode);

    for (int i = 0; i < numberOfNodes; i++) {
      getNodeManager().addNode(nodeConfiguration);
    }
  }
Example #19
0
  /**
   * Adds a default administrator account, if not running in LAN mode, and if there are no accounts
   * in the active accounts service.
   */
  private void createAdminIfNoUsers() {

    Configuration conf = context.getService(Configuration.class);
    if (!conf.getBoolean(ServerConfiguration.LAN_MODE)) {
      AccountsService accountsService = context.getAccountsService();
      if (accountsService.getAccountsSize() == 0) {
        Configuration defaults = ServerConfiguration.getDefaults();
        String username = defaults.getString(ServerConfiguration.LAN_ADMIN_USERNAME);
        String password = defaults.getString(ServerConfiguration.LAN_ADMIN_PASSWORD);
        LOG.info(
            "As there are no accounts yet, we are creating an"
                + " admin account: username=\"{}\", password=\"{}\"",
            username,
            password);
        Account admin = createAdmin(username, password);
        accountsService.addAccount(admin);
        accountsService.saveAccountsIfNeeded();
      }
    }
  }
Example #20
0
  /**
   * <code>configure</code> allows the base system to configure itself by getting all the settings
   * it requires and storing them internally. The plugin is only expected to pick the settings it
   * has registered on the configuration file for its particular use.
   *
   * @param configuration
   * @throws UnRetriableException
   */
  @Override
  public void configure(Configuration configuration) throws UnRetriableException {

    boolean configAnnoymousLoginEnabled =
        configuration.getBoolean(
            CORE_CONFIG_WORKER_ANNONYMOUS_LOGIN_ENABLED,
            CORE_CONFIG_WORKER_ANNONYMOUS_LOGIN_ENABLED_DEFAULT_VALUE);

    log.debug(
        " configure : Anonnymous login is configured to be enabled [{}]",
        configAnnoymousLoginEnabled);

    setAnnonymousLoginEnabled(configAnnoymousLoginEnabled);

    String configAnnoymousLoginUsername =
        configuration.getString(
            CORE_CONFIG_WORKER_ANNONYMOUS_LOGIN_USERNAME,
            CORE_CONFIG_ENGINE_WORKER_ANNONYMOUS_LOGIN_USERNAME_DEFAULT_VALUE);
    log.debug(
        " configure : Anonnymous login username is configured to be [{}]",
        configAnnoymousLoginUsername);
    setAnnonymousLoginUsername(configAnnoymousLoginUsername);

    String configAnnoymousLoginPassword =
        configuration.getString(
            CORE_CONFIG_WORKER_ANNONYMOUS_LOGIN_PASSWORD,
            CORE_CONFIG_ENGINE_WORKER_ANNONYMOUS_LOGIN_PASSWORD_DEFAULT_VALUE);
    log.debug(
        " configure : Anonnymous login password is configured to be [{}]",
        configAnnoymousLoginPassword);
    setAnnonymousLoginPassword(configAnnoymousLoginPassword);

    int keepaliveInSeconds =
        configuration.getInt(
            CORE_CONFIG_WORKER_CLIENT_KEEP_ALIVE_IN_SECONDS,
            CORE_CONFIG_WORKER_CLIENT_KEEP_ALIVE_IN_SECONDS_DEFAULT_VALUE);
    log.debug(" configure : Keep alive maximum is configured to be [{}]", keepaliveInSeconds);
    setKeepAliveInSeconds(keepaliveInSeconds);
  }
Example #21
0
 private Options getAsciiDocOptionsAndAttributes(ParserContext context) {
   Configuration config = context.getConfig();
   final AttributesBuilder attributes =
       attributes(config.getStringArray(Keys.ASCIIDOCTOR_ATTRIBUTES));
   if (config.getBoolean(Keys.ASCIIDOCTOR_ATTRIBUTES_EXPORT, false)) {
     final String prefix = config.getString(Keys.ASCIIDOCTOR_ATTRIBUTES_EXPORT_PREFIX, "");
     for (final Iterator<String> it = config.getKeys(); it.hasNext(); ) {
       final String key = it.next();
       if (!key.startsWith("asciidoctor")) {
         attributes.attribute(prefix + key.replace(".", "_"), config.getProperty(key));
       }
     }
   }
   final Configuration optionsSubset = config.subset(Keys.ASCIIDOCTOR_OPTION);
   final Options options = options().attributes(attributes.get()).get();
   for (final Iterator<String> iterator = optionsSubset.getKeys(); iterator.hasNext(); ) {
     final String name = iterator.next();
     options.setOption(name, guessTypeByContent(optionsSubset.getString(name)));
   }
   options.setBaseDir(context.getFile().getParentFile().getAbsolutePath());
   options.setSafe(UNSAFE);
   return options;
 }
Example #22
0
  @PostConstruct
  public void init() {
    configuration = (Configuration) context.getAttribute(Configuration.class.getName());
    configuration = configuration.subset("runtime-settings");
    callManager =
        (ActorRef) context.getAttribute("org.mobicents.servlet.restcomm.telephony.CallManager");
    daos = (DaoManager) context.getAttribute(DaoManager.class.getName());
    super.init(configuration);
    CallDetailRecordConverter converter = new CallDetailRecordConverter(configuration);
    listConverter = new CallDetailRecordListConverter(configuration);
    builder = new GsonBuilder();
    builder.registerTypeAdapter(CallDetailRecord.class, converter);
    builder.registerTypeAdapter(CallDetailRecordList.class, listConverter);
    builder.setPrettyPrinting();
    gson = builder.create();
    xstream = new XStream();
    xstream.alias("RestcommResponse", RestCommResponse.class);
    xstream.registerConverter(converter);
    xstream.registerConverter(new RestCommResponseConverter(configuration));
    xstream.registerConverter(listConverter);

    normalizePhoneNumbers = configuration.getBoolean("normalize-numbers-for-outbound-calls");
  }
Example #23
0
  /**
   * Grabs more ids from the id_table and stores it in the ids Hashtable. If adjustQuantity is set
   * to true the amount of id's retrieved for each call to storeIDs will be adjusted.
   *
   * @param tableName The name of the table for which we want an id.
   * @param adjustQuantity True if amount should be adjusted.
   * @param connection a Connection
   * @exception Exception a generic exception.
   */
  private synchronized void storeIDs(
      String tableName, boolean adjustQuantity, Connection connection) throws Exception {
    BigDecimal nextId = null;
    BigDecimal quantity = null;

    // Block on the table.  Multiple tables are allowed to ask for
    // ids simultaneously.
    // TableMap tMap = dbMap.getTable(tableName);
    // synchronized(tMap)  see comment in the getNextIds method
    // {
    if (adjustQuantity) {
      checkTiming(tableName);
    }

    boolean useNewConnection =
        (connection == null) || (configuration.getBoolean(DB_IDBROKER_USENEWCONNECTION, true));
    try {
      if (useNewConnection) {
        connection = Transaction.beginOptional(databaseName, transactionsSupported);
      }

      // Write the current value of quantity of keys to grab
      // to the database, primarily to obtain a write lock
      // on the table/row, but this value will also be used
      // as the starting value when an IDBroker is
      // instantiated.
      quantity = getQuantity(tableName, connection);
      updateQuantity(connection, tableName, quantity);

      // Read the next starting ID from the ID_TABLE.
      BigDecimal[] results = selectRow(connection, tableName);
      nextId = results[0]; // NEXT_ID column

      // Update the row based on the quantity in the
      // ID_TABLE.
      BigDecimal newNextId = nextId.add(quantity);
      updateNextId(connection, tableName, newNextId.toString());

      if (useNewConnection) {
        Transaction.commit(connection);
      }
    } catch (Exception e) {
      if (useNewConnection) {
        Transaction.rollback(connection);
      }
      throw e;
    }

    List availableIds = (List) ids.get(tableName);
    if (availableIds == null) {
      availableIds = new ArrayList();
      ids.put(tableName, availableIds);
    }

    // Create the ids and store them in the list of available ids.
    int numId = quantity.intValue();
    for (int i = 0; i < numId; i++) {
      availableIds.add(nextId);
      nextId = nextId.add(ONE);
    }
    // }
  }
Example #24
0
 private boolean isLogging(String clientIp, String key) {
   boolean defaultValue = configuration.getBoolean(key, false);
   return configuration.getBoolean(clientIp + "." + key, defaultValue);
 }
Example #25
0
  @SuppressWarnings("rawtypes")
  private SenseiZoieFactory<?> constructZoieFactory(
      ZoieConfig zoieConfig,
      List<FacetHandler<?>> facetHandlers,
      List<RuntimeFacetHandlerFactory<?, ?>> runtimeFacetHandlerFactories,
      ZoieIndexableInterpreter interpreter)
      throws ConfigurationException {
    String indexerType = _senseiConf.getString(SENSEI_INDEXER_TYPE, "zoie");
    decorator = new SenseiIndexReaderDecorator(facetHandlers, runtimeFacetHandlerFactories);
    File idxDir = new File(_senseiConf.getString(SENSEI_INDEX_DIR));
    SenseiZoieFactory<?> zoieSystemFactory = null;

    DIRECTORY_MODE dirMode;
    String modeValue = _senseiConf.getString(SENSEI_INDEXER_MODE, "SIMPLE");
    if ("SIMPLE".equalsIgnoreCase(modeValue)) {
      dirMode = DIRECTORY_MODE.SIMPLE;
    } else if ("NIO".equalsIgnoreCase(modeValue)) {
      dirMode = DIRECTORY_MODE.NIO;
    } else if ("MMAP".equalsIgnoreCase(modeValue)) {
      dirMode = DIRECTORY_MODE.MMAP;
    } else {
      logger.error("directory mode " + modeValue + " is not supported, SIMPLE is used.");
      dirMode = DIRECTORY_MODE.SIMPLE;
    }

    if (SENSEI_INDEXER_TYPE_ZOIE.equals(indexerType)) {
      SenseiZoieSystemFactory senseiZoieFactory =
          new SenseiZoieSystemFactory(idxDir, dirMode, interpreter, decorator, zoieConfig);
      int retentionDays = _senseiConf.getInt(SENSEI_ZOIE_RETENTION_DAYS, -1);
      if (retentionDays > 0) {
        RetentionFilterFactory retentionFilterFactory =
            pluginRegistry.getBeanByFullPrefix(
                SENSEI_ZOIE_RETENTION_CLASS, RetentionFilterFactory.class);
        Filter purgeFilter = null;
        if (retentionFilterFactory != null) {
          purgeFilter = retentionFilterFactory.buildRetentionFilter(retentionDays);
        } else {
          String timeColumn = _senseiConf.getString(SENSEI_ZOIE_RETENTION_COLUMN, null);
          if (timeColumn == null) {
            throw new ConfigurationException("Retention specified without a time column");
          }
          String unitString = _senseiConf.getString(SENSEI_ZOIE_RETENTION_TIMEUNIT, "seconds");
          TimeUnit unit = TimeUnit.valueOf(unitString.toUpperCase());
          if (unit == null) {
            throw new ConfigurationException("Invalid timeunit for retention: " + unitString);
          }
          purgeFilter = new TimeRetentionFilter(timeColumn, retentionDays, unit);
        }
        if (purgeFilter != null && pluggableSearchEngineManager != null) {
          purgeFilter = new PurgeFilterWrapper(purgeFilter, pluggableSearchEngineManager);
        }
        senseiZoieFactory.setPurgeFilter(purgeFilter);
      }
      zoieSystemFactory = senseiZoieFactory;
    } else if (SENSEI_INDEXER_TYPE_HOURGLASS.equals(indexerType)) {
      String schedule = _senseiConf.getString(SENSEI_HOURGLASS_SCHEDULE, "");
      int trimThreshold = _senseiConf.getInt(SENSEI_HOURGLASS_TRIMTHRESHOLD, 14);
      String frequencyString = _senseiConf.getString(SENSEI_HOURGLASS_FREQUENCY, "day");

      FREQUENCY frequency;

      if (SENSEI_HOURGLASS_FREQUENCY_MIN.equals(frequencyString)) {
        frequency = FREQUENCY.MINUTELY;
      } else if (SENSEI_HOURGLASS_FREQUENCY_HOUR.equals(frequencyString)) {
        frequency = FREQUENCY.HOURLY;
      } else if (SENSEI_HOURGLASS_FREQUENCY_DAY.equals(frequencyString)) {
        frequency = FREQUENCY.DAILY;
      } else {
        throw new ConfigurationException("unsupported frequency setting: " + frequencyString);
      }

      boolean appendOnly = _senseiConf.getBoolean(SENSEI_HOURGLASS_APPENDONLY, true);
      zoieSystemFactory =
          new SenseiHourglassFactory(
              idxDir,
              dirMode,
              interpreter,
              decorator,
              zoieConfig,
              schedule,
              appendOnly,
              trimThreshold,
              frequency,
              pluggableSearchEngineManager != null
                  ? Arrays.asList(pluggableSearchEngineManager)
                  : Collections.EMPTY_LIST);
    } else {
      ZoieFactoryFactory zoieFactoryFactory =
          pluginRegistry.getBeanByFullPrefix(indexerType, ZoieFactoryFactory.class);
      if (zoieFactoryFactory == null) {
        throw new ConfigurationException(indexerType + " not defined");
      }
      zoieSystemFactory =
          zoieFactoryFactory.getZoieFactory(idxDir, interpreter, decorator, zoieConfig);
    }
    String indexerCopier = _senseiConf.getString(SENSEI_INDEXER_COPIER);
    IndexCopier copier =
        pluginRegistry.getBeanByFullPrefix(SENSEI_INDEXER_COPIER, IndexCopier.class);
    if (copier != null) {
      zoieSystemFactory =
          new SenseiPairFactory(
              idxDir, dirMode, copier, interpreter, decorator, zoieConfig, zoieSystemFactory);
    } else if (SENSEI_INDEXER_COPIER_HDFS.equals(indexerCopier)) {
      zoieSystemFactory =
          new SenseiPairFactory(
              idxDir,
              dirMode,
              new HDFSIndexCopier(),
              interpreter,
              decorator,
              zoieConfig,
              zoieSystemFactory);
    } else {
      // do not support bootstrap index from other sources.

    }
    return zoieSystemFactory;
  }
Example #26
0
  public SenseiCore buildCore() throws ConfigurationException {
    SenseiUncaughtExceptionHandler.setAsDefaultForAllThreads();
    int nodeid = _senseiConf.getInt(NODE_ID);
    String partStr = _senseiConf.getString(PARTITIONS);
    String[] partitionArray = partStr.split("[,\\s]+");
    int[] partitions = buildPartitions(partitionArray);
    logger.info("partitions to serve: " + Arrays.toString(partitions));
    // Analyzer from configuration:
    Analyzer analyzer = pluginRegistry.getBeanByFullPrefix(SENSEI_INDEX_ANALYZER, Analyzer.class);
    if (analyzer == null) {
      analyzer = new StandardAnalyzer(Version.LUCENE_35);
    }
    // Similarity from configuration:
    Similarity similarity =
        pluginRegistry.getBeanByFullPrefix(SENSEI_INDEX_SIMILARITY, Similarity.class);
    if (similarity == null) {
      similarity = new DefaultSimilarity();
    }
    ZoieConfig zoieConfig;
    if (_gateway != null) {
      zoieConfig = new ZoieConfig(_gateway.getVersionComparator());
    } else {
      zoieConfig = new ZoieConfig();
    }

    zoieConfig.setAnalyzer(analyzer);
    zoieConfig.setSimilarity(similarity);
    zoieConfig.setBatchSize(
        _senseiConf.getInt(SENSEI_INDEX_BATCH_SIZE, ZoieConfig.DEFAULT_SETTING_BATCHSIZE));
    zoieConfig.setBatchDelay(
        _senseiConf.getLong(SENSEI_INDEX_BATCH_DELAY, ZoieConfig.DEFAULT_SETTING_BATCHDELAY));
    zoieConfig.setMaxBatchSize(
        _senseiConf.getInt(SENSEI_INDEX_BATCH_MAXSIZE, ZoieConfig.DEFAULT_MAX_BATCH_SIZE));
    zoieConfig.setRtIndexing(
        _senseiConf.getBoolean(SENSEI_INDEX_REALTIME, ZoieConfig.DEFAULT_SETTING_REALTIME));
    zoieConfig.setSkipBadRecord(_senseiConf.getBoolean(SENSEI_SKIP_BAD_RECORDS, false));
    int delay = _senseiConf.getInt(SENSEI_INDEX_FRESHNESS, 10);
    ReaderCacheFactory readercachefactory;
    if (delay > 0) {
      readercachefactory = DefaultReaderCache.FACTORY;
      zoieConfig.setFreshness(delay * 1000);
    } else {
      readercachefactory = SimpleReaderCache.FACTORY;
    }
    zoieConfig.setReadercachefactory(readercachefactory);
    ShardingStrategy strategy =
        pluginRegistry.getBeanByFullPrefix(SENSEI_SHARDING_STRATEGY, ShardingStrategy.class);
    if (strategy == null) {
      strategy = new ShardingStrategy.FieldModShardingStrategy(_senseiSchema.getUidField());
    }

    pluggableSearchEngineManager = new PluggableSearchEngineManager();
    pluggableSearchEngineManager.init(
        _senseiConf.getString(SENSEI_INDEX_DIR),
        nodeid,
        _senseiSchema,
        zoieConfig.getVersionComparator(),
        pluginRegistry,
        strategy);

    List<FacetHandler<?>> facetHandlers = new LinkedList<FacetHandler<?>>();
    List<RuntimeFacetHandlerFactory<?, ?>> runtimeFacetHandlerFactories =
        new LinkedList<RuntimeFacetHandlerFactory<?, ?>>();

    SenseiSystemInfo sysInfo = null;

    try {
      sysInfo =
          SenseiFacetHandlerBuilder.buildFacets(
              _schemaDoc,
              pluginRegistry,
              facetHandlers,
              runtimeFacetHandlerFactories,
              pluggableSearchEngineManager);
    } catch (JSONException jse) {
      throw new ConfigurationException(jse.getMessage(), jse);
    }

    if (sysInfo != null) {
      sysInfo.setSchema(_schemaDoc.toString());

      try {
        List<SenseiSystemInfo.SenseiNodeInfo> clusterInfo = new ArrayList(1);
        String addr = NetUtil.getHostAddress();
        clusterInfo.add(
            new SenseiSystemInfo.SenseiNodeInfo(
                nodeid,
                partitions,
                String.format("%s:%d", addr, _senseiConf.getInt(SERVER_PORT)),
                String.format("http://%s:%d", addr, _senseiConf.getInt(SERVER_BROKER_PORT))));
        sysInfo.setClusterInfo(clusterInfo);
      } catch (Exception e) {
        throw new ConfigurationException(e.getMessage(), e);
      }
    }
    ZoieIndexableInterpreter interpreter =
        pluginRegistry.getBeanByFullPrefix(
            SENSEI_INDEX_INTERPRETER, ZoieIndexableInterpreter.class);
    if (interpreter == null) {
      DefaultJsonSchemaInterpreter defaultInterpreter =
          new DefaultJsonSchemaInterpreter(_senseiSchema, pluggableSearchEngineManager);
      interpreter = defaultInterpreter;
      CustomIndexingPipeline customIndexingPipeline =
          pluginRegistry.getBeanByFullPrefix(SENSEI_INDEX_CUSTOM, CustomIndexingPipeline.class);
      if (customIndexingPipeline != null) {
        try {
          defaultInterpreter.setCustomIndexingPipeline(customIndexingPipeline);
        } catch (Exception e) {
          logger.error(e.getMessage(), e);
        }
      }
    }
    SenseiZoieFactory<?> zoieSystemFactory =
        constructZoieFactory(zoieConfig, facetHandlers, runtimeFacetHandlerFactories, interpreter);
    SenseiIndexingManager<?> indexingManager =
        pluginRegistry.getBeanByFullPrefix(SENSEI_INDEX_MANAGER, SenseiIndexingManager.class);

    if (indexingManager == null) {
      indexingManager =
          new DefaultStreamingIndexingManager(
              _senseiSchema,
              _senseiConf,
              pluginRegistry,
              _gateway,
              strategy,
              pluggableSearchEngineManager);
    }
    SenseiQueryBuilderFactory queryBuilderFactory =
        pluginRegistry.getBeanByFullPrefix(
            SENSEI_QUERY_BUILDER_FACTORY, SenseiQueryBuilderFactory.class);
    if (queryBuilderFactory == null) {
      QueryParser queryParser = new QueryParser(Version.LUCENE_35, "contents", analyzer);
      queryBuilderFactory = new DefaultJsonQueryBuilderFactory(queryParser);
    }
    SenseiCore senseiCore =
        new SenseiCore(
            nodeid, partitions, zoieSystemFactory, indexingManager, queryBuilderFactory, decorator);
    senseiCore.setSystemInfo(sysInfo);
    SenseiIndexPruner indexPruner =
        pluginRegistry.getBeanByFullPrefix(SENSEI_INDEX_PRUNER, SenseiIndexPruner.class);
    if (indexPruner != null) {
      senseiCore.setIndexPruner(indexPruner);
    }
    if (pluggableSearchEngineManager != null) {
      senseiCore.setPluggableSearchEngineManager(pluggableSearchEngineManager);
    }
    return senseiCore;
  }
  private Object sendMessage(
      CreditCard creditCard, Money amount, Money tax, InetAddress userIp, boolean verify)
      throws IOException, CommerceException {
    URL url = new URL(configuration.getString("jcatapult.commerce.aim.url"));
    String username = configuration.getString("jcatapult.commerce.aim.username");
    String password = configuration.getString("jcatapult.commerce.aim.password");
    if (logger.isLoggable(Level.FINEST)) {
      logger.finest("Contacting AIM with this info");
      logger.finest("URL: " + url.toExternalForm());
      logger.finest("Username: "******"Password: "******"x_version=3.1&");
    build.append("x_delim_data=TRUE&");
    build.append("x_relay_response=FALSE&");
    build.append("x_login="******"&");
    build.append("x_tran_key=").append(password).append("&");
    build.append("x_method=CC&");
    build.append("x_delim_char=|&");

    if (verify) {
      build.append("x_type=AUTH_ONLY&");
    } else {
      build.append("x_type=AUTH_CAPTURE&");
    }

    if (configuration.getBoolean("jcatapult.commerce.aim.test")) {
      build.append("x_test_request=TRUE&");
    }

    if (!creditCard.isVerified()) {
      build.append("x_card_code=").append(creditCard.getSvn()).append("&");
      build.append("x_first_name=").append(creditCard.getFirstName()).append("&");
      build.append("x_last_name=").append(creditCard.getLastName()).append("&");
      build.append("x_address=").append(creditCard.getAddress().getStreet1()).append("&");
      build.append("x_city=").append(creditCard.getAddress().getCity()).append("&");
      build.append("x_state=").append(creditCard.getAddress().getState()).append("&");
      build.append("x_zip=").append(creditCard.getAddress().getPostalCode()).append("&");
      build.append("x_country=").append(creditCard.getAddress().getCountry()).append("&");
      build.append("x_customer_ip=").append(userIp.toString()).append("&");
    }

    if (tax != null) {
      build.append("x_tax=").append(tax.toString()).append("&");
    }

    build.append("x_amount=").append(amount.toString()).append("&");
    build.append("x_currency_code=").append(amount.getCurrency().getCurrencyCode()).append("&");
    build.append("x_card_num=").append(creditCard.getNumber()).append("&");
    build.append("x_exp_date=").append(creditCard.getExpirationDate());

    huc.setConnectTimeout(
        configuration.getInt("jcatapult.commerce.aim.connectTimeoutSeconds", 60) * 1000);
    huc.setReadTimeout(
        configuration.getInt("jcatapult.commerce.aim.readTimeoutSeconds", 180) * 1000);
    huc.setUseCaches(false);
    huc.setDoInput(true);
    huc.setDoOutput(true);
    huc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    huc.connect();

    OutputStream os = huc.getOutputStream();
    os.write(build.toString().getBytes());
    os.flush();
    os.close();

    BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream()));
    String response = br.readLine();
    br.close();

    // logger.finest("Response from AIM is [" + response + "]");

    String[] parts = split(response);
    if (parts.length < 39) {
      throw new CommerceException("Invalid response from the Gateway.");
    }

    int responseCode = Integer.valueOf(parts[0]);
    String transactionID = null;
    CommerceError error = null;
    if (responseCode == 1) {
      transactionID = parts[6];
    } else {
      error = getError(parts[0], parts[2], parts[3], parts[4], parts[5]);
    }

    if (verify) {
      return new VerifyResult(error);
    }

    return new ChargeResult(transactionID, error, parts[0], parts[2], parts[3], parts[4], parts[5]);
  }
Example #28
0
 /** @return true if the elasticsearch index should be initialized if not found */
 public boolean isInitializeStorageES() {
   return config.getBoolean(APIMAN_MANAGER_STORAGE_ES_INITIALIZE, true);
 }
Example #29
0
  /**
   * Set the GEM1ERF params given the parameters defined in
   *
   * @param erf : erf for which parameters have to be set
   * @param calcConfig : calculator configuration obejct containing parameters for the ERF
   */
  public void setGEM1ERFParams(GEM1ERF erf) {
    // set minimum magnitude
    /*
     * xxr: TODO: !!!type safety!!! apache's Configuration interface handles
     * a similar problem this way: Instead of defining one single method
     * like public void setParameter(String key, Object value) {...} there
     * is one method per type defined: setString(), setDouble(), setInt(),
     * ...
     */
    erf.setParameter(GEM1ERF.MIN_MAG_NAME, config.getDouble(ConfigItems.MINIMUM_MAGNITUDE.name()));
    // set time span
    TimeSpan timeSpan = new TimeSpan(TimeSpan.NONE, TimeSpan.YEARS);
    timeSpan.setDuration(config.getDouble(ConfigItems.INVESTIGATION_TIME.name()));
    erf.setTimeSpan(timeSpan);

    // params for area source
    // set inclusion of area sources in the calculation
    erf.setParameter(
        GEM1ERF.INCLUDE_AREA_SRC_PARAM_NAME,
        config.getBoolean(ConfigItems.INCLUDE_AREA_SOURCES.name()));
    // set rupture type ("area source rupture model /
    // area_source_rupture_model / AreaSourceRuptureModel)
    erf.setParameter(
        GEM1ERF.AREA_SRC_RUP_TYPE_NAME, config.getString(ConfigItems.TREAT_AREA_SOURCE_AS.name()));
    // set area discretization
    erf.setParameter(
        GEM1ERF.AREA_SRC_DISCR_PARAM_NAME,
        config.getDouble(ConfigItems.AREA_SOURCE_DISCRETIZATION.name()));
    // set mag-scaling relationship
    erf.setParameter(
        GEM1ERF.AREA_SRC_MAG_SCALING_REL_PARAM_NAME,
        config.getString(ConfigItems.AREA_SOURCE_MAGNITUDE_SCALING_RELATIONSHIP.name()));
    // params for grid source
    // inclusion of grid sources in the calculation
    erf.setParameter(
        GEM1ERF.INCLUDE_GRIDDED_SEIS_PARAM_NAME,
        config.getBoolean(ConfigItems.INCLUDE_GRID_SOURCES.name()));
    // rupture model
    erf.setParameter(
        GEM1ERF.GRIDDED_SEIS_RUP_TYPE_NAME,
        config.getString(ConfigItems.TREAT_GRID_SOURCE_AS.name()));
    // mag-scaling relationship
    erf.setParameter(
        GEM1ERF.GRIDDED_SEIS_MAG_SCALING_REL_PARAM_NAME,
        config.getString(ConfigItems.AREA_SOURCE_MAGNITUDE_SCALING_RELATIONSHIP.name()));

    // params for fault source
    // inclusion of fault sources in the calculation
    erf.setParameter(
        GEM1ERF.INCLUDE_FAULT_SOURCES_PARAM_NAME,
        config.getBoolean(ConfigItems.INCLUDE_FAULT_SOURCE.name()));
    // rupture offset
    erf.setParameter(
        GEM1ERF.FAULT_RUP_OFFSET_PARAM_NAME,
        config.getDouble(ConfigItems.FAULT_RUPTURE_OFFSET.name()));
    // surface discretization
    erf.setParameter(
        GEM1ERF.FAULT_DISCR_PARAM_NAME,
        config.getDouble(ConfigItems.FAULT_SURFACE_DISCRETIZATION.name()));
    // mag-scaling relationship
    erf.setParameter(
        GEM1ERF.FAULT_MAG_SCALING_REL_PARAM_NAME,
        config.getString(ConfigItems.FAULT_MAGNITUDE_SCALING_RELATIONSHIP.name()));

    // mag-scaling sigma
    erf.setParameter(
        GEM1ERF.FAULT_SCALING_SIGMA_PARAM_NAME,
        config.getDouble(ConfigItems.FAULT_MAGNITUDE_SCALING_SIGMA.name()));
    // rupture aspect ratio
    erf.setParameter(
        GEM1ERF.FAULT_RUP_ASPECT_RATIO_PARAM_NAME,
        config.getDouble(ConfigItems.RUPTURE_ASPECT_RATIO.name()));
    // rupture floating type
    erf.setParameter(
        GEM1ERF.FAULT_FLOATER_TYPE_PARAM_NAME,
        config.getString(ConfigItems.RUPTURE_FLOATING_TYPE.name()));

    // params for subduction fault
    // inclusion of fault sources in the calculation
    erf.setParameter(
        GEM1ERF.INCLUDE_SUBDUCTION_SOURCES_PARAM_NAME,
        config.getBoolean(ConfigItems.INCLUDE_SUBDUCTION_FAULT_SOURCE.name()));
    // rupture offset
    erf.setParameter(
        GEM1ERF.SUB_RUP_OFFSET_PARAM_NAME,
        config.getDouble(ConfigItems.SUBDUCTION_FAULT_RUPTURE_OFFSET.name()));
    // surface discretization
    erf.setParameter(
        GEM1ERF.SUB_DISCR_PARAM_NAME,
        config.getDouble(ConfigItems.SUBDUCTION_FAULT_SURFACE_DISCRETIZATION.name()));
    // mag-scaling relationship
    erf.setParameter(
        GEM1ERF.SUB_MAG_SCALING_REL_PARAM_NAME,
        config.getString(ConfigItems.SUBDUCTION_FAULT_MAGNITUDE_SCALING_RELATIONSHIP.name()));
    // mag-scaling sigma
    erf.setParameter(
        GEM1ERF.SUB_SCALING_SIGMA_PARAM_NAME,
        config.getDouble(ConfigItems.SUBDUCTION_FAULT_MAGNITUDE_SCALING_SIGMA.name()));
    // rupture aspect ratio
    erf.setParameter(
        GEM1ERF.SUB_RUP_ASPECT_RATIO_PARAM_NAME,
        config.getDouble(ConfigItems.SUBDUCTION_RUPTURE_ASPECT_RATIO.name()));
    // rupture floating type
    erf.setParameter(
        GEM1ERF.SUB_FLOATER_TYPE_PARAM_NAME,
        config.getString(ConfigItems.SUBDUCTION_RUPTURE_FLOATING_TYPE.name()));

    // update
    erf.updateForecast();
  } // setGEM1ERFParams()
Example #30
0
  /**
   * @param aArgs
   * @return
   */
  public JWSEndPoint start(String[] aArgs) {
    // set up log4j logging
    // later this should be read from a shared log4j properties or xml file!
    Properties lProps = new Properties();
    lProps.setProperty("log4j.rootLogger", "INFO, console");
    lProps.setProperty("log4j.logger.org.apache.activemq", "WARN");
    lProps.setProperty("log4j.logger.org.springframework", "WARN");
    lProps.setProperty("log4j.logger.org.apache.xbean", "WARN");
    lProps.setProperty("log4j.logger.org.apache.camel", "INFO");
    lProps.setProperty("log4j.logger.org.eclipse.jetty", "WARN");
    lProps.setProperty("log4j.appender.console", "org.apache.log4j.ConsoleAppender");
    lProps.setProperty("log4j.appender.console.layout", "org.apache.log4j.PatternLayout");
    lProps.setProperty(
        "log4j.appender.console.layout.ConversionPattern",
        // "%p: %m%n"
        "%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %C{1}: %m%n");
    // set here the jWebSocket log level:
    lProps.setProperty("log4j.logger.org.jwebsocket", "DEBUG");
    lProps.setProperty("log4j.appender.console.threshold", "DEBUG");
    PropertyConfigurator.configure(lProps);

    final JWSAutoSelectAuthenticator lAuthenticator = new JWSAutoSelectAuthenticator();
    final JWSOAuthAuthenticator lOAuthAuthenticator = new JWSOAuthAuthenticator();
    final JWSLDAPAuthenticator lLDAPAuthenticator = new JWSLDAPAuthenticator();

    mLog.info("jWebSocket JMS Gateway Server Endpoint");
    Configuration lConfig = null;
    boolean lConfigLoaded;
    try {
      // try to load properties files from local folder or jar
      String lPath = "JMSServer.properties";
      mLog.debug("Trying to read properties from: " + lPath);
      lConfig = new PropertiesConfiguration(lPath);
    } catch (ConfigurationException ex) {
    }
    if (null == lConfig) {
      try {
        // try to load properties files from JWEBSOCKET_HOME/conf/JMSPlugIn
        String lPath = Tools.expandEnvVarsAndProps("/private/JMSServer.properties");
        // String lPath =
        // Tools.expandEnvVarsAndProps("${JWEBSOCKET_HOME}conf/JMSPlugIn/JMSServer.properties");
        mLog.debug("Tring to read properties from: " + lPath);
        lConfig = new PropertiesConfiguration(lPath);
      } catch (ConfigurationException ex) {
      }
    }
    if (null == lConfig) {
      mLog.error("Configuration file could not be opened.");
      return null;
    }

    // the URL of the message broker
    String lBrokerURL = lConfig.getString("BrokerURL", "tcp://127.0.0.1:61616");
    // "failover:(tcp://0.0.0.0:61616,tcp://127.0.0.1:61616)?initialReconnectDelay=100&randomize=false";
    // the name of the JMS Gateway topic
    String lGatewayTopic = lConfig.getString("GatewayTopic", "org.jwebsocket.jms.gateway");
    // endpoint id of JMS Gateway
    String lGatewayId = lConfig.getString("GatewayId", "org.jwebsocket.jms.gateway");
    String lEndPointId = lConfig.getString("EndPointId", UUID.randomUUID().toString());

    // get authentication information against jWebSocket
    final String lJWSUsername = lConfig.getString("JWSUsername");
    final String lJWSPassword = lConfig.getString("JWSPassword");
    final boolean lFullTextLogging = lConfig.getBoolean("FullTextLogging", false);

    // set up OAuth Authenticator
    boolean lUseOAuth = lConfig.getBoolean("UseOAuth", false);

    String lOAuthHost = lConfig.getString("OAuthHost");
    String lOAuthAppId = lConfig.getString("OAuthAppId");
    String lOAuthAppSecret = lConfig.getString("OAuthAppSecret");
    String lOAuthUsername = lConfig.getString("OAuthUsername");
    String lOAuthPassword = lConfig.getString("OAuthPassword");
    long lOAuthTimeout = lConfig.getLong("OAuthTimeout", 5000);

    lUseOAuth =
        lUseOAuth
            && null != lOAuthHost
            && null != lOAuthAppId
            && null != lOAuthAppSecret
            && null != lOAuthUsername
            && null != lOAuthPassword;

    if (lUseOAuth) {
      lOAuthAuthenticator.init(lOAuthHost, lOAuthAppId, lOAuthAppSecret, lOAuthTimeout);
      lAuthenticator.addAuthenticator(lOAuthAuthenticator);
    }

    // set up LDAP Authenticator
    boolean lUseLDAP = lConfig.getBoolean("UseLDAP", false);

    String lLDAPURL = lConfig.getString("LDAPURL");
    String lBaseDNGroups = lConfig.getString("BaseDNGroups");
    String lBaseDNUsers = lConfig.getString("BaseDNUsers");

    if (lUseLDAP) {
      lLDAPAuthenticator.init(lLDAPURL, lBaseDNGroups, lBaseDNUsers);
      lAuthenticator.addAuthenticator(lLDAPAuthenticator);
    }

    // TODO: Validate config data here!
    lConfigLoaded = true;

    if (!lConfigLoaded) {
      mLog.error("Config not loaded.");
      System.exit(1);
    }

    mLog.info(
        "Using: "
            + lBrokerURL
            + ", "
            + "topic: "
            + lGatewayTopic
            + ", "
            + "gateway-id: "
            + lGatewayId
            + ", "
            + "endpoint-id: "
            + lEndPointId);

    // todo: Comment that for production purposes
    JMSLogging.setFullTextLogging(lFullTextLogging);

    // instantiate a new jWebSocket JMS Gateway Client
    try {
      lJWSEndPoint =
          JWSEndPoint.getInstance(
              lBrokerURL,
              lGatewayTopic, // gateway topic
              lGatewayId, // gateway endpoint id
              lEndPointId, // unique node id
              5, // thread pool size, messages being processed concurrently
              JMSEndPoint.TEMPORARY // durable (for servers) or temporary (for clients)
              );
    } catch (JMSException lEx) {
      mLog.fatal("JMSEndpoint could not be instantiated: " + lEx.getMessage());
      System.exit(0);
    }

    lJWSEndPoint.addRequestListener(
        "org.jwebsocket.jms.gateway",
        "welcome",
        new JWSMessageListener(lJWSEndPoint) {
          @Override
          public void processToken(String aSourceId, Token aToken) {
            mLog.info("Received 'welcome', authenticating against jWebSocket...");
            Token lToken = TokenFactory.createToken("org.jwebsocket.plugins.system", "login");
            lToken.setString("username", lJWSUsername);
            lToken.setString("password", lJWSPassword);
            sendToken(aSourceId, lToken);
          }
        });

    // on response of the login...
    lJWSEndPoint.addResponseListener(
        "org.jwebsocket.plugins.system",
        "login",
        new JWSMessageListener(lJWSEndPoint) {
          @Override
          public void processToken(String aSourceId, Token aToken) {
            int lCode = aToken.getInteger("code", -1);
            if (0 == lCode) {
              if (mLog.isInfoEnabled()) {
                mLog.info("Authentication against jWebSocket successful.");
              }
            } else {
              mLog.error("Authentication against jWebSocket failed!");
            }
          }
        });

    // on response of the login...
    lJWSEndPoint.addRequestListener(
        "org.jwebsocket.jms.demo",
        "getUser",
        new JWSMessageListener(lJWSEndPoint) {
          @Override
          public void processToken(String aSourceId, Token aToken) {
            String lPayload = aToken.getString("payload");
            if (mLog.isInfoEnabled()) {
              mLog.info("Processing 'getUser'...");
            }
          }
        });

    // on response of the login...
    lJWSEndPoint.addRequestListener(
        "org.jwebsocket.jms.demo",
        "echo",
        new JWSMessageListener(lJWSEndPoint) {
          @Override
          public void processToken(String aSourceId, Token aToken) {
            String lPayload = aToken.getString("payload");
            if (mLog.isInfoEnabled()) {
              mLog.info("Processing 'demo1 with Payload '" + lPayload + "'");
            }
            Map<String, Object> lAdditionalResults = new FastMap<String, Object>();
            lAdditionalResults.putAll(aToken.getMap());
            // lAdditionalResults.remove("sourceId");
            lAdditionalResults.remove("payload");
            lJWSEndPoint.respondPayload(
                aToken,
                0, // return code
                "Ok", // return message
                lAdditionalResults,
                aToken.getString("payload"));
          }
        });

    // on response of the login...
    lJWSEndPoint.addRequestListener(
        "org.jwebsocket.jms.demo",
        "testProgress",
        new JWSMessageListener(lJWSEndPoint) {
          @Override
          @SuppressWarnings("SleepWhileInLoop")
          public void processToken(String aSourceId, Token aToken) {
            int lMax = 10;
            for (int lIdx = 0; lIdx < lMax; lIdx++) {
              mLog.debug("Progress iteration " + lIdx + "...");
              try {
                Thread.sleep(333);
              } catch (InterruptedException lEx) {
              }
              lJWSEndPoint.sendProgress(
                  aToken, ((lIdx + 1.0) / lMax) * 100, 0, "Iteration #" + lIdx, null);
            }
            lJWSEndPoint.respondPayload(
                aToken,
                0, // return code
                "Ok", // return message
                null,
                aToken.getString("payload"));
          }
        });

    // ...
    lJWSEndPoint.addRequestListener(
        "org.jwebsocket.jms.demo",
        "testCaughtException",
        new JWSMessageListener(lJWSEndPoint) {
          @Override
          public void processToken(String aSourceId, Token aToken) {
            mLog.debug("Testing caught exception...");
            // provoke null pointer exception and DO catch it for test purposes
            int a = 1;
            int b = 0;
            try {
              int c = a / b;
              lJWSEndPoint.respondPayload(
                  aToken,
                  0, // return code
                  "Ok", // return message
                  null,
                  aToken.getString("payload"));
            } catch (Exception Ex) {
              lJWSEndPoint.respondPayload(
                  aToken,
                  -1, // return code
                  Ex.getClass().getSimpleName() + ": " + Ex.getMessage(), // return message
                  null,
                  aToken.getString("payload"));
            }
          }
        });

    // ...
    lJWSEndPoint.addRequestListener(
        "org.jwebsocket.jms.demo",
        "testUncaughtException",
        new JWSMessageListener(lJWSEndPoint) {
          @Override
          public void processToken(String aSourceId, Token aToken) {
            mLog.debug("Testing uncaught exception...");
            // provoke null pointer exception and do NOT catch it for test purposes
            int a = 1;
            int b = 0;
            int c = a / b;

            lJWSEndPoint.respondPayload(
                aToken,
                0, // return code
                "Ok", // return message
                null,
                aToken.getString("payload"));
          }
        });

    // test for the OAuth interface
    lJWSEndPoint.addRequestListener(
        "org.jwebsocket.jms.demo",
        "testOAuth",
        new JWSMessageListener(lJWSEndPoint) {
          @Override
          public void processToken(String aSourceId, Token aToken) {

            Map<String, Object> lArgs = new FastMap<String, Object>();

            String lUsername;
            int lCode = 0;
            String lMessage = "Ok";
            try {
              lUsername = lOAuthAuthenticator.authToken(aToken);
              if (null == lUsername) {
                lCode = -1;
                lMessage = "User could not be authenticated!";
              } else {
                lArgs.put("username", lUsername);
              }
            } catch (JMSEndpointException ex) {
              lCode = -1;
              lMessage = ex.getClass().getSimpleName() + " on authentication: " + ex.getMessage();
            }

            lJWSEndPoint.respondPayload(
                aToken, lCode, // return code
                lMessage, // return message
                lArgs, // additional result fields
                null); // payload
          }
        });

    // test for the LDAP interface
    lJWSEndPoint.addRequestListener(
        "org.jwebsocket.jms.demo",
        "testLDAP",
        new JWSMessageListener(lJWSEndPoint) {
          @Override
          public void processToken(String aSourceId, Token aToken) {

            Map<String, Object> lArgs = new FastMap<String, Object>();

            String lUsername;
            int lCode = 0;
            String lMessage = "Ok";
            try {
              lUsername = lLDAPAuthenticator.authToken(aToken);
              if (null == lUsername) {
                lCode = -1;
                lMessage = "User could not be authenticated!";
              } else {
                lArgs.put("username", lUsername);
              }
            } catch (JMSEndpointException ex) {
              lCode = -1;
              lMessage = ex.getClass().getSimpleName() + " on authentication: " + ex.getMessage();
            }

            lJWSEndPoint.respondPayload(
                aToken, lCode, // return code
                lMessage, // return message
                lArgs, // additional result fields
                null); // payload
          }
        });

    // test for the auto authentication interface
    lJWSEndPoint.addRequestListener(
        "org.jwebsocket.jms.demo",
        "testAuth",
        new JWSMessageListener(lJWSEndPoint) {
          @Override
          public void processToken(String aSourceId, Token aToken) {

            mLog.debug("Testing auto authenticator...");
            Map<String, Object> lArgs = new FastMap<String, Object>();

            String lUsername;
            int lCode = 0;
            String lMessage = "Ok";
            try {
              checkADUsername(aToken);
              lUsername = lAuthenticator.authToken(aToken);
              if (null == lUsername) {
                lCode = -1;
                lMessage = "User could not be authenticated!";
              } else {
                lArgs.put("username", lUsername);
              }
            } catch (JMSEndpointException lEx) {
              lCode = -1;
              lMessage =
                  lEx.getClass().getSimpleName() + " on auto authentication: " + lEx.getMessage();
            }

            lJWSEndPoint.respondPayload(
                aToken, lCode, // return code
                lMessage, // return message
                lArgs, // additional result fields
                null); // payload
          }
        });

    lJWSEndPoint.addRequestListener(
        "tld.yourname.jms",
        "transferFile",
        new JWSMessageListener(lJWSEndPoint) {
          @Override
          public void processToken(String aSourceId, Token aToken) {
            // here you can get the additional arguments
            mLog.info(
                "Received 'transferFile' with additional args"
                    + " (arg1="
                    + aToken.getString("arg1")
                    + " (arg2="
                    + aToken.getString("arg2")
                    + ")...");
            // here you get the payload from the requester
            String lPayload = aToken.getString("payload");
            // parse the JSON payload into a Token (for simpler processing)
            Token lToken = JSONProcessor.JSONStringToToken(lPayload);
            // extract the base64 and compressed file contents into Strings
            // (it's a text message)
            // String lBase64Encoded = lToken.getString("fileAsBase64");
            String lBase64Zipped = lToken.getString("fileAsZip");

            // specify the target file
            File lFile = new File("Apache License 2.0 (copy).txt");
            try {
              // take the zipped version of the file...
              byte[] lBA = Tools.unzip(lBase64Zipped.getBytes("UTF-8"), Boolean.TRUE);
              // and save it to the hard disk
              FileUtils.writeByteArrayToFile(lFile, lBA);
            } catch (Exception lEx) {
              mLog.error("Demo file " + lFile.getAbsolutePath() + " could not be saved!");
            }
          }
        });

    // add a high level listener to listen in coming messages
    lJWSEndPoint.addRequestListener(
        "org.jwebsocket.jms.demo",
        "helloWorld",
        new JWSMessageListener(lJWSEndPoint) {
          @Override
          public void processToken(String aSourceId, Token aToken) {
            mLog.info("Received 'helloWorld'...");
            lJWSEndPoint.respondPayload(
                aToken.getString("sourceId"),
                aToken,
                0, // return code
                "Ok", // return message
                null, // here you can add additional results beside the payload
                "Hello World!");
          }
        });

    // start the endpoint all all listener have been assigned
    lJWSEndPoint.start();
    return lJWSEndPoint;
  }