Browse Source

killall_drill, showall_drill, drill_down; working on #33

pull/34/head
boB Rudis 5 years ago
parent
commit
96b9983582
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 3
      NAMESPACE
  2. 67
      R/drill-docker.R
  3. 1
      R/sergeant-package.r
  4. 8
      README.Rmd
  5. 8
      README.md
  6. 13
      man/drill_up.Rd
  7. 21
      man/killall_drill.Rd
  8. 1
      man/sergeant.Rd
  9. 17
      man/showall_drill.Rd

3
NAMESPACE

@ -17,6 +17,7 @@ export(ctas_profile)
export(drill_active)
export(drill_cancel)
export(drill_connection)
export(drill_down)
export(drill_functions)
export(drill_metrics)
export(drill_mod_storage)
@ -39,6 +40,8 @@ export(drill_up)
export(drill_uplift)
export(drill_use)
export(drill_version)
export(killall_drill)
export(showall_drill)
export(src_drill)
export(tbl)
exportClasses(DrillConnection)

67
R/drill-docker.R

@ -9,6 +9,9 @@
#' `/data` and a new `dfs` storage workspace will created (`dfs.d`) that
#' maps to `/data` and is writable.
#'
#' Use [drill_down()] to stop a running Drill container by container id
#' (full or partial).
#'
#' @md
#' @note this requires a working Docker setup on your system and it is *highly suggested*
#' you `docker pull` it yourself before running this function.
@ -26,6 +29,7 @@
#' for killing with the `$stop()` function or from the Docker command
#' line (in interactive mode the docker container ID is printed as well).
#' @export
#' @family Drill Docker functions
#' @examples \dontrun{
#' drill_up(data_dir = "~/Data")
#' }
@ -87,3 +91,66 @@ drill_up <- function(image = "drill/apache-drill:1.15.0",
invisible(drill)
}
#' @rdname drill_up
#' @param id the id of the Drill container
#' @export
drill_down <- function(id) {
docker <- stevedore::docker_client()
docker$container$get(id)$stop()
}
#' Show all dead and running Drill Docker containers
#'
#' This function will show _all_ Docker containers that are based on an
#' image matching a runtime command of "`bin/drill-embedded`".
#'
#' @family Drill Docker functions
#' @export
showall_drill <- function() {
docker <- stevedore::docker_client()
x <- docker$container$list(all=TRUE)
x <- x[grepl("bin/drill-embedded", x$command, fixed = TRUE),]
if (nrow(x) > 0) {
message(sprintf(
"Drill containers found: [%s]\nReturning data frame of container metadata (invisibly).",
paste0(substr(x$id, 1, 16), collapse=", ")
))
return(invisible(x))
} else {
message("No Drill containers running matching target command found.")
}
}
#' Prune all dead and running Drill Docker containers
#'
#' _This is a destructive function._ It will stop **any** Docker container that
#' is based on an image matching a runtime command of "`bin/drill-embedded`".
#' It's best used when you had a session forcefully interuppted and had been
#' using the R helper functions to start/stop the Drill Docker container.
#' You may want to consider using the Docker command-line interface to perform
#' this work manually.
#'
#' @family Drill Docker functions
#' @export
killall_drill <- function() {
docker <- stevedore::docker_client()
x <- docker$container$list(all=TRUE)
for (i in 1:nrow(x)) {
if (grepl("bin/drill-embedded", x$command[i], fixed = TRUE)) {
message(sprintf("Pruning: %s...", x$id[i]))
if (x$state[i] == "running") {
cntnr <- docker$container$get(x$id[i])
suppressWarnings(try(cntnr$stop(), silent = TRUE))
suppressWarnings(try(cntnr$remove()(), silent = TRUE))
}
}
}
}

1
R/sergeant-package.r

@ -27,6 +27,7 @@
#' \code{DBI} and \code{dplyr} interfaces.
#'
#' @name sergeant
#' @keywords internal
#' @references \href{https://drill.apache.org/docs/}{Drill documentation}
#' @docType package
#' @author Bob Rudis (bob@@rud.is)

8
README.Rmd

@ -86,8 +86,12 @@ Note that a number of Drill SQL functions have been mapped to R functions (e.g.
- `ctas_profile`: Generate a Drill CTAS Statement from a Query
- `drill_up`:
Start a Dockerized Drill Instance
## Installation
sart a Dockerized Drill Instance
# `sdrill_down`: stop a Dockerized Drill Instance by container id
- `howall_drill`: Show all dead and running Drill Docker containers
- `stopall_drill`: Prune all dead and running Drill Docker containers
# Installation
```{r eval=FALSE}
devtools::install_github("hrbrmstr/sergeant")

8
README.md

@ -112,8 +112,12 @@ function mappings.
- `ctas_profile`: Generate a Drill CTAS Statement from a Query
- `drill_up`: Start a Dockerized Drill Instance
## Installation
- - `drill_up`: Start a Dockerized Drill Instance
- `showall_drill`: Show all dead and running Drill Docker containers
- `sdrill_down`: stop a Dockerized Drill Instance by container id
- `topall_drill`: Prune all dead and running Drill Docker containers
# Installation
``` r
devtools::install_github("hrbrmstr/sergeant")

13
man/drill_up.Rd

@ -2,10 +2,13 @@
% Please edit documentation in R/drill-docker.R
\name{drill_up}
\alias{drill_up}
\alias{drill_down}
\title{Start a Dockerized Drill Instance}
\usage{
drill_up(image = "drill/apache-drill:1.15.0", container_name = "drill",
data_dir = getwd(), remove = TRUE)
drill_down(id)
}
\arguments{
\item{image}{Drill image to use. Must be a valid image from
@ -21,6 +24,8 @@ in the container. This will be mapped to the \code{dfs} storage plugin as the
\item{remove}{remove the Drill container instance after it's stopped?
Defaults to \code{TRUE} since you shouldn't be relying on this in production.}
\item{id}{the id of the Drill container}
}
\value{
a \code{stevedore} docker object (invisibly) which \emph{you} are responsible
@ -37,6 +42,9 @@ one at \href{https://hub.docker.com/u/drill}{Drill's Docker Hub}.
The path specified in \code{data_dir} will be mapped inside the container as
\code{/data} and a new \code{dfs} storage workspace will created (\code{dfs.d}) that
maps to \code{/data} and is writable.
Use \code{\link[=drill_down]{drill_down()}} to stop a running Drill container by container id
(full or partial).
}
\note{
this requires a working Docker setup on your system and it is \emph{highly suggested}
@ -47,3 +55,8 @@ you \code{docker pull} it yourself before running this function.
drill_up(data_dir = "~/Data")
}
}
\seealso{
Other Drill Docker functions: \code{\link{killall_drill}},
\code{\link{showall_drill}}
}
\concept{Drill Docker functions}

21
man/killall_drill.Rd

@ -0,0 +1,21 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/drill-docker.R
\name{killall_drill}
\alias{killall_drill}
\title{Prune all dead and running Drill Docker containers}
\usage{
killall_drill()
}
\description{
\emph{This is a destructive function.} It will stop \strong{any} Docker container that
is based on an image matching a runtime command of "\code{bin/drill-embedded}".
It's best used when you had a session forcefully interuppted and had been
using the R helper functions to start/stop the Drill Docker container.
You may want to consider using the Docker command-line interface to perform
this work manually.
}
\seealso{
Other Drill Docker functions: \code{\link{drill_up}},
\code{\link{showall_drill}}
}
\concept{Drill Docker functions}

1
man/sergeant.Rd

@ -39,3 +39,4 @@ Methods are provided to work with Drill via the REST APIs along with R
\author{
Bob Rudis (bob@rud.is)
}
\keyword{internal}

17
man/showall_drill.Rd

@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/drill-docker.R
\name{showall_drill}
\alias{showall_drill}
\title{Show all dead and running Drill Docker containers}
\usage{
showall_drill()
}
\description{
This function will show \emph{all} Docker containers that are based on an
image matching a runtime command of "\code{bin/drill-embedded}".
}
\seealso{
Other Drill Docker functions: \code{\link{drill_up}},
\code{\link{killall_drill}}
}
\concept{Drill Docker functions}
Loading…
Cancel
Save