package com.aliyun.odps.spark.examples.myUtils

import org.apache.spark.SparkContext
import org.apache.spark.aliyun.odps.OdpsOps
import org.springframework.data.redis.connection.RedisStandaloneConfiguration
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory
import org.springframework.data.redis.core.RedisTemplate
import org.springframework.data.redis.serializer.StringRedisSerializer
import examples.dataloader.redisBuilderMyself

object env {
  def getODPS(sparkContext: SparkContext): OdpsOps = {
    val accessKeyId = "LTAIWYUujJAm7CbH"
    val accessKeySecret = "RfSjdiWwED1sGFlsjXv0DlfTnZTG1P"
    val odpsUrl = "https://service.cn-hangzhou-vpc.maxcompute.aliyun-inc.com/api"
    val tunnelUrl = "https://dt.cn-hangzhou-vpc.maxcompute.aliyun-inc.com"

    OdpsOps(sparkContext, accessKeyId, accessKeySecret, odpsUrl, tunnelUrl)
  }

  def getRedisTemplate(): RedisTemplate[String, String] = {
    // redis的公共模版
    val redisSC = new RedisStandaloneConfiguration
    redisSC.setPort(6379)
    redisSC.setPassword("Wqsd@2019")
    redisSC.setHostName("r-bp1pi8wyv6lzvgjy5z.redis.rds.aliyuncs.com")
    val jedisCF = new JedisConnectionFactory(redisSC)
    jedisCF.afterPropertiesSet()
    val redisTemplate = new RedisTemplate[String, String]
    redisTemplate.setDefaultSerializer(new StringRedisSerializer)
    redisTemplate.setConnectionFactory(jedisCF)
    redisTemplate.afterPropertiesSet()
    redisTemplate
  }

  def getRedisTemplatev2(): RedisTemplate[String, String] = {
    redisBuilderMyself.redisTemplate(redisBuilderMyself.redisConnectionFactory())
  }
}
