agent: Remove some more dead code around the Agent upgrade

This commit is contained in:
Wido den Hollander 2013-07-12 14:46:33 +02:00
parent b9972e587c
commit 4c92c78e2e
4 changed files with 0 additions and 152 deletions

View File

@ -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());

View File

@ -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) {

View File

@ -50,7 +50,5 @@ public interface IAgentShell {
public int getPingRetries();
public void upgradeAgent(final String url);
public String getVersion();
}

View File

@ -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);
}
}
}