2017-05-21 22:41:51 +03:00
|
|
|
#' Get all HDInsight Clusters in default Subscription or details for a specified cluster name.
|
2016-12-17 00:18:42 +03:00
|
|
|
#'
|
2016-12-20 12:10:43 +03:00
|
|
|
#' @inheritParams setAzureContext
|
|
|
|
#' @inheritParams azureAuthenticate
|
|
|
|
#' @inheritParams azureListAllResources
|
2016-12-17 20:50:05 +03:00
|
|
|
#'
|
|
|
|
#' @family HDInsight functions
|
2017-05-30 12:34:22 +03:00
|
|
|
#' @references https://docs.microsoft.com/en-us/rest/api/hdinsight/hdinsight-cluster#list-by-subscription
|
2016-12-17 00:18:42 +03:00
|
|
|
#'
|
2017-05-30 12:34:22 +03:00
|
|
|
#' @return data frame with summary information of HDI clusters
|
2016-08-03 08:03:55 +03:00
|
|
|
#' @export
|
2016-12-20 12:10:43 +03:00
|
|
|
azureListHDI <- function(azureActiveContext, resourceGroup, clustername = "*",
|
2017-05-21 22:41:51 +03:00
|
|
|
subscriptionID, name, type, location, verbose = FALSE) {
|
2016-12-20 12:10:43 +03:00
|
|
|
|
2017-05-28 11:32:46 +03:00
|
|
|
assert_that(is.azureActiveContext(azureActiveContext))
|
|
|
|
if (missing(subscriptionID)) subscriptionID <- azureActiveContext$subscriptionID
|
|
|
|
if (missing(resourceGroup)) resourceGroup <- azureActiveContext$resourceGroup
|
2017-05-30 12:34:22 +03:00
|
|
|
|
2017-05-28 11:32:46 +03:00
|
|
|
assert_that(is_subscription_id(subscriptionID))
|
|
|
|
if (clustername != "*") {
|
|
|
|
assert_that(is_clustername(clustername))
|
|
|
|
assert_that(is_resource_group(resourceGroup))
|
|
|
|
}
|
|
|
|
|
|
|
|
rg <- if (clustername == "*") "" else paste0("/resourceGroups/", resourceGroup)
|
|
|
|
cn <- if (clustername == "*") "" else clustername
|
2017-05-30 12:34:22 +03:00
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
uri <- paste0("https://management.azure.com/subscriptions/", subscriptionID, rg,
|
2017-05-30 12:34:22 +03:00
|
|
|
"/providers/Microsoft.HDInsight/clusters/", cn,
|
2017-05-28 11:32:46 +03:00
|
|
|
"?api-version=2015-03-01-preview")
|
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
r <- call_azure_sm(azureActiveContext, uri = uri, verbose = verbose)
|
2017-05-28 11:32:46 +03:00
|
|
|
stopWithAzureError(r)
|
2017-05-30 12:34:22 +03:00
|
|
|
rc <- content(r)
|
|
|
|
extract_one <- function(x) {
|
|
|
|
as.data.frame(
|
2017-05-28 11:32:46 +03:00
|
|
|
c(
|
|
|
|
x[c("name", "id", "location", "type")],
|
|
|
|
x$properties[c("tier", "osType", "provisioningState", "clusterState", "createdDate")],
|
|
|
|
x$properties$clusterDefinition[c("kind")]
|
2017-05-30 12:34:22 +03:00
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
z <- if (is.null(rc$value)) {
|
|
|
|
extract_one(rc)
|
|
|
|
} else {
|
|
|
|
do.call(rbind, lapply(rc$value, extract_one))
|
|
|
|
}
|
2017-05-28 11:32:46 +03:00
|
|
|
|
2017-05-21 22:41:51 +03:00
|
|
|
azureActiveContext$resourceGroup <- resourceGroup
|
2017-05-28 11:32:46 +03:00
|
|
|
return(z)
|
2016-08-03 08:03:55 +03:00
|
|
|
}
|
|
|
|
|
2016-12-17 00:18:42 +03:00
|
|
|
|
2017-05-29 18:41:03 +03:00
|
|
|
|
2017-05-30 18:08:14 +03:00
|
|
|
#' Get configuration information for a specified cluster name.
|
2016-12-17 00:18:42 +03:00
|
|
|
#'
|
2016-12-20 12:10:43 +03:00
|
|
|
#' @inheritParams setAzureContext
|
|
|
|
#' @inheritParams azureAuthenticate
|
|
|
|
#' @inheritParams azureListHDI
|
2016-12-17 00:18:42 +03:00
|
|
|
#'
|
|
|
|
#'
|
2016-08-03 08:03:55 +03:00
|
|
|
#' @return Returns Dataframe of HDInsight Clusters information
|
2016-12-17 20:50:05 +03:00
|
|
|
#' @family HDInsight functions
|
2016-08-03 08:03:55 +03:00
|
|
|
#' @export
|
2016-12-20 12:10:43 +03:00
|
|
|
azureHDIConf <- function(azureActiveContext, clustername, resourceGroup,
|
2017-05-21 22:41:51 +03:00
|
|
|
subscriptionID, name, type, location, verbose = FALSE) {
|
2017-05-30 12:34:22 +03:00
|
|
|
assert_that(is.azureActiveContext(azureActiveContext))
|
|
|
|
if (missing(subscriptionID)) subscriptionID <- azureActiveContext$subscriptionID
|
|
|
|
if (missing(resourceGroup)) resourceGroup <- azureActiveContext$resourceGroup
|
|
|
|
if (missing(clustername)) clustername <- azureActiveContext$clustername
|
2017-05-23 23:39:39 +03:00
|
|
|
|
2017-05-30 12:34:22 +03:00
|
|
|
assert_that(is_subscription_id(subscriptionID))
|
|
|
|
assert_that(is_resource_group(resourceGroup))
|
|
|
|
assert_that(is_clustername(clustername))
|
2016-12-19 20:38:23 +03:00
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
uri <- paste0("https://management.azure.com/subscriptions/", subscriptionID,
|
2017-05-30 12:34:22 +03:00
|
|
|
"/resourceGroups/", resourceGroup,
|
|
|
|
"/providers/Microsoft.HDInsight/clusters/", clustername,
|
|
|
|
"?api-version=2015-03-01-preview")
|
2016-08-03 08:03:55 +03:00
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
r <- call_azure_sm(azureActiveContext, uri = uri, verbose = verbose)
|
2017-05-30 12:34:22 +03:00
|
|
|
rc <- content(r)
|
2016-12-19 20:38:23 +03:00
|
|
|
|
2017-05-30 12:34:22 +03:00
|
|
|
if (length(rc) == 0) {
|
|
|
|
warning("No HDInsight clusters found", immediate. = TRUE)
|
2016-08-03 08:03:55 +03:00
|
|
|
}
|
|
|
|
|
2017-05-30 12:34:22 +03:00
|
|
|
info <- paste(vapply(rc$properties$computeProfile$roles, function(x) {
|
|
|
|
sprintf("%s: %s * %s",
|
|
|
|
x$name,
|
|
|
|
x$targetInstanceCount,
|
|
|
|
x$hardwareProfile$vmSize)}, FUN.VALUE = character(1)
|
|
|
|
), collapse = ", "
|
|
|
|
)
|
2017-06-15 14:02:46 +03:00
|
|
|
return(rc)
|
|
|
|
|
2017-05-30 12:34:22 +03:00
|
|
|
|
|
|
|
dfn <- with(rc, data.frame(
|
|
|
|
name = name,
|
|
|
|
id = id,
|
|
|
|
location = location,
|
|
|
|
type = type,
|
|
|
|
tier = rc$properties$tier,
|
|
|
|
kind = rc$properties$clusterDefinition$kind,
|
|
|
|
osType = rc$properties$osType,
|
|
|
|
provisioningState = rc$properties$provisioningState,
|
|
|
|
status = rc$properties$clusterState,
|
|
|
|
created = rc$properties$createdDate,
|
|
|
|
numCores = rc$properties$quotaInfo$coresUsed,
|
|
|
|
information = info,
|
|
|
|
stringsAsFactors = FALSE
|
|
|
|
))
|
|
|
|
|
|
|
|
return(dfn)
|
2016-08-03 08:03:55 +03:00
|
|
|
}
|
2016-12-17 00:18:42 +03:00
|
|
|
|
2017-05-28 11:32:46 +03:00
|
|
|
#' Create HDInsight cluster.
|
2016-12-17 00:18:42 +03:00
|
|
|
#'
|
2016-12-20 12:10:43 +03:00
|
|
|
#' @inheritParams setAzureContext
|
|
|
|
#' @inheritParams azureAuthenticate
|
|
|
|
#' @inheritParams azureListHDI
|
2016-12-17 00:18:42 +03:00
|
|
|
#'
|
|
|
|
#'
|
2016-12-21 15:26:53 +03:00
|
|
|
#' @param version HDinsight version
|
2017-02-05 08:55:45 +03:00
|
|
|
#' @param kind HDinsight kind: "hadoop","spark" or "rserver"
|
2016-12-20 12:10:43 +03:00
|
|
|
#' @param adminUser Admin user name
|
|
|
|
#' @param adminPassword Admin user password
|
2016-12-20 20:02:19 +03:00
|
|
|
#' @param workers Define the number of worker nodes
|
2016-12-21 15:26:53 +03:00
|
|
|
#' @param sshUser SSH user name
|
|
|
|
#' @param sshPassword SSH user password
|
2016-12-20 20:02:19 +03:00
|
|
|
#' @param hiveServer URI address of the Hive server
|
2016-12-21 15:26:53 +03:00
|
|
|
#' @param hiveDB Hive DB name
|
|
|
|
#' @param hiveUser Hive user name
|
|
|
|
#' @param hivePassword Hive user password
|
2016-12-21 19:06:43 +03:00
|
|
|
#' @param componentVersion Spark componentVersion. Default : 1.6.2
|
2017-02-05 08:55:45 +03:00
|
|
|
#' @param vmSize Size of nodes: "Large", "Small", "Standard_D14_V2", etc.
|
2016-12-21 15:26:53 +03:00
|
|
|
#' @param mode Provisioning mode, "Sync" or "Async". Use "Async" to immediately return to R session after submission of request
|
2017-05-30 12:34:22 +03:00
|
|
|
#' @param debug Used for debugging purposes. If TRUE, returns json without attempting to connect to Azure
|
2016-12-17 18:49:53 +03:00
|
|
|
#'
|
|
|
|
#' @return Success message
|
2016-12-17 20:50:05 +03:00
|
|
|
#' @family HDInsight functions
|
2016-12-20 20:02:19 +03:00
|
|
|
#' @note See \url{https://docs.microsoft.com/en-us/azure/hdinsight/hdinsight-component-versioning} to learn about HDInsight Versions
|
2017-05-30 18:08:14 +03:00
|
|
|
#' @references https://docs.microsoft.com/en-us/rest/api/hdinsight/hdinsight-cluster#create
|
2016-09-14 15:09:36 +03:00
|
|
|
#' @export
|
2017-05-28 11:32:46 +03:00
|
|
|
azureCreateHDI <- function(azureActiveContext, resourceGroup, location,
|
2017-05-29 18:41:03 +03:00
|
|
|
clustername, kind = c("rserver", "spark", "hadoop"),
|
|
|
|
storageAccount, storageKey,
|
|
|
|
version = "3.5", componentVersion = "1.6.2",
|
2017-05-28 11:32:46 +03:00
|
|
|
workers = 2,
|
|
|
|
adminUser, adminPassword, sshUser, sshPassword,
|
|
|
|
hiveServer, hiveDB, hiveUser, hivePassword,
|
2017-05-30 12:34:22 +03:00
|
|
|
vmSize = "Large",
|
2017-05-29 18:41:03 +03:00
|
|
|
subscriptionID, mode = c("Sync", "Async"),
|
|
|
|
verbose = FALSE, debug = FALSE) {
|
2017-05-28 11:32:46 +03:00
|
|
|
assert_that(is.azureActiveContext(azureActiveContext))
|
2016-12-20 12:10:43 +03:00
|
|
|
|
2017-05-28 11:32:46 +03:00
|
|
|
kind <- match.arg(kind)
|
2017-05-29 18:41:03 +03:00
|
|
|
mode <- match.arg(mode)
|
2016-12-19 20:38:23 +03:00
|
|
|
|
2017-05-28 11:32:46 +03:00
|
|
|
if (missing(subscriptionID)) subscriptionID <- azureActiveContext$subscriptionID
|
|
|
|
if (missing(resourceGroup)) resourceGroup <- azureActiveContext$resourceGroup
|
|
|
|
if (missing(storageAccount)) storageAccount <- azureActiveContext$storageAccount
|
|
|
|
|
|
|
|
assert_that(is_resource_group(resourceGroup))
|
|
|
|
if (missing(location)) {
|
2017-05-29 18:41:03 +03:00
|
|
|
location <- getResourceGroupLocation(azureActiveContext, resourceGroup = resourceGroup)
|
2016-12-19 20:38:23 +03:00
|
|
|
}
|
2017-05-28 11:32:46 +03:00
|
|
|
assert_that(is_location(location))
|
|
|
|
assert_that(is_subscription_id(subscriptionID))
|
|
|
|
|
|
|
|
assert_that(is_clustername(clustername))
|
|
|
|
assert_that(is_storage_account(storageAccount))
|
|
|
|
|
|
|
|
assert_that(is_admin_user(adminUser))
|
|
|
|
assert_that(is_admin_password(adminPassword))
|
|
|
|
assert_that(is_ssh_user(sshUser))
|
|
|
|
assert_that(is_ssh_password(sshPassword))
|
|
|
|
|
|
|
|
storage_accounts <- azureListSA(azureActiveContext)
|
2017-05-29 18:41:03 +03:00
|
|
|
if (!storageAccount %in% storage_accounts$name) {
|
2017-05-28 11:32:46 +03:00
|
|
|
# create storage account
|
|
|
|
message("creating storage account: ", storageAccount)
|
|
|
|
azureCreateStorageAccount(azureActiveContext, storageAccount = storageAccount, resourceGroup = resourceGroup, location = location)
|
|
|
|
storageResGroup <- resourceGroup
|
|
|
|
} else {
|
|
|
|
# retrieve resource group of storage account
|
|
|
|
idx <- storage_accounts$name == storageAccount
|
|
|
|
storageResGroup <- storage_accounts$resourceGroup[idx]
|
2016-12-19 20:38:23 +03:00
|
|
|
}
|
2016-09-14 15:09:36 +03:00
|
|
|
|
2017-05-28 11:32:46 +03:00
|
|
|
storageKey <- azureSAGetKey(azureActiveContext, storageAccount = storageAccount, resourceGroup = storageResGroup)
|
2016-11-07 20:13:24 +03:00
|
|
|
|
2016-09-14 15:09:36 +03:00
|
|
|
HIVE <- FALSE
|
2017-05-28 11:32:46 +03:00
|
|
|
hivejson <- ""
|
2016-12-20 12:10:43 +03:00
|
|
|
if (!missing(hiveServer)) {
|
2016-11-07 20:13:24 +03:00
|
|
|
|
2016-09-14 15:09:36 +03:00
|
|
|
HIVE <- TRUE
|
2016-12-20 12:10:43 +03:00
|
|
|
if (!length(hiveDB)) {
|
|
|
|
stop("Error: hiveServer: No Valid hiveDB provided")
|
2016-12-19 20:38:23 +03:00
|
|
|
}
|
2016-12-20 12:10:43 +03:00
|
|
|
if (!length(hiveUser)) {
|
|
|
|
stop("Error: hiveServer: No Valid hiveUser provided")
|
2016-12-19 20:38:23 +03:00
|
|
|
}
|
2016-12-20 12:10:43 +03:00
|
|
|
if (!length(hivePassword)) {
|
|
|
|
stop("Error: hiveServer: No Valid hivePassword provided")
|
2016-12-19 20:38:23 +03:00
|
|
|
}
|
2017-05-28 11:32:46 +03:00
|
|
|
hivejson <- hive_json(hiveServer = hiveServer, hiveDB = hiveDB,
|
|
|
|
hiveUser = hiveUser, hivePassword = hivePassword)
|
2016-09-14 15:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
body <- hdi_json(subscriptionID = subscriptionID, clustername = clustername,
|
2017-05-28 11:32:46 +03:00
|
|
|
location = location, storageAccount = storageAccount, storageKey = storageKey,
|
|
|
|
version = version,
|
|
|
|
kind = kind, vmSize = vmSize,
|
|
|
|
hivejson = hivejson,
|
|
|
|
componentVersion = componentVersion,
|
2017-05-29 18:41:03 +03:00
|
|
|
sshUser = sshUser, sshPassword = sshPassword,
|
2017-05-28 11:32:46 +03:00
|
|
|
adminUser = adminUser, adminPassword = adminPassword,
|
|
|
|
workers = workers)
|
2016-09-14 15:09:36 +03:00
|
|
|
|
2017-05-28 11:32:46 +03:00
|
|
|
if (debug) {
|
2017-06-08 01:00:54 +03:00
|
|
|
z <- fromJSON(body)
|
2017-05-28 11:32:46 +03:00
|
|
|
return(z)
|
2016-09-14 15:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
uri <- paste0("https://management.azure.com/subscriptions/", subscriptionID,
|
2017-05-21 22:41:51 +03:00
|
|
|
"/resourceGroups/", resourceGroup,
|
2016-12-20 12:10:43 +03:00
|
|
|
"/providers/Microsoft.HDInsight/clusters/", clustername,
|
2016-12-19 20:38:23 +03:00
|
|
|
"?api-version=2015-03-01-preview")
|
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
r <- call_azure_sm(azureActiveContext, uri = uri, body = body,
|
|
|
|
verb = "PUT", verbose = verbose)
|
2017-05-28 11:32:46 +03:00
|
|
|
stopWithAzureError(r)
|
2016-12-21 15:26:53 +03:00
|
|
|
|
2017-05-28 11:32:46 +03:00
|
|
|
azureActiveContext$resourceGroup <- resourceGroup
|
2016-12-19 20:38:23 +03:00
|
|
|
rl <- content(r, "text", encoding = "UTF-8")
|
2017-05-29 18:41:03 +03:00
|
|
|
if (mode == "Sync") {
|
2017-05-28 11:32:46 +03:00
|
|
|
z <- pollStatusHDI(azureActiveContext, clustername = clustername)
|
2017-05-29 18:41:03 +03:00
|
|
|
if (!z) return(FALSE)
|
|
|
|
}
|
2016-12-20 12:10:43 +03:00
|
|
|
azureActiveContext$hdiAdmin <- adminUser
|
2017-05-29 18:41:03 +03:00
|
|
|
azureActiveContext$hdiPassword <- adminPassword
|
2016-12-20 12:10:43 +03:00
|
|
|
azureActiveContext$clustername <- clustername
|
2017-05-20 23:52:09 +03:00
|
|
|
message(paste("Finished: ", Sys.time()))
|
2017-05-28 11:32:46 +03:00
|
|
|
return(TRUE)
|
|
|
|
}
|
2016-09-14 15:09:36 +03:00
|
|
|
|
2016-12-17 00:18:42 +03:00
|
|
|
|
2017-05-29 18:41:03 +03:00
|
|
|
#' Resize a HDInsight cluster role.
|
|
|
|
#'
|
|
|
|
#' @inheritParams setAzureContext
|
|
|
|
#' @inheritParams azureAuthenticate
|
|
|
|
#' @inheritParams azureListHDI
|
|
|
|
#' @inheritParams azureCreateHDI
|
|
|
|
#'
|
|
|
|
#' @param role role type: 'worker', 'head' or 'edge'
|
|
|
|
#' @param size Numeric: the number of nodes for this type of role
|
|
|
|
#'
|
|
|
|
#' @family HDInsight functions
|
|
|
|
#' @export
|
|
|
|
azureResizeHDI <- function(azureActiveContext, clustername,
|
2017-06-14 18:11:52 +03:00
|
|
|
role = c("workernode", "headnode", "edgenode"),
|
2017-05-29 18:41:03 +03:00
|
|
|
size = 2, mode = c("Sync", "Async"), subscriptionID,
|
|
|
|
resourceGroup, verbose = FALSE) {
|
|
|
|
|
|
|
|
if (missing(resourceGroup)) resourceGroup <- azureActiveContext$resourceGroup
|
|
|
|
if (missing(subscriptionID)) subscriptionID <- azureActiveContext$subscriptionID
|
|
|
|
|
|
|
|
assert_that(is_resource_group(resourceGroup))
|
|
|
|
assert_that(is_clustername(clustername))
|
2017-06-14 18:11:52 +03:00
|
|
|
assert_that(is.integer(as.integer(size)))
|
2017-05-29 18:41:03 +03:00
|
|
|
|
|
|
|
role <- match.arg(role)
|
|
|
|
mode <- match.arg(mode)
|
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
uri <- paste0("https://management.azure.com/subscriptions/", subscriptionID,
|
2017-05-29 18:41:03 +03:00
|
|
|
"/resourceGroups/", resourceGroup,
|
|
|
|
"/providers/Microsoft.HDInsight/clusters/", clustername,
|
|
|
|
"/roles/", role, "/resize?api-version=2015-03-01-preview")
|
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
body <- list(targetInstanceCount = size)
|
|
|
|
r <- call_azure_sm(azureActiveContext, uri = uri, body = body,
|
|
|
|
verb = "POST", verbose = verbose)
|
|
|
|
stopWithAzureError(r)
|
2017-05-29 18:41:03 +03:00
|
|
|
|
|
|
|
rl <- content(r, "text", encoding = "UTF-8")
|
|
|
|
if (status_code(r) != 202) {
|
|
|
|
stop(paste("Error: Return code", status_code(r)))
|
|
|
|
}
|
|
|
|
RT <- "Request accepted"
|
|
|
|
if (mode == "Sync") {
|
|
|
|
azureActiveContext$resourceGroup <- resourceGroup
|
|
|
|
message(paste("azureResizeHDI: request submitted: ", Sys.time()))
|
|
|
|
message("Key: A - accepted, (.) - in progress, S - succeeded")
|
|
|
|
a <- 1
|
|
|
|
while (a > 0) {
|
|
|
|
rc <- azureListHDI(azureActiveContext, clustername = clustername)
|
|
|
|
rc1 <- rc[9, 1]
|
|
|
|
if (rc1 == "Running") {
|
|
|
|
message("R")
|
|
|
|
message("")
|
|
|
|
message(paste("Finished Resizing Sucessfully: ", Sys.time()))
|
|
|
|
(break)()
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc1 == "Error") {
|
|
|
|
message("")
|
|
|
|
message(paste("Error Resizing: ", Sys.time()))
|
|
|
|
(break)()
|
|
|
|
}
|
|
|
|
|
|
|
|
a <- a + 1
|
|
|
|
if (rc1 == "Accepted") {
|
|
|
|
rc1 <- "A"
|
|
|
|
}
|
|
|
|
if (rc1 == "InProgress") {
|
|
|
|
rc1 <- "R"
|
|
|
|
}
|
|
|
|
if (rc1 == "AzureVMConfiguration") {
|
|
|
|
rc1 <- "R"
|
|
|
|
}
|
|
|
|
if (rc1 == "HdInsightConfiguration") {
|
|
|
|
rc1 <- "R"
|
|
|
|
}
|
|
|
|
message(rc1)
|
|
|
|
|
|
|
|
if (a > 500)
|
|
|
|
(break)()
|
|
|
|
Sys.sleep(5)
|
|
|
|
}
|
|
|
|
# RT <- clusters[12,1]
|
|
|
|
}
|
|
|
|
message(paste("Finished: ", Sys.time()))
|
|
|
|
|
|
|
|
return(TRUE)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#' Delete HDInsight cluster.
|
|
|
|
#'
|
|
|
|
#' @inheritParams setAzureContext
|
|
|
|
#' @inheritParams azureAuthenticate
|
|
|
|
#' @inheritParams azureListHDI
|
|
|
|
#'
|
2017-05-30 22:43:32 +03:00
|
|
|
#' @return Data frame with HDInsight clusters information
|
2017-05-29 18:41:03 +03:00
|
|
|
#' @family HDInsight functions
|
2017-05-30 22:43:32 +03:00
|
|
|
#' @references https://docs.microsoft.com/en-us/rest/api/hdinsight/hdinsight-cluster#delete
|
2017-05-29 18:41:03 +03:00
|
|
|
#' @export
|
|
|
|
azureDeleteHDI <- function(azureActiveContext, clustername, subscriptionID,
|
|
|
|
resourceGroup, verbose = FALSE) {
|
|
|
|
|
|
|
|
assert_that(is.azureActiveContext(azureActiveContext))
|
|
|
|
|
|
|
|
assert_that(is_clustername(clustername))
|
|
|
|
if (missing(subscriptionID)) subscriptionID <- azureActiveContext$subscriptionID
|
|
|
|
if (missing(resourceGroup)) resourceGroup <- azureActiveContext$resourceGroup
|
|
|
|
|
|
|
|
assert_that(is_resource_group(resourceGroup))
|
|
|
|
assert_that(is_clustername(clustername))
|
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
uri <- paste0("https://management.azure.com/subscriptions/", subscriptionID,
|
2017-05-30 18:08:14 +03:00
|
|
|
"/resourceGroups/", resourceGroup,
|
|
|
|
"/providers/Microsoft.HDInsight/clusters/", clustername,
|
|
|
|
"?api-version=2015-03-01-preview")
|
2017-05-29 18:41:03 +03:00
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
r <- call_azure_sm(azureActiveContext, uri = uri,
|
|
|
|
verb = "DELETE", verbose = verbose)
|
2017-05-29 18:41:03 +03:00
|
|
|
stopWithAzureError(r)
|
|
|
|
|
|
|
|
message("Delete request accepted")
|
|
|
|
return(TRUE)
|
|
|
|
}
|
|
|
|
|
|
|
|
#' Run script action on HDI cluster.
|
2016-12-17 00:18:42 +03:00
|
|
|
#'
|
2016-12-20 12:10:43 +03:00
|
|
|
#' @inheritParams setAzureContext
|
|
|
|
#' @inheritParams azureAuthenticate
|
|
|
|
#' @inheritParams azureListHDI
|
|
|
|
#' @inheritParams azureListVM
|
2016-12-17 00:18:42 +03:00
|
|
|
#'
|
2017-05-29 18:41:03 +03:00
|
|
|
#' @param scriptname Identifier for Custom action script operation
|
|
|
|
#' @param scriptURL URL to custom action script
|
|
|
|
#' @param headNode install on head nodes
|
|
|
|
#' @param workerNode install on worker nodes
|
|
|
|
#' @param edgeNode install on worker nodes
|
2016-12-20 12:10:43 +03:00
|
|
|
#' @param parameters parameters
|
2017-05-30 18:08:14 +03:00
|
|
|
#' @param wait If TRUE, runs script action synchronously, i.e. waits for successfull completion. If FALSE, submits the action asynchronously
|
2016-12-17 00:18:42 +03:00
|
|
|
#'
|
2016-09-14 15:09:36 +03:00
|
|
|
#' @return Returns Success Message
|
2016-12-17 20:50:05 +03:00
|
|
|
#' @family HDInsight functions
|
2017-05-30 18:08:14 +03:00
|
|
|
#' @references https://docs.microsoft.com/en-us/rest/api/hdinsight/hdinsight-cluster#run-script-actions-on-a-running-cluster-linux-cluster-only
|
2016-09-14 15:09:36 +03:00
|
|
|
#' @export
|
2017-05-29 18:41:03 +03:00
|
|
|
azureRunScriptAction <- function(azureActiveContext, scriptname, scriptURL,
|
2016-12-21 15:26:53 +03:00
|
|
|
headNode = TRUE, workerNode = FALSE, edgeNode = FALSE,
|
|
|
|
clustername, resourceGroup,
|
2017-05-30 18:08:14 +03:00
|
|
|
parameters = "", subscriptionID,
|
|
|
|
wait = TRUE, verbose = FALSE) {
|
2017-05-29 18:41:03 +03:00
|
|
|
assert_that(is.azureActiveContext(azureActiveContext))
|
2017-05-21 22:41:51 +03:00
|
|
|
|
2017-05-29 18:41:03 +03:00
|
|
|
if (missing(subscriptionID)) subscriptionID <- azureActiveContext$subscriptionID
|
|
|
|
if (missing(resourceGroup)) resourceGroup <- azureActiveContext$resourceGroup
|
|
|
|
if (missing(clustername)) clustername <- azureActiveContext$clustername
|
2017-05-23 23:39:39 +03:00
|
|
|
|
2017-05-29 18:41:03 +03:00
|
|
|
assert_that(is_resource_group(resourceGroup))
|
|
|
|
assert_that(is_subscription_id(subscriptionID))
|
|
|
|
assert_that(is_clustername(clustername))
|
2016-12-19 20:38:23 +03:00
|
|
|
|
2017-05-30 18:08:14 +03:00
|
|
|
if (!length(scriptname)) stop("Error: No Valid scriptname provided")
|
|
|
|
if (!length(scriptURL)) stop("Error: No Valid scriptURL provided")
|
2017-05-29 18:41:03 +03:00
|
|
|
if (!any(headNode, workerNode, edgeNode)) {
|
2016-12-20 12:10:43 +03:00
|
|
|
stop("Error: No role(headNode,workerNode,edgeNode) flag set to TRUE")
|
2016-09-14 15:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-05-29 18:41:03 +03:00
|
|
|
roles <- c(headNode = '"headnode"',
|
|
|
|
workerNode = '"workernode"',
|
|
|
|
edgeNode = '"edgenode"')
|
|
|
|
RL <- paste(roles[c(headNode, workerNode, edgeNode)], sep = ", ")
|
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
body <- paste0('
|
2017-05-29 18:41:03 +03:00
|
|
|
{
|
|
|
|
"scriptActions": [{
|
|
|
|
"name":"', scriptname, '",
|
|
|
|
"uri":"', scriptURL, '",
|
|
|
|
"parameters":"', parameters, '",
|
|
|
|
"roles":[', RL, ']
|
|
|
|
}],
|
|
|
|
"persistOnSuccess": true
|
|
|
|
}')
|
2016-09-14 15:09:36 +03:00
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
uri <- paste0("https://management.azure.com/subscriptions/", subscriptionID,
|
2017-05-29 18:41:03 +03:00
|
|
|
"/resourceGroups/", resourceGroup,
|
|
|
|
"/providers/Microsoft.HDInsight/clusters/", clustername,
|
|
|
|
"/executeScriptActions?api-version=2015-03-01-preview")
|
2016-09-14 15:09:36 +03:00
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
r <- call_azure_sm(azureActiveContext, uri = uri, body = body,
|
|
|
|
verb = "POST", verbose = verbose)
|
2017-05-29 18:41:03 +03:00
|
|
|
stopWithAzureError(r)
|
2016-11-07 20:13:24 +03:00
|
|
|
|
2017-05-28 11:32:46 +03:00
|
|
|
azureActiveContext$clustername <- clustername
|
2017-06-06 19:12:27 +03:00
|
|
|
azureActiveContext$resourceGroup <- resourceGroup
|
|
|
|
|
|
|
|
|
2017-05-21 23:20:17 +03:00
|
|
|
message("Accepted")
|
2017-06-06 19:12:27 +03:00
|
|
|
if (wait) pollStatusScriptAction(azureActiveContext, scriptname = scriptname, resourceGroup = resourceGroup)
|
2017-05-21 23:20:17 +03:00
|
|
|
return(TRUE)
|
2016-09-14 15:09:36 +03:00
|
|
|
}
|
|
|
|
|
2016-12-17 00:18:42 +03:00
|
|
|
|
2017-05-29 18:41:03 +03:00
|
|
|
#' Get all HDInsight script action history for a specified cluster name.
|
2016-12-17 00:18:42 +03:00
|
|
|
#'
|
2016-12-20 12:10:43 +03:00
|
|
|
#' @inheritParams setAzureContext
|
|
|
|
#' @inheritParams azureListHDI
|
|
|
|
#' @inheritParams azureRunScriptAction
|
2016-12-17 00:18:42 +03:00
|
|
|
#'
|
2017-05-21 22:41:51 +03:00
|
|
|
#' @return Dataframe of HDInsight Clusters
|
2016-12-17 20:50:05 +03:00
|
|
|
#' @family HDInsight functions
|
2017-05-30 18:08:14 +03:00
|
|
|
#' @references https://docs.microsoft.com/en-us/rest/api/hdinsight/hdinsight-cluster#list-all-persisted-script-actions-for-a-cluster-linux-cluster-only
|
2016-09-14 15:09:36 +03:00
|
|
|
#' @export
|
2016-12-20 12:10:43 +03:00
|
|
|
azureScriptActionHistory <- function(azureActiveContext, resourceGroup,
|
2017-05-21 22:41:51 +03:00
|
|
|
clustername = "*", subscriptionID,
|
2016-12-20 12:10:43 +03:00
|
|
|
name, type, verbose = FALSE) {
|
2017-05-29 18:41:03 +03:00
|
|
|
assert_that(is.azureActiveContext(azureActiveContext))
|
2017-05-21 22:41:51 +03:00
|
|
|
|
2017-05-29 18:41:03 +03:00
|
|
|
if (missing(resourceGroup)) resourceGroup <- azureActiveContext$resourceGroup
|
|
|
|
if (missing(subscriptionID)) subscriptionID <- azureActiveContext$subscriptionID
|
|
|
|
if (missing(clustername)) clustername <- azureActiveContext$clustername
|
2017-05-23 23:39:39 +03:00
|
|
|
|
2017-05-29 18:41:03 +03:00
|
|
|
assert_that(is_resource_group(resourceGroup))
|
|
|
|
assert_that(is_subscription_id(subscriptionID))
|
|
|
|
assert_that(is_clustername(clustername))
|
2016-09-14 15:09:36 +03:00
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
uri <- paste0("https://management.azure.com/subscriptions/", subscriptionID,
|
2017-05-29 18:41:03 +03:00
|
|
|
"/resourceGroups/", resourceGroup,
|
|
|
|
"/providers/Microsoft.HDInsight/clusters/", clustername,
|
|
|
|
"/scriptExecutionHistory/?api-version=2015-03-01-preview")
|
2016-09-14 15:09:36 +03:00
|
|
|
|
2017-06-08 01:00:54 +03:00
|
|
|
r <- call_azure_sm(azureActiveContext, uri = uri,
|
|
|
|
verb = "GET", verbose = verbose)
|
2017-05-29 18:41:03 +03:00
|
|
|
stopWithAzureError(r)
|
2016-09-14 15:09:36 +03:00
|
|
|
|
2017-06-06 19:12:27 +03:00
|
|
|
rc <- content(r, bigint_as_char = TRUE)$value
|
2017-05-29 18:41:03 +03:00
|
|
|
if (length(rc) == 0) {
|
|
|
|
message("No script action history found")
|
2016-12-19 20:38:23 +03:00
|
|
|
}
|
2017-05-30 18:08:14 +03:00
|
|
|
class(rc) <- "azureScriptActionHistory"
|
|
|
|
|
2016-09-14 15:09:36 +03:00
|
|
|
|
2017-05-30 18:08:14 +03:00
|
|
|
azureActiveContext$clustername <- clustername
|
|
|
|
return(rc)
|
|
|
|
}
|
|
|
|
|
|
|
|
#' @export
|
2017-05-30 22:43:32 +03:00
|
|
|
#' @param object azureScriptActionHistory object, created by [azureScriptActionHistory()]
|
|
|
|
#' @param ... not used
|
2017-05-30 18:08:14 +03:00
|
|
|
#' @rdname azureScriptActionHistory
|
2017-05-30 22:43:32 +03:00
|
|
|
summary.azureScriptActionHistory <- function(object, ...) {
|
|
|
|
do.call(rbind, lapply(object, function(x) {
|
2017-05-29 18:41:03 +03:00
|
|
|
data.frame(
|
2017-05-30 22:43:32 +03:00
|
|
|
x[c("name", "scriptExecutionId", "startTime")],
|
|
|
|
if (is.null(x$endTime)) list(endTime = NA) else x["endTime"],
|
|
|
|
x[c("status", "uri", "parameters")]
|
2017-05-29 18:41:03 +03:00
|
|
|
)
|
|
|
|
}))
|
2016-09-14 15:09:36 +03:00
|
|
|
}
|