1
- # ' Creates a configuration file for the user's cluster setup.
1
+ # ' Creates a credentials file for rAzureBatch package authentication
2
2
# '
3
- # ' @param fileName Cluster configuration's file name.
3
+ # ' @param fileName Credentials file name
4
4
# ' @param ... Further named parameters
5
5
# ' \itemize{
6
6
# ' \item{"batchAccount"}: {A list of files that the Batch service will download to the compute node before running the command line.}
11
11
# '}
12
12
# ' @return The request to the Batch service was successful.
13
13
# ' @examples {
14
- # ' generateClusterConfig ("test_config.json")
15
- # ' generateClusterConfig ("test_config.json", batchAccount = "testbatchaccount", batchKey = "test_batch_account_key", batchUrl = "http://testbatchaccount.azure.com", storageAccount = "teststorageaccount", storageKey = "test_storage_account_key")
14
+ # ' generateCredentialsConfig ("test_config.json")
15
+ # ' generateCredentialsConfig ("test_config.json", batchAccount = "testbatchaccount", batchKey = "test_batch_account_key", batchUrl = "http://testbatchaccount.azure.com", storageAccount = "teststorageaccount", storageKey = "test_storage_account_key")
16
16
# ' }
17
- generateClusterConfig <- function (fileName , ... ){
17
+ # ' @export
18
+ generateCredentialsConfig <- function (fileName , ... ){
18
19
args <- list (... )
19
20
20
21
batchAccount <- ifelse(is.null(args $ batchAccount ), " batch_account_name" , args $ batchAccount )
@@ -31,35 +32,64 @@ generateClusterConfig <- function(fileName, ...){
31
32
batchAccount = list (
32
33
name = batchAccount ,
33
34
key = batchKey ,
34
- url = batchUrl ,
35
- pool = list (
36
- name = " myPoolName" ,
37
- vmSize = " Standard_D2_v2" ,
38
- maxTasksPerNode = 1 ,
39
- poolSize = list (
40
- minNodes = 3 ,
41
- maxNodes = 10 ,
42
- autoscaleFormula = " QUEUE"
43
- )
44
- ),
45
- rPackages = list (
46
- cran = vector(),
47
- github = vector()
48
- )
35
+ url = batchUrl
49
36
),
50
37
storageAccount = list (
51
38
name = storageName ,
52
39
key = storageKey
53
- ),
54
- settings = list (
55
- verbose = FALSE
56
40
)
57
41
)
58
42
59
43
configJson <- jsonlite :: toJSON(config , auto_unbox = TRUE , pretty = TRUE )
60
44
write(configJson , file = paste0(getwd(), " /" , fileName ))
61
45
62
46
print(sprintf(" A config file has been generated %s. Please enter your Batch credentials." , paste0(getwd(), " /" , fileName )))
47
+ }
48
+ }
49
+
50
+ # ' Creates a configuration file for the user's cluster setup.
51
+ # '
52
+ # ' @param fileName Cluster settings file name
53
+ # ' @return The request to the Batch service was successful.
54
+ # ' @examples {
55
+ # ' generateClusterConfig("test_config.json")
56
+ # ' generateClusterConfig("test_config.json")
57
+ # ' }
58
+ # '
59
+ # ' @export
60
+ generateClusterConfig <- function (fileName , ... ){
61
+ args <- list (... )
62
+
63
+ packages <- ifelse(is.null(args $ packages ), list (), args $ packages )
64
+
65
+ if (! file.exists(fileName ) || ! file.exists(paste0(getwd(), " /" , fileName ))){
66
+ config <- list (
67
+ pool = list (
68
+ name = " myPoolName" ,
69
+ vmSize = " Standard_D2_v2" ,
70
+ maxTasksPerNode = 1 ,
71
+ poolSize = list (
72
+ dedicatedNodes = list (
73
+ min = 3 ,
74
+ max = 3
75
+ ),
76
+ lowPriorityNodes = list (
77
+ min = 3 ,
78
+ max = 3
79
+ ),
80
+ autoscaleFormula = " QUEUE"
81
+ )
82
+ ),
83
+ rPackages = list (
84
+ cran = vector(),
85
+ github = vector()
86
+ )
87
+ )
88
+
89
+ configJson <- jsonlite :: toJSON(config , auto_unbox = TRUE , pretty = TRUE )
90
+ write(configJson , file = paste0(getwd(), " /" , fileName ))
91
+
92
+ print(sprintf(" A cluster settings has been generated %s. Please enter your cluster specification." , paste0(getwd(), " /" , fileName )))
63
93
print(" Note: To maximize all CPU cores, set the maxTasksPerNode property up to 4x the number of cores for the VM size." )
64
94
}
65
95
}
@@ -69,35 +99,48 @@ generateClusterConfig <- function(fileName, ...){
69
99
# ' @param fileName Cluster configuration's file name
70
100
# ' @param fullName A boolean flag for checking the file full name
71
101
# ' @param wait A boolean flag to wait for all nodes to boot up
102
+ # ' @param resourceFiles A list of files that Batch will download to the compute node before running the command line
72
103
# '
73
104
# ' @return The request to the Batch service was successful.
74
105
# ' @examples
75
106
# ' cluster <- makeCluster("cluster_config.json", fullName = TRUE, wait = TRUE)
76
- makeCluster <- function (fileName = " az_config.json" , fullName = FALSE , wait = TRUE , resourceFiles = list ()){
77
- setPoolOption(fileName , fullName )
107
+ # ' @export
108
+ makeCluster <- function (clusterSetting = " cluster_settings.json" , fullName = FALSE , wait = TRUE , resourceFiles = list ()){
109
+ if (fullName ){
110
+ pool <- rjson :: fromJSON(file = paste0(clusterSetting ))
111
+ }
112
+ else {
113
+ pool <- rjson :: fromJSON(file = paste0(getwd(), " /" , clusterSetting ))
114
+ }
115
+
78
116
config <- getOption(" az_config" )
79
- pool <- config $ batchAccount $ pool
117
+ if (is.null(config )){
118
+ stop(" Credentials were not set." )
119
+ }
120
+
121
+ config $ poolId = pool $ pool $ name
122
+ options(" az_config" = config )
80
123
81
124
packages <- NULL
82
- if (! is.null(config $ batchAccount $ rPackages ) && ! is.null(config $ batchAccount $ rPackages $ cran ) && length(config $ batchAccount $ rPackages $ cran ) > 0 ){
83
- packages <- getInstallationCommand(config $ batchAccount $ rPackages $ cran )
125
+ if (! is.null(pool $ rPackages ) && ! is.null(pool $ rPackages $ cran ) && length(pool $ rPackages $ cran ) > 0 ){
126
+ packages <- getInstallationCommand(pool $ rPackages $ cran )
84
127
}
85
128
86
- if (! is.null(config $ batchAccount $ rPackages ) && ! is.null(config $ batchAccount $ rPackages $ github ) && length(config $ batchAccount $ rPackages $ github ) > 0 ){
129
+ if (! is.null(pool $ rPackages ) && ! is.null(pool $ rPackages $ github ) && length(pool $ rPackages $ github ) > 0 ){
87
130
if (is.null(packages )){
88
- packages <- getGithubInstallationCommand(config $ batchAccount $ rPackages $ github )
131
+ packages <- getGithubInstallationCommand(pool $ rPackages $ github )
89
132
}
90
133
else {
91
- packages <- paste0(packages , " ;" , getGithubInstallationCommand(config $ batchAccount $ rPackages $ github ))
134
+ packages <- paste0(packages , " ;" , getGithubInstallationCommand(pool $ rPackages $ github ))
92
135
}
93
136
}
94
137
95
138
response <- .addPool(
96
- pool = pool ,
139
+ pool = pool $ pool ,
97
140
packages = packages ,
98
141
resourceFiles = resourceFiles )
99
142
100
- pool <- getPool(pool $ name )
143
+ pool <- getPool(pool $ pool $ name )
101
144
102
145
if (grepl(" AuthenticationFailed" , response )){
103
146
stop(" Check your credentials and try again." );
@@ -108,36 +151,49 @@ makeCluster <- function(fileName = "az_config.json", fullName = FALSE, wait = TR
108
151
}
109
152
else {
110
153
if (wait ){
111
- waitForNodesToComplete(pool $ id , 60000 , targetDedicated = pool $ targetDedicated )
154
+ waitForNodesToComplete(pool $ id , 60000 )
112
155
}
113
156
}
114
157
115
158
print(" Your pool has been registered." )
116
- print(sprintf(" Node Count: %i" , pool $ targetDedicated ))
159
+ print(sprintf(" Dedicated Node Count: %i" , pool $ targetDedicatedNodes ))
160
+ print(sprintf(" Low Priority Node Count: %i" , pool $ targetLowPriorityNodes ))
117
161
return (getOption(" az_config" ))
118
162
}
119
163
120
164
# ' Deletes the cluster from your Azure account.
121
165
# '
122
166
# ' @param cluster The cluster configuration that was created in \code{makeCluster}
123
167
# '
124
- # ' @return The request to the Batch service was successful.
125
168
# ' @examples
126
- # ' clusterConfiguration <- makeCluster("pool_configuration .json")
169
+ # ' clusterConfiguration <- makeCluster("cluster_settings .json")
127
170
# ' stopCluster(clusterConfiguration)
171
+ # ' @export
128
172
stopCluster <- function (cluster ){
129
- deletePool(pool $ batchAccount $ pool $ name )
173
+ deletePool(cluster $ poolId )
174
+
175
+ print(sprintf(" Your %s cluster has been destroyed." , cluster $ poolId ))
130
176
}
131
177
132
- setPoolOption <- function (fileName = " az_config.json" , fullName = FALSE ){
133
- if (fullName ){
178
+ # ' Deletes the cluster from your Azure account.
179
+ # '
180
+ # ' @param fileName The cluster configuration that was created in \code{makeCluster}
181
+ # '
182
+ # ' @return The request to the Batch service was successful.
183
+ # ' @examples
184
+ # ' clusterConfiguration <- makeCluster("cluster_settings.json")
185
+ # ' stopCluster(clusterConfiguration)
186
+ # ' @export
187
+ setCredentials <- function (fileName = " az_config.json" ){
188
+ if (file.exists(fileName )){
134
189
config <- rjson :: fromJSON(file = paste0(fileName ))
135
190
}
136
191
else {
137
192
config <- rjson :: fromJSON(file = paste0(getwd(), " /" , fileName ))
138
193
}
139
194
140
195
options(" az_config" = config )
196
+ print(" Your azure credentials have been set." )
141
197
}
142
198
143
199
getPoolWorkers <- function (poolId , ... ){
0 commit comments