WebtopNaming.java revision 72450cb9c2ca854c6d3479832c2738196c1d3282
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (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
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: WebtopNaming.java,v 1.31 2009/06/20 06:17:02 bigfatrat Exp $
*
*/
/*
* Portions Copyrighted 2010-2013 ForgeRock AS
*/
/*
* these are here temporarily, just to see how long it takes to
* build the monitoring stuff
*/
/*
* and this stuff is here for retrieving session config
*/
/**
* The <code>WebtopNaming</code> class is used to get URLs for various
* services such as session, profile, logging etc. The lookup is based on the
* service name and the host name. The Naming Service shall contain URLs for all
* services on all servers. For instance, two machines might host session
* services. The Naming Service profile may look like the following:
*
* <pre>
* host1.session.URL="http://host1:8080/SessionServlet"
* host2.session.URL="https://host2:9090/SessionServlet"
* </pre>
*/
public class WebtopNaming {
/**
* The unique identifier for the Naming Service.
*/
/**
* The delimiter used to separate server IDs in the service attribute.
*/
//This is created for storing server id and lbcookievalue mapping
//key:serverid | value:lbcookievalue
//This is created for ignore case comparison
/**
* The debug instance.
*/
private static boolean serverMode;
private static boolean sitemonitorDisabled;
private static String amServerURI;
private static String MAP_SITE_TO_SERVER =
"com.iplanet.am.naming.map.site.to.server";
static {
initialize();
}
public static void initialize() {
if (!serverMode) {
while (st.hasMoreTokens()) {
if (idx != -1) {
}
}
}
}
try {
getAMServer();
}
}
try {
} catch (MalformedURLException e) {
}
}
/**
* Determines whether WebtopNaming code runs in the core server mode
* or in the client SDK run-time mode.
*
* @return <code>true</code> running in the core server mode,
* <code>false</code> otherwise
*/
public static boolean isServerMode() {
return serverMode;
}
/**
* Tells whether the provided ID belongs to a server or not.
*
* @param serverID The ID that needs to be checked.
* @return <code>true</code> if the ID corresponds to a server.
*/
}
/**
* Tells whether the provided ID belongs to a site or not.
*
* @param siteID The ID that needs to be checked.
* @return <code>true</code> if the ID corresponds to a site.
*/
}
/**
* Tells whether the provided ID belongs to a secondary site or not.
*
* @param secondarySiteID The ID that needs to be checked.
* @return <code>true</code> if the ID corresponds to a secondary site.
*/
}
/**
* Determines whether Site is enabled for the given server instance.
*
* @param protocol protocol of the server instance
* @param host host of the server instance
* @param port port of the server instance
* @param uri uri of the server instance
*
* @return <code>true</code> if Site is enabled,
* <code>false</code> otherwise
*
* @throws Exception if server entry is not found or there is any
* other run-time error
*/
public static boolean isSiteEnabled(
) throws Exception {
return isSiteEnabled(serverid);
}
/**
* Determines whether Site is enabled for the given server ID.
* @param serverid server ID
*
* @return <code>true</code> if Site is enabled,
* <code>false</code> otherwise
*
* @throws Exception if the given server ID is null
*/
}
/**
* Returns the server ID.
*
* @return Server ID
*
* @throws ServerEntryNotFoundException if the Naming Service
* can not find that server entry
*/
}
private static void getAMServer() {
}
private static void initializeNamingService() {
try {
// Initilaize the list of naming URLs
if (!serverMode && !sitemonitorDisabled) {
}
}
}
/**
* Returns the URL of the specified service on the specified
* host.
*
* @param service the name of the service.
* @param protocol the service protocol
* @param host the service host name
* @param port the service listening port
* @param uri the deployment uri
*
* @return the URL of the specified service on the specified host.
*
* @throws URLNotFoundException if the Naming Service can not
* find a URL for a specified service
*/
}
/**
* Returns the URL of the specified service on the specified host.
*
* @param service the name of the service.
* @param url the deployment URI.
* @param validate a boolean value indicate whether or not to
* validate the protocol, host and port of the server
*
* @return the URL of the specified service on the specified host.
*
* @throws URLNotFoundException if the Naming Service can not
* find a URL for a specified service
*/
throws URLNotFoundException {
validate);
}
/**
* Returns the URL of the specified service on the specified host.
*
* @param service the name of the service.
* @param protocol the service protocol.
* @param host the service host name.
* @param port the ervice listening port.
* @param validate a boolean value indicate whether or not to
* validate the protocol, host and port of the server
*
* @return the URL of the specified service on the specified host.
*
* @throws URLNotFoundException if the Naming Service can not
* find a URL for a specified service
*/
public static URL getServiceURL(
boolean validate
) throws URLNotFoundException {
try {
} catch (MalformedURLException ex) {
}
}
public static URL mapSiteToServer(
) throws URLNotFoundException {
if (!mapSiteToServer.isEmpty()) {
try {
} catch (MalformedURLException e) {
throw new URLNotFoundException(e.getMessage());
}
}
return null;
}
/**
* Returns the URL of the specified service on the specified host.
*
* @param service name of the service.
* @param protocol service protocol.
* @param host service host name.
* @param port service listening port.
* @param uri the deployment uri.
* @param validate a boolean value indicate whether or not to
* validate the protocol, host and port of the server.
*
* @return the URL of the specified service on the specified host.
*
* @throws URLNotFoundException if the Naming Service can not
* find a URL for a specified service
*/
public static URL getServiceURL(
boolean validate
) throws URLNotFoundException {
try {
// check before the first naming table update to avoid deadlock
// uri can be empty string for pre-OpenSSO 8.0 releases
) {
+ service);
}
}
if (namingTable == null) {
getNamingProfile(false);
}
}
// If replacement is required, the protocol, host, and port
// validation is needed against the server list
// (iplanet-am-platform-server-list)
}
// %protocol processing
int idx;
+ protocol
.length());
}
// %host processing
+ host
.length());
}
// %port processing
// plugin the server name
+ port
.length());
}
// %uri processing
// uri can be null for previous releases.
while (test > 0) {
}
}
} else {
+ service);
}
} catch (Exception e) {
throw new URLNotFoundException(e.getMessage());
}
}
/**
* Returns all the URLs of the specified service based on the
* servers in platform server list.
*
* @param service the name of the service.
*
* @return the URL of the specified service on the specified host.
*
* @throws URLNotFoundException if the Naming Service can not
* find a URL for a specified service
*/
throws URLNotFoundException {
try {
if (namingTable == null) {
getNamingProfile(false);
}
}
if (monitorThread == null) {
} else {
}
} else {
}
}
}
return allurls;
} catch (Exception e) {
throw new URLNotFoundException(e.getMessage());
}
}
/**
* Returns the platform server list. Note: Calling this method would
* cause performance impact, as it involves xml request over the wire.
*
* @return platform server list
*
* @throws Exception if an error occurs when updating the
* nameing table
*/
return getPlatformServerList(true);
}
/**
* Returns the platform server list.
*
* @param update a boolean flag indicating whether a refresh of the
* naming profile is needed.
*
* @return platform server list
*
* @throws Exception if an error occurs when updating the
* nameing table
*/
throws Exception {
return platformServers;
}
/**
* Returns key value from a hashtable, ignoring the case of the
* key.
*/
{ return null; }
{ return null; }
}
}
}
return null;
}
/**
* Returns local server name from naming table.
*
* @return server name opensso is deployed.
*/
public static String getLocalServer() {
try {
} catch (ServerEntryNotFoundException e) {
}
return server;
}
/**
* Returns the server ID that is there in the platform server
* list for a corresponding server.
*
* @param protocol procotol of the server instance
* @param host host of the server instance
* @param port port of the server instance
* @param uri uri of the server instance
*
* @return Server ID
*
* @throws ServerEntryNotFoundException if the Naming Service
* can not find that server entry
*/
public static String getServerID(
throws ServerEntryNotFoundException {
}
/**
* Returns the server ID that is there in the platform server
* list for a corresponding server.
*
* @param protocol procotol of the server instance
* @param host host of the server instance
* @param port port of the server instance
* @param uri uri of the server instance
* @param updatetbl a boolean flag indicating whether a refresh of the
* naming profile is needed.
*
* @return Server ID
*
* @throws ServerEntryNotFoundException if the Naming Service
* can not find that server entry
*/
public static String getServerID(
boolean updatetbl
) throws ServerEntryNotFoundException {
try {
// check before the first naming table update to avoid deadlock
}
}
} else {
}
if (serverIdTable != null) {
//try without URI, this is for prior release of OpenSSO
//Enterprise 8.0
}
// try with the URI, Agent 3.0 preferred naming URL
// is missing the amServer URI
}
}
//update the naming table and as well as server id table
//if it can not find it
getNamingProfile(true);
//try without URI, this is for prior release of OpenSSO
//Enterprise 8.0
}
// try with the URI, Agent 3.0 preferred naming URL
// is missing the amServer URI
}
}
if (!sitemonitorDisabled) {
"for server: " + server);
} else {
"for server: " + server);
}
}
if (!sitemonitorDisabled) {
throw new ServerEntryNotFoundException(
}
}
return serverID;
} catch (Exception e) {
}
throw new ServerEntryNotFoundException(e);
}
}
/**
* Returns the server URL based on the server ID.
*
* @param serverID Server ID
*
* @return server URL
*
* @throws ServerEntryNotFoundException if the Naming Service
* can not find that server entry
*/
throws ServerEntryNotFoundException {
try {
// refresh local naming table in case the key is not found
if (namingTable != null) {
}
getNamingProfile(true);
}
throw new ServerEntryNotFoundException(NamingBundle
.getString("noServer" ));
}
} catch (Exception e) {
+ "server name for server ID : " + serverID, e);
throw new ServerEntryNotFoundException(e);
}
return server;
}
/**
* Returns all server IDs.
*
* @return all server IDs.
*
* @throws Exception if an error occurs when updating the
* nameing table
*/
if (namingTable == null) {
getNamingProfile(false);
}
return platformServerIDs;
}
private static void updateLBCookieValueMappings() {
return;
}
while (tok.hasMoreTokens()) {
if (idx != -1) {
}
}
if (debug.messageEnabled()) {
}
return;
}
/**
* Returns the lbCookieValue corresponding to the server ID.
*
* @param serverid the server id
*
* @return the LB cookie value corresponding to server ID
*/
if (debug.messageEnabled()) {
" server id is null, returning null ");
}
return null;
} else if (lbCookieValuesTable == null) {
if (debug.messageEnabled()) {
" lbCookieValues table is null, returning server id: " +
serverid);
}
return serverid;
}
if (lbCookieValue == null) {
if (debug.messageEnabled()) {
" lbCookieValue from table is null, returning server id: " +
serverid);
}
return serverid;
}
if (debug.messageEnabled()) {
}
return lbCookieValue;
}
/**
* Returns the unique identifier of the site which the given
* server instance belongs to.
*
* @param protocol procotol of the server instance
* @param host host of the server instance
* @param port port of the server instance
* @param uri uri of the server instance
*
* @return Site ID
*
* @throws ServerEntryNotFoundException if the Naming Service
* can not find that server entry
*/
) throws ServerEntryNotFoundException {
}
/**
* Returns the unique identifier of the site which the given
* server instance belongs to.
*
* @param serverid server ID
*
* @return Site ID
*/
if (siteIdTable == null) {
return null;
}
}
if (debug.messageEnabled()) {
+ primary_site);
}
return primary_site;
}
if (siteNameToIdTable == null) {
return null;
}
if (debug.messageEnabled()) {
+ siteId);
}
return siteId;
}
if (siteNameToIdTable == null) {
return null;
}
break;
}
}
if (debug.messageEnabled()) {
+ siteId);
}
return siteName;
}
/**
* Returns the String representation of the separator delimited
* secondary site list.
*
* @param protocol procotol of the server instance
* @param host host of the server instance
* @param port port of the server instance
* @param uri uri of the server instance
*
* @return the secondary site list
* @throws ServerEntryNotFoundException if the Naming Service
* can not find that server entry
*/
public static String getSecondarySites(
throws ServerEntryNotFoundException {
return getSecondarySites(serverid);
}
/**
* Returns the String representation of the separator delimited
* secondary site list.
*
* @param serverid server ID
*
* @return the secondary site list
*/
if (siteIdTable == null) {
return null;
}
return null;
}
if (index != -1) {
}
if (debug.messageEnabled()) {
+ " is " + secondarysites);
}
return secondarysites;
}
/**
* Returns all the node ID for the site.
*
* @param serverid one of server IDs within the site, it can also
* be the loab balancer's ID
*
* @return HashSet has all the node is for the site.
*
* @throws Exception if an error occurs when updating the
* nameing table
*/
if (namingTable == null) {
getNamingProfile(false);
}
while (e.hasMoreElements()) {
continue;
}
}
}
return nodeset;
}
/**
* Returns the class of the specified service.
*
* @param service the name of the service.
*
* @return The class name of the specified service.
*
* @throws ClassNotFoundException if no definition for the class
* with the specified name could be found.
*/
throws ClassNotFoundException {
try {
if (namingTable == null) {
getNamingProfile(false);
}
+ "-class";
}
+ service);
}
return cls;
} catch (Exception e) {
throw new ClassNotFoundException(e.getMessage());
}
}
/**
* Returns the URL of the notification service on the local
* host.
*
* @return the notification URL
*
* @throws URLNotFoundException if the Naming Service can not
* find a URL for a specified service
*/
public synchronized static URL getNotificationURL()
throws URLNotFoundException {
try {
throw new URLNotFoundException(NamingBundle
.getString("noNotificationURL"));
}
} catch (Exception e) {
throw new URLNotFoundException(e.getMessage());
}
}
private synchronized static void getNamingProfile(boolean update)
throws Exception {
}
}
while (idx > 0) {
}
amServer);
if (debug.messageEnabled()) {
}
}
try {
throw new Exception(NamingBundle
.getString("unexpectedResponse"));
}
}
} catch (SendRequestException sre) {
} catch (Exception e) {
}
return nametbl;
}
private static void updateNamingTable() throws Exception {
if (!serverMode) {
if (namingServiceURL == null) {
}
// Try for the primary server first, if it fails and then
// for the second server. We get connection refused error
// if it doesn't succeed.
(i < namingServiceURL.length)); i++) {
}
throw new Exception(NamingBundle
.getString("noNamingServiceAvailable"));
} else {
}
} else {
}
while (st.hasMoreTokens()) {
}
}
if (debug.messageEnabled()) {
+ platformServerIDs.toString());
}
}
/*
* This method is to update the servers and their IDs in a seprate
* hash. It will get updated each time when the naming table gets
* updated. Note: this table will have all the entries in the
* naming table but in a reverse order except the platform server
* list. We can just keep only server ID mappings but we need to
* exclude each other entry which is there in.
*/
private static void updateServerIdMappings() {
while (e.hasMoreElements()) {
continue;
}
// If the key is server list skip it, since it would
// have the same value
continue;
}
}
}
private static void updateSiteIdMappings() {
return;
}
while (tok.hasMoreTokens()) {
if (idx != -1) {
}
}
if (debug.messageEnabled()) {
}
return;
}
private static void updatePlatformServerIDs()
}
}
}
private static void updateSiteNameToIDMappings() {
return;
}
while (tok.hasMoreTokens()) {
if (idx != -1) {
}
}
if (debug.messageEnabled()) {
}
return;
}
private static void updatePlatformSets() {
//the first one is always the primary site ID, which we don't need now
while (tokenizer.hasMoreTokens()) {
}
}
}
}
private static void validate(
) throws URLNotFoundException {
try {
// first check if this is the local server, proto, and port,
// if it is there is no need to
// validate that it is in the trusted server platform server list
) {
return;
}
if (debug.messageEnabled()) {
}
getNamingProfile(true);
throw new URLNotFoundException(NamingBundle
.getString("invalidServiceHost")
+ " " + server);
}
}
} catch (Exception e) {
throw new URLNotFoundException(e.getMessage());
}
}
/**
* Returns a list of the naming service urls.
*
* @return a String array of naming service urls.
*
* @throws Exception if there is no configured url or there is an
* error when trying to get the urls
*/
// Initilaize the list of naming URLs
// Get the naming service URLs from properties files
if (configURLListString != null) {
while (stok.hasMoreTokens()) {
if (debug.warningEnabled()) {
"Duplicate naming service URL specified "
+ nextURL + ", will be ignored.");
}
} else {
}
}
}
throw new Exception(
} else {
if (debug.messageEnabled()) {
}
}
}
return namingServiceURL;
}
// Site monitor is already started.
if (monitorThread != null) {
return;
}
// Start naming service monitor
}
/**
* Removes a server from the available site list.
*
* @param server the <code>String</code> to parse as a URL of
* the server to be removed from the site list
*/
if (monitorThread != null) {
try {
} catch (MalformedURLException e) {
}
}
return;
}
/**
* Removes a server from the available site list.
*
* @param url url of the server to be removed from the site list
*/
if (monitorThread != null) {
try {
} catch (ServerEntryNotFoundException e) {
}
}
return;
}
/**
* Returns the uri of the specified URL.
*
* @param url the URL that includes uri.
*
* @return a uri of the specified <code>URL</code>.
*/
while (idx > 0) {
}
return uri;
}
/**
* Provides the Monitoring Agent site and server related information.
*
* @return 0 (zero) if all information collected and provided successfully;
* -1 if server protocol, hostname, port or URI is null;
* -2 if not serverMode, or Monitoring Agent already running
* -3 if unable to get the ServerID
*
*/
public static int configMonitoring() {
/*
* start the monitoring agent, if not already started
*/
if (debug.warningEnabled()) {
"start monitoring config" + "\n" +
}
if ((amServerProtocol != null) &&
(amServerPort != null) &&
(amServerURI != null))
{
try {
} catch (ServerEntryNotFoundException sefx) {
return -3;
}
boolean isEmbeddedDS =
/*
* session failover status and site configuration
* (SiteConfiguration.getSites()) (to get the site names)
* require an SSOToken, which we can't get at this point.
*/
if (debug.messageEnabled()) {
"monitoring agent config returned\n" +
}
return 0;
} else {
return -1;
}
}
return -2;
}
/**
* The <code>SiteMonitor</code> class is used to monitor the
* health status of all the sites.
*/
static public class SiteMonitor extends GeneralTaskRunnable {
static long sleepInterval;
/**
* A boolean flag indicating whether site monitoring is enabled.
*/
static public boolean keepMonitoring = false;
static {
try {
"com.iplanet.services.naming.SiteStatusCheckThreadImpl");
if (debug.messageEnabled()) {
+ checkClass);
}
getNamingProfile(false);
} catch (Exception e) {
}
}
/**
* Constructs a WebtopNaming$SiteMonitor object with the provided
* site urls.
*
* @param urlList a String containing the urls of the sites
*/
}
return false;
}
return false;
}
public boolean isEmpty() {
return true;
}
public long getRunPeriod() {
return sleepInterval;
}
public void run() {
keepMonitoring = true;
try {
} catch (Exception e) {
}
}
static void runCheckValidSite() {
}
/**
* Checks if the site is up.
*
* @param siteurl a site url
*
* @return <code>true</code> if the site is up
*/
}
private static Vector checkAvailableSiteList() {
try {
continue;
}
} catch (MalformedURLException ex) {
if (debug.messageEnabled()) {
}
} catch (ServerEntryNotFoundException ex) {
if (debug.messageEnabled()) {
}
}
}
return siteList;
}
/**
* Checks if the site of the url is up.
*
* @param url a site url
*
* @return <code>true</code> if the site is up
*
* @throws Exception if failing to get the naming service url.
*/
return true;
}
try {
} catch (ServerEntryNotFoundException e) {
if (debug.messageEnabled()) {
}
return true;
}
boolean available = false;
available = true;
break;
}
}
if (debug.messageEnabled()) {
if (available) {
} else {
}
}
return available;
}
/**
* Checks if the url is one of configured sites.
*
* @param url a site url
*
* @return <code>true</code> if the url is one of configured sites.
*
* @throws Exception if failing to get the naming service url.
*/
return true;
}
try {
} catch (ServerEntryNotFoundException e) {
if (debug.messageEnabled()) {
}
return true;
}
boolean isCurrent = false;
}
}
return isCurrent;
}
if (availableSiteList.isEmpty()) {
}
}
if (debug.messageEnabled()) {
}
return sites;
}
}
return;
}
if (debug.messageEnabled()) {
+ availableSiteList.toString());
}
return;
}
if (serverMode) {
return;
}
return;
}
if (debug.messageEnabled()) {
"Server properties are changed for service failover");
}
try {
currentSiteID = sid;
} catch (Exception e) {
}
}
return;
}
}
/**
* The interface <code>SiteStatusCheck</code> provides
* method that will be used by SiteMonitor to check each site is alive.
* Each implementation class has to implement doCheckSiteStatus method.
*/
public interface SiteStatusCheck {
/**
* Check if the site is alive.
* @param siteurl the url which needs to be checked alive
*
* @return <code>true</code> if the site is up.
*/
}
}