1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.gwe.app.client.admin;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.gwe.app.client.ProgressTracker;
22 import org.gwe.drivers.bundleManagers.BundleType;
23 import org.gwe.drivers.bundleManagers.DeploymentException;
24 import org.gwe.persistence.model.DaemonConfigDesc;
25
26
27
28
29
30 enum InstallationPhase {
31 deploy("deployed"), setup("setup"), launch("launched");
32
33 private String pastTense;
34 private InstallationPhase(String pastTense) { this.pastTense = pastTense; }
35 public String getPastTense() { return pastTense; }
36 }
37
38 public class ClientDaemonInstaller {
39
40 private static Log log = LogFactory.getLog(ClientDaemonInstaller.class);
41
42 private ProgressTracker tracker;
43 private ClientDaemonAppManager daemonAppManager;
44
45 public ClientDaemonInstaller(ProgressTracker tracker, DaemonConfigDesc daemonConfig) {
46 this.tracker = tracker;
47 this.daemonAppManager = new ClientDaemonAppManager(daemonConfig);
48 }
49
50 public void setupDaemon() throws InstallerException {
51 setupDaemon(BundleType.ZIP);
52 }
53
54 public void setupDaemon(BundleType bundleType) throws InstallerException {
55 try {
56 installDaemon(bundleType);
57 tracker.trackProgress("GWE daemon running and ready!");
58 } catch (InstallerException e) {
59 tracker.trackProgress(e.getMessage());
60 tracker.trackProgress("GWE daemon could not be launched.");
61 log.fatal(e);
62 throw e;
63 }
64 }
65
66 public void installDaemon() throws InstallerException {
67 installDaemon(BundleType.ZIP);
68 }
69
70 public void installDaemon(BundleType bundleType) throws InstallerException {
71 tracker.trackProgress("Deploying bundle containing GWE daemon's distribution (this may take a few minutes)...");
72 boolean newlyDeployed;
73 try {
74 newlyDeployed = daemonAppManager.deployDaemon(bundleType);
75 trackPhaseProgress(InstallationPhase.deploy, newlyDeployed);
76 } catch (DeploymentException e) {
77 throw new InstallerException(InstallationPhase.deploy, e);
78 }
79
80 if (newlyDeployed) {
81 try {
82 tracker.trackProgress("Setting up GWE daemon (this may take a few minutes)...");
83 boolean setup = daemonAppManager.setupDaemon();
84 trackPhaseProgress(InstallationPhase.setup, setup);
85 } catch (RemoteExecutionException e) {
86 throw new InstallerException(InstallationPhase.setup, e);
87 }
88 }
89
90 try {
91 tracker.trackProgress("Launching GWE daemon (this may take a few minutes)...");
92 daemonAppManager.launchDaemon();
93 tracker.trackProgress("GWE daemon launched.");
94 } catch (RemoteExecutionException e) {
95 throw new InstallerException(InstallationPhase.launch, e);
96 }
97 }
98
99 private void trackPhaseProgress(InstallationPhase phase, boolean performedJustNow) {
100 String performedTime = performedJustNow ? "" : "was already ";
101 tracker.trackProgress("GWE daemon " + performedTime + phase.getPastTense() + ".");
102 }
103 }