DsFrameworkCliServer.java revision abb16d70d9d4b5daf29b49db1e78676d4609276a
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2009 Sun Microsystems, Inc.
*/
/**
* This class is handling server group CLI.
*/
public class DsFrameworkCliServer implements DsFrameworkCliSubCommandGroup
{
// Strings used in property help.
private final static Message DESCRIPTION_OPTIONS_TITLE =
private final static Message DESCRIPTION_OPTIONS_READ =
private final static Message DESCRIPTION_OPTIONS_WRITE =
private final static Message DESCRIPTION_OPTIONS_MANDATORY =
private final static Message DESCRIPTION_OPTIONS_SINGLE =
/**
* The subcommand Parser.
*/
private DsFrameworkCliParser argParser;
/**
* The enumeration containing the different subCommand names.
*/
private enum SubCommandNameEnum
{
/**
* The register-server subcommand.
*/
REGISTER_SERVER("register-server"),
/**
* The unregister-server subcommand.
*/
UNREGISTER_SERVER("unregister-server"),
/**
* The list-servers subcommand.
*/
LIST_SERVERS("list-servers"),
/**
* The get-server-properties subcommand.
*/
GET_SERVER_PROPERTIES("get-server-properties"),
/**
* The set-server-properties subcommand.
*/
SET_SERVER_PROPERTIES("set-server-properties"),
/**
* The list-servers subcommand.
*/
LIST_SERVER_PROPERTIES("list-server-properties");
// String representation of the value.
// Private constructor.
{
}
/**
* {@inheritDoc}
*/
{
return name;
}
// A lookup table for resolving a unit from its name.
static
{
{
}
}
{
}
}
/**
* The 'register-server' subcommand.
*/
private SubCommand registerServerSubCmd;
/**
* The 'serverID' argument of the 'register-server' subcommand.
*/
private StringArgument registerServerServerIdArg;
/**
* The 'serverName' argument of the 'register-server' subcommand.
*/
private StringArgument registerServerSetArg;
/**
* The 'unregister-server' subcommand.
*/
private SubCommand unregisterServerSubCmd;
/**
* The 'serverHost' argument of the 'unregister-server' subcommand.
*/
/**
* The 'list-server-properties' subcommand.
*/
private SubCommand listServerPropertiesSubCmd;
/**
* The 'list-servers' subcommand.
*/
private SubCommand listServersSubCmd;
/**
* The 'get-server-properties' subcommand.
*/
private SubCommand getServerPropertiesSubCmd;
/**
* The 'serverID' argument of the 'get-server-properties' subcommand.
*/
/**
* The 'set-server-properties' subcommand.
*/
private SubCommand setServerPropertiesSubCmd;
/**
* The 'serverID' argument of the 'set-server-properties' subcommand.
*/
/**
* The 'serverName' argument of the 'set-server-properties' subcommand.
*/
private StringArgument setServerPropertiesSetArg;
/**
* Association between ADSContext enum and properties.
*/
/**
* List of read-only server properties.
*/
/**
* The subcommand list.
*/
/**
* Indicates whether this subCommand should be hidden in the usage
* information.
*/
private boolean isHidden;
/**
* The subcommand group name.
*/
/**
* {@inheritDoc}
*/
{
return subCommands;
}
/**
* {@inheritDoc}
*/
public boolean isHidden()
{
return isHidden;
}
/**
* {@inheritDoc}
*/
public String getGroupName()
{
return groupName;
}
/**
* {@inheritDoc}
*/
{
isHidden = false;
groupName = "server";
// list-server-properties subcommand
// register-server subcommand
OPTION_SHORT_SET, OPTION_LONG_SET, false, true, true,
// unregister-server subcommand
// list-servers subcommand
// get-server-properties subcommand
// set-server-properties subcommand
OPTION_SHORT_SET, OPTION_LONG_SET, false, true, true,
// Create association between ADSContext enum and server
// properties
// Server properties are mapped to Argument.
/**
* The ID used to identify the server.
*/
{
}
/**
* The host name of the server.
*/
{
}
/**
* The LDAP port of the server.
*/
{
}
/**
* The JMX port of the server.
*/
{
arg.setMultiValued(true);
}
/**
* The JMX secure port of the server.
*/
{
arg.setMultiValued(true);
}
/**
* The LDAPS port of the server.
*/
{
arg.setMultiValued(true);
}
/**
* The certificate used by the server.
*/
{
}
/**
* The path where the server is installed.
*/
{
}
/**
* The description of the server.
*/
{
}
/**
* The OS of the machine where the server is installed.
*/
{
}
/**
* Whether LDAP is enabled or not.
*/
{
}
/**
* Whether LDAPS is enabled or not.
*/
{
}
/**
* Whether StartTLS is enabled or not.
*/
{
}
/**
* Whether JMX is enabled or not.
*/
{
}
/**
* Whether JMXS is enabled or not.
*/
{
}
/**
* The location of the server.
*/
{
}
/**
* The list of groups in which the server is registered.
*/
{
}
/**
* The INSTANCE_KEY_ID used to identify the server key ID.
*/
{
null);
}
/**
* The INSTANCE_PUBLIC_KEY_CERTIFICATE associated to the server.
*/
{
null);
}
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
throws ADSContextException, ArgumentException
{
try
{
// -----------------------
// register-server subcommand
// -----------------------
{
{
}
else
{
}
{
return CANNOT_CONNECT_TO_ADS;
}
}
else
// -----------------------
// unregister-server subcommand
// -----------------------
{
{
}
else
{
}
{
return CANNOT_CONNECT_TO_ADS;
}
// update groups in which server was registered
boolean found = false;
{
{
found = true ;
break ;
}
}
if ( ! found )
{
}
// unregister the server
}
else
// -----------------------
// list-servers subcommand
// -----------------------
{
{
return CANNOT_CONNECT_TO_ADS;
}
{
// print out server ID
}
}
else
// -----------------------
// get-server-properties subcommand
// -----------------------
{
{
return CANNOT_CONNECT_TO_ADS;
}
.getValues();
{
{
continue;
}
// print out server ID
{
{
continue;
}
}
}
}
else
// -----------------------
// set-server-properties subcommand
// -----------------------
{
// if the ID is specify in the --set list, it may mean that
// the user wants to rename the serverID
// replace the serverID in the map
{
return CANNOT_CONNECT_TO_ADS;
}
}
else
// -----------------------
// list-server-properties subcommand
// -----------------------
{
{
{
continue;
}
.get(serverProp)));
{
.getDefaultValue());
}
else
{
}
}
}
else
{
// Should never occurs: If we are here, it means that the code
// to
// handle to subcommand is not yet written.
}
}
catch (ADSContextException e)
{
{
try
{
}
catch (NamingException x)
{
}
}
throw e;
}
// Close the connection, if needed
{
try
{
}
catch (NamingException x)
{
}
}
// return part
return returnCode;
}
// Compute the options field.
{
StringBuilder b = new StringBuilder();
{
}
else
{
}
if (arg.isRequired())
{
b.append('m');
}
else
{
b.append('-');
}
if (arg.isMultiValued())
{
b.append('-');
}
else
{
b.append('s');
}
return b.toString();
}
/**
* Translate a Set properties a to a MAP.
*
* @param propertySetArgument
* The input set argument.
* @return The created map.
* @throws ArgumentException
* If error error occurs during set parsing.
*/
{
{
// Parse the property "property:value".
if (sep < 0)
{
}
if (sep == 0)
{
}
{
}
// Check that propName is a known prop.
if (serverProperty == null)
{
throw new ArgumentException(message);
}
// Check that propName is not hidden.
{
throw new ArgumentException(message);
}
// Check the property Syntax.
{
throw new ArgumentException(message);
}
// add to the map.
}
// Check that all mandatory props are set.
{
{
continue;
}
if (map.containsKey(s))
{
continue ;
}
if ( ! arg.isRequired())
{
continue ;
}
// If we are here, it means that the argument is required
// but not yet is the map. Check if we have a default value.
{
throw new ArgumentException(message);
}
else
{
}
}
return map;
}
}