Author: chatellier Date: 2009-12-10 16:58:27 +0000 (Thu, 10 Dec 2009) New Revision: 2813 Removed: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulatorServer.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/IsisFishServerSimulationLauncher.java Modified: isis-fish/trunk/pom.xml Log: Remove xml-rpc client and server Modified: isis-fish/trunk/pom.xml =================================================================== --- isis-fish/trunk/pom.xml 2009-12-10 15:07:57 UTC (rev 2812) +++ isis-fish/trunk/pom.xml 2009-12-10 16:58:27 UTC (rev 2813) @@ -145,28 +145,6 @@ <version>1.0.12</version> </dependency> - <!-- XML-RPC Client and server --> - <dependency> - <groupId>org.apache.xmlrpc</groupId> - <artifactId>xmlrpc-client</artifactId> - <version>${xmlrpc.version}</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>org.apache.xmlrpc</groupId> - <artifactId>xmlrpc-server</artifactId> - <version>${xmlrpc.version}</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>commons-httpclient</groupId> - <artifactId>commons-httpclient</artifactId> - <version>3.1</version> - <scope>runtime</scope> - </dependency> - <!-- encore utilise pour les pre-scripts --> <dependency> <groupId>org.beanshell</groupId> Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulatorServer.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulatorServer.java 2009-12-10 15:07:57 UTC (rev 2812) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulatorServer.java 2009-12-10 16:58:27 UTC (rev 2813) @@ -1,294 +0,0 @@ -/* *##% - * Copyright (C) 2007, 2009 - * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -package fr.ifremer.isisfish.simulator; - -import static org.nuiton.i18n.I18n._; - -import java.io.File; -import java.io.IOException; -import java.util.Hashtable; -import java.util.Map; -import java.util.Vector; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.xmlrpc.XmlRpcException; -import org.apache.xmlrpc.XmlRpcHandler; -import org.apache.xmlrpc.XmlRpcRequest; -import org.apache.xmlrpc.XmlRpcRequestConfig; -import org.apache.xmlrpc.common.XmlRpcHttpRequestConfig; -import org.apache.xmlrpc.server.XmlRpcHandlerMapping; -import org.apache.xmlrpc.server.XmlRpcNoSuchHandlerException; -import org.apache.xmlrpc.server.XmlRpcServer; -import org.apache.xmlrpc.webserver.WebServer; -import org.nuiton.util.FileUtil; - -import fr.ifremer.isisfish.IsisFish; -import fr.ifremer.isisfish.datastore.SimulationStorage; -import fr.ifremer.isisfish.simulator.launcher.InProcessSimulatorLauncher; -import fr.ifremer.isisfish.simulator.launcher.SimulationItem; -import fr.ifremer.isisfish.simulator.launcher.SimulatorLauncher; - -/** - * Cette classe permet de lancer un serveur XML-RPC qui attend des demandes - * de simulation. Il est ensuite possible de lui demander ou en est rendu - * une simulation. - * - * Created: Thu Aug 22 2002 - * - * @author <poussin at codelutin.com> Copyright Code Lutin - * - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - * - * @deprecated since ... a long time this implementation is unmaintained. - */ -public class SimulatorServer implements XmlRpcHandler, XmlRpcHandlerMapping { // SimulatorServer - - /** to use log facility, just put in your code: log.info(\"...\"); */ - private static Log log = LogFactory.getLog(SimulatorServer.class); - - /** - * TODO dans SimulationControl ajouter une date de lancement de - * simulation. Si cette date est par exemple > 7 j on supprime - * automatiquement de simulationControls. Et on fait - * ce petit traitement a chaque connexion au serveur. - */ - protected Hashtable<String, SimulationControl> simulationControls = new Hashtable<String, SimulationControl>(); - - /* - * @see org.apache.xmlrpc.server.XmlRpcHandlerMapping#getHandler(java.lang.String) - */ - @Override - public XmlRpcHandler getHandler(String handler) - throws XmlRpcNoSuchHandlerException, XmlRpcException { - - if (log.isDebugEnabled()) { - log.debug("Request handler : " + handler); - } - - return this; - } - - /* - * @see org.apache.xmlrpc.XmlRpcHandler#execute(org.apache.xmlrpc.XmlRpcRequest) - */ - @Override - public Object execute(XmlRpcRequest request) throws XmlRpcException { - - /* - * Parametres: - * method les 2 noms de methodes possibles sont <b>simulate</b> pour - * commencer une nouvelle simulation, et <b>checkPoint</b> pour - * demander ou en est la simulation que l'utilisateur a demande. - * param params si la methode est <b>simulate</b>, il faut donnee l'id, - * et le zip de la simulation. Si la methode est <b>checkPoint</b> - * il faut redonner le meme id que pour le lancement de la - * simulation. - * user le login a utiliser pour pouvoir faire une simulation - * password le mot de passe - * si la methode est <b>simulate</b> retourne un objet - * {@link Simulation} Simulation sous forme XML. Si la - * methode est <b>checkPoint</b> retourne le nombre de mois simule. - */ - - String user = null; - String password = null; - - // get basic connection info - XmlRpcRequestConfig config = request.getConfig(); - if (config instanceof XmlRpcHttpRequestConfig) { - XmlRpcHttpRequestConfig httpConfig = (XmlRpcHttpRequestConfig) config; - user = httpConfig.getBasicUserName(); - password = httpConfig.getBasicPassword(); - } - - // TODO check authenticated users - - // get params - Vector params = new Vector(); - for (int index = 0; index < request.getParameterCount(); ++index) { - params.add(request.getParameter(index)); - } - - // launch requested method - String method = request.getMethodName(); - Object result = null; - try { - if ("simulate".equals(method)) { - result = new SimulatorServer().simulate(params); - } else if ("checkPoint".equals(method)) { - result = checkPoint(params); - } else { - throw new NoSuchMethodException("Erreur: la methode " + method - + " n'existe pas"); - } - } catch (Exception e) { - throw new XmlRpcException("Error during xmlrpc call", e); - } - - return result; - } - - /** - * Lance une nouvelle simulation - * - * @param params les parametres - * <li>String id de simulation - * <li>String xml de la base - * <li>HashTable nom : rule - * <li>HashTable nom : script - * <li>HashTable nom : export - * <li>HashTable SimulationParameter - * @return La simulation sous forme d'un fichier zip representé par byte[] - * @throws Exception - */ - protected Object simulate(Vector params) throws Exception { - // on creer une nouvelle simulation - if (params.size() < 2) { - throw new IllegalArgumentException("Mauvais nombre d'argument"); - } - - String id = (String) params.get(0); - File zip = FileUtil.byteToFile((byte[]) params.get(1)); - - SimulationControl control = new SimulationControl(id); - SimulationStorage simulation = null; - - simulationControls.put(id, control); - try { - SimulatorLauncher launcher = new InProcessSimulatorLauncher(); - SimulationItem item = new SimulationItem(control, null); - item.setSimulationZip(zip); - launcher.simulate(null, item); - // FIXME null - simulation = launcher.getSimulationStorage(null, control); - - zip = simulation.createZip(); - byte[] result = FileUtil.fileToByte(zip); - - return result; - } catch (Exception eee) { - log.warn(_("isisfish.error.during.simulation"), eee); - throw eee; - } finally { - simulationControls.remove(id); - if (simulation != null) { - simulation.delete(false); - } - } - } - - /** - * synchronized two SimulationControl (local and remote) - * - * @param params - * @return - * @throws Exception - */ - synchronized protected Object checkPoint(Vector params) throws Exception { - // on retourne a l'utilisateur on en est la simulation - if (params.size() < 1) { - throw new IllegalArgumentException("Mauvais nombre d'argument"); - } - - Hashtable<String, Object> args = new Hashtable<String, Object>(); - args.putAll((Map<String, Object>) params.get(0)); - - String id = (String) args.get("id"); - SimulationControl callback = (SimulationControl) simulationControls - .get(id); - - if (callback == null) { - throw new SimulatorServerBadIdException("Erreur: " + id - + " n'est pas un identifiant de simulation"); - } - - callback.updateFromHashtable(args); - - return callback.getUpdateHashtable(); - } - - // synchronized protected Object stop(Vector params) throws Exception { - // if (params.size() < 1) - // throw new IllegalArgumentException("Mauvais nombre d'argument"); - // - // String id = (String) params.get(0); - // SimulationControl callback = (SimulationControl) simulationControls - // .get(id); - // if (callback == null) - // throw new SimulationException("Erreur: " + id - // + " n'est pas un identifiant de simulation"); - // - // callback.stopSimulation(); - // - // return ""; - // } - - /** - * Method main permet de lancer un serveur de simulation sur une machine. - * - * @param args - */ - public static void main(String[] args) { - - try { - IsisFish.init(); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("Can't ini IsisFish", e); - } - } - - System.out.println("Usage: SimulatorServer [port]"); - - int p = 9090; - - if (args.length > 0) { - try { - p = Integer.parseInt(args[0]); - } catch (NumberFormatException nfx) { - System.err.println("Error parsing port number: " + args[0]); - } - } - - // FIXME KeepAlive in xmlrpc 3.x ? - //XmlRpc.setKeepAlive(true); - - try { - WebServer webserver = new WebServer(p); - XmlRpcServer xmlRpcServer = webserver.getXmlRpcServer(); - - //xmlRpcServer.addHandler("$default", new SimulatorServer()); // 2.x - xmlRpcServer.setHandlerMapping(new SimulatorServer()); // 3.x - - webserver.start(); - System.out.println("Started web server on port " + p); - - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Error creating web server", e); - } - } - } - -} // SimulatorServer Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/IsisFishServerSimulationLauncher.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/IsisFishServerSimulationLauncher.java 2009-12-10 15:07:57 UTC (rev 2812) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/IsisFishServerSimulationLauncher.java 2009-12-10 16:58:27 UTC (rev 2813) @@ -1,262 +0,0 @@ -/* *##% - * Copyright (C) 2002-2009 Code Lutin, Benjamin Poussin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - * USA. - *##%*/ - -package fr.ifremer.isisfish.simulator.launcher; - -import static org.nuiton.i18n.I18n._; - -import java.io.File; -import java.net.URL; -import java.rmi.RemoteException; -import java.util.Hashtable; -import java.util.Vector; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.xmlrpc.client.XmlRpcClient; -import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; -import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory; -import org.nuiton.util.FileUtil; - -import fr.ifremer.isisfish.IsisFish; -import fr.ifremer.isisfish.datastore.SimulationStorage; -import fr.ifremer.isisfish.simulator.SimulationControl; - -/** - * Launch simulation on remote IsisFish server throw XML-RPC. - * - * @author poussin - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - * - * @deprecated Since ... a long time this implementation is unmaintained. - */ -public class IsisFishServerSimulationLauncher implements SimulatorLauncher { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - private static Log log = LogFactory - .getLog(IsisFishServerSimulationLauncher.class); - - @Override - public void simulate(SimulationService simulationService, - SimulationItem simulationItem) throws RemoteException { - - SimulationControl control = simulationItem.getControl(); - File simulationZip = simulationItem.getSimulationZip(); - - String simulationId = control.getId(); - SimulationStorage simulation = null; - try { - simulation = SimulationStorage.importAndRenameZip(simulationZip, - simulationId); - simulation = remoteSimulate(control, simulation); - } catch (Exception eee) { - log.error(_("Can't do simulation %s", simulationId), eee); - // FIXME simulation allways null here - if (simulation != null) { - simulation.getInformation().setException(eee); - } - } - - // on retourne directement le simulation storage passe en argument - // car la simulation a ete faite avec - //return simulation; - - } - - @Override - public int maxSimulationThread() { - // TODO a rendre configurable - return 1; - } - - /* - * @see fr.ifremer.isisfish.simulator.launcher.SimulatorLauncher#getCheckProgressionInterval() - */ - @Override - public int getCheckProgressionInterval() { - - // par defaut, pour les serveur xmlrpc 20 secondes - - int interval = 20; - return interval; - } - - /** - * execute la simulation en remote - * - * @param control le controleur de simulation, peut-etre null si on ne - * souhaite pas controler la simulation - * @param simulation la simulation a faire - * - * @return le storage après simulation - * @throws Exception pour toute erreur - */ - public SimulationStorage remoteSimulate(SimulationControl control, - SimulationStorage simulation) throws Exception { - // export en zip du storage - File zip = simulation.createZip(); - - if (control != null) { - // creation du thread de surveillance de la simulation distante - // qui sert a mettre a jour les valeurs de control - new SimulationCheckpointRemoteThread(control).start(); - } - - // envoie le zip au serveur de simulation - // appel synchrone pour attendre la fin de la simulation - // recuperation du zip de la simulation terminé - Vector<Object> a = new Vector<Object>(); - //fixme : on peut avori control à null ? - a.add(control.getId()); - a.add(FileUtil.fileToByte(zip)); - - // lancement de la simulation - //XmlRpcClient c = new XmlRpcClient(IsisFish.config.getSimulatorServer()); - //c.setBasicAuthentication(IsisFish.config.getSimulatorUsername(), - // IsisFish.config.getSimulatorPassword()); - - XmlRpcClientConfigImpl xmlrpcconfig = new XmlRpcClientConfigImpl(); - xmlrpcconfig - .setServerURL(new URL(IsisFish.config.getSimulatorServer())); - xmlrpcconfig.setBasicUserName(IsisFish.config.getSimulatorUsername()); - xmlrpcconfig.setBasicPassword(IsisFish.config.getSimulatorPassword()); - XmlRpcClient client = new XmlRpcClient(); - client.setTransportFactory(new XmlRpcCommonsTransportFactory(client)); - client.setConfig(xmlrpcconfig); - - byte[] callResult = (byte[]) client.execute("simulate", a); - - // ecriture du resultat dans un fichier - File tmpzip = FileUtil.byteToFile(callResult); - - // remplacement du storage local par le storage recu - simulation.closeStorage(); - simulation.delete(false); - SimulationStorage result; - result = SimulationStorage.importAndRenameZip(tmpzip, control.getId()); - return result; - } - - /** - * This thread is responsible to synchronized SimulationControl used localy with - * remote simulation control for remote simulation. - * - * This thread dead when {@link SimulationControl#isRunning()} is false - * - * @author poussin - */ - protected class SimulationCheckpointRemoteThread extends Thread { // SimulationCheckpointRemoteThread - - protected SimulationControl control = null; - int badId = 0; - - public SimulationCheckpointRemoteThread(SimulationControl control) { - this.control = control; - } - - public void run() { - int sleepTime = 2000; - while (true) { - try { - Thread.sleep(sleepTime); - - updateControl(control); - // on remet de le temps normal, vu que la connexion a reussi - sleepTime = 2000; - - if (!control.isRunning()) { - return; - } - - } catch (Exception eee) { - // on supporte 10 erreurs puis ensuite on quitte le thread. - if (badId++ > 10) { - log.error("Error !!! ", eee); - break; - } else { - // on a echouer sur une tentative, on allonge un - // peu le temps - sleepTime += 2000; - } - } - } - - } - - public void updateControl(SimulationControl control) throws Exception { - // essai l'ancienne etait en dur: "http://localhost:9090" - - XmlRpcClientConfigImpl xmlrpcconfig = new XmlRpcClientConfigImpl(); - xmlrpcconfig.setServerURL(new URL(IsisFish.config - .getSimulatorServer())); - xmlrpcconfig.setBasicUserName(IsisFish.config - .getSimulatorUsername()); - xmlrpcconfig.setBasicPassword(IsisFish.config - .getSimulatorPassword()); - XmlRpcClient client = new XmlRpcClient(); - client.setTransportFactory(new XmlRpcCommonsTransportFactory( - client)); - client.setConfig(xmlrpcconfig); - - Vector a = new Vector(); - a.add(control.getUpdateHashtable()); - Hashtable<String, Object> result = (Hashtable<String, Object>) client - .execute("checkPoint", a); - // on remet de le temps normal, vu que la connexion a reussi - control.updateFromHashtable(result); - } - } // SimulationCheckpointRemoteThread - - @Override - public String toString() { - return _("Remote IsisFish server"); - } - - /* - * @see fr.ifremer.isisfish.simulator.launcher.SimulatorLauncher#getSimulationStorage(fr.ifremer.isisfish.simulator.launcher.SimulationService, fr.ifremer.isisfish.simulator.SimulationControl) - */ - @Override - public SimulationStorage getSimulationStorage( - SimulationService simulationService, SimulationControl control) - throws RemoteException { - return null; - } - - /* - * @see fr.ifremer.isisfish.simulator.launcher.SimulatorLauncher#updateControl(fr.ifremer.isisfish.simulator.launcher.SimulationService, fr.ifremer.isisfish.simulator.SimulationControl) - */ - @Override - public void updateControl(SimulationService simulationService, - SimulationControl control) throws RemoteException { - - } - - /** - * {@inheritDoc} - * - * Do nothing (no restriction on xml rpc launcher). - */ - @Override - public void simulationStopRequest(SimulationJob job) { - - } -}