package edu.usc.glidein.service.impl;

import java.net.URL;
import java.rmi.RemoteException;

import org.apache.axis.MessageContext;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.apache.log4j.Logger;
import org.globus.wsrf.ResourceContext;
import org.globus.wsrf.ResourceKey;
import org.globus.wsrf.container.ServiceHost;
import org.globus.wsrf.utils.AddressingUtils;

import edu.usc.glidein.stubs.types.Glidein;

public class GlideinFactoryService
{
	private Logger logger = Logger.getLogger(GlideinFactoryService.class);
	
	public GlideinFactoryService() { }	
	
	public EndpointReferenceType createGlidein(Glidein glidein)
	throws RemoteException
	{
		// Create a new resource
		ResourceKey key = null;
		try {
			ResourceContext rctx = ResourceContext.getResourceContext();
			GlideinResourceHome home = (GlideinResourceHome) rctx.getResourceHome();
			key = home.create(glidein);
		} catch (Exception e) {
			String message = "Unable to create glidein resource";
			logger.error(message,e);
			throw new RemoteException(message, e);
		}
		
		// Create an endpoint reference for the new resource
		EndpointReferenceType epr = null;
		try {
			URL baseURL = ServiceHost.getBaseURL();
			MessageContext mctx = MessageContext.getCurrentContext();
			String svc = (String) mctx.getService().getOption("instance");
			String instanceURI = baseURL.toString() + svc;
			epr = AddressingUtils.createEndpointReference(instanceURI, key);
		} catch (Exception e) {
			String message = "Unable to create endpoint reference";
			logger.error(message,e);
			throw new RemoteException(message, e);
		}
		
		// Return the endpoint reference to the client
		return epr;
	}
}
@@ -223,16 +223,56 @@
 Logger;%0A
+import org.globus.gsi.GlobusCredential;%0A
 import o
@@ -460,266 +460,1249 @@
 in.s
-tubs.types.Glidein;%0A%0Apublic class GlideinFactoryService%0A%7B%0A%09private Logger logger = Logger.getLogger(GlideinFactoryService.class);%0A%09%0A%09public GlideinFactoryService() %7B %7D%09%0A%09%0A%09public EndpointReferenceType createGlidein(Glidein glidein)%0A%09throws RemoteException%0A%09%7B
+ervice.db.Database;%0Aimport edu.usc.glidein.service.db.DatabaseException;%0Aimport edu.usc.glidein.service.db.GlideinDAO;%0Aimport edu.usc.glidein.stubs.types.Glidein;%0Aimport edu.usc.glidein.stubs.types.GlideinStatus;%0Aimport edu.usc.glidein.stubs.types.Glideins;%0Aimport edu.usc.glidein.util.ProxyUtil;%0A%0Apublic class GlideinFactoryService%0A%7B%0A%09private Logger logger = Logger.getLogger(GlideinFactoryService.class);%0A%09%0A%09public GlideinFactoryService() %7B %7D%09%0A%09%0A%09public EndpointReferenceType createGlidein(Glidein glidein)%0A%09throws RemoteException%0A%09%7B%0A%09%09// TODO Init glidein%0A%09%09glidein.setStatus(GlideinStatus.NEW);%0A%09%09glidein.setStatusMessage(%22Created%22);%0A%09%09%0A%09%09// TODO Get site or fail%0A%09%09%0A%09%09/* TODO Move the following to instance service */%0A%09%09// Setup cert%0A%09%09GlobusCredential cred = ProxyUtil.getCallerCredential();%0A%09%09%0A%09%09// Check cert: This is just an initial check. Because we don't know%0A%09%09// when the job will start we can not be certain that the cert won't%0A%09%09// need to be renewed at some point.%0A%09%09long timeLeft = cred.getTimeLeft()/60;%0A%09%09if (timeLeft %3C glidein.getWallTime()) %7B%0A%09%09%09throw new RemoteException(%22Not enough time left on proxy. %22 +%0A%09%09%09%09%09%22Need %22+glidein.getWallTime()+%22, have %22+timeLeft);%0A%09%09%7D%0A%09%09%0A%09%09// TODO Save cert to file in site's temp dir%0A%09%09
 %0A%09%09/
@@ -2705,9 +2705,355 @@
 epr;%0A%09%7D%0A
+%09%0A%09public Glideins listGlideins(boolean longFormat)%0A%09throws RemoteException%0A%09%7B%0A%09%09try %7B%0A%09%09%09Database db = Database.getDatabase();%0A%09%09%09GlideinDAO dao = db.getGlideinDAO();%0A%09%09%09Glidein%5B%5D glideins = dao.list(longFormat);%0A%09%09%09return new Glideins(glideins);%0A%09%09%7D catch(DatabaseException de) %7B%0A%09%09%09throw new RemoteException(%22Unable to list sites%22,de);%0A%09%09%7D%0A%09%7D%0A
 %7D

Add create initialization stuff Add listGlideins