|
24 | 24 | import java.io.InputStream; |
25 | 25 | import java.lang.reflect.Constructor; |
26 | 26 | import java.lang.reflect.InvocationTargetException; |
27 | | -import java.net.HttpURLConnection; |
28 | 27 | import java.util.ArrayList; |
29 | 28 | import java.util.Collections; |
30 | 29 | import java.util.Date; |
@@ -173,91 +172,6 @@ public void setPersistentProperty(String prefix, String name, String value) { |
173 | 172 | _storage.persist(name, value); |
174 | 173 | } |
175 | 174 |
|
176 | | - @Override |
177 | | - public void upgradeAgent(final String url) { |
178 | | - s_logger.info("Updating agent with binary from " + url); |
179 | | - synchronized (this) { |
180 | | - final Class<?> c = this.getClass(); |
181 | | - String path = c.getResource(c.getSimpleName() + ".class") |
182 | | - .toExternalForm(); |
183 | | - final int begin = path.indexOf(File.separator); |
184 | | - int end = path.lastIndexOf("!"); |
185 | | - end = path.lastIndexOf(File.separator, end); |
186 | | - path = path.substring(begin, end); |
187 | | - |
188 | | - s_logger.debug("Current binaries reside at " + path); |
189 | | - |
190 | | - File file = null; |
191 | | - try { |
192 | | - file = File.createTempFile("agent-", |
193 | | - "-" + Long.toString(new Date().getTime())); |
194 | | - wget(url, file); |
195 | | - } catch (final IOException e) { |
196 | | - s_logger.warn( |
197 | | - "Exception while downloading agent update package, ", e); |
198 | | - throw new CloudRuntimeException("Unable to update from " + url |
199 | | - + ", exception:" + e.getMessage(), e); |
200 | | - } |
201 | | - |
202 | | - if (s_logger.isDebugEnabled()) { |
203 | | - s_logger.debug("Unzipping " + file.getAbsolutePath() + " to " |
204 | | - + path); |
205 | | - } |
206 | | - |
207 | | - final Script unzip = new Script("unzip", 120000, s_logger); |
208 | | - unzip.add("-o", "-q"); // overwrite and quiet |
209 | | - unzip.add(file.getAbsolutePath()); |
210 | | - unzip.add("-d", path); |
211 | | - |
212 | | - final String result = unzip.execute(); |
213 | | - if (result != null) { |
214 | | - throw new CloudRuntimeException( |
215 | | - "Unable to unzip the retrieved file: " + result); |
216 | | - } |
217 | | - |
218 | | - if (s_logger.isDebugEnabled()) { |
219 | | - s_logger.debug("Closing the connection to the management server"); |
220 | | - } |
221 | | - } |
222 | | - |
223 | | - if (s_logger.isDebugEnabled()) { |
224 | | - s_logger.debug("Exiting to start the new agent."); |
225 | | - } |
226 | | - System.exit(ExitStatus.Upgrade.value()); |
227 | | - } |
228 | | - |
229 | | - public static void wget(String url, File file) throws IOException { |
230 | | - final HttpClient client = new HttpClient(s_httpClientManager); |
231 | | - final GetMethod method = new GetMethod(url); |
232 | | - int response; |
233 | | - response = client.executeMethod(method); |
234 | | - if (response != HttpURLConnection.HTTP_OK) { |
235 | | - method.releaseConnection(); |
236 | | - s_logger.warn("Retrieving from " + url + " gives response code: " |
237 | | - + response); |
238 | | - throw new CloudRuntimeException("Unable to download from " + url |
239 | | - + ". Response code is " + response); |
240 | | - } |
241 | | - |
242 | | - final InputStream is = method.getResponseBodyAsStream(); |
243 | | - s_logger.debug("Downloading content into " + file.getAbsolutePath()); |
244 | | - |
245 | | - final FileOutputStream fos = new FileOutputStream(file); |
246 | | - byte[] buffer = new byte[4096]; |
247 | | - int len = 0; |
248 | | - while ((len = is.read(buffer)) > 0) |
249 | | - fos.write(buffer, 0, len); |
250 | | - fos.close(); |
251 | | - |
252 | | - try { |
253 | | - is.close(); |
254 | | - } catch (IOException e) { |
255 | | - s_logger.warn("Exception while closing download stream from " |
256 | | - + url + ", ", e); |
257 | | - } |
258 | | - method.releaseConnection(); |
259 | | - } |
260 | | - |
261 | 175 | private void loadProperties() throws ConfigurationException { |
262 | 176 | final File file = PropertiesUtil.findConfigFile("agent.properties"); |
263 | 177 | if (file == null) { |
|
0 commit comments