-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from Sunbird-Obsrv/release-5.0.0
Merge Release-5.0.0 to Release-5.1.0
- Loading branch information
Showing
9 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...tics-core/src/main/scala/org/ekstep/analytics/framework/dispatcher/GcloudDispatcher.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.ekstep.analytics.framework.dispatcher | ||
|
||
import org.apache.spark.SparkContext | ||
import org.apache.spark.rdd.RDD | ||
import org.ekstep.analytics.framework.{FrameworkContext, StorageConfig} | ||
import org.ekstep.analytics.framework.exception.DispatcherException | ||
import org.ekstep.analytics.framework.util.CommonUtil | ||
|
||
object GcloudDispatcher extends HadoopDispatcher with IDispatcher { | ||
|
||
implicit val className = "org.ekstep.analytics.framework.dispatcher.GcloudDispatcher" | ||
|
||
override def dispatch(config: Map[String, AnyRef], events: RDD[String])(implicit sc: SparkContext, fc: FrameworkContext): Unit = { | ||
|
||
val bucket = config.getOrElse("bucket", null).asInstanceOf[String]; | ||
val key = config.getOrElse("key", null).asInstanceOf[String]; | ||
val isPublic = config.getOrElse("public", false).asInstanceOf[Boolean]; | ||
|
||
if (null == bucket || null == key) { | ||
throw new DispatcherException("'bucket' & 'key' parameters are required to send output to GCloud") | ||
} | ||
|
||
val srcFile = CommonUtil.getGCloudFile(bucket, "_tmp/" + key); | ||
val destFile = CommonUtil.getGCloudFile(bucket, key); | ||
dispatchData(srcFile, destFile, sc.hadoopConfiguration, events) | ||
} | ||
|
||
override def dispatch(events: RDD[String], config: StorageConfig)(implicit sc: SparkContext, fc: FrameworkContext): Unit = { | ||
val bucket = config.container; | ||
val key = config.fileName; | ||
|
||
dispatch(Map[String, AnyRef]("bucket" -> bucket, "key" -> key), events); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
analytics-core/src/main/scala/org/ekstep/analytics/framework/fetcher/GcloudDataFetcher.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.ekstep.analytics.framework.fetcher | ||
|
||
import org.ekstep.analytics.framework.{FrameworkContext, Query} | ||
import org.ekstep.analytics.framework.exception.DataFetcherException | ||
import org.sunbird.cloud.storage.conf.AppConf | ||
|
||
object GcloudDataFetcher { | ||
|
||
@throws(classOf[DataFetcherException]) | ||
def getObjectKeys(queries: Array[Query])(implicit fc: FrameworkContext): Array[String] = { | ||
|
||
val keys = for(query <- queries) yield { | ||
val paths = if(query.folder.isDefined && query.endDate.isDefined && query.folder.getOrElse("false").equals("true")) { | ||
Array("gs://"+getBucket(query.bucket) + "/" + getPrefix(query.prefix) + query.endDate.getOrElse("")) | ||
} else { | ||
getKeys(query); | ||
} | ||
if(query.excludePrefix.isDefined) { | ||
paths.filter { x => !x.contains(query.excludePrefix.get) } | ||
} else { | ||
paths | ||
} | ||
} | ||
keys.flatMap { x => x.map { x => x } } | ||
} | ||
|
||
private def getKeys(query: Query)(implicit fc: FrameworkContext) : Array[String] = { | ||
val storageService = fc.getStorageService("gcloud", "gcloud_client_key", "gcloud_private_secret"); | ||
val keys = storageService.searchObjects(getBucket(query.bucket), getPrefix(query.prefix), query.startDate, query.endDate, query.delta, query.datePattern.getOrElse("yyyy-MM-dd")) | ||
storageService.getPaths(getBucket(query.bucket), keys).toArray | ||
} | ||
|
||
private def getBucket(bucket: Option[String]) : String = { | ||
bucket.getOrElse("telemetry-data-store"); | ||
} | ||
|
||
private def getPrefix(prefix: Option[String]) : String = { | ||
prefix.getOrElse("raw/"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters