• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Settings类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中org.elasticsearch.common.settings.Settings的典型用法代码示例。如果您正苦于以下问题:Scala Settings类的具体用法?Scala Settings怎么用?Scala Settings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Settings类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: getClient

//设置package包名称以及导入依赖的类
package au.csiro.data61.magda.search.elasticsearch

import akka.actor.Scheduler
import akka.event.LoggingAdapter
import au.csiro.data61.magda.AppConfig
import au.csiro.data61.magda.util.ErrorHandling.retry
import com.sksamuel.elastic4s.{ TcpClient, ElasticsearchClientUri }
import org.elasticsearch.common.settings.Settings

import scala.concurrent.{ ExecutionContext, Future }
import scala.concurrent.duration._

trait ClientProvider {
  def getClient(implicit scheduler: Scheduler, logger: LoggingAdapter, ec: ExecutionContext): Future[TcpClient]
}

class DefaultClientProvider extends ClientProvider {
  private var clientFuture: Option[Future[TcpClient]] = None

  override def getClient(implicit scheduler: Scheduler, logger: LoggingAdapter, ec: ExecutionContext): Future[TcpClient] = {
    val outerFuture = clientFuture match {
      case Some(future) => future
      case None =>
        val future = retry(() => Future {
          val uri = ElasticsearchClientUri(AppConfig.conf().getString("elasticSearch.serverUrl"))
          val settings = Settings.builder().put("cluster.name", "myesdb").build()
          TcpClient.transport(settings, uri)
        }, 10 seconds, 10, onRetry(logger))
          .map { client =>
            logger.info("Successfully connected to elasticsearch client")
            client
          }

        clientFuture = Some(future)

        future
    }

    outerFuture
  }

  private def onRetry(logger: LoggingAdapter)(retriesLeft: Int, error: Throwable) = logger.error("Failed to make initial contact with ES server, {} retries left", retriesLeft, error)
} 
开发者ID:TerriaJS,项目名称:magda,代码行数:44,代码来源:ClientProvider.scala


示例2: ElasticWriteConfig

//设置package包名称以及导入依赖的类
package com.yannick_cw.elastic_indexer4s.elasticsearch.elasic_config

import com.sksamuel.elastic4s.TcpClient
import org.elasticsearch.common.settings.Settings
import org.joda.time.DateTime

import scala.concurrent.duration.{FiniteDuration, _}

case class ElasticWriteConfig(
  hosts: List[String],
  port: Int,
  cluster: String,
  indexPrefix: String,
  docType: String,
  mappingSetting: MappingSetting = TypedMappingSetting(),
  writeBatchSize: Int = 50,
  writeConcurrentRequest: Int = 10,
  writeMaxAttempts: Int = 5,
  logWriteSpeedEvery: FiniteDuration = 1 minute,
  waitForElasticTimeout: FiniteDuration = 5 seconds
) {
  val indexName = indexPrefix + "_" + new DateTime().toString("yyyy-MM-dd't'HH:mm:ss")
  private def settings = Settings.builder().put("cluster.name", cluster).build()
  lazy val client: TcpClient = TcpClient.transport(settings, "elasticsearch://" + hosts
    .map(host => s"$host:$port").mkString(","))
}

object ElasticWriteConfig {
  def apply(
    esTargetHosts: List[String],
    esTargetPort: Int,
    esTargetCluster: String,
    esTargetIndexPrefix: String,
    esTargetType: String
  ): ElasticWriteConfig =
    new ElasticWriteConfig(esTargetHosts, esTargetPort, esTargetCluster, esTargetIndexPrefix, esTargetType)
} 
开发者ID:yannick-cw,项目名称:elastic-indexer4s,代码行数:38,代码来源:ElasticWriteConfig.scala


示例3: init

//设置package包名称以及导入依赖的类
package com.techmonad.es

import java.io.File

import com.techmonad.logger.Logging
import org.apache.commons.io.FileUtils
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest
import org.elasticsearch.client.Client
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.node.NodeBuilder


trait ESTestHelper extends Logging {

  val indexName = "catalogue-test-index"

  private val esDataDir = "es-data"

 lazy private val settings = Settings.settingsBuilder()
    .put("cluster.name", "elasticsearch-test")
    .put("discovery.zen.ping.multicast.enabled", false)
    .put("http.enabled", false)
    .put("client", true)
    .put("path.home", esDataDir)
    .put("local", true)
    .put("client.transport.sniff", false)


  lazy val node = NodeBuilder.nodeBuilder().settings(settings).node()

  lazy val client: Client = node.client()


  def init() = {
    val scalaBook ="""{"id":2, "type":"book", "author":"Martin Odersky", "title": "Programming in Scala"}"""
    val akkaBook ="""{"id":3, "type":"book", "author":"Derek Wyatt" , "title": "Akka Concurrency"}"""
    val builder = client.prepareBulk()
    builder.add(client.prepareIndex().setIndex(indexName).setId("2").setType("book").setSource(scalaBook))
    builder.add(client.prepareIndex().setIndex(indexName).setId("3").setType("book").setSource(akkaBook))
    val result = builder.execute().actionGet().hasFailures
    info("inserted record into ES, result -> " + result)
    refresh()
  }

  def refresh() = {
    client.admin().indices().refresh(new RefreshRequest(indexName)).get
  }

  def close() = {
    info("Closing ES node....")
    node.close()
    info("Deleting es data directory....")
    FileUtils.deleteDirectory(new File(esDataDir));
  }
} 
开发者ID:techmonad,项目名称:activator-akka-http-elasticsearch,代码行数:56,代码来源:ESTestHelper.scala


示例4:

//设置package包名称以及导入依赖的类
package util

import org.elasticsearch.common.settings.Settings
import org.elasticsearch.node.{Node, NodeBuilder}

trait TestHelper {

  val localClient: Node = {
    val esSettings = Settings.settingsBuilder()
      .put("cluster.name", "elasticsearch")
      .put("discovery.zen.ping.multicast.enabled", false)
      .put("http.enabled", false)
      .put("client", true)
      .put("path.home","data")
      .put("local", true)
      .put("client.transport.sniff", false)
    val node =NodeBuilder.nodeBuilder().settings(esSettings).node()
    node
  }

} 
开发者ID:knoldus,项目名称:activator-play-elasticsearch-autocomplete.g8,代码行数:22,代码来源:TestHelper.scala


示例5: FundsService

//设置package包名称以及导入依赖的类
package models

import javax.inject.Inject

import com.sksamuel.elastic4s.ElasticClient
import com.sksamuel.elastic4s.ElasticDsl._
import org.elasticsearch.common.settings.Settings
import play.api.Logger

import scala.collection.mutable
import scala.util.{Failure, Success, Try}

@javax.inject.Singleton
class FundsService @Inject() (
  configuration: play.api.Configuration
) {

  val settings = Settings.settingsBuilder()
    .put("http.enabled", false)
    .put("path.home", configuration.underlying.getString("elastic.data.path"))
  val client = ElasticClient.local(settings.build)

  Try(insertBlocking(Funds(mutable.Buffer.empty))) match {
    case Success(_) => ()

    case Failure(cause) =>
      Logger.error(s"Could not create index - " + cause)
  }

  def find(filter: String, offset: Int, pageSize: Int) = {
    client.execute { search in "gov" / "funds" query filter from offset size pageSize }
  }

  def findBlocking(filter: String, offset: Int, pageSize: Int) = {
    client.execute { search in "gov" / "funds" query filter from offset size pageSize }.await
  }

  def insert(funds: Funds) = {
    client.execute { index into "gov" / "funds" fields funds.data }
  }

  def insertBlocking(funds: Funds) = {
    client.execute { index into "gov" / "funds" fields funds.data }.await
  }

  def deleteAll() = {
    client.execute { deleteIndex("gov") }
  }
}

case class Funds(data: mutable.Buffer[(String, String)]) 
开发者ID:radusw,项目名称:eu_funds,代码行数:52,代码来源:FundsService.scala


示例6: ESLoader

//设置package包名称以及导入依赖的类
package twitter

import com.sksamuel.elastic4s._
import com.sksamuel.elastic4s.ElasticDsl._
import com.sksamuel.elastic4s.mappings.FieldType.{DateType, GeoPointType, StringType}
import org.elasticsearch.common.geo.GeoPoint
import org.elasticsearch.common.settings.Settings


object ESLoader {

  val settings = Settings.builder
    .put("http.enabled", "false")
    .put("cluster.name", "elasticsearch_airton").build()

  val uri = ElasticsearchClientUri("elasticsearch://localhost:9300")
  val client = ElasticClient.transport(settings, uri)

  def saveToES(tweet: AnalyzedTweet) = client.execute {index into "twitter2/tweets" fields toMap(tweet) }.await

  def toMap(tweet: AnalyzedTweet) = {
    val l = tweet.location match {
      case Some(location) => new GeoPoint(location("lat"), location("lon")).geohash()
      case None           => null
    }
    Map(
      "text"      -> tweet.text,
      "created"   -> tweet.created,
      "location"  -> l,
      "language"  -> tweet.language,
      "user"      -> tweet.user,
      "sentiment" -> tweet.sentiment)
  }

  def createIndex = client.execute {
    create index "twitter2" mappings(
      "tweets" as (
        "text"      typed StringType,
        "language"  typed StringType,
        "user"      typed StringType,
        "sentiment" typed StringType index "not_analyzed",
        "location"  typed GeoPointType,
        "created"   typed DateType
        ))
  }.await

  def main(args: Array[String]) = {
    println("kdkvadvad")
    createIndex
    println("kdkvadvad")
  }

} 
开发者ID:airtonjal,项目名称:DevCamp-2016,代码行数:54,代码来源:ESLoader.scala


示例7: createNode

//设置package包名称以及导入依赖的类
package houseprices.elasticsearch.config

import org.elasticsearch.client.Client
import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.common.transport.InetSocketTransportAddress
import org.elasticsearch.node.NodeBuilder
import org.elasticsearch.common.settings.Settings
import java.net.InetAddress
import org.elasticsearch.node.Node

trait EsClientBuilder {
  this: EsConfig =>

  val settings = Settings.settingsBuilder()
    .put("http.enabled", this.httpEnabled)
    .put("path.home", this.pathHome)
    .put("path.data", this.pathData)
    .put("node.local", this.isLocal)
    .put("node.client", this.isClient)
    .put("node.name", "node." + this.clusterName)

  def createNode: Node = {
    NodeBuilder.nodeBuilder()
      .clusterName(clusterName)
      .settings(settings)
      .build()
  }

  def build: Client = {
    createNode.start().client()
  }
}

object EsClientBuilder {
  def buildClient(env: String = "dev"): Client = {
    env match {
      case "qa" => (new EsClientBuilder with QaConfig) build
      case _ => (new EsClientBuilder with DevConfig) build
    }
  }

  def transportClient = {
    val settings = Settings.settingsBuilder().put("cluster.name", "dev.pricepaid")
    TransportClient.builder().settings(settings).build().addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost, 9300))
  }

} 
开发者ID:ayubmalik,项目名称:houseprices,代码行数:48,代码来源:EsClientBuilder.scala


示例8: CreateIndex

//设置package包名称以及导入依赖的类
package houseprices.elasticsearch

import org.elasticsearch.client.Client
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest
import org.slf4j.LoggerFactory
import org.elasticsearch.action.ActionListener
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.io.stream.StreamOutput
import org.elasticsearch.common.io.stream.OutputStreamStreamOutput
import org.elasticsearch.common.io.stream.BytesStreamOutput

class CreateIndex(val client: Client, val indexName: String, val typeName: String, mappingJsonSource: Option[String]) {

  private val log = LoggerFactory.getLogger(getClass)
  private val admin = client.admin()

  def recreate = {
    log.info("Deleting index " + indexName)
    val f = admin.indices.prepareDelete(indexName).execute
      .addListener(new ActionListener[DeleteIndexResponse] {
        def onFailure(error: Throwable) = createIndex
        def onResponse(response: DeleteIndexResponse) = createIndex
      })
  }

  def createIfNotExists = {
    val response = admin.indices.prepareExists(indexName).execute.actionGet
    if (!response.isExists) createIndex
    else
      log.info("{} index already exists...skipping", indexName)
  }

  private def createIndex = {
    log.info("Creating index " + indexName)
    admin.indices.prepareCreate(indexName)
      .setSettings(Settings.builder
        .put("index.number_of_shards", 1)
        .put("index.number_of_replicas", 0))
      .execute.actionGet

    mappingJsonSource.map { json =>
      log.info("Updating mapping...")
      val mappingRequest = new PutMappingRequest(indexName).`type`(typeName).source(json)
      admin.indices.putMapping(mappingRequest).actionGet();
    }
    admin.cluster.prepareHealth(indexName).setWaitForActiveShards(1).execute.actionGet
  }
} 
开发者ID:ayubmalik,项目名称:houseprices,代码行数:50,代码来源:CreateIndex.scala


示例9:

//设置package包名称以及导入依赖的类
package com.puroguramingu.util

import java.io.File
import java.util.UUID

import com.sksamuel.elastic4s.ElasticClient
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.node.NodeBuilder
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Suite}

trait ElasticSearch extends BeforeAndAfterEach with BeforeAndAfterAll {
  this: Suite =>

  private val tempFile = File.createTempFile("elasticsearchtests", "tmp")
  private val homeDir = new File(tempFile.getParent + "/" + UUID.randomUUID().toString)

  homeDir.mkdir()
  homeDir.deleteOnExit()
  tempFile.deleteOnExit()

  protected val settings = Settings.settingsBuilder()
    .put("node.http.enabled", true)
    .put("http.enabled", true)
    .put("index.store.type", "niofs")
    .put("path.home", homeDir.getAbsolutePath)
    .put("index.number_of_shards", 1)
    .put("index.number_of_replicas", 0)
    .put("es.logger.level", "DEBUG")
    .put("http.port", 9500)
    .put("transport.tcp.port", 9400)
    .build()

  val node = NodeBuilder.nodeBuilder().settings(settings).local(false).build().start()

  val client = ElasticClient.fromNode(node)

} 
开发者ID:mdymczyk,项目名称:spark-es-writer,代码行数:38,代码来源:ElasticSearch.scala


示例10: ApplicationModule

//设置package包名称以及导入依赖的类
package com.pharmpress.dmdbrowser

import com.google.inject.AbstractModule
import com.pharmpress.elasticsearch.{Elastic4sServiceImpl, IElasticSearch}
import com.sksamuel.elastic4s.{ElasticClient, ElasticsearchClientUri}
import org.elasticsearch.common.settings.{ImmutableSettings, Settings}
import play.api.{Configuration, Environment, Logger}


class ApplicationModule(
                         environment: Environment,
                         configuration: Configuration
                       ) extends AbstractModule {

  def configure: Unit = {

    val conf = configuration.underlying
    val rpsConfigUri = conf.getString("es.rps.client.uri")
    val rpsConfigCluster = conf.getString("es.rps.cluster.name")

    bind(classOf[IElasticSearch]) toInstance new Elastic4sServiceImpl(() => {
      Logger.info(s"Connecting to Elasticsearch at $rpsConfigUri with cluster $rpsConfigCluster")
      ElasticClient.remote(
        ImmutableSettings.settingsBuilder()
          .classLoader(classOf[Settings].getClassLoader)
          .put("cluster.name", rpsConfigCluster)
          .build(),
        ElasticsearchClientUri(rpsConfigUri)
      )
    })
  }
} 
开发者ID:pharmpress,项目名称:DmdBrowserScalaJs,代码行数:33,代码来源:ApplicationModule.scala


示例11: buildTransportSettings

//设置package包名称以及导入依赖的类
package com.github.jparkie.spark.elasticsearch.transport

import com.github.jparkie.spark.elasticsearch.conf.SparkEsTransportClientConf
import org.apache.spark.Logging
import org.elasticsearch.client.Client
import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.InetSocketTransportAddress

import scala.collection.mutable

private[elasticsearch] trait SparkEsTransportClientManager extends Serializable with Logging {
  @transient
  private[transport] val internalTransportClients = mutable.HashMap.empty[SparkEsTransportClientConf, TransportClient]

  private[transport] def buildTransportSettings(clientConf: SparkEsTransportClientConf): Settings = {
    val esSettingsBuilder = Settings.builder()

    clientConf.transportSettings foreach { currentSetting =>
      esSettingsBuilder.put(currentSetting._1, currentSetting._2)
    }

    esSettingsBuilder.build()
  }

  private[transport] def buildTransportClient(clientConf: SparkEsTransportClientConf, esSettings: Settings): TransportClient = {
    import SparkEsTransportClientConf._

    val esClient = TransportClient.builder()
      .settings(esSettings)
      .build()

    getTransportAddresses(clientConf.transportAddresses, clientConf.transportPort) foreach { inetSocketAddress =>
      esClient.addTransportAddresses(new InetSocketTransportAddress(inetSocketAddress))
    }

    sys.addShutdownHook {
      logInfo("Closed Elasticsearch Transport Client.")

      esClient.close()
    }

    logInfo(s"Connected to the following Elasticsearch nodes: ${esClient.connectedNodes()}.")

    esClient
  }

  
  def closeTransportClient(clientConf: SparkEsTransportClientConf): Unit = synchronized {
    internalTransportClients.remove(clientConf) match {
      case Some(transportClient) =>
        transportClient.close()
      case None =>
        logError(s"No TransportClient for $clientConf.")
    }
  }
}

object SparkEsTransportClientManager extends SparkEsTransportClientManager 
开发者ID:jparkie,项目名称:Spark2Elasticsearch,代码行数:60,代码来源:SparkEsTransportClientManager.scala


示例12: PinyinClient

//设置package包名称以及导入依赖的类
package io.github.chenfh5.lucene_analysis.pinyin

import org.elasticsearch.analysis.PinyinConfig
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.index.analysis.PinyinAnalyzer
import org.slf4j.LoggerFactory

import io.github.chenfh5.lucene_analysis.CustomAnalyzer


object PinyinClient extends CustomAnalyzer {
  private val LOG = LoggerFactory.getLogger(getClass.getName)

  
  private lazy val pinyinSetting = {
    Settings.builder()
        .put("keep_first_letter", true)
        .put("keep_full_pinyin", false) //necessary for my business
        .put("keep_joined_full_pinyin", true)
        .put("none_chinese_pinyin_tokenize", false)
        .put("limit_first_letter_length", 30)
        .put("keep_original", true)
  }

  private lazy val pinyinAnalyzer = {
    val setting = pinyinSetting.build()
    val pinyinAnalyzer = new PinyinAnalyzer(new PinyinConfig(setting))
    LOG.info("this is the pinyinAnalyzer={}, initialized successfully", pinyinAnalyzer)

    pinyinAnalyzer
  }

  def getPinyinTokens(inputText: String) = {
    getTokens(inputText, pinyinAnalyzer)
  }

} 
开发者ID:chenfh5,项目名称:test-spark-connect-es,代码行数:38,代码来源:PinyinClient.scala


示例13: IkClient

//设置package包名称以及导入依赖的类
package io.github.chenfh5.lucene_analysis.ik

import java.io.File

import org.apache.commons.lang3.StringUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.env.Environment
import org.slf4j.LoggerFactory
import org.wltea.analyzer.cfg.Configuration
import org.wltea.analyzer.lucene.IKAnalyzer

import io.github.chenfh5.lucene_analysis.CustomAnalyzer


object IkClient extends CustomAnalyzer {
  private val LOG = LoggerFactory.getLogger(getClass.getName)

  private val ikSetting = {
    val path = new File(getClass.getClassLoader.getResource("es-config").toURI)
    Settings.builder()
        .put("path.home", "")
        .put("path.conf", path)
        .put("use_smart", true)
  }

  private lazy val ikAnalyzerSmart = {
    val setting = ikSetting.build()
    val ikAnalyzerSmart = new IKAnalyzer(new Configuration(new Environment(setting), setting))
    LOG.info("this is the ikAnalyzerSmart={}, initialized successfully", ikAnalyzerSmart)

    ikAnalyzerSmart
  }

  private lazy val ikAnalyzerFull = {
    val setting = ikSetting
        .put("use_smart", false)
        .build()
    val ikAnalyzerFull = new IKAnalyzer(new Configuration(new Environment(setting), setting))
    LOG.info("this is the ikAnalyzerFull={}, initialized successfully", ikAnalyzerFull)

    ikAnalyzerFull
  }

  def getIkTokens(inputText: String, useSmart: Boolean = true) = {
    require(StringUtils.isNotBlank(inputText), "An input text must be specified")
    val ikAnalyzer = if (useSmart) ikAnalyzerSmart else ikAnalyzerFull

    getTokens(inputText, ikAnalyzer)
  }

} 
开发者ID:chenfh5,项目名称:test-spark-connect-es,代码行数:52,代码来源:IkClient.scala


示例14: EsClient

//设置package包名称以及导入依赖的类
package io.github.chenfh5.java_api

import java.net.InetAddress

import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.InetSocketTransportAddress
import org.slf4j.LoggerFactory

import io.github.chenfh5.common.OwnConfigReader


object EsClient {
  private val LOG = LoggerFactory.getLogger(getClass.getName)

  private val clusterName = OwnConfigReader.getOwnProperty.clusterName
  private val ips = OwnConfigReader.getOwnProperty.ips
  private val port = OwnConfigReader.getOwnProperty.javaClientPort.toInt

  private val transportClient = {
    val settings = Settings
        .builder()
        .put("client.transport.sniff", true)
        .put("cluster.name", clusterName)
        .build()

    val transportClient = addIps(TransportClient.builder().settings(settings).build())
    LOG.info("this is the transportClient={}, initialized successfully", transportClient)
    transportClient
  }

  private def addIps(transportClient: TransportClient) = {
    val ipArray = ips.split(",")
    for (oneIP <- ipArray) {
      transportClient
          .addTransportAddresses(new InetSocketTransportAddress(InetAddress.getByName(oneIP.trim), port))
    }
    transportClient
  }

  def getEsClient = this.transportClient

  def getBuckClient = {
    this.transportClient.prepareBulk()
  }

} 
开发者ID:chenfh5,项目名称:test-spark-connect-es,代码行数:48,代码来源:EsClient.scala


示例15: ESPersistence

//设置package包名称以及导入依赖的类
package com.stratio.ioft.persistence

import com.sksamuel.elastic4s.ElasticClient
import com.sksamuel.elastic4s.ElasticDsl._
import com.stratio.ioft.settings.IOFTConfig
import org.apache.spark.streaming.dstream.DStream
import org.elasticsearch.common.settings.Settings

import scala.collection.JavaConversions._

object ESPersistence extends IOFTConfig {

  val settings = Settings.settingsBuilder()

  esConfig.entrySet().map {
    entry =>
      settings.put(entry.getKey, esConfig.getAnyRef(entry.getKey))
  }

  val client = ElasticClient.local(settings.build)

  def persist(dStream: DStream[(String, String)]) ={
    dStream.foreachRDD{ rdd =>
      client.execute{ index into "ioft" / "drone" fields rdd.collect()}
    }
  }

} 
开发者ID:pfcoperez,项目名称:sparkstream_ioft,代码行数:29,代码来源:ESPersistence.scala


示例16: transportPort

//设置package包名称以及导入依赖的类
package orm.elasticsearch

import java.net.InetAddress
import java.util.concurrent.RejectedExecutionException

import org.elasticsearch.client.Client
import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.InetSocketTransportAddress
import webby.api.Application
import webby.mvc.AppStub

trait ElasticPluginConf extends webby.api.Plugin {

  private var _client: Client = _

  val clusterName: String
  val httpHost: InetAddress
  val httpPort: Int
  def transportPort: Int = 9300

  def client: Client = {
    if (_client == null) synchronized {
      if (_client == null) _client = startClient()
    }
    _client
  }

  override def onStart() {
    if (AppStub.isRealProd(app)) _client = startClient()
  }

  override def onStop() {
    if (_client != null) {
      try {
        _client.close()
      } catch {
        case e: RejectedExecutionException => webby.api.Logger(getClass).info("ElasticSearch bug on shutdown: " + e.toString)
      }
    }
  }

  protected def app: Application

  protected def startClient(): Client = {
    TransportClient.builder()
      .settings(Settings.builder().put("cluster.name", clusterName))
      .build()
      .addTransportAddress(new InetSocketTransportAddress(httpHost, transportPort))
  }
} 
开发者ID:citrum,项目名称:webby,代码行数:52,代码来源:ElasticPluginConf.scala


示例17: executionContext

//设置package包名称以及导入依赖的类
package de.is24.jest4s

import java.net.URI
import java.nio.file.Files
import java.util
import java.util.UUID

import de.is24.jest4s.utils.SLF4JLogging
import org.apache.commons.io.FileUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.node.{ InternalSettingsPreparer, Node }
import org.elasticsearch.plugins.Plugin
import org.elasticsearch.transport.Netty3Plugin

import scala.concurrent.{ ExecutionContext, Future, blocking }
import scala.util.control.NonFatal

trait EmbeddedElasticSearchSupport extends SLF4JLogging {

  implicit def executionContext: ExecutionContext

  private lazy val clusterId = UUID.randomUUID().toString
  private lazy val clusterName = "embedded-elasticsearch-$clusterId"
  private lazy val dataDir = Files.createTempDirectory(s"${clusterName}_data").toFile
  private lazy val settings = Settings.builder
    .put("path.home", dataDir.toString)
    .put("path.data", dataDir.toString)
    .put("cluster.name", clusterName)
    .put("http.enabled", true)
    .put("transport.type", "local")
    .put("http.type", "netty3")
    .build

  private lazy val node = new PluginConfigurableNode(settings, util.Arrays.asList(classOf[Netty3Plugin]))

  def startEmbeddedElasticSearch(): ElasticSearchHttpUri = {
    node.start()
    val uri = ElasticSearchHttpUri(new URI("http://localhost:9200"))
    log.info(s"Embedded elasticsearch starting at $uri")
    uri
  }

  def stopEmbeddedElasticSearch(): Future[Unit] = {
    Future {
      blocking {
        node.close()
        try {
          FileUtils.forceDelete(dataDir)
        } catch {
          case NonFatal(e) ?
            log.warn(s"Failed to cleanup elasticsearch data at $dataDir", e)
        }
      }
    }
  }

  private class PluginConfigurableNode(settings: Settings, classpathPlugins: util.Collection[Class[_ <: Plugin]]) extends Node(InternalSettingsPreparer.prepareEnvironment(settings, null), classpathPlugins)

} 
开发者ID:ImmobilienScout24,项目名称:jest4s,代码行数:60,代码来源:EmbeddedElasticSearchSupport.scala


示例18: ElasticSearch2

//设置package包名称以及导入依赖的类
package teleporter.integration.component.elasticsearch

import java.net.InetAddress

import org.elasticsearch.action.index.IndexRequest
import org.elasticsearch.action.update.UpdateRequest
import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.InetSocketTransportAddress
import org.elasticsearch.index.VersionType
import org.scalatest.FunSuite


class ElasticSearch2$Test extends FunSuite {
  test("elasticsearch") {
    val settings = Settings.settingsBuilder()
      .put("cluster.name", "rube-es").build()
    val client = TransportClient.builder().settings(settings).build()
      .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300))
    val indexRequest = new IndexRequest()
    val updateRequest = new UpdateRequest()
    client.prepareIndex("test_mapping3", "teststop", "9")
      .setSource("""{"trade_from": "eeeeeeeeeeeggg"}""")
      .setVersionType(VersionType.EXTERNAL)
      .setVersion(System.currentTimeMillis())
      .execute().get()
  }
} 
开发者ID:huanwuji,项目名称:teleporter,代码行数:29,代码来源:ElasticSearch2$Test.scala


示例19: EncryptedIndexStoreTest

//设置package包名称以及导入依赖的类
package org.elasticsearch.index.store

import org.elasticsearch.client.Client
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.unit.ByteSizeValue
import org.elasticsearch.env.NodeEnvironment
import org.elasticsearch.index.settings.IndexSettingsService
import org.elasticsearch.index.{Index, IndexService}
import org.elasticsearch.indices.store.IndicesStore
import org.scalatest.FlatSpec
import org.scalatest.mockito.MockitoSugar
import org.mockito.Mockito.when
import org.mockito.Matchers

class EncryptedIndexStoreTest extends FlatSpec with org.scalatest.Matchers with MockitoSugar {

  behavior of "#shardDirectory"
  it should "return EncryptedDirectoryService" in {
    val settings = mock[Settings]
    when(settings.getComponentSettings(Matchers.any())).thenReturn(null)
    when(settings.get(Matchers.eq("index.store.throttle.type"), Matchers.anyString())).thenReturn("all")
    when(settings.getAsBytesSize(Matchers.eq("index.store.throttle.max_bytes_per_sec"), Matchers.any())).thenReturn(new ByteSizeValue(1000))
    val nodeEnv = mock[NodeEnvironment]
    when(nodeEnv.hasNodeFile).thenReturn(false)
    val indexService = mock[IndexService]
    val indexSettingsService = mock[IndexSettingsService]
    when(indexService.settingsService).thenReturn(indexSettingsService)
    val eis = new EncryptedIndexStore(mock[Index], settings, indexService, mock[IndicesStore], nodeEnv, mock[Client])
    eis.shardDirectory() shouldBe classOf[EncryptedDirectoryService]
  }

} 
开发者ID:Workday,项目名称:elasticrypt,代码行数:33,代码来源:EncryptedIndexStoreTest.scala


示例20: EncryptedDirectoryServiceTest

//设置package包名称以及导入依赖的类
package org.elasticsearch.index.store

import java.io.File

import org.elasticsearch.client.Client
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.index.Index
import org.elasticsearch.index.shard.ShardId
import org.mockito.Mockito.when
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{FlatSpec, Matchers}

class EncryptedDirectoryServiceTest extends FlatSpec with Matchers with MockitoSugar {

  behavior of "#newFSDirectory"
  it should "return EncryptedDirectory" in {
    val shardId = mock[ShardId]
    when(shardId.index()).thenReturn(mock[Index])
    when(shardId.id()).thenReturn(0)

    val settings = mock[Settings]
    when(settings.getAsBoolean("logger.logHostAddress", false)).thenReturn(false)
    when(settings.getAsBoolean("logger.logHostName", false)).thenReturn(false)
    when(settings.get("name")).thenReturn("test")

    val file = new File("/tmp")

    val eds = new EncryptedDirectoryService(shardId, settings, mock[EncryptedIndexStore], mock[Client], mock[NodeKeyProviderComponent])
    eds.newFSDirectory(file, null) shouldBe an[EncryptedDirectory]
  }

} 
开发者ID:Workday,项目名称:elasticrypt,代码行数:33,代码来源:EncryptedDirectoryServiceTest.scala



注:本文中的org.elasticsearch.common.settings.Settings类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala HttpResponse类代码示例发布时间:2022-05-23
下一篇:
Scala ServletContainer类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap