Skip to content

Commit 4c92c78

Browse files
committed
agent: Remove some more dead code around the Agent upgrade
1 parent b9972e5 commit 4c92c78

4 files changed

Lines changed: 0 additions & 152 deletions

File tree

agent/src/com/cloud/agent/Agent.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -214,27 +214,6 @@ public String getResourceName() {
214214
return _resource.getClass().getSimpleName();
215215
}
216216

217-
public void upgradeAgent(final String url, boolean protocol) {
218-
// shell needs to take care of synchronization when multiple-instances demand upgrade
219-
// at the same time
220-
_shell.upgradeAgent(url);
221-
222-
// To stop agent after it has been upgraded, as shell executor may prematurely time out
223-
// tasks if agent is in shutting down process
224-
if (protocol) {
225-
if (_connection != null) {
226-
_connection.stop();
227-
_connection = null;
228-
}
229-
if (_resource != null) {
230-
_resource.stop();
231-
_resource = null;
232-
}
233-
} else {
234-
stop(ShutdownCommand.Update, null);
235-
}
236-
}
237-
238217
public void start() {
239218
if (!_resource.start()) {
240219
s_logger.error("Unable to start the resource: " + _resource.getName());

agent/src/com/cloud/agent/AgentShell.java

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.io.InputStream;
2525
import java.lang.reflect.Constructor;
2626
import java.lang.reflect.InvocationTargetException;
27-
import java.net.HttpURLConnection;
2827
import java.util.ArrayList;
2928
import java.util.Collections;
3029
import java.util.Date;
@@ -173,91 +172,6 @@ public void setPersistentProperty(String prefix, String name, String value) {
173172
_storage.persist(name, value);
174173
}
175174

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-
261175
private void loadProperties() throws ConfigurationException {
262176
final File file = PropertiesUtil.findConfigFile("agent.properties");
263177
if (file == null) {

agent/src/com/cloud/agent/IAgentShell.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,5 @@ public interface IAgentShell {
5050

5151
public int getPingRetries();
5252

53-
public void upgradeAgent(final String url);
54-
5553
public String getVersion();
5654
}

agent/test/com/cloud/agent/TestAgentShell.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)