qaecology / boab

Files for administering Boab server
0 stars 0 forks source link

Headless exception error #4

Open cvisintin opened 5 years ago

cvisintin commented 5 years ago

https://github.com/qaecology/boab/blob/7baf111575d9622d3a35f587b0cc98748b23d7c9/Dockerfile#L185-L186

When initiating NetLogo, we get an error in about a headless exception. It would be great to have this work without additional tinkering...

jdyen commented 5 years ago

What do you mean by initiating NetLogo? In your current image (qaeco_lab:latest) I can install and run the RNetLogo package in R, as long as I add java-8 to the library path: Sys.setenv(LD_LIBRARY_PATH=paste("/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/", Sys.getenv("LD_LIBRARY_PATH"), sep=":"))

cvisintin commented 5 years ago

Meaning when I spin up the container, login to rstudio, load the RNetLogo package, and run the function NLStart():

library("RNetLogo") nlheadless1 <- "nlheadless1" nl.path <- "/opt/NetLogo_6.1.0/app" NLStart(nl.path, gui=F, nl.obj=nlheadless1, nl.jarname = "netlogo-6.1.0.jar")

Error in .jcall(preobj, "S", "cpsettings", .jnew("java/lang/String", nl.path), : java.awt.HeadlessException

It would be good to get this working automatically - perhaps we can run those commands in the create user script?

jdyen commented 5 years ago

Ugh, this is awful. I know this isn't the solution you're after, but these are the steps we need within an R session:

  1. update path: Sys.setenv(LD_LIBRARY_PATH=paste("/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/", Sys.getenv("LD_LIBRARY_PATH"), sep=":"))
  2. install RNetLogo: install.packages("RNetLogo")
  3. load java for rJava: dyn.load("/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so")
  4. Then you can load rNetLogo and your NLStart() example works fine.
cvisintin commented 5 years ago

So can we put that in a dockerfile or user creation script? Can you execute those on the command line? Do we absolutely need to be in an rsession?

jdyen commented 5 years ago

I think your approach with setting the PATH is pretty close for my steps 1 and 2. It's just that R gets the PATH from .Renviron file not from the system PATH (https://csgillespie.github.io/efficientR/3-3-r-startup.html#rprofile). So we could possibly edit that directly: RUN echo "LB_LIBRARY_PATH=${JAVA_HOME}:${LD_LIBRARY_PATH}" >> /usr/local/lib/R/etc/Renviron

cvisintin commented 5 years ago

Sounds feasible. Thanks for working on this.

cvisintin commented 5 years ago

Well tried adding the commands to a dockerfile with no luck, LB_LIBRARY_PATH not being set.

cat /usr/local/lib/R/etc/Renviron

### etc/Renviron.  Generated from Renviron.in by configure.
###
### ${R_HOME}/etc/Renviron
###
### Record R system environment variables.

R_PLATFORM=${R_PLATFORM-'x86_64-pc-linux-gnu'}
## Default printer paper size: first record if user set R_PAPERSIZE
R_PAPERSIZE_USER=${R_PAPERSIZE}
R_PAPERSIZE=${R_PAPERSIZE-'letter'}
## Default print command
R_PRINTCMD=${R_PRINTCMD-'/usr/bin/lpr'}
# for Rd2pdf, reference manual
R_RD4PDF=${R_RD4PDF-'times,inconsolata,hyper'}
## used for options("texi2dvi")
R_TEXI2DVICMD=${R_TEXI2DVICMD-${TEXI2DVI-'/usr/bin/texi2dvi'}}
## used by untar(support_old_tars = TRUE) and installing grDevices
R_GZIPCMD=${R_GZIPCMD-'/bin/gzip'}
## Default zip/unzip commands
R_UNZIPCMD=${R_UNZIPCMD-'/usr/bin/unzip'}
R_ZIPCMD=${R_ZIPCMD-'/usr/bin/zip'}
R_BZIPCMD=${R_BZIPCMD-'/bin/bzip2'}
## Default browser
R_BROWSER=${R_BROWSER-'xdg-open'}
## Default editor
EDITOR=${EDITOR-${VISUAL-vi}}
## Default pager
PAGER=${PAGER-'/usr/bin/pager'}
## Default PDF viewer
R_PDFVIEWER=${R_PDFVIEWER-'/usr/bin/xdg-open'}
## Used by libtool
LN_S='ln -s'
MAKE=${MAKE-'make'}
## Prefer a POSIX-compliant sed on e.g. Solaris
SED=${SED-'/bin/sed'}
## Prefer a tar that can automagically read compressed archives
TAR=${TAR-'/bin/tar'}

## System and compiler types.
R_SYSTEM_ABI='linux,gcc,gxx,gfortran,gfortran'

## Strip shared objects and static libraries.
R_STRIP_SHARED_LIB=${R_STRIP_SHARED_LIB-'strip --strip-unneeded'}
R_STRIP_STATIC_LIB=${R_STRIP_STATIC_LIB-'strip --strip-debug'}

R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/3.6'}
#R_LIBS_USER=${R_LIBS_USER-'~/Library/R/3.6/library'}

### Local Variables: ***
### mode: sh ***
### sh-indentation: 2 ***
### End: ***
LB_LIBRARY_PATH=${JAVA_HOME}:${LD_LIBRARY_PATH}
LANG=en_US.UTF-8
HOSTNAME=edae9edf069c
R_LIBS_USER=~/.r-dir/R/library
PASSWORD=NTdjMmM3NDhh
USER=test
ROOT=FALSE
PWD=/
HOME=/home/test
https_proxy=http://wwwproxy.unimelb.edu.au:8000/
DEBIAN_FRONTEND=noninteractive
http_proxy=http://wwwproxy.unimelb.edu.au:8000/
SUPERVISOR_PROCESS_NAME=userconf
EMAIL=user@unknown.com
SUPERVISOR_ENABLED=1
SHLVL=1
LANGUAGE=en_US.UTF-8
SUPERVISOR_GROUP_NAME=userconf
PATH=/opt/julia:/usr/lib/rstudio-server/bin:/opt/julia:/usr/lib/rstudio-server/bin:/zonation/zig4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SUPERVISOR_SERVER_URL=unix:///var/run/supervisor.sock
USERID=1081
_=/usr/bin/env
LANG=en_US.UTF-8
HOSTNAME=edae9edf069c
R_LIBS_USER=~/.r-dir/R/library
PASSWORD=NTdjMmM3NDhh
USER=test
ROOT=FALSE
PWD=/
HOME=/home/test
https_proxy=http://wwwproxy.unimelb.edu.au:8000/
DEBIAN_FRONTEND=noninteractive
http_proxy=http://wwwproxy.unimelb.edu.au:8000/
SUPERVISOR_PROCESS_NAME=userconf
EMAIL=user@unknown.com
SUPERVISOR_ENABLED=1
SHLVL=1
LANGUAGE=en_US.UTF-8
SUPERVISOR_GROUP_NAME=userconf
PATH=/opt/julia:/usr/lib/rstudio-server/bin:/opt/julia:/usr/lib/rstudio-server/bin:/zonation/zig4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SUPERVISOR_SERVER_URL=unix:///var/run/supervisor.sock
USERID=1081
_=/usr/bin/env
LANG=en_US.UTF-8
HOSTNAME=edae9edf069c
R_LIBS_USER=~/.r-dir/R/library
PASSWORD=NTdjMmM3NDhh
USER=test
ROOT=FALSE
PWD=/
HOME=/home/test
https_proxy=http://wwwproxy.unimelb.edu.au:8000/
DEBIAN_FRONTEND=noninteractive
http_proxy=http://wwwproxy.unimelb.edu.au:8000/
SUPERVISOR_PROCESS_NAME=userconf
EMAIL=user@unknown.com
SUPERVISOR_ENABLED=1
SHLVL=1
LANGUAGE=en_US.UTF-8
SUPERVISOR_GROUP_NAME=userconf
PATH=/opt/julia:/usr/lib/rstudio-server/bin:/opt/julia:/usr/lib/rstudio-server/bin:/zonation/zig4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SUPERVISOR_SERVER_URL=unix:///var/run/supervisor.sock
USERID=1081
_=/usr/bin/env
LANG=en_US.UTF-8
HOSTNAME=edae9edf069c
R_LIBS_USER=~/.r-dir/R/library
PASSWORD=NTdjMmM3NDhh
USER=test
ROOT=FALSE
PWD=/
HOME=/home/test
https_proxy=http://wwwproxy.unimelb.edu.au:8000/
DEBIAN_FRONTEND=noninteractive
http_proxy=http://wwwproxy.unimelb.edu.au:8000/
SUPERVISOR_PROCESS_NAME=userconf
EMAIL=user@unknown.com
SUPERVISOR_ENABLED=1
SHLVL=1
LANGUAGE=en_US.UTF-8
SUPERVISOR_GROUP_NAME=userconf
PATH=/opt/julia:/usr/lib/rstudio-server/bin:/opt/julia:/usr/lib/rstudio-server/bin:/zonation/zig4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SUPERVISOR_SERVER_URL=unix:///var/run/supervisor.sock
USERID=1081
_=/usr/bin/env
jdyen commented 5 years ago

Two things:

jdyen commented 5 years ago

There a few symlinks already in the dockerfile (e.g. for julia and for landis). I'm trying out some variations to see if I can get that working. No luck yet.

cvisintin commented 5 years ago

Thanks mate. With the typo fixed:

java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.

Then using: unset DISPLAY

java.lang.Error: no ComponentUI class for: javax.swing.JOptionPane[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=,icon=,initialValue=,message=Error in setting cp. Class path is :/usr/local/lib/R/site-library/rJava/java/boot:/usr/local/lib/R/site-library/RNetLogo/java:/usr/local/lib/R/site-library/RNetLogo/java/RNetLogo.jar,messageType=WARNING_MESSAGE,optionType=DEFAULT_OPTION,wantsInput=false] at java.desktop/javax.swing.UIDefaults.getUIError(UIDefaults.java:760) at java.desktop/javax.swing.MultiUIDefaults.getUIError(MultiUIDefaults.java:133) at java.desktop/javax.swing.UIDefaults.getUI(UIDefaults.java:790) at java.desktop/javax.swing.UIManager.getUI(UIManager.java:1065) at java.desktop/javax.swing.JOptionPane.updateUI(JOptionPane.java:1873) at java.desktop/javax.swing.JOptionPane.(JOptionPane.java:1838) at java.desktop/javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:862) at java.desktop/javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:670) at java.desktop/javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:641) at nlcon.Preprocess.cpsettings(Preprocess.java:71) Error in .jcall(preobj, "S", "cpsettings", .jnew("java/lang/String", nl.path), : java.lang.NoClassDefFoundError: Could not initialize class java.awt.GraphicsEnvironment$LocalGE

jdyen commented 5 years ago

OK, I can get these errors now if I set JAVA_HOME within an R session (in a container). FWIW, I don't think Java 11 is the issue -- I get the second error immediately if I set JAVA_HOME to java 11. So does that mean the headless exception error is R not finding java at all, and then we have this new issue to work out?

jdyen commented 5 years ago

@cvisintin, @goldingn, I can get the following working with the current docker file:

# add this line to load the java DLL
dyn.load("/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so")

# as before
library(RNetLogo)
nl.path <- "/opt/NetLogo_6.1.0/app"
nlheadless1 <- "nlheadless1"
NLStart(nl.path, gui = FALSE, nl.obj = nlheadless1, nl.jarname = "netlogo-6.1.0.jar")

Is this a fix in itself? I don't see how we can dynamically load this DLL in every session without breaking other things (for example, this breaks maxent, which I assume is using java 11).

Additional point, even with this fix I still get NetLogo errors if I try to go further and use:

model.path <- "/models/Sample Models/Earth Science/Fire.nlogo"
NLLoadModel(paste(nl.path,model.path,sep=""), nl.obj=nlheadless1)

[1] "Java-Object{java.lang.NoSuchMethodError: org.nlogo.workspace.Controllable.open(Ljava/lang/String;)V}" Error in NLLoadModel(paste(nl.path, model.path, sep = ""), nl.obj = nlheadless1) :

jdyen commented 5 years ago

OK -- explicitly setting R's JAVA_HOME variable in the dockerfile means we no longer need the dyn.load call, which is nice.

But still getting this error: "Java-Object{java.lang.NoSuchMethodError: org.nlogo.workspace.Controllable.open(Ljava/lang/String;)V}"

My googling suggests that this happens when the Java used to compile the model doesn't match the Java used to run it. Is that plausible? If so, how might we fix it? I've tried forcing java versions when installing rJava and RNetLogo, with no success.

jdyen commented 5 years ago

This line: RUN update-java-alternatives -s java-1.8.0-openjdk-amd64 will tell R to use java 8, but it doesn't solve the netlogo issue.

jdyen commented 5 years ago

Have tried quite a few different things, including compiling NetLogo from source within a container. Not fixed the issue. My suggestion is to pull NetLogo from the main container and set up a second image specifically designed to get NL working. One option for this image to use an older ubuntu release that doesn't require java11.

Jonathan463 commented 1 month ago

From what I have read so far, does it mean RNetLogo only support Java 8? @jdyen