Documente Academic
Documente Profesional
Documente Cultură
Table of Contents
Table of Contents.......................................................................................................................................... 1
1. Introduction ........................................................................................................................................... 2
1.1. Overview ..................................................................................................................................... 2
2. Best Practice........................................................................................................................................... 3
2.1. Before We Begin ......................................................................................................................... 3
2.1.1. A Brief Overview of the BLCLI............................................................................................. 3
2.1.2. How is the BLCLI useful? ...................................................................................................... 3
2.1.3. How do I read the BLCLI API?.............................................................................................. 3
2.1.4. Common Uses of the BLCLI.................................................................................................. 4
2.2. Caching Credentials .................................................................................................................... 4
2.2.1. Encoded .dat File .................................................................................................................... 4
2.2.2. BLTray Utility ........................................................................................................................ 5
2.3. Server / Proxy Mode.................................................................................................................... 5
2.3.1. blcli2.exe ................................................................................................................................ 6
2.3.2. Without blcli2.exe .................................................................................................................. 6
2.4. Other Possibilities for Increasing Speed of the BLCLI ............................................................... 8
2.4.1. Using the Subshell .................................................................................................................. 8
2.4.2. Experimental: Using Jython ................................................................................................... 8
2.5. Options and Recommendations for Production Implementation................................................. 9
2.5.1. Starting Server from Within Script......................................................................................... 9
2.5.2. Running Server as Service...................................................................................................... 9
3. Behind the Scenes .................................................................................................................................. 9
3.1. How the BLCLI works ................................................................................................................ 9
3.1.1. Released / Unreleased Commands........................................................................................ 10
3.1.2. Context and the Target Object .............................................................................................. 10
3.1.3. API Commands..................................................................................................................... 11
3.1.4. Load Commands................................................................................................................... 11
3.1.5. Save Commands ................................................................................................................... 11
3.1.6. Procedure Commands........................................................................................................... 11
3.2. Complex Commands ................................................................................................................. 12
3.2.1. Complex Commands – Piece by Piece ................................................................................. 12
3.2.2. SmartServerGroup createNewGroup Explained................................................................... 14
4. Appendices ........................................................................................................................................... 17
4.1. BLCLI Usage and Flags ............................................................................................................ 17
4.2. Troubleshooting the BLCLI ...................................................................................................... 17
4.3. Compiling Unreleased API Documentation .............................................................................. 17
1 of 18
©2004 BladeLogic, Inc. All rights reserved.
Confidential and Proprietary
1. Introduction
1.1. Overview
The goal of this document is to discuss the Best Practices for using the
BladeLogic Command Line Interface, better known as the BLCLI. In its present
form, this document is intended to remain internal to BladeLogic Professional
Services, as it will explore some aspects of the BLCLI functionality not yet
completely available to our customers. There is a trimmed-down version of this
document available for our clients.
The next section provides an in depth look at how the BLCLI works, unreleased
commands, session context, and command types. This section also explains each
section of a complex command, in detail, before explaining in detail a specific
example command, SmartServerGroup createNewGroup.
Finally, the appendices discuss usage details of the BLCLI. Next, the paper looks
at how to troubleshoot building BLCLI Complex commands, before finally
explaining how to compile the API documentation for unreleased BLCLI
commands.
2 of 18
©2004 BladeLogic, Inc. All rights reserved.
Confidential and Proprietary
2. Best Practice
2.1. Before We Begin
2.1.1. A Brief Overview of the BLCLI
The BladeLogic Command Line Interface is a Java-based command line tool,
hence its name, for accessing BladeLogic API operations. Though released
functionality remains somewhat limited, a sufficiently sophisticated user could
conceivably use the BLCLI to complete any operations through the command line
that would traditionally be only accessible via the BladeLogic GUI. The BLCLI
tool accepts input from the command line, parses that input, and processes that
input against XML-formatted commands to become the user’s bridge to the
BladeLogic API.
The BLCLI is not a shell. It is its own application command line interface, as
every command line execution requires the BLCLI to startup and shutdown. As
each instance of a BLCLI execution requires the Java Virtual Machine (JVM) to
start and for the BLCLI to authenticate against the Application Server, by default,
each BLCLI command takes a significant amount of time to execute. There are
ways to get around this, and we will discuss them in more detail later in this
document.
Each BLCLI command is broken down into three parts, Namespace, Command,
and Arguments. These are defined in the XML command descriptor files that the
BLCLI uses to know how to execute each command. The BLCLI commands
should take the following format:
The argument number and data type(s) depend on the command and are explained
in the API documentation available in the Doc directory of each Operations
Manager installation. BLCLI commands can be scripted using Network Shell,
Perl Scripts, Batch Jobs, or other languages that can execute system calls.
3 of 18
©2004 BladeLogic, Inc. All rights reserved.
Confidential and Proprietary
The BLCLI API is a set of HTML files organized into 3 frames. The left top
frame is the list of namespaces, with the commands for the selected namespace in
the frame below that. The namespace commands appear in the main frame along
with descriptions, return types, and argument lists. The argument lists are in a
table but, of course, should be passed as command line arguments when executing
the BLCLI. Arguments as String data types require quotes if the value has any
white space.
The BLCLI can be used to load bulk data into the BladeLogic system via a script.
Using BLCLI extended functionality, we can write a script to parse a formatted
data file and pre-load virtually any data into the BladeLogic system with BLCLI
commands during the initial implementation.
We can use the BLCLI command to sidestep issues. One recent use involved
setting up a NSH script job to call a script that would retrieve information from
BladeLogic, use that information to compile a SQL statement, and execute that
SQL statement against the BladeLogic database. This solves a problem of setting
BlPackage ownership, a construct that does not presently exist within the
BladeLogic code base.
On UNIX, the task is much simpler. The BladeLogic server runs as bladmin and
the <user_home> directory can be determined either by running sudo –u
bladmin echo $HOME as root or as a user with root privileges or by becoming
the bladmin user and running cd ~; pwd.
In order to instantiate the BLCLI server with blcli2, execute the following
command from within Network Shell:
Where <port#> is port on which the server should listen, and –m server starts the
BLCLI in server mode. The port most often used is 5555. This process will open
a listening port on the specified port number that will listen for BLCLI commands
to be sent from the client.
To utilize the BLCLI proxy using blcli2, call blcli2 with the following
command from Network Shell:
Where <port#> is the same port specified in the instantiation of the server, telling
the BLCLI through which port to connect to proxy.
6 of 18
©2004 BladeLogic, Inc. All rights reserved.
Confidential and Proprietary
In Windows, assuming that a user has installed Operations Manager in the default
C:\Program Files\BladeLogic directory, the following batch files will
instantiate the server mode and the proxy client.
Windows:
blcliserver.bat
@echo off
clear
set PORT=-Dcom.bladelogic.cli.port=5555
echo BladeLogic CLI server connected to application server %srvr% on port %portnum%.
echo Press CTRL+C to exit.
blcliproxy.bat
@echo off
$JAVA_HOME/bin/java -Dblx.cmrootdir=$BLADELOGIC_HOME/br \
-Dcom.bladelogic.cli.xmldir=$BLADELOGIC_HOME/br/xml/cli \
-Dcom.bladelogic.cli.port=5555 \
com.bladelogic.cli.CLIMain "${@}" -m server
Blcliproxy
#!/bin/sh
BLADELOGIC_HOME=/usr/nsh
JAVA_HOME=/usr/nsh/br/java
BLDEPLOY=$BLADELOGIC_HOME/br
STDLIB=$BLDEPLOY/stdlib
CLASSPATH=$BLADELOGIC_HOME/br:$BLADELOGIC_HOME/br/bladelogic.jar:$JAVA_HOME/jre/lib/rt.jar:
$STDLIB:$STDLIB/activation.jar:$STDLIB/jaxp.jar:$STDLIB/log4j-1.2.4.jar:$STDLIB/looks-1.1.2.jar:
$STDLIB/mailapi.jar:$STDLIB/msbase.jar:$STDLIB/mssqlserver.jar:$STDLIB/msutil.jar:$STDLIB/mysql.jar:
$STDLIB/oracle.jar:$STDLIB/parser.jar:$STDLIB/smtp.jar:$STDLIB/xerces.jar:$STDLIB/xml-writer.jar
PATH=/usr/nsh/bin:/usr/nsh/sbin:$PATH
LD_LIBRARY_PATH=${LD_LIBRARY_PATH:=}${LD_LIBRARY_PATH:+:}$BLADELOGIC_HOME/lib
export JAVA_HOME CLASSPATH LD_LIBRARY_PATH PATH
$JAVA_HOME/bin/java -Dblx.cmrootdir=$BLADELOGIC_HOME/br \
-Dcom.bladelogic.cli.xmldir=$BLADELOGIC_HOME/br/xml/cli \
-Dcom.bladelogic.cli.port=5555 \
com.bladelogic.cli.CLIClient "${@}"
If there are many BLCLI commands to be executed at once, the results of which
do not rely on one another, then one can pass them to the subshell by running cat
against a file full of BLCLI namespaces and commands, and piping it to blcli –
m subshell.
This tool allows scripting in Jython, with all BLCLI calls made directly through
the Java classes, due to Jython’s native interoperability with Java. With this
approach, the Jython code imports the Java libraries, authenticates against the
Application Server, and makes BLCLI calls directly via the Jython interface with
Java. This best-of-all-worlds hybrid solution combines the speed of the BLCLI
8 of 18
©2004 BladeLogic, Inc. All rights reserved.
Confidential and Proprietary
server with the scripting capabilities of Network Shell or Perl. Because the
Jython tool makes a single connection and then runs all commands through Java,
essentially, we are scripting the BLCLI subshell.
The BLCLI operates in sessions, whether in the execution of a command from the
command line or in subshell mode. For each instance of a BLCLI session,
execution of these commands is linear, and data passes between them via the
BLCLI’s concept of context. Context is persistent from when a session begins
until the session ends. The context is NULL when a session begins, and any
attempt to access the context will result in a thrown Java exception.
When a Load command is executed, the resulting object is loaded into memory as
the context, and any API command can be executed against that without explicitly
requiring an argument. Strings, integers, and boolean values cannot be stored in
context, but “Model Objects” can. When returning strings, integers, or boolean
data in a complex command, we can save into the BLCLIs session memory, into a
list of what are called Named Objects. This will make more sense as we discuss
Load and Complex commands.
Once an object handle is loaded into the context via a Load command, it becomes
known as the Target Object. It remains the BLCLI target object for the duration
of the execution of that BLCLI command until it is overridden by the loading of
another object into context, or until a different target object is explicitly set within
the code. An API command may return a handle to an object, but it will not set
the Target Object because it is not a Load command. If an API command returns
an object handle, we call ‘Utility setTargetObject’ to complete the loading
of the object handle into context.
10 of 18
©2004 BladeLogic, Inc. All rights reserved.
Confidential and Proprietary
is passed and the user is returned the group Id. What really happens is that a
command is run to find that group by name and load the object into context.
Then, another command is run without taking any explicit arguments to get that
group’s Id and return it as the result value. Instead of an explicit argument, it
looks to the BLCLI context.
While most API commands will require a Target Object to be set, some may
operate without a Target Object, creating and setting their own. This applies to
some Load commands (referenced below) and to Factory methods that create new
instances of objects.
11 of 18
©2004 BladeLogic, Inc. All rights reserved.
Confidential and Proprietary
namespace, and do not have corresponding XML commands in the xml/cli
directory.
12 of 18
©2004 BladeLogic, Inc. All rights reserved.
Confidential and Proprietary
<command_inventory>
The <command_inventory> tag is the wrapper around all the commands in the
XML file. Every BLCLI XML file needs a <command_inventory> tag at the
beginning (after the <xml> and <doctype> tags) and again at the end to close the
tag.
<name_space name=””>
The <name_space> tag wraps around all the commands for a given namespace.
This namespace becomes the case-sensitive first argument passed before each
BLCLI command. The standard naming convention is that of no spaces, but
where the first letter of each new word is capitalized.
<complex_command release=””>
The <complex_command> tag is the XML wrapper tag around all other elements
in the Complex command. Release takes a value of ‘yes’ or ‘no’, where ‘yes’
indicates that a user can access the command directly from the command line. A
value of ‘no’ for release indicates that this command is only accessible from
within other BLCLI Complex commands.
<name></name>
The <name> tag defines the name of the command, and this becomes the argument
to BLCLI after the namespace. The standard naming convention requires no
spaces, where the first letter of each new word is capitalized, but for one
exception. The first letter of each command is in lower case. Complex
commends are allowed to be overloaded. This means that there can be multiple
complex commands with the same name, so long as they have a different number
of arguments.
<description>
The <description> tag wraps around the <author>, <general_info>, and
<result> commands.
<author></author>
As the first author of a command, one should place one’s name between these two
tags.
<general_info></general_info>
The <general_info> tag is a free form text field, and there can be multiple
<general_info> tags. Here, one should describe what the command does, the
date it was written, and should note any edits one has made to the original
command.
<return_value_info></return_value_info>
The <return_value_info> tag tells us which data type or information to expect
as a result of a successful invocation of the command.
</description>
<argument_list>
This is the wrapper around the list of arguments expected from the command line.
<argument name=”” desc=””></argument>
The <argument> tag, of which there may be more than one, tells the Complex
command which argument types to expect for each argument. The name property
takes as a value the name of the argument, to be referenced later as $argName$
and should follow the same naming conventions as the command name. The
desc property gives a description of the argument’s purpose. Between the
<argument></argument> tags we add the argument type, where valid values are
java.lang.String, int, or boolean.
</argument_list>
<commands_to_execute>
13 of 18
©2004 BladeLogic, Inc. All rights reserved.
Confidential and Proprietary
The <commands_to_execute> tags wrap around the series of
<command_invocation> elements.
<command_invocation>
These <command_invocation> commands each ‘invoke’ a BLCLI command, and
wrap around the command input.
<namespace_ref></namespace_ref>
The <namespace_ref> tags tell each command invocation with which namespace
to associate the command, to come next. This is the same as the first argument
passed to the BLCLI executable.
<name></name>
The <name> tag tells the command invocation which command to execute from
the preceding namespace.
<input></input> [<input/>]
The <input> tags pass the input string to the command invocation. This string
must have the same format as command line input. Any strings that may contain
quotes must be delimited by " special characters. A command that does not
require an input should have either nothing between the input tags or just a single
<input/> tag.
<store_result><name></name><store_result>
Often times, an API command will return a string or integer result necessary to
use later in the command invocation. We store this in the BLCLI context list of
named objects. After the <input> tags, we place these <store_result><name>
tags and place the name of the new named object between them. This variable is
referenced later as NAMED_OBJECT=objectName.
</command_invocation>
</commands_to_execute>
This creates a group, though it will not yet contain any conditions and therefore
will not actually show Windows 2003 servers. To determine how to add
conditions and to set the Match-All property on the group, see the full
SmartServerGroup-PSAdditional.xml file available in the Professional
Services Knowledge Base.
14 of 18
©2004 BladeLogic, Inc. All rights reserved.
Confidential and Proprietary
The XML on the following page creates a Complex command that is released to
the command line interface. The name of the Complex command is
createNewGroup. The description lists Brad Jacobs as the author and explains
that this Complex command will create a smart server group with no conditions.
The command will return the database Id of the group with type Integer.
The command takes two arguments, both of type String. One is the
parentGroupName and the other is the groupName.
We use the NAMED_OBJECT that we set in the first command invocation to set the
parent Id of the new smart server group. Because a SmartServerGroup is just an
abstraction of the Group object, we call the ‘Group save’ command next.
Finally, we call SmartServerGroup getGroupId, a command which takes as
input the object in the BLCLI context. As this is the last command in the
Complex command, the result is returned to <STDOUT>.
15 of 18
©2004 BladeLogic, Inc. All rights reserved.
Confidential and Proprietary
SmartServerGroup createNewGroup
<complex_command release="yes">
<name>createNewGroup</name>
<description>
<author>Brad Jacobs</author>
<general_info>Create Smart Server Group with zero conditions. Need addCondition
command below to add conditions.</general_info>
<return_value_info>Integer of Group Id</return_value_info>
</description>
<argument_list>
<argument name="parentGroupName" desc="Qualified name of parent
group.">java.lang.String</argument>
<argument name="groupName" desc="Name of Smart Server
Group.">java.lang.String</argument>
</argument_list>
<commands_to_execute>
<command_invocation>
<namespace_ref>ServerGroup</namespace_ref>
<name>groupNameToId</name>
<input>$parentGroupName$</input>
<store_result><name>parentGroupId</name></store_result>
</command_invocation>
<command_invocation>
<namespace_ref>Utility</namespace_ref>
<name>createModelObject</name>
<input>SmartServerGroup</input>
</command_invocation>
<command_invocation>
<namespace_ref>SmartServerGroup</namespace_ref>
<name>setName</name>
<input>$groupName$</input>
</command_invocation>
<command_invocation>
<namespace_ref>SmartServerGroup</namespace_ref>
<name>setParentGroupId</name>
<input>NAMED_OBJECT=parentGroupId</input>
</command_invocation>
<command_invocation>
<namespace_ref>Group</namespace_ref>
<name>save</name>
<input/>
</command_invocation>
<command_invocation>
<namespace_ref>SmartServerGroup</namespace_ref>
<name>getGroupId</name>
<input/>
</command_invocation>
</commands_to_execute>
</complex_command>
16 of 18
©2004 BladeLogic, Inc. All rights reserved.
Confidential and Proprietary
4. Appendices
4.1. BLCLI Usage and Flags
-D<jvmopt> Pass a single –D flag to the JVM
-X<jvmopt> Pass a single –X flag to the JVM
-a <appserver> Specifies against which Application Server the BLCLI should run.
-c <port> Connect to a BLCLI server listening on the specified port.
-m <mode> Start the BLCLI in server or subshell mode.
-u <user> Assume the specified user upon execution.
-r <role> Assume the specified role upon execution.
-i <user_info.dat> Use the specified user_info.dat file.
blcli2.exe –Dcom.bladelogic.cli.debug.release-only=”false” –m
subshell
set XML_COMMANDS_DIRECTORY=C:\progra~1\bladelogic\om\br\xml\cli
set XML_OUTPUT_DIRECTORY=C:\com.bladelogic\cli-docs
17 of 18
©2004 BladeLogic, Inc. All rights reserved.
Confidential and Proprietary