From 4c92c78e2e4b5c4fb971772e5e374ccbf2505ca3 Mon Sep 17 00:00:00 2001 From: Wido den Hollander Date: Fri, 12 Jul 2013 14:46:33 +0200 Subject: [PATCH] agent: Remove some more dead code around the Agent upgrade --- agent/src/com/cloud/agent/Agent.java | 21 ----- agent/src/com/cloud/agent/AgentShell.java | 86 ------------------- agent/src/com/cloud/agent/IAgentShell.java | 2 - .../test/com/cloud/agent/TestAgentShell.java | 43 ---------- 4 files changed, 152 deletions(-) delete mode 100644 agent/test/com/cloud/agent/TestAgentShell.java diff --git a/agent/src/com/cloud/agent/Agent.java b/agent/src/com/cloud/agent/Agent.java index 28d04709d34..f309474fbc5 100755 --- a/agent/src/com/cloud/agent/Agent.java +++ b/agent/src/com/cloud/agent/Agent.java @@ -214,27 +214,6 @@ public class Agent implements HandlerFactory, IAgentControl { return _resource.getClass().getSimpleName(); } - public void upgradeAgent(final String url, boolean protocol) { - // shell needs to take care of synchronization when multiple-instances demand upgrade - // at the same time - _shell.upgradeAgent(url); - - // To stop agent after it has been upgraded, as shell executor may prematurely time out - // tasks if agent is in shutting down process - if (protocol) { - if (_connection != null) { - _connection.stop(); - _connection = null; - } - if (_resource != null) { - _resource.stop(); - _resource = null; - } - } else { - stop(ShutdownCommand.Update, null); - } - } - public void start() { if (!_resource.start()) { s_logger.error("Unable to start the resource: " + _resource.getName()); diff --git a/agent/src/com/cloud/agent/AgentShell.java b/agent/src/com/cloud/agent/AgentShell.java index e7f114bc412..bf1e8180e44 100644 --- a/agent/src/com/cloud/agent/AgentShell.java +++ b/agent/src/com/cloud/agent/AgentShell.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.net.HttpURLConnection; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -173,91 +172,6 @@ public class AgentShell implements IAgentShell, Daemon { _storage.persist(name, value); } - @Override - public void upgradeAgent(final String url) { - s_logger.info("Updating agent with binary from " + url); - synchronized (this) { - final Class c = this.getClass(); - String path = c.getResource(c.getSimpleName() + ".class") - .toExternalForm(); - final int begin = path.indexOf(File.separator); - int end = path.lastIndexOf("!"); - end = path.lastIndexOf(File.separator, end); - path = path.substring(begin, end); - - s_logger.debug("Current binaries reside at " + path); - - File file = null; - try { - file = File.createTempFile("agent-", - "-" + Long.toString(new Date().getTime())); - wget(url, file); - } catch (final IOException e) { - s_logger.warn( - "Exception while downloading agent update package, ", e); - throw new CloudRuntimeException("Unable to update from " + url - + ", exception:" + e.getMessage(), e); - } - - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unzipping " + file.getAbsolutePath() + " to " - + path); - } - - final Script unzip = new Script("unzip", 120000, s_logger); - unzip.add("-o", "-q"); // overwrite and quiet - unzip.add(file.getAbsolutePath()); - unzip.add("-d", path); - - final String result = unzip.execute(); - if (result != null) { - throw new CloudRuntimeException( - "Unable to unzip the retrieved file: " + result); - } - - if (s_logger.isDebugEnabled()) { - s_logger.debug("Closing the connection to the management server"); - } - } - - if (s_logger.isDebugEnabled()) { - s_logger.debug("Exiting to start the new agent."); - } - System.exit(ExitStatus.Upgrade.value()); - } - - public static void wget(String url, File file) throws IOException { - final HttpClient client = new HttpClient(s_httpClientManager); - final GetMethod method = new GetMethod(url); - int response; - response = client.executeMethod(method); - if (response != HttpURLConnection.HTTP_OK) { - method.releaseConnection(); - s_logger.warn("Retrieving from " + url + " gives response code: " - + response); - throw new CloudRuntimeException("Unable to download from " + url - + ". Response code is " + response); - } - - final InputStream is = method.getResponseBodyAsStream(); - s_logger.debug("Downloading content into " + file.getAbsolutePath()); - - final FileOutputStream fos = new FileOutputStream(file); - byte[] buffer = new byte[4096]; - int len = 0; - while ((len = is.read(buffer)) > 0) - fos.write(buffer, 0, len); - fos.close(); - - try { - is.close(); - } catch (IOException e) { - s_logger.warn("Exception while closing download stream from " - + url + ", ", e); - } - method.releaseConnection(); - } - private void loadProperties() throws ConfigurationException { final File file = PropertiesUtil.findConfigFile("agent.properties"); if (file == null) { diff --git a/agent/src/com/cloud/agent/IAgentShell.java b/agent/src/com/cloud/agent/IAgentShell.java index 93aaa00c733..dde67381a4a 100644 --- a/agent/src/com/cloud/agent/IAgentShell.java +++ b/agent/src/com/cloud/agent/IAgentShell.java @@ -50,7 +50,5 @@ public interface IAgentShell { public int getPingRetries(); - public void upgradeAgent(final String url); - public String getVersion(); } diff --git a/agent/test/com/cloud/agent/TestAgentShell.java b/agent/test/com/cloud/agent/TestAgentShell.java deleted file mode 100644 index b0f748067d0..00000000000 --- a/agent/test/com/cloud/agent/TestAgentShell.java +++ /dev/null @@ -1,43 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.agent; - -import java.io.File; -import java.io.IOException; - -import junit.framework.TestCase; - -import org.apache.log4j.Logger; - -public class TestAgentShell extends TestCase { - protected final static Logger s_logger = Logger.getLogger(TestAgentShell.class); - - public void testWget() { - File file = null; - try { - file = File.createTempFile("wget", ".html"); - AgentShell.wget("http://www.apache.org/", file); - - if (s_logger.isDebugEnabled()) { - s_logger.debug("file saved to " + file.getAbsolutePath()); - } - - } catch (final IOException e) { - s_logger.warn("Exception while downloading agent update package, ", e); - } - } -}