ServerGroup.java revision 9d1321897216c79ea0639b6d8e0f92d0565876b6
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/**
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * The contents of this file are subject to the terms
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * of the Common Development and Distribution License
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * (the License). You may not use this file except in
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * compliance with the License.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * You can obtain a copy of the License at
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * https://opensso.dev.java.net/public/CDDLv1.0.html or
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * opensso/legal/CDDLv1.0.txt
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * See the License for the specific language governing
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * permission and limitations under the License.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * When distributing Covered Code, include this CDDL
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Header Notice in each file and include the License file
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * at opensso/legal/CDDLv1.0.txt.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * If applicable, add the following below the CDDL Header,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * with the fields enclosed by brackets [] replaced by
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * your own identifying information:
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * "Portions Copyrighted [year] [name of copyright owner]"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * $Id: ServerGroup.java,v 1.5 2009/01/28 05:34:49 ww203982 Exp $
355b4669e025ff377602b6fc7caaf30dbc218371jacobs *
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs/*
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Portions Copyrighted 2011 ForgeRock AS
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobspackage com.iplanet.services.ldap;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport com.iplanet.services.util.GenericNode;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport com.iplanet.services.util.ParseOutput;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport com.iplanet.services.util.XMLException;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport com.iplanet.services.util.XMLParser;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport com.iplanet.ums.IUMSConstants;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport java.util.ArrayList;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport java.util.Collection;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport java.util.HashMap;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport java.util.Hashtable;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport java.util.Vector;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport com.sun.identity.shared.Constants;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport com.sun.identity.shared.ldap.LDAPDN;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport com.sun.identity.shared.ldap.util.DN;
355b4669e025ff377602b6fc7caaf30dbc218371jacobsimport java.util.List;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobspublic class ServerGroup implements ParseOutput {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs /**
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * Not to be called. This is a method to be called by the parser to read the
355b4669e025ff377602b6fc7caaf30dbc218371jacobs * xml information.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs */
355b4669e025ff377602b6fc7caaf30dbc218371jacobs public void process(
355b4669e025ff377602b6fc7caaf30dbc218371jacobs XMLParser parser,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs String name,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs Vector elems,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs Hashtable atts,
355b4669e025ff377602b6fc7caaf30dbc218371jacobs String Pcdata
355b4669e025ff377602b6fc7caaf30dbc218371jacobs ) throws XMLException {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (DSConfigMgr.debugger.messageEnabled()) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs DSConfigMgr.debugger.message("in ServerGroup.process()");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (name.equals(DSConfigMgr.SERVERGROUP)) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs // get the group ID.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs groupName = (String) atts.get(DSConfigMgr.NAME);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs // Get the Servers
355b4669e025ff377602b6fc7caaf30dbc218371jacobs for (int i = 0; i < elems.size(); i++) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs Object obj = elems.elementAt(i);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (DSConfigMgr.debugger.messageEnabled()) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs DSConfigMgr.debugger.message("Object of type:"
355b4669e025ff377602b6fc7caaf30dbc218371jacobs + obj.getClass().getName());
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (obj instanceof Server) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (servers == null) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (DSConfigMgr.debugger.messageEnabled()) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs DSConfigMgr.debugger
355b4669e025ff377602b6fc7caaf30dbc218371jacobs .message("Initializing servers list.");
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs servers = new ArrayList<Server>();
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs servers.add((Server) obj);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs } else if (obj instanceof LDAPUser) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (users == null) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs users = new ArrayList();
355b4669e025ff377602b6fc7caaf30dbc218371jacobs }
355b4669e025ff377602b6fc7caaf30dbc218371jacobs users.add(obj);
355b4669e025ff377602b6fc7caaf30dbc218371jacobs } else if (obj instanceof GenericNode) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs // if it is generic node, its probably the base dn.
355b4669e025ff377602b6fc7caaf30dbc218371jacobs GenericNode x = (GenericNode) obj;
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (x._name.equals(DSConfigMgr.BASE_DN)) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (x._pcdata != null) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs if (!DN.isDN(x._pcdata)) {
355b4669e025ff377602b6fc7caaf30dbc218371jacobs throw new XMLException(
355b4669e025ff377602b6fc7caaf30dbc218371jacobs DSConfigMgr.getString(
355b4669e025ff377602b6fc7caaf30dbc218371jacobs IUMSConstants.DSCFG_INVALID_BASE_DN)
+ x._pcdata);
}
}
baseDN = LDAPDN.normalize(x._pcdata);
} else if (x._name.equals(DSConfigMgr.MISC_CONFIG)) {
String attrName = (String) x._atts
.get(DSConfigMgr.NAME);
String attrValue = (String) x._atts
.get(DSConfigMgr.VALUE);
if (name != null && name.length() > 0) {
if (miscConfig == null) {
miscConfig = new HashMap();
}
miscConfig.put(attrName, attrValue);
}
}
}
}
if (servers == null || baseDN == null) {
String errorMsg = null;
if (servers == null) {
errorMsg = "No server object found in the server group:"
+ groupName;
}
if (baseDN == null) {
errorMsg = "No base DN string defined in the server group:"
+ groupName;
}
throw new XMLException(errorMsg);
}
// Get the rest of the attributes
String maxConnPoolStr = System.getProperty("max_conn_pool");
if (maxConnPoolStr == null)
maxConnPoolStr = (String) atts.get(DSConfigMgr.MAX_CONN_POOL);
String minConnPoolStr = System.getProperty("min_conn_pool");
if (minConnPoolStr == null)
minConnPoolStr = (String) atts.get(DSConfigMgr.MIN_CONN_POOL);
try {
maxConnPool = Integer.parseInt(maxConnPoolStr);
} catch (NumberFormatException ex) {
maxConnPool = 10;
}
try {
minConnPool = Integer.parseInt(minConnPoolStr);
} catch (NumberFormatException ex) {
minConnPool = 1;
}
String ldapHeartbeatStr = System.getProperty(Constants.LDAP_HEARTBEAT);
if (ldapHeartbeatStr == null)
ldapHeartbeatStr = (String) atts.get(Constants.LDAP_HEARTBEAT);
try {
ldapHeartbeat = Integer.parseInt(ldapHeartbeatStr);
} catch (NumberFormatException ex) {
ldapHeartbeat = 10;
}
} else {
throw new XMLException(DSConfigMgr
.getString(IUMSConstants.DSCFG_SERVERGROUP_NODE_EXPECTED));
}
// Put it in the list of groups.
parser.getGroupContainer().put(groupName, this);
}
/**
* Get the server instance that's currently active.
*
* @param authType
* Defined in LDAPUser.java there are four types of users.
* @return ServerInstance The active instance is returned. If no instance is
* active, null is returned.
* @see LDAPUser.Type
*/
public ServerInstance getServerInstance(LDAPUser.Type authType) {
Server serv = null;
for (int i = 0; i < servers.size(); i++) {
serv = servers.get(i);
if (serv != null && serv.getActiveStatus() == true) {
break;
}
}
LDAPUser user = null;
for (int i = 0; i < users.size(); i++) {
user = (LDAPUser) users.get(i);
if (user != null && user.getAuthType().equals(authType)) {
break;
}
}
if ((serv != null) && (user != null)) {
return new ServerInstance(this, serv, user);
}
return null;
}
public String serverGroupName() {
return groupName;
}
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("Server Group Name=");
buf.append(groupName);
for (int i = 0; i < users.size(); i++) {
buf.append('\n');
buf.append(' ');
buf.append(users.get(i).toString());
}
for (int i = 0; i < servers.size(); i++) {
buf.append('\n');
buf.append(' ');
buf.append(servers.get(i).toString());
}
buf.append("Min Connection Pool=");
buf.append(minConnPool);
buf.append(" Max Connection Pool=");
buf.append(maxConnPool);
return buf.toString();
}
/**
* The list of servers that are defined in this server group.
*/
public Collection getServersList() {
return servers;
}
public int getLdapHeartbeat() {
return ldapHeartbeat;
}
String baseDN = null;
int maxConnPool = -1;
int minConnPool = -1;
List<Server> servers = null;
List users = null;
HashMap miscConfig = null;
private String groupName;
private int ldapHeartbeat;
}