summaryrefslogtreecommitdiffstats
path: root/clover/spark/src/main/scala/CloverFast.scala
blob: b7467607f47146b82cd51192228e2b394b88ec54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) Authors of Clover
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Apache License, Version 2.0
// which accompanies this distribution, and is available at
// http://www.apache.org/licenses/LICENSE-2.0

import org.apache.spark.sql.SparkSession
import com.datastax.spark.connector._
import org.apache.spark.sql.cassandra._
import org.apache.spark.SparkContext
import org.apache.spark.SparkConf

import com.redis._

object CloverFast {
  def main(args: Array[String]) {
    val sp = SparkSession.builder.appName("Clover Fast")
                         .getOrCreate()
    sp.stop()

    val CassandraConnect = "cassandra.clover-system"
    val RedisConnect = "redis.default"

    // Cassandra, Redis, Spark Context
    val scch = "spark.cassandra.connection.host"
    val conf = new SparkConf(true).set(scch, CassandraConnect)
    val redis = new RedisClient(RedisConnect, 6379)
    val sc = new SparkContext(conf)

    for(  x <- 1 to 10000 ) {

        try {
            val spans = sc.cassandraTable("visibility", "spans")
                          .select("spanid").cassandraCount()
            redis.set("span_count", spans)

            val traces = sc.cassandraTable("visibility", "traces")
                           .select("traceid").cassandraCount()
            redis.set("trace_count", traces)

            val metrics = sc.cassandraTable("visibility", "metrics")
                            .select("monitor_time").cassandraCount()
            redis.set("metric_count", metrics)

        }
        catch {
            case unknown : Throwable => println("System counts exception: "
                                                + unknown)
        }

    }

  }
}