DsFrameworkCliServerGroup.java revision fbbcdae277f66a56a2e5450858b249f82470dc56
/*
* 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-2008 Sun Microsystems, Inc.
*/
/**
* This class is handling server group CLI.
*/
public class DsFrameworkCliServerGroup implements DsFrameworkCliSubCommandGroup
{
/**
* End Of Line.
*/
/**
* The subcommand Parser.
*/
/**
* The verbose argument.
*/
/**
* The enumeration containing the different subCommand names.
*/
private enum SubCommandNameEnum
{
/**
* The create-group subcommand.
*/
CREATE_GROUP("create-group"),
/**
* The delete-group subcommand.
*/
DELETE_GROUP("delete-group"),
/**
* The modify-group subcommand.
*/
MODIFY_GROUP("modify-group"),
/**
* The list-groups subcommand.
*/
LIST_GROUPS("list-groups"),
/**
* The list-members subcommand.
*/
LIST_MEMBERS("list-members"),
/**
* The list-membership subcommand.
*/
LIST_MEMBERSHIP("list-membership"),
/**
* The add-to-group subcommand.
*/
ADD_TO_GROUP("add-to-group"),
/**
* The remove-from-group subcommand.
*/
REMOVE_FROM_GROUP("remove-from-group");
// String representation of the value.
// Private constructor.
{
}
/**
* {@inheritDoc}
*/
{
return name;
}
// A lookup table for resolving a unit from its name.
static
{
{
}
}
{
}
}
/**
* The 'create-group' subcommand.
*/
public SubCommand createGroupSubCmd;
/**
* The 'description' argument of the 'create-group' subcommand.
*/
private StringArgument createGroupDescriptionArg;
/**
* The 'group-name' argument of the 'create-group' subcommand.
*/
private StringArgument createGroupGroupNameArg;
/**
* The 'modify-group' subcommand.
*/
private SubCommand modifyGroupSubCmd;
/**
* The 'description' argument of the 'modify-group' subcommand.
*/
private StringArgument modifyGroupDescriptionArg;
/**
* The 'group-id' argument of the 'modify-group' subcommand.
*/
private StringArgument modifyGroupGroupIdArg;
/**
* The 'group-name' argument of the 'modify-group' subcommand.
*/
private StringArgument modifyGroupGroupNameArg;
/**
* The 'delete-group' subcommand.
*/
private SubCommand deleteGroupSubCmd;
/**
* The 'group-name' argument of the 'delete-group' subcommand.
*/
private StringArgument deleteGroupGroupNameArg;
/**
* The 'list-group' subcommand.
*/
private SubCommand listGroupSubCmd;
/**
* The 'add-to-group' subcommand.
*/
private SubCommand addToGroupSubCmd;
/**
* The 'group-name' argument of the 'add-to-group' subcommand.
*/
private StringArgument addToGroupGroupNameArg;
/**
* The 'member-id' argument of the 'add-to-group' subcommand.
*/
private StringArgument addToGoupMemberNameArg;
/**
* The 'remove-from-group' subcommand.
*/
private SubCommand removeFromGroupSubCmd;
/**
* The 'group-name' argument of the 'remove-from-group' subcommand.
*/
/**
* The 'member-id' argument of the 'remove-from-group' subcommand.
*/
/**
* The 'list-members' subcommand.
*/
private SubCommand listMembersSubCmd;
/**
* The 'group-name' argument of the 'list-members' subcommand.
*/
private StringArgument listMembersGroupNameArg;
/**
* The 'list-membership' subcommand.
*/
private SubCommand listMembershipSubCmd;
/**
* The 'member-name' argument of the 'list-membership' subcommand.
*/
/**
* Association between ADSContext enum and display field.
*/
/**
* The subcommand list.
*/
/**
* Indicates whether this subCommand should be hidden in the usage
* information.
*/
private boolean isHidden;
/**
* The subcommand group name.
*/
/**
* Get the display attribute name for a given attribute.
* @param prop The server property
* @return the display attribute name for a given attribute
*/
{
}
/**
* {@inheritDoc}
*/
{
return subCommands;
}
/**
* {@inheritDoc}
*/
public boolean isHidden()
{
return isHidden;
}
/**
* {@inheritDoc}
*/
public String getGroupName()
{
return groupName ;
}
/**
* {@inheritDoc}
*/
throws ArgumentException
{
this.verboseArg = verboseArg ;
isHidden = false ;
groupName = "server-group";
// Create-group subcommand
OPTION_SHORT_DESCRIPTION, OPTION_LONG_DESCRIPTION, false, false,
OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
// modify-group
OPTION_SHORT_DESCRIPTION, OPTION_LONG_DESCRIPTION, false, false,
OPTION_SHORT_NEWGROUPNAME, OPTION_LONG_NEWGROUPNAME, false, false, true,
OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
// delete-group
OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
// list-groups
// add-to-group
OPTION_SHORT_MEMBERNAME, OPTION_LONG_MEMBERNAME, true, true,
OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
// remove-from-group
OPTION_SHORT_MEMBERNAME, OPTION_LONG_MEMBERNAME, true, true,
OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
// list-members
OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
// list-membership
OPTION_SHORT_MEMBERNAME, OPTION_LONG_MEMBERNAME, true, true,
// Create association between ADSContext enum and display field
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
throws ADSContextException, ArgumentException
{
try
{
// -----------------------
// create-group subcommand
// -----------------------
{
// get the GROUP_NAME
// get the Description
{
}
// Create the group
{
return CANNOT_CONNECT_TO_ADS;
}
}
// -----------------------
// delete-group subcommand
// -----------------------
{
{
return ACCESS_PERMISSION ;
}
// Get ADS context
{
return CANNOT_CONNECT_TO_ADS;
}
// update server Property "GROUPS"
{
// serverId contains "cn=" string, just remove it.
}
// Delete the group
}
// -----------------------
// list-groups subcommand
// -----------------------
{
{
return CANNOT_CONNECT_TO_ADS;
}
// if not verbose mode, print group name (1 per line)
if (! verboseArg.isPresent())
{
{
// Get the group name
}
}
else
{
// Look for the max group identifier length
int uidLength = 0 ;
{
{
}
}
uidLength++;
{
// Get the group name
// add space
.length();
{
}
// Write other props
{
{
// We have already displayed the group Id
continue;
}
// add space
{
}
{
{
boolean indent = false;
{
if (indent)
{
{
}
}
else
{
indent = true;
}
}
}
}
else
{
{
}
}
}
}
}
try
{
}
catch (IOException e)
{
}
}
// -----------------------
// modify-group subcommand
// -----------------------
{
new HashSet<ServerGroupProperty>();
Boolean updateRequired = false;
Boolean removeRequired = false;
// get the GROUP_ID
if (modifyGroupGroupIdArg.isPresent())
{
// rename the entry !
updateRequired = true;
}
else
{
}
// get the Description
{
{
removeRequired = true;
}
else
{
updateRequired = true;
}
}
// Update the server group
if ( ! (updateRequired || removeRequired ) )
{
}
// We need to perform an update
{
return CANNOT_CONNECT_TO_ADS;
}
if (updateRequired)
{
}
if (removeRequired)
{
}
}
// -----------------------
// add-to-group subcommand
// -----------------------
{
{
return CANNOT_CONNECT_TO_ADS;
}
// Check if the server is registered inside to ADS
boolean found = false ;
{
{
found = true;
break;
}
}
if ( !found )
{
}
// Add the server inside the group
}
// -----------------------
// remove-from-group subcommand
// -----------------------
{
{
return CANNOT_CONNECT_TO_ADS;
}
}
// -----------------------
// list-members subcommand
// -----------------------
{
{
return CANNOT_CONNECT_TO_ADS;
}
// get the current member list
if (memberList == null)
{
}
{
// We shouldn't print out the "cn="
}
try
{
}
catch (IOException e)
{
}
}
// -----------------------
// list-membership subcommand
// -----------------------
{
{
return CANNOT_CONNECT_TO_ADS;
}
{
// Get the group name;
// look for member list attribute
{
{
continue;
}
// Check if the member list contains the member-id
{
MemberId.toLowerCase()))
{
break;
}
}
break;
}
}
try
{
}
catch (IOException e)
{
}
}
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;
}
/**
* Remove a server from a group.
*
* @param adsCtx
* The ADS context to use.
* @param groupId
* The group identifier from which a server has to be
* remove.
* @param serverId
* The server identifier to be removed.
* @return The return code.
* @throws ADSContextException
* If there is a problem with any of the parameters used
* to create this argument.
*/
throws ADSContextException
{
// get the current group member list
if (memberList == null)
{
}
{
}
// Update the server group
// Update the server property "GROUPS"
boolean found = false;
{
{
found = true ;
serverProperties = elm ;
break ;
}
}
if ( ! found )
{
return SERVER_NOT_REGISTERED ;
}
if (rawGroupList != null)
{
{
{
continue ;
}
}
}
return returnCode;
}
/**
* Add a server inside a group.
*
* @param adsCtx
* The ADS context to use.
* @param groupId
* The group identifier in which a server has to be added.
* @param map
* The properties of the server that have to be added to the
* group.
* @return the return code.
* @throws ADSContextException
* If there is a problem with any of the parameters used
* to create this argument.
*/
throws ADSContextException
{
// Add the server inside the group
if (memberList == null)
{
}
{
}
// Update the server property "GROUPS"
if (rawGroupList != null)
{
{
}
}
return returnCode;
}
}