<commit_before>/*
 *
 *  Copyright 2012 Netflix, Inc.
 *
 *     Licensed under the Apache License, Version 2.0 (the "License");
 *     you may not use this file except in compliance with the License.
 *     You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS,
 *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *     See the License for the specific language governing permissions and
 *     limitations under the License.
 *
 */
package com.netflix.edda.basic

import com.netflix.edda.aws.AwsBeanMapper
import com.netflix.edda.aws.AwsCollectionBuilder
import com.netflix.edda.aws.AwsClient
import com.netflix.edda.CollectionManager
import com.netflix.edda.mongo.MongoDatastore
import com.netflix.edda.mongo.MongoElector

import javax.servlet.http.HttpServlet

import org.slf4j.LoggerFactory

/** simple servlet that specifies the datastores being used and creates
  * accessors to initialize the AWS client credentials and start the collections.
  * It is recommended to create a separate Servlet if behavior changes are required
  * for special collections or datastores
  */
class BasicServer extends HttpServlet {
  private[this] val logger = LoggerFactory.getLogger(getClass)

  override def init() {
    logger.info("Staring Server")
    val dsFactory = (name: String) => Some(new MongoDatastore(BasicContext, name))
    val elector = new MongoElector(BasicContext)

    val bm = new BasicBeanMapper(BasicContext) with AwsBeanMapper

    val awsClientFactory = (account: String, region: String) => {
      Option(BasicContext.config.getProperty("edda.aws.accessKey")) match {
        case None => new AwsClient(region)
        case Some(accessKey) => new AwsClient(
          accessKey,
          BasicContext.config.getProperty("edda.aws.secretKey"),
          region)
      }
    }

    AwsCollectionBuilder.buildAll(BasicContext, awsClientFactory, bm, elector, dsFactory)

    logger.info("Starting Collections")
    CollectionManager.start()

    super.init()
  }

  override def destroy() {
    CollectionManager.stop()
    super.destroy()
  }
}<commit_msg>Fix BasicServer to use Utils.getProperty for account credentials.<commit_after>/*
 *
 *  Copyright 2012 Netflix, Inc.
 *
 *     Licensed under the Apache License, Version 2.0 (the "License");
 *     you may not use this file except in compliance with the License.
 *     You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS,
 *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *     See the License for the specific language governing permissions and
 *     limitations under the License.
 *
 */
package com.netflix.edda.basic

import com.netflix.edda.aws.AwsBeanMapper
import com.netflix.edda.aws.AwsCollectionBuilder
import com.netflix.edda.aws.AwsClient
import com.netflix.edda.CollectionManager
import com.netflix.edda.mongo.MongoDatastore
import com.netflix.edda.mongo.MongoElector
import com.netflix.edda.Utils

import javax.servlet.http.HttpServlet

import org.slf4j.LoggerFactory

/** simple servlet that specifies the datastores being used and creates
  * accessors to initialize the AWS client credentials and start the collections.
  * It is recommended to create a separate Servlet if behavior changes are required
  * for special collections or datastores
  */
class BasicServer extends HttpServlet {
  private[this] val logger = LoggerFactory.getLogger(getClass)

  override def init() {
    logger.info("Staring Server")
    val dsFactory = (name: String) => Some(new MongoDatastore(BasicContext, name))
    val elector = new MongoElector(BasicContext)

    val bm = new BasicBeanMapper(BasicContext) with AwsBeanMapper

    val awsClientFactory = (account: String, region: String) => {
      Option(Utils.getProperty(BasicContext.config, "edda", "aws.accessKey", account, null)) match {
        case None => new AwsClient(region)
        case Some(accessKey) => new AwsClient(
          accessKey,
          Utils.getProperty(BasicContext.config, "edda", "aws.secretKey", account, null),
          region)
      }
    }

    AwsCollectionBuilder.buildAll(BasicContext, awsClientFactory, bm, elector, dsFactory)

    logger.info("Starting Collections")
    CollectionManager.start()

    super.init()
  }

  override def destroy() {
    CollectionManager.stop()
    super.destroy()
  }
}
{'fraction_non_alphanumeric': 0.08456973293768547, 'fraction_numerical': 0.0038151759220008477, 'mean_word_length': 3.631010794896958, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1213818', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1308, 'n_words': 423}