Mercurial > hg > release > thermostat-0.4
changeset 350:3ae960d641db
Show additional information when starting service after storage
Show additional help to the user when 'service --start' fails becaure
'storage --start' was previously used.
Reviewed-by: neugens
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-May/001674.html
PR995
line wrap: on
line diff
--- a/common/src/main/java/com/redhat/thermostat/common/tools/ApplicationException.java Thu May 31 23:28:41 2012 +0200 +++ b/common/src/main/java/com/redhat/thermostat/common/tools/ApplicationException.java Thu May 31 21:19:17 2012 -0400 @@ -40,9 +40,6 @@ private static final long serialVersionUID = 5910852125476383826L; - public ApplicationException() { - } - public ApplicationException(String message) { super(message); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/src/main/java/com/redhat/thermostat/common/tools/ProcessStartException.java Thu May 31 21:19:17 2012 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ +package com.redhat.thermostat.common.tools; + +public class ProcessStartException extends ApplicationException { + + private String commandName; + + /** + * @param commandName the name of the program that failed to execute + * @param cause the original exception + */ + public ProcessStartException(String commandName, Throwable cause) { + super("unable to execute " + commandName, cause); + this.commandName = commandName; + } + + public String getCommandName() { + return commandName; + } +}
--- a/common/src/main/java/com/redhat/thermostat/common/utils/LoggedExternalProcess.java Thu May 31 23:28:41 2012 +0200 +++ b/common/src/main/java/com/redhat/thermostat/common/utils/LoggedExternalProcess.java Thu May 31 21:19:17 2012 -0400 @@ -44,7 +44,12 @@ import java.util.logging.Logger; import com.redhat.thermostat.common.tools.ApplicationException; +import com.redhat.thermostat.common.tools.ProcessStartException; +/** + * Runs a process and logs it's output. The process's output and error streams + * will be unreadable. + */ public class LoggedExternalProcess extends Thread { private static final Logger logger = LoggingUtils.getLogger(LoggedExternalProcess.class); @@ -72,7 +77,7 @@ try { p = b.start(); } catch (IOException ioe) { - throw new ApplicationException("unable to execute " + commands[0], ioe); + throw new ProcessStartException(commands[0], ioe); } reader = new BufferedReader(new InputStreamReader(p.getInputStream())); this.start(); @@ -96,4 +101,4 @@ } } } -} \ No newline at end of file +}
--- a/tools/src/main/java/com/redhat/thermostat/tools/ThermostatService.java Thu May 31 23:28:41 2012 +0200 +++ b/tools/src/main/java/com/redhat/thermostat/tools/ThermostatService.java Thu May 31 21:19:17 2012 -0400 @@ -58,9 +58,11 @@ import com.redhat.thermostat.common.cli.SimpleArguments; import com.redhat.thermostat.common.config.InvalidConfigurationException; import com.redhat.thermostat.common.config.StartupConfiguration; +import com.redhat.thermostat.common.tools.ApplicationException; import com.redhat.thermostat.common.tools.ApplicationState; import com.redhat.thermostat.common.tools.BasicCommand; import com.redhat.thermostat.tools.db.DBService; +import com.redhat.thermostat.tools.db.StorageAlreadyRunningException; /** * Simple service that allows starting Agent and DB Backend @@ -154,6 +156,15 @@ case FAIL: System.err.println("error starting db"); + Object payload = actionEvent.getPayload(); + if (payload instanceof ApplicationException) { + ApplicationException exception = (ApplicationException) payload; + if (exception instanceof StorageAlreadyRunningException) { + System.err.println("Storage is already running. " + + "Please use the \"agent --start\" command to start the agent"); + } + } + notifier.fireAction(ApplicationState.FAIL); break; }
--- a/tools/src/main/java/com/redhat/thermostat/tools/db/DBService.java Thu May 31 23:28:41 2012 +0200 +++ b/tools/src/main/java/com/redhat/thermostat/tools/db/DBService.java Thu May 31 21:19:17 2012 -0400 @@ -114,7 +114,7 @@ getNotifier().fireAction(ApplicationState.SUCCESS); } catch (Exception e) { - getNotifier().fireAction(ApplicationState.FAIL); + getNotifier().fireAction(ApplicationState.FAIL, e); } }
--- a/tools/src/main/java/com/redhat/thermostat/tools/db/MongoProcessRunner.java Thu May 31 23:28:41 2012 +0200 +++ b/tools/src/main/java/com/redhat/thermostat/tools/db/MongoProcessRunner.java Thu May 31 21:19:17 2012 -0400 @@ -112,7 +112,7 @@ ", exit status: " + status + ". Please check that your configuration is valid"; display(message); - throw new ApplicationException(message); + throw new StorageStopException(configuration.getDBPath(), status, message); } } @@ -131,15 +131,18 @@ String pid = getPid(); if (pid != null) { String message = null; + ApplicationException ex = null; if (!checkExistingProcess()) { message = "A stale pid file (" + configuration.getPidFile() + ") is present " + "but there is no matching mongod process. Please remove the file if it has been shut down"; + ex = new StalePidFileException(configuration.getPidFile()); } else { message = "An instance of the storage is already running with pid " + pid; + ex = new StorageAlreadyRunningException(Integer.valueOf(pid), message); } display(message); - throw new ApplicationException(message); + throw ex; } List<String> commands = new ArrayList<>(Arrays.asList(MONGO_BASIC_ARGS)); @@ -191,7 +194,7 @@ ", exit status: " + status + ". Please check that your configuration is valid"; display(message); - throw new ApplicationException(message); + throw new StorageStartException(configuration.getDBPath(), status, message); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/src/main/java/com/redhat/thermostat/tools/db/StalePidFileException.java Thu May 31 21:19:17 2012 -0400 @@ -0,0 +1,55 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ +package com.redhat.thermostat.tools.db; + +import java.io.File; + +import com.redhat.thermostat.common.tools.ApplicationException; + +public class StalePidFileException extends ApplicationException { + + private final File pidFile; + + public StalePidFileException(File pidFile) { + super("stale pid file: " + pidFile); + this.pidFile = pidFile; + } + + public File getPidFile() { + return pidFile; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/src/main/java/com/redhat/thermostat/tools/db/StorageAlreadyRunningException.java Thu May 31 21:19:17 2012 -0400 @@ -0,0 +1,53 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ +package com.redhat.thermostat.tools.db; + +import com.redhat.thermostat.common.tools.ApplicationException; + +public class StorageAlreadyRunningException extends ApplicationException { + + private final int storagePid; + + public StorageAlreadyRunningException(int pid, String message) { + super(message); + storagePid = pid; + } + + public int getStoragePid() { + return storagePid; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/src/main/java/com/redhat/thermostat/tools/db/StorageStartException.java Thu May 31 21:19:17 2012 -0400 @@ -0,0 +1,61 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ +package com.redhat.thermostat.tools.db; + +import java.io.File; + +import com.redhat.thermostat.common.tools.ApplicationException; + +public class StorageStartException extends ApplicationException { + + private final File dbFile; + private final int status; + + public StorageStartException(File dbPath, int status, String message) { + super(message); + this.dbFile = dbPath; + this.status = status; + } + + public File getDbPath() { + return dbFile; + } + + public int getStatus() { + return status; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/src/main/java/com/redhat/thermostat/tools/db/StorageStopException.java Thu May 31 21:19:17 2012 -0400 @@ -0,0 +1,61 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ +package com.redhat.thermostat.tools.db; + +import java.io.File; + +import com.redhat.thermostat.common.tools.ApplicationException; + +public class StorageStopException extends ApplicationException { + + private final File dbConfig; + private final int status; + + public StorageStopException(File dbConfig, int status, String message) { + super(message); + this.dbConfig = dbConfig; + this.status = status; + } + + public File getDbConfig() { + return dbConfig; + } + + public int getStatus() { + return status; + } + +}
--- a/unix-process-handler/src/main/java/com/redhat/thermostat/service/process/UnixProcessUtilities.java Thu May 31 23:28:41 2012 +0200 +++ b/unix-process-handler/src/main/java/com/redhat/thermostat/service/process/UnixProcessUtilities.java Thu May 31 21:19:17 2012 -0400 @@ -46,7 +46,7 @@ import java.util.logging.Logger; import com.redhat.thermostat.common.tools.ApplicationException; -import com.redhat.thermostat.common.utils.LoggedExternalProcess; +import com.redhat.thermostat.common.tools.ProcessStartException; public class UnixProcessUtilities implements UNIXProcessHandler { @@ -112,7 +112,7 @@ try { process = builder.start(); } catch (IOException e) { - throw new ApplicationException("unable to start " + args.get(0), e); + throw new ProcessStartException(args.get(0), e); } return process; }