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'
Browse files Browse the repository at this point in the history
* dev:
  Rename addins
  Bug fix in progress bar
  Create RStudio addins #72
  Add function to retrieve status of all VMs #72
  Fix merge errors
  Update tests #70
  Export read.AzureSMR.config() and enable reading settings file in createAzureContext() #70
  Remove spurious reference to storageAccountK
  Add resourceGroup argument when polling for script actions #58
  Fix  example_azureCreateHDI.R - Remove DEBUG flag, set legal password
  test-6-ARM.R - Changed Deploy 2 to a quicker VNET build.
  • Loading branch information
andrie committed Jun 6, 2017
2 parents 7ecbf00 + db99e30 commit 0293485
Show file tree
Hide file tree
Showing 27 changed files with 223 additions and 63 deletions.
6 changes: 5 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ Imports:
jsonlite,
XML,
base64enc,
digest
digest,
shiny (>= 0.13),
miniUI (>= 0.1.1),
rstudioapi (>= 0.5),
DT
Depends:
R(>= 3.0.0)
Suggests:
Expand Down
10 changes: 10 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export(azureDeleteVM)
export(azureDeletestorageAccount)
export(azureDeployStatus)
export(azureDeployTemplate)
export(azureGetAllVMstatus)
export(azureGetBlob)
export(azureHDIConf)
export(azureHiveSQL)
Expand Down Expand Up @@ -57,7 +58,10 @@ export(azureVMStatus)
export(createAzureContext)
export(dumpAzureContext)
export(is.azureActiveContext)
export(read.AzureSMR.config)
export(setAzureContext)
importFrom(DT,dataTableOutput)
importFrom(DT,renderDataTable)
importFrom(XML,htmlParse)
importFrom(XML,xmlValue)
importFrom(XML,xpathApply)
Expand All @@ -78,6 +82,12 @@ importFrom(httr,headers)
importFrom(httr,http_status)
importFrom(httr,status_code)
importFrom(jsonlite,fromJSON)
importFrom(miniUI,gadgetTitleBar)
importFrom(miniUI,miniContentPanel)
importFrom(miniUI,miniPage)
importFrom(shiny,observeEvent)
importFrom(shiny,paneViewer)
importFrom(shiny,runGadget)
importFrom(utils,URLencode)
importFrom(utils,browseURL)
importFrom(utils,ls.str)
Expand Down
25 changes: 18 additions & 7 deletions R/AzureContextObject.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,30 @@
#' @inheritParams setAzureContext
#' @family azureActiveContext functions
#'
#' @seealso [setAzureContext()], [azureAuthenticate()]
#' @seealso [setAzureContext()], [azureAuthenticate()], [read.AzureSMR.config)]
#' @return An `azureActiveContext` object
#' @export
createAzureContext <- function(tenantID, clientID, authKey){
createAzureContext <- function(tenantID, clientID, authKey, configFile){
azEnv <- new.env(parent = emptyenv())
azEnv <- as.azureActiveContext(azEnv)

if (!missing(tenantID)) azEnv$tenantID <- tenantID else azEnv$tenantID <- "?"
if (!missing(clientID)) azEnv$clientID <- clientID else azEnv$tenantID <- "?"
if (!missing(authKey)) azEnv$authKey <- authKey else azEnv$tenantID <- "?"
list2env(
list(tenantID = "", clientID = "", authKey = ""),
envir = azEnv
)
if (!missing(configFile)) {
config <- read.AzureSMR.config(configFile)
list2env(config, envir = azEnv)
azureAuthenticate(azEnv)
} else {
if (!missing(tenantID)) azEnv$tenantID <- tenantID
if (!missing(clientID)) azEnv$clientID <- clientID
if (!missing(authKey)) azEnv$authKey <- authKey
if (!missing(tenantID) && !missing(clientID) && !missing(authKey)) {
azureAuthenticate(azEnv)
}
}

if (!missing(tenantID) && !missing(clientID) && !missing(authKey) )
azureAuthenticate(azEnv,tenantID, clientID, authKey)
return(azEnv)
}

Expand Down
7 changes: 5 additions & 2 deletions R/AzureHDI.R
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,11 @@ azureRunScriptAction <- function(azureActiveContext, scriptname, scriptURL,
stopWithAzureError(r)

azureActiveContext$clustername <- clustername
azureActiveContext$resourceGroup <- resourceGroup


message("Accepted")
if (wait) pollStatusScriptAction(azureActiveContext, scriptname = scriptname)
if (wait) pollStatusScriptAction(azureActiveContext, scriptname = scriptname, resourceGroup = resourceGroup)
return(TRUE)
}

Expand Down Expand Up @@ -497,7 +500,7 @@ azureScriptActionHistory <- function(azureActiveContext, resourceGroup,
r <- GET(URL, azureApiHeaders(azToken), verbosity)
stopWithAzureError(r)

rc <- content(r)$value
rc <- content(r, bigint_as_char = TRUE)$value
if (length(rc) == 0) {
message("No script action history found")
}
Expand Down
1 change: 0 additions & 1 deletion R/AzureStorageAccount.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ azureSAGetKey <- function(azureActiveContext, storageAccount,
rl <- content(r, "text", encoding = "UTF-8")
df <- fromJSON(rl)
azureActiveContext$storageAccount <- storageAccount
azureActiveContext$storageAccountK <- storageAccount
azureActiveContext$resourceGroup <- resourceGroup
azureActiveContext$storageKey <- df$keys$value[1]

Expand Down
35 changes: 35 additions & 0 deletions R/AzureVM.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,41 @@ azureListVM <- function(azureActiveContext, resourceGroup, location, subscriptio
return(dfn)
}

#' List the status of every virtual machine in the azure active context.
#'
#' First queries the azure active context for all visible resources, then sequentially queries the status of all virtuam machines.
#'
#' @inheritParams setAzureContext
#' @inheritParams azureListAllResources
#'
#' @family Virtual machine functions
#' @export
azureGetAllVMstatus <- function(azureActiveContext) {
res <- azureListAllResources(azureActiveContext)
vms <- res[res$type == "Microsoft.Compute/virtualMachines",]
n <- nrow(vms)
pb <- txtProgressBar(min = 0, max = n, style = 3)
on.exit(close(pb))
z <- lapply(seq_len(n), function(i) {
setTxtProgressBar(pb, i)
z <- tryCatch(azureVMStatus(azureActiveContext,
resourceGroup = vms$resourceGroup[i],
vmName = vms$name[i],
subscriptionID = vms$subscriptionID[i]
), error = function(e) e)
z <- if (inherits(z, "error")) NA_character_ else z
data.frame(
name = vms$name[i],
resourceGroup = vms$resourceGroup[i],
subscriptionID = vms$subscriptionID[i],
provisioning = gsub("Provisioning (.*?), .*$", "\\1", z),
status = gsub(".*?, VM (.*)$", "\\1", z)
)
})
do.call(rbind, z)
}



#' Start a Virtual Machine.
#'
Expand Down
45 changes: 45 additions & 0 deletions R/addins.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# this is a template to view a DT object
# @param data.frame
# @param title Text to display in pane title

#' @importFrom miniUI miniPage gadgetTitleBar miniContentPanel
#' @importFrom DT dataTableOutput renderDataTable
#' @importFrom shiny observeEvent paneViewer runGadget
dataTableViewer <- function(x, title = "") {

ui <- miniPage(
gadgetTitleBar(title),
miniContentPanel(
DT::dataTableOutput("dt", height = "100%")
)
)

server <- function(input, output, session) {
output$dt <- DT::renderDataTable(x)

observeEvent(input$done, stopApp())
}

viewer <- paneViewer()
runGadget(ui, server, viewer = viewer)

}


addinListAllResources <- function() {
settingsfile <- getOption("AzureSMR.config")
assert_that(file.exists(settingsfile))
az <- createAzureContext(configFile = settingsfile)
z <- azureListAllResources(az)
z$id <- NULL
dataTableViewer(z, title = "All resources")
}

addinGetAllVMstatus <- function() {
settingsfile <- getOption("AzureSMR.config")
assert_that(file.exists(settingsfile))
az <- createAzureContext(configFile = settingsfile)
z <- azureGetAllVMstatus(az)
z$id <- NULL
dataTableViewer(z, title = "All virtual machines")
}
15 changes: 9 additions & 6 deletions R/config.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Reads settings from configuration file in JSON format.
#' Reads settings from configuration file in JSON format.
#'
#' @param config location of file that contains configuration in JSON format
#' @export
#
# @param config location of file that contains configuration in JSON format
#
read.AzureSMR.config <- function(config = getOption("AzureSMR.config")){
z <- tryCatch(fromJSON(file(config)),
read.AzureSMR.config <- function(configFile = getOption("AzureSMR.config")) {
assert_that(is.character(configFile))
assert_that(file.exists(configFile))
z <- tryCatch(fromJSON(file(configFile)),
error = function(e)e
)
# Error check the settings file for invalid JSON
if(inherits(z, "error")) {
msg <- sprintf("Your config file contains invalid json", config)
msg <- sprintf("Your config file contains invalid json", configFile)
msg <- paste(msg, z$message, sep = "\n\n")
stop(msg, call. = FALSE)
}
Expand Down
5 changes: 2 additions & 3 deletions R/internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ extractStorageAccount <- function(x) gsub(".*?/storageAccounts/(.*?)(/.*)*$",


refreshStorageKey <- function(azureActiveContext, storageAccount, resourceGroup){
if (length(azureActiveContext$storageAccountK) < 1 ||
storageAccount != azureActiveContext$storageAccountK ||
length(azureActiveContext$storageKey) <1
if (storageAccount != azureActiveContext$storageAccount ||
length(azureActiveContext$storageKey) == 0
) {
message("Fetching Storage Key..")
azureSAGetKey(azureActiveContext, resourceGroup = resourceGroup, storageAccount = storageAccount)
Expand Down
5 changes: 3 additions & 2 deletions R/pollStatus.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,16 @@ pollStatusHDI <- function(azureActiveContext, clustername) {
}


pollStatusScriptAction <- function(azureActiveContext, scriptname) {
pollStatusScriptAction <- function(azureActiveContext, scriptname, resourceGroup) {

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)
status <- azureScriptActionHistory(azureActiveContext,
resourceGroup = resourceGroup)
idx <- which(sapply(status, "[[", "name") == scriptname)[1]
summary <- status[[idx]]$status
rc <- switch(tolower(summary),
Expand Down
5 changes: 3 additions & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
AzureSMR.config.default <- "~/.azureml/settings.json"
AzureSMR.config.default <- "~/.azuresmr/config.json"

.onAttach <- function(libname, pkgname){
.onAttach <- function(libname, pkgname) {
if (is.null(getOption("AzureSMR.config")))
options(AzureSMR.config = AzureSMR.config.default)
}
16 changes: 6 additions & 10 deletions inst/examples/example_azureCreateHDI.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
\dontrun{
library(AzureSMR)

azureCreateHDI(context,
resourceGroup = RG,
azureCreateHDI(context,
resourceGroup = RG,
clustername = "smrhdi", # only low case letters, digit, and dash.
storageAccount = "smrhdisa",
adminUser = "hdiadmin",
adminUser = "hdiadmin",
adminPassword = "AzureSMR_password123",
sshUser = "hdisshuser",
sshUser = "hdisshuser",
sshPassword = "AzureSMR_password123", # need at least digits.
kind = "rserver",
debug = FALSE
kind = "rserver"
)

}
}
9 changes: 9 additions & 0 deletions inst/rstudio/addins.dcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Name: Azure-resources
Description: List all Azure resources.
Binding: addinListAllResources
Interactive: true

Name: Azure-VM status
Description: List the status of all virtual machines.
Binding: addinGetAllVMstatus
Interactive: true
3 changes: 2 additions & 1 deletion man/azureDeleteVM.Rd

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

22 changes: 22 additions & 0 deletions man/azureGetAllVMstatus.Rd

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

1 change: 1 addition & 0 deletions man/azureListScaleSetNetwork.Rd

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

1 change: 1 addition & 0 deletions man/azureListScaleSetVM.Rd

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

1 change: 1 addition & 0 deletions man/azureListScaleSets.Rd

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

1 change: 1 addition & 0 deletions man/azureListVM.Rd

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

1 change: 1 addition & 0 deletions man/azureStartVM.Rd

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

1 change: 1 addition & 0 deletions man/azureStopVM.Rd

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

1 change: 1 addition & 0 deletions man/azureVMStatus.Rd

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

Loading

0 comments on commit 0293485

Please sign in to comment.