1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.launcher; |
12 | |
|
13 | |
import org.mule.module.reboot.MuleContainerBootstrapUtils; |
14 | |
import org.mule.util.FileUtils; |
15 | |
import org.mule.util.FilenameUtils; |
16 | |
|
17 | |
import java.beans.Introspector; |
18 | |
import java.io.File; |
19 | |
import java.io.IOException; |
20 | |
import java.net.URISyntaxException; |
21 | |
import java.net.URL; |
22 | |
|
23 | |
import org.apache.commons.logging.Log; |
24 | |
import org.apache.commons.logging.LogFactory; |
25 | |
|
26 | 0 | public class DefaultMuleDeployer implements MuleDeployer |
27 | |
{ |
28 | |
|
29 | 0 | protected transient final Log logger = LogFactory.getLog(getClass()); |
30 | |
|
31 | |
public void deploy(Application app) |
32 | |
{ |
33 | |
try |
34 | |
{ |
35 | 0 | app.install(); |
36 | 0 | app.init(); |
37 | 0 | app.start(); |
38 | |
} |
39 | 0 | catch (Throwable t) |
40 | |
{ |
41 | |
|
42 | 0 | t.printStackTrace(); |
43 | 0 | } |
44 | 0 | } |
45 | |
|
46 | |
public void undeploy(Application app) |
47 | |
{ |
48 | |
try |
49 | |
{ |
50 | 0 | app.stop(); |
51 | 0 | app.dispose(); |
52 | 0 | final File appDir = new File(MuleContainerBootstrapUtils.getMuleAppsDir(), app.getAppName()); |
53 | 0 | FileUtils.deleteDirectory(appDir); |
54 | |
|
55 | 0 | File marker = new File(MuleContainerBootstrapUtils.getMuleAppsDir(), String.format("%s-anchor.txt", app.getAppName())); |
56 | 0 | marker.delete(); |
57 | 0 | Introspector.flushCaches(); |
58 | |
} |
59 | 0 | catch (Throwable t) |
60 | |
{ |
61 | |
|
62 | 0 | t.printStackTrace(); |
63 | 0 | } |
64 | |
|
65 | 0 | } |
66 | |
|
67 | |
public Application installFromAppDir(String packedMuleAppFileName) throws IOException |
68 | |
{ |
69 | 0 | final File appsDir = MuleContainerBootstrapUtils.getMuleAppsDir(); |
70 | 0 | File appFile = new File(appsDir, packedMuleAppFileName); |
71 | |
|
72 | |
|
73 | 0 | if (!appFile.getParentFile().equals(appsDir)) |
74 | |
{ |
75 | 0 | throw new SecurityException("installFromAppDir() can only deploy from $MULE_HOME/apps. Use installFrom(url) instead."); |
76 | |
} |
77 | 0 | return installFrom(appFile.toURL()); |
78 | |
} |
79 | |
|
80 | |
public Application installFrom(URL url) throws IOException |
81 | |
{ |
82 | |
|
83 | 0 | if (!url.toString().endsWith(".zip")) |
84 | |
{ |
85 | 0 | throw new IllegalArgumentException("Only Mule application zips are supported: " + url); |
86 | |
} |
87 | |
|
88 | 0 | final File appsDir = MuleContainerBootstrapUtils.getMuleAppsDir(); |
89 | |
String appName; |
90 | |
try |
91 | |
{ |
92 | 0 | final String fullPath = url.toURI().toString(); |
93 | |
|
94 | 0 | if (logger.isInfoEnabled()) |
95 | |
{ |
96 | 0 | logger.info("Exploding a Mule application archive: " + fullPath); |
97 | |
} |
98 | |
|
99 | 0 | appName = FilenameUtils.getBaseName(fullPath); |
100 | 0 | File appDir = new File(appsDir, appName); |
101 | |
|
102 | 0 | final File source = new File(url.toURI()); |
103 | |
|
104 | 0 | FileUtils.unzip(source, appDir); |
105 | 0 | if ("file".equals(url.getProtocol())) |
106 | |
{ |
107 | 0 | FileUtils.deleteQuietly(source); |
108 | |
} |
109 | |
} |
110 | 0 | catch (URISyntaxException e) |
111 | |
{ |
112 | 0 | final IOException ex = new IOException(e.getMessage()); |
113 | 0 | ex.fillInStackTrace(); |
114 | 0 | throw ex; |
115 | 0 | } |
116 | |
|
117 | |
|
118 | 0 | return new ApplicationWrapper(new DefaultMuleApplication(appName)); |
119 | |
} |
120 | |
} |