72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * The contents of this file are subject to the terms of the Common Development and
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Distribution License (the License). You may not use this file except in compliance with the
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * specific language governing permission and limitations under the License.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * When distributing Covered Software, include this CDDL Header Notice in each file and include
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Header, with the fields enclosed by brackets [] replaced by your own identifying
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * information: "Portions copyright [year] [name of copyright owner]".
a4544a5a0e622ef69e38641f87ab1b5685e05911Phill Cunnington * Copyright 2014-2015 ForgeRock AS.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshottimport com.iplanet.services.naming.ServerEntryNotFoundException;
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshottimport com.iplanet.services.naming.WebtopNaming;
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshottimport com.iplanet.services.naming.WebtopNamingQuery;
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottimport org.forgerock.openam.session.SessionConstants;
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Responsible for providing supporting functions for the {@link WebtopNaming} service.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * In particular translating concepts that are based on users Sessions into
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * those which WebtopNaming operates in.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Guice initialised default constructor.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * @param debug Required for debugging.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * @param query Required for performing WebtopNaming operations.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott public WebtopNamingSiteUtils(@Named(SessionConstants.SESSION_DEBUG) Debug debug, WebtopNamingQuery query) {
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Determines if the Session is associated with a Server that is part of a
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Site. If this is the case then the function will determine the other
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Servers in the cluster.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * @param session A non null Session which must be associated with a Server ID.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * @return A set of the nodes that make up the cluster or Site. If the server
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * is not part of a Site then just the Server ID will be returned in the Set.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * @throws IllegalStateException If WebtopNaming was unable to find the IDs
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * for Servers in the Site. Unlikely as at this point it has indicated that
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * the Server in question is part of a Site.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott public Set<String> getSiteNodes(Session session) {
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott String siteOrServerID = session.getID().getSessionServerID();
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott // Check for the Servers Site.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott // This server has no site.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott return new HashSet<String>(Arrays.asList(siteOrServerID));
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott String err = "Failed to find nodes for Site ID: " + siteOrServerID;
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Determines the Site (if any) that the Session is based in, and then calculates
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * the Servers that make up that Site.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * @param session Non null Session to use for query.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * @return The URLs for each node in the Site that the Session belongs to. If the
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Session comes from a Server that is not part of a Site, then just the URL for
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * that Server will be returned. Never null.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * @throws IllegalStateException Thrown if WebtopNaming returned an invalid URL.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott public Set<URL> getSiteNodeURLs(Session session) {
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott URL url = new URL(query.getServerFromID(node));
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott String err = "WebtopNaming returned invalid URL";