001: /**
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found at $PEGASUS_HOME/GTPL or
004: * http://www.globus.org/toolkit/download/license.html.
005: * This notice must appear in redistributions of this file
006: * with or without modification.
007: *
008: * Redistributions of this Software, with or without modification, must reproduce
009: * the GTPL in:
010: * (1) the Software, or
011: * (2) the Documentation or
012: * some other similar material which is provided with the Software (if any).
013: *
014: * Copyright 1999-2004
015: * University of Chicago and The University of Southern California.
016: * All rights reserved.
017: */package org.griphyn.cPlanner.engine;
018:
019: import org.griphyn.cPlanner.classes.AuthenticateRequest;
020: import org.griphyn.cPlanner.classes.GridFTPServer;
021: import org.griphyn.cPlanner.classes.JobManager;
022:
023: import org.griphyn.cPlanner.common.LogManager;
024: import org.griphyn.cPlanner.common.PegasusProperties;
025:
026: import java.util.HashSet;
027: import java.util.Iterator;
028: import java.util.List;
029: import java.util.Set;
030:
031: /**
032: * It authenticates the user with the sites, that the user specifies at the
033: * execution time. It spawns out a thread for each pool that authenticates
034: * against the jobmanager for the vanilla universe as specified in the pool
035: * configuration file.
036: *
037: * @author Karan Vahi
038: * @version $Revision: 50 $
039: */
040: public class AuthenticateEngine extends Engine {
041:
042: /**
043: * The Set of pools that need to be authenticated against.
044: */
045: private Set mExecPools;
046:
047: /**
048: * The overloaded constructor.
049: *
050: * @param props the <code>PegasusProperties</code> to be used.
051: * @param pools The set of pools against which you want to authenticate the
052: * user.
053: */
054: public AuthenticateEngine(PegasusProperties props, Set pools) {
055: super (props);
056: mExecPools = pools;
057:
058: }
059:
060: /**
061: * It returns a set of pools against which the user can authenticate to.
062: *
063: * @return the set of authenticated pools.
064: */
065: public Set authenticate() {
066: Iterator it = mExecPools.iterator();
067: ThreadPool manager = new ThreadPool(mProps, mExecPools);
068: String pool;
069: JobManager jm;
070: GridFTPServer gserv;
071: String contact;
072:
073: //we need synchronization to ensure that an threads are started only
074: //when all the requests have been sent to the threadpool, as this
075: //failure to authenticate against a pool leads to it's removal from
076: //this set.
077: synchronized (mExecPools) {
078: while (it.hasNext()) {
079: pool = (String) it.next();
080:
081: List jmList = mPoolHandle.getJobmanagers(pool);
082: Iterator it1 = jmList.iterator();
083: while (it1.hasNext()) {
084: jm = (JobManager) it1.next();
085: contact = jm.getInfo(JobManager.URL);
086: AuthenticateRequest ar = new AuthenticateRequest(
087: 'j', pool, contact);
088: manager.acceptRequest(ar);
089: }
090:
091: List gridFtpList = mPoolHandle.getGridFTPServers(pool);
092: it1 = gridFtpList.iterator();
093: while (it1.hasNext()) {
094: gserv = (GridFTPServer) it1.next();
095: contact = gserv.getInfo(GridFTPServer.GRIDFTP_URL);
096: AuthenticateRequest ar = new AuthenticateRequest(
097: 'g', pool, contact);
098: manager.acceptRequest(ar);
099:
100: }
101: }
102: }
103: manager.shutdown();
104: purgePools();
105:
106: return mExecPools;
107: }
108:
109: /**
110: * It removies from the list of pools the pool that was not authenticated
111: * against. It queries the soft state of the pool config to see if there
112: * are at least one jobmanager and gridftp server on the pool.
113: * Due to the authentication the unauthenticated jobmanagers and servers
114: * would have been removed from the soft state of the pool config.
115: */
116: private synchronized void purgePools() {
117: Iterator it = mExecPools.iterator();
118: String pool;
119: List l;
120:
121: while (it.hasNext()) {
122: pool = (String) it.next();
123: l = mPoolHandle.getGridFTPServers(pool);
124: if (l == null || l.isEmpty()) {
125: mLogger.log("Removing Exec pool " + pool
126: + " as no authenticated gridftp server",
127: LogManager.DEBUG_MESSAGE_LEVEL);
128: it.remove();
129: continue;
130: }
131:
132: l = mPoolHandle.getJobmanagers(pool, "vanilla");
133: List l1 = mPoolHandle.getJobmanagers(pool, "transfer");
134: if ((l == null || l.isEmpty())
135: || (l1 == null || l1.isEmpty())) {
136: //we have no jobmanagers for universe vanilla or transfer universe
137: mLogger.log("Removing Exec pool " + pool
138: + " as no authenticated jobmanager",
139: LogManager.DEBUG_MESSAGE_LEVEL);
140: it.remove();
141: continue;
142: }
143:
144: }
145:
146: }
147:
148: /**
149: * The main testing method.
150: *
151: */
152: public static void main(String[] args) {
153: Set s = new HashSet();
154: //s.add("isi_condor");
155: s.add("isi_lsf");
156:
157: AuthenticateEngine a = new AuthenticateEngine(PegasusProperties
158: .getInstance(), s);
159: a.mLogger.setLevel(1);
160:
161: a.authenticate();
162:
163: System.out.println("Authentication Done!!");
164: System.out.println(a.mPoolHandle.getGridFTPServers("isi_lsf"));
165: a.mLogger.log("Vanilla JMS "
166: + a.mPoolHandle.getJobmanagers("isi_lsf"),
167: LogManager.DEBUG_MESSAGE_LEVEL);
168:
169: }
170:
171: }
|