Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mediakind changes #796

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ azure {
}
}

azure_mediakind{
project_name="subcitionname"
auth_token="authToken"
account_name="media servcie accountname"
api {
endpoint="https://api.mk.io/api"
}
transform {
default = "media_transform_default"
}
stream {
base_url = "https://ep-default-mkservicepoc.japaneast.streaming.mediakind.com"
endpoint_name = "default"
protocol = "Hls"
policy_name = "Predefined_ClearStreamingOnly"
}
}

azure_tenant="tenant"
azure_subscription_id="subscription id"
azure_account_name="account name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.sunbird.job.videostream.helpers

object AzureRequestBody {

val create_asset = " {\"properties\": {\"description\": \"assetDescription\",\"alternateId\" : \"assetId\"}}"
val create_asset = " {\"properties\": {\"storageAccountName\": \"assetStorageAccountName\",\"description\": \"assetDescription\",\"alternateId\" : \"assetId\"}}"
val submit_job = "{\"properties\": {\"input\": {\"@odata.type\": \"#Microsoft.Media.JobInputHttp\",\"baseUri\": \"baseInputUrl\",\"files\": [\"inputVideoFile\"]},\"outputs\": [{\"@odata.type\": \"#Microsoft.Media.JobOutputAsset\",\"assetName\": \"assetId\"}]}}"
val create_stream_locator="{\"properties\":{\"assetName\": \"assetId\",\"streamingPolicyName\": \"policyName\"}}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import scala.collection.immutable.HashMap
abstract class AzureMediaService extends IMediaService {

private var API_ACCESS_TOKEN: String = ""

private def getToken()(implicit config: VideoStreamGeneratorConfig, httpUtil: HttpUtil): String = {
val tenant = config.getSystemConfig("azure.tenant")
val clientKey = config.getSystemConfig("azure.token.client_key")
Expand Down Expand Up @@ -51,9 +50,11 @@ abstract class AzureMediaService extends IMediaService {
}

protected def createAsset(assetId: String, jobId: String)(implicit config: VideoStreamGeneratorConfig, httpUtil: HttpUtil): MediaResponse = {
val accountName: String = config.getConfig("azure_mediakind.account_name")
val url = getApiUrl("asset").replace("assetId", assetId)
val requestBody = AzureRequestBody.create_asset.replace("assetId", assetId)
.replace("assetDescription", "Output Asset for " + jobId)
.replace("assetStorageAccountName", accountName)
val response:MediaResponse = Response.getResponse(httpUtil.put(url, requestBody, getDefaultHeader()))
if(response.responseCode == "OK"){
response
Expand All @@ -64,7 +65,7 @@ abstract class AzureMediaService extends IMediaService {

protected def createStreamingLocator(streamingLocatorName: String, assetName: String)(implicit config: VideoStreamGeneratorConfig, httpUtil: HttpUtil): MediaResponse = {
val url = getApiUrl("stream_locator").replace("streamingLocatorName", streamingLocatorName)
val streamingPolicyName = config.getConfig("azure.stream.policy_name")
val streamingPolicyName = config.getConfig("azure_mediakind.stream.policy_name")
val reqBody = AzureRequestBody.create_stream_locator.replace("assetId", assetName).replace("policyName", streamingPolicyName)
Response.getResponse(httpUtil.put(url, reqBody, getDefaultHeader()))
}
Expand All @@ -90,42 +91,33 @@ abstract class AzureMediaService extends IMediaService {
}

protected def getApiUrl(apiName: String)(implicit config: VideoStreamGeneratorConfig, httpUtil: HttpUtil): String = {
val subscriptionId: String = config.getSystemConfig("azure.subscription_id")
val resourceGroupName: String = config.getSystemConfig("azure.resource_group_name")
val accountName: String = config.getSystemConfig("azure.account_name")
val apiVersion: String = config.getConfig("azure.api.version")
val transformName: String = config.getConfig("azure.transform.default")

val baseUrl: String = new StringBuilder().append(config.getConfig("azure.api.endpoint")+"/subscriptions/")
.append(subscriptionId)
.append("/resourceGroups/")
.append(resourceGroupName)
.append("/providers/Microsoft.Media/mediaServices/")
.append(accountName).mkString

val transformName: String = config.getConfig("azure_mediakind.transform.default")
val projectName:String = config.getConfig("azure_mediakind.project_name")

val baseUrl: String = new StringBuilder().append(config.getConfig("azure_mediakind.api.endpoint")+"/ams/")
.append(projectName).mkString

apiName.toLowerCase() match {
case "asset" => baseUrl + "/assets/assetId?api-version=" + apiVersion
case "job" => baseUrl + "/transforms/" + transformName + "/jobs/jobIdentifier?api-version=" + apiVersion
case "stream_locator" => baseUrl + "/streamingLocators/streamingLocatorName?api-version=" + apiVersion
case "list_paths" => baseUrl + "/streamingLocators/streamingLocatorName/listPaths?api-version=" + apiVersion
case "asset" => baseUrl + "/assets/assetId"
case "job" => baseUrl + "/transforms/" + transformName + "/jobs/jobIdentifier"
case "stream_locator" => baseUrl + "/streamingLocators/streamingLocatorName"
case "list_paths" => baseUrl + "/streamingLocators/streamingLocatorName/listPaths"
case _ => throw new MediaServiceException("ERR_INVALID_API_NAME", "Please Provide Valid Media Service API Name")
}
}

protected def getDefaultHeader()(implicit config: VideoStreamGeneratorConfig, httpUtil: HttpUtil): Map[String, String] = {
val accessToken = if (StringUtils.isNotBlank(API_ACCESS_TOKEN)) API_ACCESS_TOKEN else getToken()
val authToken = "Bearer " + accessToken
val authToken = config.getConfig("azure_mediakind.auth_token")
HashMap[String, String](
"Content-Type" -> "application/json",
"Accept" -> "application/json",
"Authorization" -> authToken
"content-type" -> "application/json",
"accept" -> "application/json",
"x-mkio-token" -> authToken
)
}

protected def prepareStreamingUrl(streamLocatorName: String, jobId: String)(implicit config: VideoStreamGeneratorConfig, httpUtil: HttpUtil): Map[String, AnyRef] = {
val streamType = config.getConfig("azure.stream.protocol")
val streamHost = config.getConfig("azure.stream.base_url")
val streamType = config.getConfig("azure_mediakind.stream.protocol")
val streamHost = config.getConfig("azure_mediakind.stream.base_url")
var url = ""
val listPathResponse = getStreamUrls(streamLocatorName)
if (listPathResponse.responseCode.equalsIgnoreCase("OK")) {
Expand All @@ -146,4 +138,4 @@ abstract class AzureMediaService extends IMediaService {
HashMap[String, AnyRef]("streamUrl" -> streamUrl)
}
}
}
}
18 changes: 17 additions & 1 deletion video-stream-generator/src/test/resources/test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,23 @@ threshold.batch.write.size = 4
client_secret = "client secret"
}
}

azure_mediakind{
project_name="subcitionname"
auth_token="authToken"
account_name="media servcie accountname"
api {
endpoint="https://api.mk.io/api"
}
transform {
default = "media_transform_default"
}
stream {
base_url = "https://ep-default-mkservicepoc.japaneast.streaming.mediakind.com"
endpoint_name = "default"
protocol = "Hls"
policy_name = "Predefined_ClearStreamingOnly"
}
}
azure_tenant="test_tenant"
azure_subscription_id="test_id"
azure_account_name="test_account_name"
Expand Down