View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.deploy;
17  
18  import java.util.List;
19  import java.util.Properties;
20  
21  import org.kuali.common.util.FormatUtils;
22  import org.kuali.common.util.LoggerLevel;
23  import org.kuali.common.util.execute.Executable;
24  import org.kuali.common.util.secure.Result;
25  import org.kuali.common.util.secure.SecureChannel;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  public class TomcatApplicationServer implements ApplicationServer {
30  
31  	private static final Logger logger = LoggerFactory.getLogger(TomcatApplicationServer.class);
32  
33  	SecureChannel channel;
34  	boolean validateShutdownExitValue = false;
35  	String username;
36  	String group;
37  	String shutdown;
38  	String startup;
39  	// Can be either files or dirs
40  	List<String> pathsToDelete;
41  	// Must be dirs
42  	List<String> dirsToCreate;
43  	// Can be either files or dirs
44  	List<String> pathsToChown;
45  	// Files that need to be transferred
46  	List<Deployable> deployables;
47  	// Properties used to filter deployables (if filter=true)
48  	Properties filterProperties;
49  	// If true, no files are transferred from local to remote
50  	boolean skipFiles;
51  	// The sign that tomcat has started up correctly is getting an HTTP 200 from an application url
52  	Executable httpWait;
53  
54  	@Override
55  	public void stop() {
56  		long start = System.currentTimeMillis();
57  		logger.info("[tomcat:stopping]");
58  		Result result = DeployUtils.runscript(channel, username, shutdown, false);
59  		if (result.getExitValue() != 0) {
60  			DeployUtils.logResult(result, logger, LoggerLevel.WARN);
61  		}
62  		logger.info("[tomcat:stopped] - {}", FormatUtils.getTime(System.currentTimeMillis() - start));
63  	}
64  
65  	@Override
66  	public void prepare() {
67  		long start = System.currentTimeMillis();
68  		logger.info("[tomcat:preparing]");
69  		// Remove old stuff (jdbc drivers, logs, applications, configuration files in /home/tomcat etc)
70  		DeployUtils.delete(channel, pathsToDelete);
71  		// Re-create directories that need to be there
72  		DeployUtils.mkdirs(channel, dirsToCreate);
73  		// Copy files to the remote server
74  		if (!skipFiles) {
75  			// Copy files from local to remote
76  			DeployUtils.copyFiles(channel, deployables, filterProperties);
77  		}
78  		// Make sure everything is owned by tomcat:tomcat
79  		DeployUtils.chown(channel, username, group, pathsToChown);
80  		logger.info("[tomcat:prepared] - {}", FormatUtils.getTime(System.currentTimeMillis() - start));
81  	}
82  
83  	@Override
84  	public void start() {
85  		long start = System.currentTimeMillis();
86  		logger.info("[tomcat:start]");
87  		DeployUtils.runscript(channel, username, startup);
88  		httpWait.execute();
89  		logger.info("[tomcat:started] - {}", FormatUtils.getTime(System.currentTimeMillis() - start));
90  	}
91  
92  	public boolean isValidateShutdownExitValue() {
93  		return validateShutdownExitValue;
94  	}
95  
96  	public void setValidateShutdownExitValue(boolean validateShutdownExitValue) {
97  		this.validateShutdownExitValue = validateShutdownExitValue;
98  	}
99  
100 	public SecureChannel getChannel() {
101 		return channel;
102 	}
103 
104 	public void setChannel(SecureChannel channel) {
105 		this.channel = channel;
106 	}
107 
108 	public String getUsername() {
109 		return username;
110 	}
111 
112 	public void setUsername(String username) {
113 		this.username = username;
114 	}
115 
116 	public String getShutdown() {
117 		return shutdown;
118 	}
119 
120 	public void setShutdown(String shutdown) {
121 		this.shutdown = shutdown;
122 	}
123 
124 	public String getStartup() {
125 		return startup;
126 	}
127 
128 	public void setStartup(String startup) {
129 		this.startup = startup;
130 	}
131 
132 	public String getGroup() {
133 		return group;
134 	}
135 
136 	public void setGroup(String group) {
137 		this.group = group;
138 	}
139 
140 	public List<String> getPathsToDelete() {
141 		return pathsToDelete;
142 	}
143 
144 	public void setPathsToDelete(List<String> pathsToDelete) {
145 		this.pathsToDelete = pathsToDelete;
146 	}
147 
148 	public List<String> getDirsToCreate() {
149 		return dirsToCreate;
150 	}
151 
152 	public void setDirsToCreate(List<String> dirsToCreate) {
153 		this.dirsToCreate = dirsToCreate;
154 	}
155 
156 	public List<String> getPathsToChown() {
157 		return pathsToChown;
158 	}
159 
160 	public void setPathsToChown(List<String> pathsToChown) {
161 		this.pathsToChown = pathsToChown;
162 	}
163 
164 	public List<Deployable> getDeployables() {
165 		return deployables;
166 	}
167 
168 	public void setDeployables(List<Deployable> deployables) {
169 		this.deployables = deployables;
170 	}
171 
172 	public boolean isSkipFiles() {
173 		return skipFiles;
174 	}
175 
176 	public void setSkipFiles(boolean skipFiles) {
177 		this.skipFiles = skipFiles;
178 	}
179 
180 	public Properties getFilterProperties() {
181 		return filterProperties;
182 	}
183 
184 	public void setFilterProperties(Properties filterProperties) {
185 		this.filterProperties = filterProperties;
186 	}
187 
188 	public Executable getHttpWait() {
189 		return httpWait;
190 	}
191 
192 	public void setHttpWait(Executable httpWait) {
193 		this.httpWait = httpWait;
194 	}
195 
196 }