Este conteúdo não está disponível no idioma selecionado.
1.4. AdminShell
1.4.1. AdminShell Features
- Administration
- AdminShell can be used to connect to a JBoss Data Virtualization instance in order to perform various administrative tasks.
- Data Access
- AdminShell can be used to connect to a virtual database (VDB) and run SQL commands to query VDB data and view results.
- Migration
- AdminShell can be used to develop scripts that will move VDBs and associated components from one development environment to another. (Users can test and automate migration scripts before executing them in production deployments.)
- Testing
- The built-in JUnit Test Framework allows users to write regression tests to check system health and data integrity. The written tests validate system functionality automatically, removing the need for manual verification by QA Personnel.
1.4.2. AdminShell Scripting
- All commands and functions are case sensitive.
- Groovy commands are not required to end with a semicolon; this is optional.
- A function will take zero or more parameters as input.
- Function parameters are provided within parentheses.
- String parameters must be provided within single or double quotes.
connectAsAdmin("localhost", "9999", "user", "password", "conn1")
- Other Java classes and methods can be accessed and invoked from within scripts as long as required libraries are already in the class path. (JAR files added to the
lib
directory will be included in the class path automatically.)import my.package.*; myObject = new MyClass(); myObject.doSomething();
Note
disconnect()
command.
References
- For more information about Groovy scripting, refer to http://groovy.codehaus.org/.
- For more information about Groovy scripting and SQL, refer to http://groovy.codehaus.org/Database+features.
- For more information about testing using Groovy scripting, refer to http://groovy.codehaus.org/Unit+Testing and http://junit.org/.
1.4.3. AdminShell Help
adminHelp()
method (note that only the custom AdminShell methods will be shown):
adminHelp()
adminHelp("METHOD")
:
adminHelp("deploy") /* *Deploy a VDB from file */ void deploy( String /* file name */) throws AdminException throws FileNotFoundException
sqlHelp()
method to list all SQL extension methods:
sqlHelp()
sqlHelp("METHOD")
.
1.4.4. Install the Interactive AdminShell
Procedure 1.3. Install the AdminShell Anywhere
- Open a command line terminal.
- Go to the AdminShell directory: cd
/EAP_HOME/dataVirtualization/teiid-adminshell/
. - Copy the zipped
teiid-VERSION-adminshell-dist.zip
file to your desired location. - Unzip the AdminShell:
unzip teiid-VERSION-adminshell-dist.zip
1.4.5. Launch the Interactive AdminShell
Procedure 1.4. Launch the Interactive AdminShell
- Run the
./adminshell.sh
command.The log output is as follows:====================================================================== Teiid AdminShell Bootstrap Environment TEIID_HOME = /EAP_HOME/dataVirtualization/teiid-adminshell-VERSION CLASSPATH = /EAP_HOME/dataVirtualization/teiid-adminshell-VERSION/lib/patches/*:/EAP_HOME/dataVirtualization/teiid-adminshell-VERSION/lib/teiid-adminshell-VERSION.jar:/EAP_HOME/dataVirtualization/teiid-adminshell-VERSION/lib/* JAVA = /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/java ====================================================================== ===> [import static org.teiid.adminshell.AdminShell.*; import static org.teiid.adminshell.GroovySqlExtensions.*; import org.teiid.adminapi.*;] Groovy Shell (1.7.2, JVM: 1.7.0_25) Type 'help' or '\h' for help. ------------------------------------------------------------------------------- groovy:000>
The interactive AdminShell is running. At this point you can execute individual commands line by line.
Note
exit
command.
1.4.6. AdminShell Basic Commands
Command | Description |
---|---|
adminHelp(); |
Displays all of the custom AdminShell methods available.
|
adminHelp("METHOD"); |
Displays the definition and input parameters for the AdminShell method supplied.
|
sqlHelp(); |
Displays all of the custom SQL AdminShell methods available.
|
sqlHelp("METHOD"); |
Displays the definition and input parameters for the SQL AdminShell method supplied.
|
println "STRING"; |
Print something to console.
|
sql = connect(); |
Get an extended Groovy SQL connection using the default connection specified in the
connection.properties file.
|
sql.execute("SQL"); |
Run any SQL command.
|
connectAsAdmin(); |
Connects as an admin user using the default connection specified in the
connection.properties file. This command does not require a VDB name. Note that this is an admin connection, not a JDBC connection, so you cannot issue SQL commands using this connection. Note that if SSL is being used, you would need to adjust the connection URL and the client SSL settings as necessary (typically only for 2-way SSL).
|
println getConnectionName(); |
Returns the active connection name.
|
useConnection("cNAME"); |
Switches to using the given connection.
|
disconnect(); |
Disconnects the active connection.
|
disconnectAll(); |
Disconnects all connections (both active and suspended).
|
1.4.7. Execute a Script in Non-interactive AdminShell
Procedure 1.5. Execute a Script in Non-interactive AdminShell
Open a Command Line Terminal
Run the Script
Run the/adminshell.sh load [-Dparam=value] PATH/FILENAME
command.
Note
-D
can be accessed from within the script file by using System.getProperty()
.
value = System.getProperty("param")
Important
1.4.8. Helpful Tips for the Interactive AdminShell
Command | Description |
---|---|
↑ ('up arrow') |
Displays previous commands executed, starting with the most recent.
|
help |
Displays additional commands provided specifically for use within the interactive shell.
|
The interactive shell uses a special interpreter and displays behavior different from what would be expected from running a Groovy script:
- def statements do not define a variable in the context of the shell; For example, do not use
def x = 1
, usex = 1
. - The shell cannot parse Groovy classes that use annotations.
1.4.9. Save a Script in Interactive AdminShell
Procedure 1.6. Save a Script in Interactive AdminShell
Open the Interactive AdminShell
- Open a command line terminal.
- Navigate to
/EAP_HOME/dataVirtualization/teiid-adminshell-VERSION/
. - Run the
./adminshell.sh
command.
Start Recording to a File
Enter therecord start PATH/FILENAME
command.Enter Desired Commands to Record
Enter a series of commands for which you want to record the input/output.Stop Recording to the File
Enter therecord stop
command.
All input and output between the moments you issue the record start
and record stop
commands are captured in PATH/FILENAME.
Note
1.4.10. Execute a Script in Interactive AdminShell
Procedure 1.7. Execute a Script in Interactive AdminShell
Open the Interactive AdminShell
- Open a command line terminal.
- Navigate to
/EAP_HOME/dataVirtualization/teiid-adminshell-VERSION/
. - Run the
./adminshell.sh
command.
Run the Script
Run the Script using the Interactive Shell
load
CommandRun theload PATH/FILENAME
command.Run the Script using the Groovy
evaluate
CommandRun theevaluate("PATH/FILENAME" as File)
command.
Note
1.4.11. Launch the AdminShell GUI
Procedure 1.8. Launch the AdminShell GUI
Navigate to the
adminshell
Directory- Open a command line terminal.
- Navigate to
/EAP_HOME/dataVirtualization/teiid-adminshell-VERSION/
.
Launch the
adminshell-console
ScriptRun the./adminshell-console.sh
command.
The AdminShell GUI is displayed.
Note
1.4.12. Save a Script in AdminShell GUI
Procedure 1.9. Save a Script in AdminShell GUI
Navigate to the
adminshell
Directory- Open a command line terminal.
- Navigate to
/EAP_HOME/dataVirtualization/teiid-adminshell-VERSION/
.
Type a Script
Type your script in the upper script window of the AdminShell GUI. You may find it useful to test the script as you are preparing it by executing it via. Save the Script
- Select
. - Choose a location and filename for the script and click on.
1.4.13. Execute a Script in AdminShell GUI
Procedure 1.10. Execute a Script in AdminShell GUI
Open the AdminShell GUI
- Open a command line terminal.
- Navigate to
/EAP_HOME/dataVirtualization/teiid-adminshell-VERSION/
. - Run the
./adminshell-console.sh
command.
Prepare the Script
Type a New Script
Type your script in the upper script window of the AdminShell GUI.Load a Saved Script
- Select
. - Locate the desired script file and click on.The script will appear in the upper script window of the AdminShell GUI.
Run the Script
Select.
1.4.14. AdminShell Connection Properties
EAP_HOME/dataVirtualization/teiid-adminshell-VERSION/connection.properties
file provides the default connection properties used by AdminShell to connect to an JBoss Data Virtualization instance:
jdbc.user=user jdbc.password=user jdbc.url=jdbc:teiid:admin@mm://localhost:31000; admin.host=localhost admin.port=9999 admin.user=admin admin.password=admin
connect()
or connectionAsAdmin()
without any input parameters will connect to JBoss Data Virtualization using the settings defined in this properties file. connect()
uses those properties prefixed with jdbc
and connectAsAdmin()
uses those properties prefixed with admin
. Alternatively, you can include parameters in the connect()
or connectAsAdmin()
methods to connect using properties of your choice:
connect("URL", "USER", "PASSWORD")
Warning
1.4.15. Multiple Connections in AdminShell
getConnectionName()
method returns the name of the active connection. The connection name can be assigned to a variable cName by the following command:
cName = getConnectionName();
useConnection()
command, supplying the name (or a variable with the name assigned) of the connection you wish to use:
useConnection(cName);
The following example demonstrates how to use two connections and switch between them:
// Create a connection connectAsAdmin(); //Assign the connection name to conn1 conn1 = getConnectionName(); deploy("file.vdb") // Create a second connection (which is now the active connection) connectAsAdmin(); //Assign the new connection name to conn2 conn2 = getConnectionName(); deploy("file.vdb") // Switch the active connection back to conn1 useConnection(conn1); // Close the active connection (conn1) disconnect();
1.4.16. Example Scripts
Example 1.1. Deploying a VDB
connectAsAdmin(); deploy("/path/to/<name>.vdb"); // check to validate the deployment VDB vdb = getVDB("<name>", 1); if (vdb != null){ print (vdb.getName()+"."+vdb.getVersion()+" is deployed"; } else { print ("<name>.vdb failed to deploy"; }
Example 1.2. Create a Datasource (Oracle)
connectAsAdmin(); // first deploy the JDBC jar file for Oracle deploy("ojdbc6.jar"); props = new Properties(); props.setProperty("connection-url","jdbc:oracle:thin:@<host>:1521:<sid>"); props.setProperty("user-name", "scott"); props.setProperty("password", "tiger"); createDataSource("oracleDS", "ojdbc6.jar", props);
Example 1.3. Execute SQL Query against Teiid
sql = connect("jdbc:teiid:<vdb>@mm://<host>:31000", "user", "user"); // select sql.eachRow("select * from sys.tables") { println "${it}" } // update, insert, delete sql.execute(<sql command>);
1.4.17. AdminShell FAQ
- Q: Why won't the adminhelp command work in the GUI tool?
- Q: Are there any pre-built scripts available?
- Q: What is the difference between connectAsAdmin() and connect()?
- Q: What does getAdmin() do? Why do I need it?
- Q: Is IDE support available for writing the scripts?
- Q: Can I use AdminShell methods in other environments?
- Q: Is debugging support available?
adminhelp
command work in the GUI tool?
load
, help
, and adminhelp
, since they are not directly supported by Groovy. In the GUI you should use the equivalent functional form; for example, instead of using adminhelp
use adminHelp()
.
connectAsAdmin()
and connect()
?
connectAsAdmin()
method creates a contextual connection to the AdminAPI of JBoss Data Virtualization. The connect()
method returns an extension of the Groovy SQL object to be used for SQL calls to JBoss Data Virtualization.
getAdmin()
do? Why do I need it?
getAdmin()
method returns the current contextual connection object that was created when you connected with connectAsAdmin()
. This object implements the interface org.teiid.adminapi.Admin . The AdminShell commands provided are wrappers around this API. Advanced users can use this API directly if the provided wrapper commands do not meet their needs.
EAP_HOME/dataVirtualization/teiid-adminshell-VERSION/lib/teiid-VERSION.jar
and EAP_HOME/dataVirtualization/teiid-adminshell-VERSION/lib/teiid-adminshell-VERSION.jar
are in your class path.
import static org.teiid.adminshell.AdminShell.*; import org.teiid.adminapi.*;