CRaSH: the shell for the Java Platform

29
CRaSH THE SHELL FOR THE JAVA PLATFORM SEPTEMBER 2013 @julienviet @defrancea

description

Learn how to provide a powerful command line interface to your JVM with CRaSH the shell for the Java Platform. CRaSH is an open source shell for extending and monitoring a Java Virtual Machine. The shell can be accessed by various means, either remotely using network protocols such as SSH or locally by attaching a shell to a running virtual machine. Commands are written in the Groovy language and can be developed live making the extensibility of the shell easy with quick development cycles. CRaSH comes with a bunch of commands such as thread management, log management, database access and JMX. The session will begin with an introduction to the shell, showing basic CRaSH features like auto completion and basic commands. The main part of the quickie will focus on showing how to develop CRaSH commands with several examples, showing how easy and powerful the development of a command can be. The target audience is pretty much anyone using a JVM. Attendees will learn how to install CRaSH, connect to an instance and develop a CRaSH command to interact with virtual machine resources or services.

Transcript of CRaSH: the shell for the Java Platform

Page 1: CRaSH: the shell for the Java Platform

CRaSHT H E S H E L L F O R T H E J AVA P L AT F O R M

S E P T E M B E R 2 0 1 3

@julienviet@defrancea

Page 2: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 2

JULIEN VIET

−Contact

[email protected]−@julienviet−http://github.com/vietj

−Open source for 10 years

−Official mission: deliver enterprise grade portal server

−Marseille JUG Leader

−Involved in Java Community Process

Page 3: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 3

WHAT IS EXO PLATFORM?

eXo Platform is an open source social collaboration software solution designed for the Enterprise.

It is full featured, standard based, extensible and has an amazing design.

eXo Platform is featured in Gartner's Magic Quadrant for Horizontal Portal Products 2012 as a User eXperience Platform.

Page 4: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 4

ALAIN DEFRANCE

−Contact

[email protected]−@alaindefrance−http://github.com/defrancea

−Open source for 3 years

−Contributed to open source projects like Crash

−Marseille JUG Leader

Page 5: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 5

BITTITAN

−SAAS Products

−MigrationWiz: Email migration−SMTPLogic: SMTP gateway−UserActivation: Easy onboarding to

Office365

−Our blog−http://blog.bittitan.com

Page 6: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 6

CRASH PROJECT

−Latest stable 1.2

−Work in progress 1.3

−Licensed under LGPL

−Compatibility

−Java 6+−Groovy 1.7+

Page 7: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 7

KEY CONCEPTS

−Command Line Interface for JVM

−Create easily and quickly commands

−Compose commands into pipelines

−Connectors provide local or remote access

Page 8: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 8

MODULAR DESIGN

−Core, connectors, plugins

−Only use what you need

−Memory−Dependencies

Page 9: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 9

CONNECTORS

−Defines shell interactions

−Asynchronous design

−Implemented by

−System.in / System.out−Telnet−SSH−Web−Attach

Page 10: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 10

PLUGIN ARCHITECTURE

−Keep core small and lightweight

−New features without impacting core

−Current plugins

−Authentication: simple, jaas, key, crowd, …−Languages: java, groovy, ruby, …−Services: mail, cron, …

Page 11: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 11

USER INTERFACE

−Interactive Real-Eval-Print-Loop

−SSH asynchronous execution

−Cron based execution (1.3)

Page 12: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 12

POLYGLOT

−Leverage polyglot JVM ecosystem

−Groovy

−Commands−REPL (1.3)

−Java

−Commands (1.3)

−Ruby work in progress

Page 13: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 13

EXECUTION MODES

−Standalone

−Attach to a running JVM

−Embedded

−Servlet listener−Spring−Guice−Grails−VisualVM

Page 14: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 14

BASE COMMANDS

−Covers JVM packages

−system−jdbc−jndi−jmx

−Utilities: filter, sort, egrep, sleep

Page 15: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 15

STANDALONE DEMO

Page 16: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 16

JNDI/JDBC/JPAATTACH

DEMO

Page 17: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 17

WRITING A COMMAND

public class mycommand {

@Command

@Usage(“the command”)

public void main(

@Usage(“foo option”)

@Option(names=[ “foo”]) String foo,

@Usage(“command arguments”)

@Argument List<String> args) {

}

}

% mycommand –foo the_option value1 value2

Page 18: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 18

EMBEDDED

−Trivial to embed

−Programmatic−Spring−Guice−Servlet listener

−Levels

−Embed−Virtual file system

Page 19: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 19

EMBEDDED BY

Page 20: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 20

SPRING EMDEDDEDTWITTER COMMAND

DEMO

Page 21: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 21

GIT LIKE COMMAND

public class git { @Command public void add(…) {…}

@Command public void commit(…) {…} …}

% git add .% git commit –m “feature implemented”

Page 22: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 22

TYPES

−String, primitive types, enums

−Converter

−properties, jmx object name …

−Completer

−java.io.File−system property name−enums−…

Page 23: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 23

COMMAND PIPE

% jmx find …

jmx find

ObjectName Map

jmx get

sort

Page 24: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 24

COMMAND PIPE

public class wc {

@Command

public PipeCommand<String, Integer>) main() {

return new PipeCommand<String, Integer>() {

int count = 0;

public void provide(String s) {

count += s.split(“\n”).length;

}

public void close() {

context.provide(count);

}

}

}

}

Page 25: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 25

JMX PIPE DEMO

Page 26: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 26

MAIL/CRONDEMO

Page 27: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 27

READ-EVAL-PRINT-LOOP

−Feature of 1.3

−Polyglot

Page 28: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 28

REPLDEMO

Page 29: CRaSH: the shell for the Java Platform

www.exoplatform.com - Copyright 2012 eXo Platform 29

WRAP UP

−A multi facet, powerful and extensible tool for all of us

−Try online : try.crashub.org

−Reach us at

−crashub.org−@crashub−[email protected]