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

Commit

Permalink
improve error handling for create cluster (#241)
Browse files Browse the repository at this point in the history
* improve error handling for create cluster

* remove extra space
  • Loading branch information
zfengms authored Apr 6, 2018
1 parent cea0550 commit b5b02e9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 30 deletions.
82 changes: 52 additions & 30 deletions R/cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,42 +223,64 @@ makeCluster <-
commandLine = commandLine
)

if (grepl("AuthenticationFailed", response)) {
stop("Check your credentials and try again.")
}
if (nchar(response) > 0) {
responseObj <- rjson::fromJSON(response)
errorMessage <- getHttpErrorMessage(responseObj)

if (responseObj$code == "PoolBeingDeleted") {
message <- paste(
"Cluster '%s' already exists and is being deleted.",
"Another cluster with the same name cannot be created",
"until it is deleted. Please wait for the cluster to be deleted",
"or create one with a different name"
)

if (grepl("PoolBeingDeleted", response)) {
message <- paste(
"Cluster '%s' already exists and is being deleted.",
"Another cluster with the same name cannot be created",
"until it is deleted. Please wait for the cluster to be deleted",
"or create one with a different name"
)
if (wait == TRUE) {
pool <- rAzureBatch::getPool(poolConfig$name)

if (wait == TRUE) {
pool <- rAzureBatch::getPool(poolConfig$name)
cat(sprintf(message,
poolConfig$name),
fill = TRUE)

cat(sprintf(message,
poolConfig$name),
fill = TRUE)
while (!is.null(pool) && !is.null(pool$state) && pool$state == "deleting") {
cat(".")
Sys.sleep(10)
pool <- rAzureBatch::getPool(poolConfig$name)
}

while (rAzureBatch::getPool(poolConfig$name)$state == "deleting") {
cat(".")
Sys.sleep(10)
}
cat("\n")

cat("\n")
response <- .addPool(
pool = poolConfig,
packages = packages,
environmentSettings = environmentSettings,
resourceFiles = resourceFiles,
commandLine = commandLine
)

response <- .addPool(
pool = poolConfig,
packages = packages,
environmentSettings = environmentSettings,
resourceFiles = resourceFiles,
commandLine = commandLine
)
} else {
stop(sprintf(message,
poolConfig$name))
if (nchar(response) > 0) {
responseObj <- rjson::fromJSON(response)
errorMessage <- getHttpErrorMessage(responseObj)
}
else {
responseObj <- NULL
errorMessage <- NULL
}
} else {
stop(sprintf(message,
poolConfig$name))
}
}

if (nchar(response) > 0) {
if (responseObj$code == "AuthenticationFailed") {
stop(paste0("Check your credentials and try again.\r\n", errorMessage))
}
else {
if (responseObj$code != "PoolExists") {
stop(errorMessage)
}
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions R/utility.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,15 @@ hasDataSet <- function(list) {

return(FALSE)
}

getHttpErrorMessage <- function(responseObj) {
detailMessage <- paste0(responseObj$code, ": ", responseObj$message$value)

if (length(responseObj$values) > 0) {
for (i in 1:length(responseObj$values)) {
detailMessage <- paste0(detailMessage, "\r\n", responseObj$values[[i]]$key, ": ", responseObj$values[[i]]$value)
}
}
detailMessage <- paste0(detailMessage, "\r\nodata.metadata: ", responseObj$odata.metadata)
return(detailMessage)
}

0 comments on commit b5b02e9

Please sign in to comment.