Skip to content
This repository has been archived by the owner on Oct 31, 2019. It is now read-only.

Commit

Permalink
Merge branch 'dev' of https://github.com/Microsoft/AzureSMR into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Alanwe committed May 30, 2017
2 parents 88f19e2 + 7905be3 commit fc8693f
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 63 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Description: Helps users to manage Azure Services and objects from within an
an Azure Active Directory application and service principal in the Azure portal.
Type: Package
Version: 0.2.4
Date: 2017-05-29
Date: 2017-05-30
Authors@R: c(
person(family="Microsoft Corporation", role="cph"),
person("Alan", "Weaver", role=c("aut", "cre"), email="alanwe@microsoft.com"),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

S3method(print,azureActiveContext)
S3method(str,azureActiveContext)
S3method(summary,azureScriptActionHistory)
export(AzureListRG)
export(as.azureActiveContext)
export(azureAuthenticate)
Expand Down
52 changes: 31 additions & 21 deletions R/AzureHDI.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ azureListHDI <- function(azureActiveContext, resourceGroup, clustername = "*",



#' Get Configuration Information for a specified cluster name.
#' Get configuration information for a specified cluster name.
#'
#' @inheritParams setAzureContext
#' @inheritParams azureAuthenticate
Expand Down Expand Up @@ -87,6 +87,7 @@ azureHDIConf <- function(azureActiveContext, clustername, resourceGroup,
"?api-version=2015-03-01-preview")

r <- GET(URL, azureApiHeaders(azToken), verbosity)
browser()
rc <- content(r)

if (length(rc) == 0) {
Expand Down Expand Up @@ -146,6 +147,7 @@ azureHDIConf <- function(azureActiveContext, clustername, resourceGroup,
#' @return Success message
#' @family HDInsight functions
#' @note See \url{https://docs.microsoft.com/en-us/azure/hdinsight/hdinsight-component-versioning} to learn about HDInsight Versions
#' @references https://docs.microsoft.com/en-us/rest/api/hdinsight/hdinsight-cluster#create
#' @export
azureCreateHDI <- function(azureActiveContext, resourceGroup, location,
clustername, kind = c("rserver", "spark", "hadoop"),
Expand Down Expand Up @@ -354,8 +356,9 @@ azureResizeHDI <- function(azureActiveContext, clustername,
#' @inheritParams azureAuthenticate
#' @inheritParams azureListHDI
#'
#' @return Returns Dataframe of HDInsight Clusters information
#' @return Data frame with HDInsight clusters information
#' @family HDInsight functions
#' @references https://docs.microsoft.com/en-us/rest/api/hdinsight/hdinsight-cluster#delete
#' @export
azureDeleteHDI <- function(azureActiveContext, clustername, subscriptionID,
resourceGroup, verbose = FALSE) {
Expand All @@ -373,8 +376,9 @@ azureDeleteHDI <- function(azureActiveContext, clustername, subscriptionID,
assert_that(is_clustername(clustername))

URL <- paste0("https://management.azure.com/subscriptions/", subscriptionID,
"/resourceGroups/", resourceGroup, "/providers/Microsoft.HDInsight/clusters/",
clustername, "?api-version=2015-03-01-preview")
"/resourceGroups/", resourceGroup,
"/providers/Microsoft.HDInsight/clusters/", clustername,
"?api-version=2015-03-01-preview")

r <- DELETE(URL, azureApiHeaders(azToken), verbosity)
stopWithAzureError(r)
Expand All @@ -396,14 +400,17 @@ azureDeleteHDI <- function(azureActiveContext, clustername, subscriptionID,
#' @param workerNode install on worker nodes
#' @param edgeNode install on worker nodes
#' @param parameters parameters
#' @param wait If TRUE, runs script action synchronously, i.e. waits for successfull completion. If FALSE, submits the action asynchronously
#'
#' @return Returns Success Message
#' @family HDInsight functions
#' @references https://docs.microsoft.com/en-us/rest/api/hdinsight/hdinsight-cluster#run-script-actions-on-a-running-cluster-linux-cluster-only
#' @export
azureRunScriptAction <- function(azureActiveContext, scriptname, scriptURL,
headNode = TRUE, workerNode = FALSE, edgeNode = FALSE,
clustername, resourceGroup,
parameters = "", subscriptionID, verbose = FALSE) {
parameters = "", subscriptionID,
wait = TRUE, verbose = FALSE) {
assert_that(is.azureActiveContext(azureActiveContext))
azureCheckToken(azureActiveContext)
azToken <- azureActiveContext$Token
Expand All @@ -417,13 +424,8 @@ azureRunScriptAction <- function(azureActiveContext, scriptname, scriptURL,
assert_that(is_subscription_id(subscriptionID))
assert_that(is_clustername(clustername))

if (!length(scriptname)) {
stop("Error: No Valid scriptname provided")
}
if (!length(scriptURL)) {
stop("Error: No Valid scriptURL provided")
}

if (!length(scriptname)) stop("Error: No Valid scriptname provided")
if (!length(scriptURL)) stop("Error: No Valid scriptURL provided")
if (!any(headNode, workerNode, edgeNode)) {
stop("Error: No role(headNode,workerNode,edgeNode) flag set to TRUE")
}
Expand Down Expand Up @@ -456,6 +458,7 @@ azureRunScriptAction <- function(azureActiveContext, scriptname, scriptURL,

azureActiveContext$clustername <- clustername
message("Accepted")
if (wait) pollStatusScriptAction(azureActiveContext, scriptname = scriptname)
return(TRUE)
}

Expand All @@ -468,6 +471,7 @@ azureRunScriptAction <- function(azureActiveContext, scriptname, scriptURL,
#'
#' @return Dataframe of HDInsight Clusters
#' @family HDInsight functions
#' @references https://docs.microsoft.com/en-us/rest/api/hdinsight/hdinsight-cluster#list-all-persisted-script-actions-for-a-cluster-linux-cluster-only
#' @export
azureScriptActionHistory <- function(azureActiveContext, resourceGroup,
clustername = "*", subscriptionID,
Expand All @@ -494,20 +498,26 @@ azureScriptActionHistory <- function(azureActiveContext, resourceGroup,
stopWithAzureError(r)

rc <- content(r)$value

if (length(rc) == 0) {
message("No script action history found")
}
class(rc) <- "azureScriptActionHistory"

dfn <- do.call(rbind, lapply(rc, function(x) {
data.frame(
x[c("name", "scriptExecutionId", "startTime")],
if (is.null(x$endTime)) list(endTime = NA) else x["endTime"],
x[c("status", "uri", "parameters")]
)
}))

azureActiveContext$clustername <- clustername
return(dfn)
return(rc)
}

#' @export
#' @param object azureScriptActionHistory object, created by [azureScriptActionHistory()]
#' @param ... not used
#' @rdname azureScriptActionHistory
summary.azureScriptActionHistory <- function(object, ...) {
do.call(rbind, lapply(object, function(x) {
data.frame(
x[c("name", "scriptExecutionId", "startTime")],
if (is.null(x$endTime)) list(endTime = NA) else x["endTime"],
x[c("status", "uri", "parameters")]
)
}))
}
2 changes: 1 addition & 1 deletion R/internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ getSig <- function(azureActiveContext, url, verb, key, storageAccount,


stopWithAzureError <- function(r) {
if(status_code(r) < 300) return()
if (status_code(r) < 300) return()
msg <- paste0(as.character(sys.call(1))[1], "()") # Name of calling fucntion
addToMsg <- function(x) {
if (!is.null(x)) x <- strwrap(x)
Expand Down
41 changes: 41 additions & 0 deletions R/pollStatus.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,44 @@ pollStatusHDI <- function(azureActiveContext, clustername) {
message("HDI request completed: ", Sys.time())
return(TRUE)
}


pollStatusScriptAction <- function(azureActiveContext, scriptname) {

message("Script action request submitted: ", Sys.time())
message("Key: A - accepted, (.) - in progress, S - succeeded, E - error, F - failed")
iteration <- 0
waiting <- TRUE
while (iteration < 500 && waiting) {

status <- azureScriptActionHistory(azureActiveContext)
idx <- which(sapply(status, "[[", "name") == scriptname)[1]
summary <- status[[idx]]$status
rc <- switch(tolower(summary),
accepted = "A",
succeeded = "S",
error = "E",
failed = "F",
inprogress = ".",
"?"
)

message(rc, appendLF = FALSE)
if (rc %in% c("S", "E", "F")) {
waiting = FALSE
}
if (rc %in% c("E", "F")) {
message("")
warning(paste("Error deploying: ", Sys.time()), call. = FALSE, immediate. = TRUE)
return(FALSE)
}

if (rc == "?") message(summary)

iteration <- iteration + 1
if (!rc %in% c("S", "E", "F")) Sys.sleep(5)
}
message("")
message("Script action completed: ", Sys.time())
return(TRUE)
}
5 changes: 4 additions & 1 deletion man/azureCreateHDI.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/azureDeleteHDI.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/azureHDIConf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/azureRunScriptAction.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions man/azureScriptActionHistory.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fc8693f

Please sign in to comment.