From f922c6fc032fbba59a18d683cc4e001d69be6afc Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Thu, 10 Jan 2013 14:46:52 -0800 Subject: [PATCH] Keep removing --- agent/src/com/cloud/agent/AgentShell.java | 39 +- agent/src/com/cloud/agent/VmmAgentShell.java | 406 +++++++++--------- .../AgentComponentLibraryBase.java | 76 ---- .../test/com/cloud/agent/TestAgentShell.java | 13 +- .../ObjectInDataStoreManagerImpl.java | 2 + .../resource/LibvirtComputingResource.java | 281 ++++++------ server/src/com/cloud/api/ApiDispatcher.java | 4 + .../api/commands/ListTrafficMonitorsCmd.java | 28 +- .../com/cloud/storage/s3/S3ManagerImpl.java | 163 ++++--- usage/src/com/cloud/usage/UsageServer.java | 3 +- .../com/cloud/utils/db/TransactionTest.java | 8 +- .../utils/log/CglibThrowableRendererTest.java | 6 +- 12 files changed, 452 insertions(+), 577 deletions(-) delete mode 100755 agent/src/com/cloud/agent/configuration/AgentComponentLibraryBase.java diff --git a/agent/src/com/cloud/agent/AgentShell.java b/agent/src/com/cloud/agent/AgentShell.java index eac3e50d92c..0e020935e90 100644 --- a/agent/src/com/cloud/agent/AgentShell.java +++ b/agent/src/com/cloud/agent/AgentShell.java @@ -53,10 +53,7 @@ import com.cloud.utils.ProcessUtil; import com.cloud.utils.PropertiesUtil; import com.cloud.utils.backoff.BackoffAlgorithm; import com.cloud.utils.backoff.impl.ConstantTimeBackoff; -import com.cloud.utils.component.Adapters; -import com.cloud.utils.component.LegacyComponentLocator; import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.net.MacAddress; import com.cloud.utils.script.Script; public class AgentShell implements IAgentShell { @@ -146,6 +143,7 @@ public class AgentShell implements IAgentShell { return _guid; } + @Override public Map getCmdLineProperties() { return _cmdLineProperties; } @@ -378,8 +376,6 @@ public class AgentShell implements IAgentShell { public void init(String[] args) throws ConfigurationException { - final LegacyComponentLocator locator = LegacyComponentLocator.getLocator("agent"); - final Class c = this.getClass(); _version = c.getPackage().getImplementationVersion(); if (_version == null) { @@ -396,12 +392,9 @@ public class AgentShell implements IAgentShell { s_logger.debug("Found property: " + property); } - _storage = locator.getManager(StorageComponent.class); - if (_storage == null) { - s_logger.info("Defaulting to using properties file for storage"); - _storage = new PropertiesStorage(); - _storage.configure("Storage", new HashMap()); - } + s_logger.info("Defaulting to using properties file for storage"); + _storage = new PropertiesStorage(); + _storage.configure("Storage", new HashMap()); // merge with properties from command line to let resource access // command line parameters @@ -410,22 +403,9 @@ public class AgentShell implements IAgentShell { _properties.put(cmdLineProp.getKey(), cmdLineProp.getValue()); } - final Adapters adapters = locator.getAdapters(BackoffAlgorithm.class); - final Enumeration en = adapters.enumeration(); - while (en.hasMoreElements()) { - _backoff = (BackoffAlgorithm) en.nextElement(); - break; - } - if (en.hasMoreElements()) { - s_logger.info("More than one backoff algorithm specified. Using the first one "); - } - - if (_backoff == null) { - s_logger.info("Defaulting to the constant time backoff algorithm"); - _backoff = new ConstantTimeBackoff(); - _backoff.configure("ConstantTimeBackoff", - new HashMap()); - } + s_logger.info("Defaulting to the constant time backoff algorithm"); + _backoff = new ConstantTimeBackoff(); + _backoff.configure("ConstantTimeBackoff", new HashMap()); } private void launchAgent() throws ConfigurationException { @@ -469,6 +449,7 @@ public class AgentShell implements IAgentShell { openPortWithIptables(port); _consoleProxyMain = new Thread(new Runnable() { + @Override public void run() { try { Class consoleProxyClazz = Class.forName("com.cloud.consoleproxy.ConsoleProxy"); @@ -522,7 +503,7 @@ public class AgentShell implements IAgentShell { } catch (final SecurityException e) { throw new ConfigurationException( "Security excetion when loading resource: " + name - + " due to: " + e.toString()); + + " due to: " + e.toString()); } catch (final NoSuchMethodException e) { throw new ConfigurationException( "Method not found excetion when loading resource: " @@ -534,7 +515,7 @@ public class AgentShell implements IAgentShell { } catch (final InstantiationException e) { throw new ConfigurationException( "Instantiation excetion when loading resource: " + name - + " due to: " + e.toString()); + + " due to: " + e.toString()); } catch (final IllegalAccessException e) { throw new ConfigurationException( "Illegal access exception when loading resource: " diff --git a/agent/src/com/cloud/agent/VmmAgentShell.java b/agent/src/com/cloud/agent/VmmAgentShell.java index ec2867940a2..190d1168284 100644 --- a/agent/src/com/cloud/agent/VmmAgentShell.java +++ b/agent/src/com/cloud/agent/VmmAgentShell.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -41,19 +40,15 @@ import com.cloud.agent.dao.impl.PropertiesStorage; import com.cloud.agent.transport.Request; import com.cloud.resource.ServerResource; import com.cloud.utils.NumbersUtil; -import com.cloud.utils.ProcessUtil; import com.cloud.utils.PropertiesUtil; import com.cloud.utils.backoff.BackoffAlgorithm; import com.cloud.utils.backoff.impl.ConstantTimeBackoff; -import com.cloud.utils.component.Adapters; -import com.cloud.utils.component.LegacyComponentLocator; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.MacAddress; import com.cloud.utils.nio.HandlerFactory; import com.cloud.utils.nio.Link; import com.cloud.utils.nio.NioServer; import com.cloud.utils.nio.Task; -import com.cloud.utils.nio.Task.Type; /** * Implementation of agent shell to run the agents on System Center Virtual Machine manager @@ -61,7 +56,7 @@ import com.cloud.utils.nio.Task.Type; public class VmmAgentShell implements IAgentShell, HandlerFactory { - private static final Logger s_logger = Logger.getLogger(VmmAgentShell.class.getName()); + private static final Logger s_logger = Logger.getLogger(VmmAgentShell.class.getName()); private final Properties _properties = new Properties(); private final Map _cmdLineProperties = new HashMap(); private StorageComponent _storage; @@ -76,112 +71,112 @@ public class VmmAgentShell implements IAgentShell, HandlerFactory { private int _proxyPort; private int _workers; private String _guid; - static private NioServer _connection; - static private int _listenerPort=9000; + static private NioServer _connection; + static private int _listenerPort=9000; private int _nextAgentId = 1; private volatile boolean _exit = false; private int _pingRetries; - private Thread _consoleProxyMain = null; + private final Thread _consoleProxyMain = null; private final List _agents = new ArrayList(); public VmmAgentShell() { } - + @Override public Properties getProperties() { - return _properties; + return _properties; } - + @Override public BackoffAlgorithm getBackoffAlgorithm() { - return _backoff; + return _backoff; } - + @Override public int getPingRetries() { - return _pingRetries; + return _pingRetries; } - + @Override public String getZone() { - return _zone; + return _zone; } - + @Override public String getPod() { - return _pod; + return _pod; } - + @Override public String getHost() { - return _host; + return _host; } - + @Override public String getPrivateIp() { - return _privateIp; + return _privateIp; } - + @Override public int getPort() { - return _port; + return _port; } - + @Override public int getProxyPort() { - return _proxyPort; + return _proxyPort; } - + @Override public int getWorkers() { - return _workers; + return _workers; } - + @Override public String getGuid() { - return _guid; + return _guid; } - @Override - public void upgradeAgent(String url) { - // TODO Auto-generated method stub - - } + @Override + public void upgradeAgent(String url) { + // TODO Auto-generated method stub - @Override + } + + @Override public String getVersion() { - return _version; + return _version; } - @Override - public Map getCmdLineProperties() { - // TODO Auto-generated method stub - return _cmdLineProperties; - } - - public String getProperty(String prefix, String name) { - if(prefix != null) - return _properties.getProperty(prefix + "." + name); - - return _properties.getProperty(name); + @Override + public Map getCmdLineProperties() { + // TODO Auto-generated method stub + return _cmdLineProperties; } - - @Override - public String getPersistentProperty(String prefix, String name) { - if(prefix != null) - return _storage.get(prefix + "." + name); - return _storage.get(name); - } - @Override - public void setPersistentProperty(String prefix, String name, String value) { - if(prefix != null) - _storage.persist(prefix + "." + name, value); - else - _storage.persist(name, value); - } + public String getProperty(String prefix, String name) { + if(prefix != null) + return _properties.getProperty(prefix + "." + name); - private void loadProperties() throws ConfigurationException { + return _properties.getProperty(name); + } + + @Override + public String getPersistentProperty(String prefix, String name) { + if(prefix != null) + return _storage.get(prefix + "." + name); + return _storage.get(name); + } + + @Override + public void setPersistentProperty(String prefix, String name, String value) { + if(prefix != null) + _storage.persist(prefix + "." + name, value); + else + _storage.persist(name, value); + } + + private void loadProperties() throws ConfigurationException { final File file = PropertiesUtil.findConfigFile("agent.properties"); if (file == null) { throw new ConfigurationException("Unable to find agent.properties."); @@ -197,7 +192,7 @@ public class VmmAgentShell implements IAgentShell, HandlerFactory { throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex); } } - + protected boolean parseCommand(final String[] args) throws ConfigurationException { String host = null; String workers = null; @@ -211,7 +206,7 @@ public class VmmAgentShell implements IAgentShell, HandlerFactory { System.out.println("Invalid Parameter: " + args[i]); continue; } - + // save command line properties _cmdLineProperties.put(tokens[0], tokens[1]); @@ -222,14 +217,14 @@ public class VmmAgentShell implements IAgentShell, HandlerFactory { } else if (tokens[0].equalsIgnoreCase("host")) { host = tokens[1]; } else if(tokens[0].equalsIgnoreCase("zone")) { - zone = tokens[1]; + zone = tokens[1]; } else if(tokens[0].equalsIgnoreCase("pod")) { - pod = tokens[1]; + pod = tokens[1]; } else if(tokens[0].equalsIgnoreCase("guid")) { - guid = tokens[1]; - } else if(tokens[0].equalsIgnoreCase("eth1ip")) { - _privateIp = tokens[1]; - } + guid = tokens[1]; + } else if(tokens[0].equalsIgnoreCase("eth1ip")) { + _privateIp = tokens[1]; + } } if (port == null) { @@ -237,7 +232,7 @@ public class VmmAgentShell implements IAgentShell, HandlerFactory { } _port = NumbersUtil.parseInt(port, 8250); - + _proxyPort = NumbersUtil.parseInt(getProperty(null, "consoleproxy.httpListenPort"), 443); if (workers == null) { @@ -254,42 +249,42 @@ public class VmmAgentShell implements IAgentShell, HandlerFactory { host = "localhost"; } _host = host; - + if(zone != null) - _zone = zone; + _zone = zone; else - _zone = getProperty(null, "zone"); + _zone = getProperty(null, "zone"); if (_zone == null || (_zone.startsWith("@") && _zone.endsWith("@"))) { - _zone = "default"; + _zone = "default"; } if(pod != null) - _pod = pod; + _pod = pod; else - _pod = getProperty(null, "pod"); + _pod = getProperty(null, "pod"); if (_pod == null || (_pod.startsWith("@") && _pod.endsWith("@"))) { - _pod = "default"; + _pod = "default"; } if (_host == null || (_host.startsWith("@") && _host.endsWith("@"))) { throw new ConfigurationException("Host is not configured correctly: " + _host); } - + final String retries = getProperty(null, "ping.retries"); _pingRetries = NumbersUtil.parseInt(retries, 5); String value = getProperty(null, "developer"); boolean developer = Boolean.parseBoolean(value); - + if(guid != null) - _guid = guid; + _guid = guid; else - _guid = getProperty(null, "guid"); + _guid = getProperty(null, "guid"); if (_guid == null) { - if (!developer) { - throw new ConfigurationException("Unable to find the guid"); - } - _guid = MacAddress.getMacAddress().toString(":"); + if (!developer) { + throw new ConfigurationException("Unable to find the guid"); + } + _guid = MacAddress.getMacAddress().toString(":"); } return true; @@ -303,63 +298,46 @@ public class VmmAgentShell implements IAgentShell, HandlerFactory { } s_logger.trace("Launching agent based on type=" + typeInfo); } - + private void launchAgent() throws ConfigurationException { String resourceClassNames = getProperty(null, "resource"); s_logger.trace("resource=" + resourceClassNames); if(resourceClassNames != null) { - launchAgentFromClassInfo(resourceClassNames); - return; + launchAgentFromClassInfo(resourceClassNames); + return; } - + launchAgentFromTypeInfo(); } - + private void init(String[] args) throws ConfigurationException{ - - final LegacyComponentLocator locator = LegacyComponentLocator.getLocator("agent"); - + final Class c = this.getClass(); _version = c.getPackage().getImplementationVersion(); if (_version == null) { throw new CloudRuntimeException("Unable to find the implementation version of this agent"); } s_logger.info("Implementation Version is " + _version); - + parseCommand(args); - - _storage = locator.getManager(StorageComponent.class); - if (_storage == null) { - s_logger.info("Defaulting to using properties file for storage"); - _storage = new PropertiesStorage(); - _storage.configure("Storage", new HashMap()); - } + + s_logger.info("Defaulting to using properties file for storage"); + _storage = new PropertiesStorage(); + _storage.configure("Storage", new HashMap()); // merge with properties from command line to let resource access command line parameters for(Map.Entry cmdLineProp : getCmdLineProperties().entrySet()) { - _properties.put(cmdLineProp.getKey(), cmdLineProp.getValue()); - } - - final Adapters adapters = locator.getAdapters(BackoffAlgorithm.class); - final Enumeration en = adapters.enumeration(); - while (en.hasMoreElements()) { - _backoff = (BackoffAlgorithm)en.nextElement(); - break; - } - if (en.hasMoreElements()) { - s_logger.info("More than one backoff algorithm specified. Using the first one "); + _properties.put(cmdLineProp.getKey(), cmdLineProp.getValue()); } - if (_backoff == null) { - s_logger.info("Defaulting to the constant time backoff algorithm"); - _backoff = new ConstantTimeBackoff(); - _backoff.configure("ConstantTimeBackoff", new HashMap()); - } + s_logger.info("Defaulting to the constant time backoff algorithm"); + _backoff = new ConstantTimeBackoff(); + _backoff.configure("ConstantTimeBackoff", new HashMap()); } private void launchAgentFromClassInfo(String resourceClassNames) throws ConfigurationException { - String[] names = resourceClassNames.split("\\|"); - for(String name: names) { + String[] names = resourceClassNames.split("\\|"); + for(String name: names) { Class impl; try { impl = Class.forName(name); @@ -368,41 +346,41 @@ public class VmmAgentShell implements IAgentShell, HandlerFactory { ServerResource resource = (ServerResource)constructor.newInstance(); launchAgent(getNextAgentId(), resource); } catch (final ClassNotFoundException e) { - throw new ConfigurationException("Resource class not found: " + name); + throw new ConfigurationException("Resource class not found: " + name); } catch (final SecurityException e) { - throw new ConfigurationException("Security excetion when loading resource: " + name); + throw new ConfigurationException("Security excetion when loading resource: " + name); } catch (final NoSuchMethodException e) { - throw new ConfigurationException("Method not found excetion when loading resource: " + name); + throw new ConfigurationException("Method not found excetion when loading resource: " + name); } catch (final IllegalArgumentException e) { - throw new ConfigurationException("Illegal argument excetion when loading resource: " + name); + throw new ConfigurationException("Illegal argument excetion when loading resource: " + name); } catch (final InstantiationException e) { - throw new ConfigurationException("Instantiation excetion when loading resource: " + name); + throw new ConfigurationException("Instantiation excetion when loading resource: " + name); } catch (final IllegalAccessException e) { - throw new ConfigurationException("Illegal access exception when loading resource: " + name); + throw new ConfigurationException("Illegal access exception when loading resource: " + name); } catch (final InvocationTargetException e) { - throw new ConfigurationException("Invocation target exception when loading resource: " + name); + throw new ConfigurationException("Invocation target exception when loading resource: " + name); } - } + } } private void launchAgent(int localAgentId, ServerResource resource) throws ConfigurationException { - // we don't track agent after it is launched for now - Agent agent = new Agent(this, localAgentId, resource); - _agents.add(agent); - agent.start(); + // we don't track agent after it is launched for now + Agent agent = new Agent(this, localAgentId, resource); + _agents.add(agent); + agent.start(); } public synchronized int getNextAgentId() { - return _nextAgentId++; + return _nextAgentId++; } - - private void run(String[] args) { - - try { + + private void run(String[] args) { + + try { System.setProperty("java.net.preferIPv4Stack","true"); - loadProperties(); - init(args); - + loadProperties(); + init(args); + String instance = getProperty(null, "instance"); if (instance == null) { instance = ""; @@ -413,22 +391,22 @@ public class VmmAgentShell implements IAgentShell, HandlerFactory { // TODO need to do this check. For Agentshell running on windows needs different approach //final String run = "agent." + instance + "pid"; //s_logger.debug("Checking to see if " + run + "exists."); - //ProcessUtil.pidCheck(run); - - + //ProcessUtil.pidCheck(run); + + // TODO: For Hyper-V agent.properties need to be revamped to support multiple agents // corresponding to multiple clusters but running on a SCVMM host - + // read the persistent storage and launch the agents - //launchAgent(); + //launchAgent(); // FIXME get rid of this approach of agent listening for boot strap commands from the management server - // now listen for bootstrap request from the management server and launch agents - _connection = new NioServer("VmmAgentShell", _listenerPort, 1, this); - _connection.start(); - s_logger.info("SCVMM agent is listening on port " +_listenerPort + " for bootstrap command from management server"); - while(_connection.isRunning()); + // now listen for bootstrap request from the management server and launch agents + _connection = new NioServer("VmmAgentShell", _listenerPort, 1, this); + _connection.start(); + s_logger.info("SCVMM agent is listening on port " +_listenerPort + " for bootstrap command from management server"); + while(_connection.isRunning()); } catch(final ConfigurationException e) { s_logger.error("Unable to start agent: " + e.getMessage()); System.out.println("Unable to start agent: " + e.getMessage()); @@ -438,89 +416,89 @@ public class VmmAgentShell implements IAgentShell, HandlerFactory { System.out.println("Unable to start agent: " + e.getMessage()); System.exit(ExitStatus.Error.value()); } - } + } - @Override - public Task create(com.cloud.utils.nio.Task.Type type, Link link, - byte[] data) { - return new AgentBootStrapHandler(type, link, data); - } + @Override + public Task create(com.cloud.utils.nio.Task.Type type, Link link, + byte[] data) { + return new AgentBootStrapHandler(type, link, data); + } - public void stop() { - _exit = true; - if(_consoleProxyMain != null) { - _consoleProxyMain.interrupt(); - } - } - - public static void main(String[] args) { - - VmmAgentShell shell = new VmmAgentShell(); - Runtime.getRuntime().addShutdownHook(new ShutdownThread(shell)); - shell.run(args); - } + public void stop() { + _exit = true; + if(_consoleProxyMain != null) { + _consoleProxyMain.interrupt(); + } + } - // class to handle the bootstrap command from the management server - private class AgentBootStrapHandler extends Task { + public static void main(String[] args) { - public AgentBootStrapHandler(Task.Type type, Link link, byte[] data) { - super(type, link, data); - } + VmmAgentShell shell = new VmmAgentShell(); + Runtime.getRuntime().addShutdownHook(new ShutdownThread(shell)); + shell.run(args); + } - @Override - protected void doTask(Task task) throws Exception { - final Type type = task.getType(); - s_logger.info("recieved task of type "+ type.toString() +" to handle in BootStrapTakHandler"); - if (type == Task.Type.DATA) - { - final byte[] data = task.getData(); - final Request request = Request.parse(data); - final Command cmd = request.getCommand(); - - if (cmd instanceof StartupVMMAgentCommand) { + // class to handle the bootstrap command from the management server + private class AgentBootStrapHandler extends Task { - StartupVMMAgentCommand vmmCmd = (StartupVMMAgentCommand) cmd; + public AgentBootStrapHandler(Task.Type type, Link link, byte[] data) { + super(type, link, data); + } - _zone = Long.toString(vmmCmd.getDataCenter()); - _cmdLineProperties.put("zone", _zone); + @Override + protected void doTask(Task task) throws Exception { + final Type type = task.getType(); + s_logger.info("recieved task of type "+ type.toString() +" to handle in BootStrapTakHandler"); + if (type == Task.Type.DATA) + { + final byte[] data = task.getData(); + final Request request = Request.parse(data); + final Command cmd = request.getCommand(); - _pod = Long.toString(vmmCmd.getPod()); - _cmdLineProperties.put("pod", _pod); + if (cmd instanceof StartupVMMAgentCommand) { - _cluster = vmmCmd.getClusterName(); - _cmdLineProperties.put("cluster", _cluster); + StartupVMMAgentCommand vmmCmd = (StartupVMMAgentCommand) cmd; - _guid = vmmCmd.getGuid(); - _cmdLineProperties.put("guid", _guid); + _zone = Long.toString(vmmCmd.getDataCenter()); + _cmdLineProperties.put("zone", _zone); - _host = vmmCmd.getManagementServerIP(); - _port = NumbersUtil.parseInt(vmmCmd.getport(), 8250); + _pod = Long.toString(vmmCmd.getPod()); + _cmdLineProperties.put("pod", _pod); - s_logger.info("Recieved boot strap command from management server with parameters " + - " Zone:"+ _zone + " "+ - " Cluster:"+ _cluster + " "+ - " pod:"+_pod + " "+ - " host:"+ _host +" "+ - " port:"+_port); + _cluster = vmmCmd.getClusterName(); + _cmdLineProperties.put("cluster", _cluster); - launchAgentFromClassInfo("com.cloud.hypervisor.hyperv.resource.HypervResource"); - - // TODO: persist the info in agent.properties for agent restarts - } - } - } - } + _guid = vmmCmd.getGuid(); + _cmdLineProperties.put("guid", _guid); + + _host = vmmCmd.getManagementServerIP(); + _port = NumbersUtil.parseInt(vmmCmd.getport(), 8250); + + s_logger.info("Recieved boot strap command from management server with parameters " + + " Zone:"+ _zone + " "+ + " Cluster:"+ _cluster + " "+ + " pod:"+_pod + " "+ + " host:"+ _host +" "+ + " port:"+_port); + + launchAgentFromClassInfo("com.cloud.hypervisor.hyperv.resource.HypervResource"); + + // TODO: persist the info in agent.properties for agent restarts + } + } + } + } private static class ShutdownThread extends Thread { - VmmAgentShell _shell; + VmmAgentShell _shell; public ShutdownThread(VmmAgentShell shell) { this._shell = shell; } - + @Override public void run() { _shell.stop(); } } - + } \ No newline at end of file diff --git a/agent/src/com/cloud/agent/configuration/AgentComponentLibraryBase.java b/agent/src/com/cloud/agent/configuration/AgentComponentLibraryBase.java deleted file mode 100755 index 4ea101c3951..00000000000 --- a/agent/src/com/cloud/agent/configuration/AgentComponentLibraryBase.java +++ /dev/null @@ -1,76 +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.configuration; - -import java.util.List; -import java.util.Map; - -import com.cloud.utils.component.Adapter; -import com.cloud.utils.component.ComponentLibraryBase; -import com.cloud.utils.component.LegacyComponentLocator.ComponentInfo; -import com.cloud.utils.component.Manager; -import com.cloud.utils.component.PluggableService; -import com.cloud.utils.db.GenericDao; - -public class AgentComponentLibraryBase extends ComponentLibraryBase { - @Override - public Map>> getDaos() { - return null; - } - - @Override - public Map> getManagers() { - if (_managers.size() == 0) { - populateManagers(); - } - return _managers; - } - - @Override - public Map>> getAdapters() { - if (_adapters.size() == 0) { - populateAdapters(); - } - return _adapters; - } - - @Override - public Map, Class> getFactories() { - return null; - } - - protected void populateManagers() { - // addManager("StackMaidManager", StackMaidManagerImpl.class); - } - - protected void populateAdapters() { - - } - - protected void populateServices() { - - } - - @Override - public Map> getPluggableServices() { - if (_pluggableServices.size() == 0) { - populateServices(); - } - return _pluggableServices; - } - -} diff --git a/agent/test/com/cloud/agent/TestAgentShell.java b/agent/test/com/cloud/agent/TestAgentShell.java index d7210acbef3..0e9be0f1312 100644 --- a/agent/test/com/cloud/agent/TestAgentShell.java +++ b/agent/test/com/cloud/agent/TestAgentShell.java @@ -19,24 +19,23 @@ package com.cloud.agent; import java.io.File; import java.io.IOException; +import junit.framework.TestCase; + import org.apache.log4j.Logger; -import com.cloud.agent.AgentShell; -import com.cloud.utils.testcase.Log4jEnabledTestCase; - -public class TestAgentShell extends Log4jEnabledTestCase { +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.google.com/", 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); } diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java index 26cd5592bab..7c310b777f3 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java @@ -1,5 +1,7 @@ package org.apache.cloudstack.storage.datastore; +import javax.inject.Inject; + import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.storage.db.ObjectInDataStoreDao; import org.apache.cloudstack.storage.db.ObjectInDataStoreVO; diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index cd1971dd427..af5b2a4c33b 100755 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -25,9 +25,7 @@ import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.lang.reflect.InvocationTargetException; import java.net.InetAddress; -import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; @@ -44,15 +42,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.ejb.Local; import javax.naming.ConfigurationException; @@ -167,7 +164,13 @@ import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.StorageFilerTO; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.api.to.VolumeTO; +import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource; +import com.cloud.dc.Vlan; +import com.cloud.exception.InternalErrorException; +import com.cloud.host.Host.Type; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool; +import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ClockDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ConsoleDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.CpuTuneDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DevicesDef; @@ -182,16 +185,10 @@ import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef.hostNicType; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.SerialDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.TermPolicy; -import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ClockDef; -import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource; import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk; import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk.PhysicalDiskFormat; import com.cloud.hypervisor.kvm.storage.KVMStoragePool; import com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager; -import com.cloud.dc.Vlan; -import com.cloud.exception.InternalErrorException; -import com.cloud.host.Host.Type; -import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.IsolationType; import com.cloud.network.Networks.RouterPrivateIpStrategy; @@ -199,6 +196,7 @@ import com.cloud.network.Networks.TrafficType; import com.cloud.network.PhysicalNetworkSetupInfo; import com.cloud.resource.ServerResource; import com.cloud.resource.ServerResourceBase; +import com.cloud.storage.JavaStorageLayer; import com.cloud.storage.Storage; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.StoragePoolType; @@ -212,7 +210,6 @@ import com.cloud.storage.template.TemplateLocation; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.PropertiesUtil; - import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; import com.cloud.utils.script.OutputInterpreter; @@ -246,7 +243,7 @@ import com.cloud.vm.VirtualMachineName; **/ @Local(value = { ServerResource.class }) public class LibvirtComputingResource extends ServerResourceBase implements - ServerResource { +ServerResource { private static final Logger s_logger = Logger .getLogger(LibvirtComputingResource.class); @@ -329,8 +326,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements private boolean _can_bridge_firewall; protected String _localStoragePath; protected String _localStorageUUID; - private Map _pifs = new HashMap(); - private Map> hostNetInfo = new HashMap>(); + private final Map _pifs = new HashMap(); + private final Map> hostNetInfo = new HashMap>(); private final Map _vmStats = new ConcurrentHashMap(); protected boolean _disconnected = true; @@ -375,7 +372,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements tokens[3] = Integer.toString(lastbyte); StringBuilder end = new StringBuilder(15); end.append(tokens[0]).append(".").append(tokens[1]).append(".") - .append(tokens[2]).append(".").append(tokens[3]); + .append(tokens[2]).append(".").append(tokens[3]); return end.toString(); } @@ -444,16 +441,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements return false; } - try { - Class clazz = Class - .forName("com.cloud.storage.JavaStorageLayer"); - _storage = (StorageLayer) ComponentLocator.inject(clazz); - _storage.configure("StorageLayer", params); - } catch (ClassNotFoundException e) { - throw new ConfigurationException("Unable to find class " - + "com.cloud.storage.JavaStorageLayer"); - } - + _storage = new JavaStorageLayer(); + _storage.configure("StorageLayer", params); String domrScriptsDir = (String) params.get("domr.scripts.dir"); if (domrScriptsDir == null) { @@ -685,7 +674,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements String[] isoPaths = { "/usr/lib64/cloud/agent/vms/systemvm.iso", "/usr/lib/cloud/agent/vms/systemvm.iso", "/usr/lib64/cloud/common/vms/systemvm.iso", - "/usr/lib/cloud/common/vms/systemvm.iso" }; + "/usr/lib/cloud/common/vms/systemvm.iso" }; for (String isoPath : isoPaths) { if (_storage.exists(isoPath)) { _sysvmISOPath = isoPath; @@ -723,7 +712,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements if (_mountPoint == null) { _mountPoint = "/mnt"; } - + value = (String) params.get("vm.migrate.speed"); _migrateSpeed = NumbersUtil.parseInt(value, -1); if (_migrateSpeed == -1) { @@ -736,7 +725,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements try { _migrateSpeed = Integer.parseInt(tokens[0]); } catch (Exception e) { - + } s_logger.debug("device " + _pifs.get("public") + " has speed: " + String.valueOf(_migrateSpeed)); } @@ -750,28 +739,28 @@ public class LibvirtComputingResource extends ServerResourceBase implements bridges.put("private", _privBridgeName); bridges.put("guest", _guestBridgeName); - params.put("libvirt.host.bridges", (Object) bridges); - params.put("libvirt.host.pifs", (Object) _pifs); + params.put("libvirt.host.bridges", bridges); + params.put("libvirt.host.pifs", _pifs); // Load the vif driver String vifDriverName = (String) params.get("libvirt.vif.driver"); if (vifDriverName == null) { - s_logger.info("No libvirt.vif.driver specififed. Defaults to BridgeVifDriver."); - vifDriverName = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver"; + s_logger.info("No libvirt.vif.driver specififed. Defaults to BridgeVifDriver."); + vifDriverName = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver"; } - params.put("libvirt.computing.resource", (Object) this); + params.put("libvirt.computing.resource", this); try { - Class clazz = Class.forName(vifDriverName); - _vifDriver = (VifDriver) clazz.newInstance(); - _vifDriver.configure(params); + Class clazz = Class.forName(vifDriverName); + _vifDriver = (VifDriver) clazz.newInstance(); + _vifDriver.configure(params); } catch (ClassNotFoundException e) { - throw new ConfigurationException("Unable to find class for libvirt.vif.driver " + e); + throw new ConfigurationException("Unable to find class for libvirt.vif.driver " + e); } catch (InstantiationException e) { - throw new ConfigurationException("Unable to instantiate class for libvirt.vif.driver " + e); + throw new ConfigurationException("Unable to instantiate class for libvirt.vif.driver " + e); } catch (Exception e) { - throw new ConfigurationException("Failed to initialize libvirt.vif.driver " + e); + throw new ConfigurationException("Failed to initialize libvirt.vif.driver " + e); } @@ -802,7 +791,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements String vlan = Script.runSimpleBashScript("ls /proc/net/vlan/" + pif); if (vlan != null && !vlan.isEmpty()) { - pif = Script.runSimpleBashScript("grep ^Device\\: /proc/net/vlan/" + pif + " | awk {'print $2'}"); + pif = Script.runSimpleBashScript("grep ^Device\\: /proc/net/vlan/" + pif + " | awk {'print $2'}"); } return pif; @@ -1105,8 +1094,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements KVMStoragePool secondaryStoragePool = null; try { KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool( - pool.getType(), - pool.getUuid()); + pool.getType(), + pool.getUuid()); String volumeName = UUID.randomUUID().toString(); if (copyToSecondary) { @@ -1116,20 +1105,20 @@ public class LibvirtComputingResource extends ServerResourceBase implements String volumeDestPath = "/volumes/" + cmd.getVolumeId() + File.separator; secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI( - secondaryStorageUrl); + secondaryStorageUrl); secondaryStoragePool.createFolder(volumeDestPath); secondaryStoragePool.delete(); secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI( - secondaryStorageUrl - + volumeDestPath); + secondaryStorageUrl + + volumeDestPath); _storagePoolMgr.copyPhysicalDisk(volume, destVolumeName,secondaryStoragePool); return new CopyVolumeAnswer(cmd, true, null, null, volumeName); } else { volumePath = "/volumes/" + cmd.getVolumeId() + File.separator; secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI( - secondaryStorageUrl - + volumePath); + secondaryStorageUrl + + volumePath); KVMPhysicalDisk volume = secondaryStoragePool .getPhysicalDisk(cmd.getVolumePath() + ".qcow2"); _storagePoolMgr.copyPhysicalDisk(volume, volumeName, @@ -1148,7 +1137,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements protected Answer execute(DeleteStoragePoolCommand cmd) { try { _storagePoolMgr.deleteStoragePool(cmd.getPool().getType(), - cmd.getPool().getUuid()); + cmd.getPool().getUuid()); return new Answer(cmd); } catch (CloudRuntimeException e) { return new Answer(cmd, false, e.toString()); @@ -1190,7 +1179,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements long disksize; try { primaryPool = _storagePoolMgr.getStoragePool(pool.getType(), - pool.getUuid()); + pool.getUuid()); disksize = dskch.getSize(); if (cmd.getTemplateUrl() != null) { @@ -1199,7 +1188,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements } else { BaseVol = primaryPool.getPhysicalDisk(cmd.getTemplateUrl()); vol = _storagePoolMgr.createDiskFromTemplate(BaseVol, UUID - .randomUUID().toString(), primaryPool); + .randomUUID().toString(), primaryPool); } if (vol == null) { return new Answer(cmd, false, @@ -1273,8 +1262,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements try { KVMStoragePool pool = _storagePoolMgr.getStoragePool( - vol.getPoolType(), - vol.getPoolUuid()); + vol.getPoolType(), + vol.getPoolUuid()); pool.deletePhysicalDisk(vol.getPath()); String vmName = cmd.getVmName(); String poolPath = pool.getLocalPath(); @@ -1289,7 +1278,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements _storagePoolMgr.deleteVbdByPath(vol.getPoolType(),patchVbd.getAbsolutePath()); } catch(CloudRuntimeException e) { s_logger.warn("unable to destroy patch disk '" + patchVbd.getAbsolutePath() + - "' while removing root disk for " + vmName + " : " + e); + "' while removing root disk for " + vmName + " : " + e); } } else { s_logger.debug("file '" +patchVbd.getAbsolutePath()+ "' not found"); @@ -1425,7 +1414,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements String dev = "eth" + nic.getDeviceId(); String netmask = NetUtils.getSubNet(routerGIP, nic.getNetmask()); String result = _virtRouterResource.assignGuestNetwork(dev, routerIP, - routerGIP, gateway, cidr, netmask, dns, domainName ); + routerGIP, gateway, cidr, netmask, dns, domainName ); if (result != null) { return new SetupGuestNetworkAnswer(cmd, false, "Creating guest network failed due to " + result); @@ -1461,7 +1450,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements String rule = sb.toString(); String result = _virtRouterResource.assignNetworkACL(routerIp, - dev, nic.getIp(), netmask, rule); + dev, nic.getIp(), netmask, rule); if (result != null) { for (int i=0; i < results.length; i++) { @@ -1492,21 +1481,21 @@ public class LibvirtComputingResource extends ServerResourceBase implements List pluggedNics = getInterfaces(conn, routerName); for (InterfaceDef pluggedNic : pluggedNics) { - String pluggedVlanBr = pluggedNic.getBrName(); - String pluggedVlanId = getVlanIdFromBridge(pluggedVlanBr); - if (pubVlan.equalsIgnoreCase(Vlan.UNTAGGED) - && pluggedVlanBr.equalsIgnoreCase(_publicBridgeName)) { - break; - } else if (pluggedVlanBr.equalsIgnoreCase(_linkLocalBridgeName)){ - /*skip over, no physical bridge device exists*/ - } else if (pluggedVlanId == null) { - /*this should only be true in the case of link local bridge*/ - return new SetSourceNatAnswer(cmd, false, "unable to find the vlan id for bridge "+pluggedVlanBr+ - " when attempting to set up" + pubVlan + " on router " + routerName); - } else if (pluggedVlanId.equals(pubVlan)) { - break; - } - devNum++; + String pluggedVlanBr = pluggedNic.getBrName(); + String pluggedVlanId = getVlanIdFromBridge(pluggedVlanBr); + if (pubVlan.equalsIgnoreCase(Vlan.UNTAGGED) + && pluggedVlanBr.equalsIgnoreCase(_publicBridgeName)) { + break; + } else if (pluggedVlanBr.equalsIgnoreCase(_linkLocalBridgeName)){ + /*skip over, no physical bridge device exists*/ + } else if (pluggedVlanId == null) { + /*this should only be true in the case of link local bridge*/ + return new SetSourceNatAnswer(cmd, false, "unable to find the vlan id for bridge "+pluggedVlanBr+ + " when attempting to set up" + pubVlan + " on router " + routerName); + } else if (pluggedVlanId.equals(pubVlan)) { + break; + } + devNum++; } String dev = "eth" + devNum; @@ -1544,8 +1533,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements vlanToNicNum.put("LinkLocal",devNum); } else if (pluggedVlan.equalsIgnoreCase(_publicBridgeName) - || pluggedVlan.equalsIgnoreCase(_privBridgeName) - || pluggedVlan.equalsIgnoreCase(_guestBridgeName)) { + || pluggedVlan.equalsIgnoreCase(_privBridgeName) + || pluggedVlan.equalsIgnoreCase(_guestBridgeName)) { vlanToNicNum.put(Vlan.UNTAGGED,devNum); } else { @@ -1560,7 +1549,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements String netmask = Long.toString(NetUtils.getCidrSize(ip.getVlanNetmask())); String subnet = NetUtils.getSubNet(ip.getPublicIp(), ip.getVlanNetmask()); _virtRouterResource.assignVpcIpToRouter(routerIP, ip.isAdd(), ip.getPublicIp(), - nicName, ip.getVlanGateway(), netmask, subnet); + nicName, ip.getVlanGateway(), netmask, subnet); results[i++] = ip.getPublicIp() + " - success"; } @@ -1587,14 +1576,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements if (nic.getBrName().equalsIgnoreCase(_linkLocalBridgeName)) { vlanAllocatedToVM.put("LinkLocal", nicPos); } else { - if (nic.getBrName().equalsIgnoreCase(_publicBridgeName) - || nic.getBrName().equalsIgnoreCase(_privBridgeName) - || nic.getBrName().equalsIgnoreCase(_guestBridgeName)) { - vlanAllocatedToVM.put(Vlan.UNTAGGED, nicPos); - } else { - String vlanId = getVlanIdFromBridge(nic.getBrName()); - vlanAllocatedToVM.put(vlanId, nicPos); - } + if (nic.getBrName().equalsIgnoreCase(_publicBridgeName) + || nic.getBrName().equalsIgnoreCase(_privBridgeName) + || nic.getBrName().equalsIgnoreCase(_guestBridgeName)) { + vlanAllocatedToVM.put(Vlan.UNTAGGED, nicPos); + } else { + String vlanId = getVlanIdFromBridge(nic.getBrName()); + vlanAllocatedToVM.put(vlanId, nicPos); + } } nicPos++; } @@ -1649,13 +1638,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements } KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool( - cmd.getPool().getType(), - cmd.getPool().getUuid()); + cmd.getPool().getType(), + cmd.getPool().getUuid()); if (primaryPool.getType() == StoragePoolType.RBD) { s_logger.debug("Snapshots are not supported on RBD volumes"); return new ManageSnapshotAnswer(cmd, false, - "Snapshots are not supported on RBD volumes"); + "Snapshots are not supported on RBD volumes"); } KVMPhysicalDisk disk = primaryPool.getPhysicalDisk(cmd @@ -1728,7 +1717,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Connect conn = LibvirtConnection.getConnection(); secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI( - secondaryStoragePoolUrl); + secondaryStoragePoolUrl); String ssPmountPath = secondaryStoragePool.getLocalPath(); snapshotRelPath = File.separator + "snapshots" + File.separator @@ -1739,8 +1728,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements + File.separator + dcId + File.separator + accountId + File.separator + volumeId; KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool( - cmd.getPool().getType(), - cmd.getPrimaryStoragePoolNameLabel()); + cmd.getPool().getType(), + cmd.getPrimaryStoragePoolNameLabel()); KVMPhysicalDisk snapshotDisk = primaryPool.getPhysicalDisk(cmd .getVolumePath()); Script command = new Script(_manageSnapshotPath, _cmdsTimeout, @@ -1768,8 +1757,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements } KVMStoragePool primaryStorage = _storagePoolMgr.getStoragePool( - cmd.getPool().getType(), - cmd.getPool().getUuid()); + cmd.getPool().getType(), + cmd.getPool().getUuid()); if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING && !primaryStorage.isExternalSnapshot()) { String vmUuid = vm.getUUIDString(); @@ -1853,7 +1842,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements KVMStoragePool secondaryStoragePool = null; try { secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(cmd - .getSecondaryStorageUrl()); + .getSecondaryStorageUrl()); String ssPmountPath = secondaryStoragePool.getLocalPath(); String snapshotDestPath = ssPmountPath + File.separator @@ -1884,15 +1873,15 @@ public class LibvirtComputingResource extends ServerResourceBase implements int index = snapshotPath.lastIndexOf("/"); snapshotPath = snapshotPath.substring(0, index); KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI( - cmd.getSecondaryStorageUrl() - + snapshotPath); + cmd.getSecondaryStorageUrl() + + snapshotPath); KVMPhysicalDisk snapshot = secondaryPool.getPhysicalDisk(cmd .getSnapshotName()); String primaryUuid = cmd.getPrimaryStoragePoolNameLabel(); KVMStoragePool primaryPool = _storagePoolMgr .getStoragePool(cmd.getPool().getType(), - primaryUuid); + primaryUuid); String volUuid = UUID.randomUUID().toString(); KVMPhysicalDisk disk = _storagePoolMgr.copyPhysicalDisk(snapshot, volUuid, primaryPool); @@ -1928,7 +1917,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements .getSnapshotName()); secondaryPool = _storagePoolMgr.getStoragePoolByURI( - cmd.getSecondaryStorageUrl()); + cmd.getSecondaryStorageUrl()); String templatePath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder; @@ -1978,8 +1967,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) { try { KVMStoragePool sp = _storagePoolMgr.getStoragePool( - cmd.getPooltype(), - cmd.getStorageId()); + cmd.getPooltype(), + cmd.getStorageId()); return new GetStorageStatsAnswer(cmd, sp.getCapacity(), sp.getUsed()); } catch (CloudRuntimeException e) { @@ -1999,11 +1988,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements String templateInstallFolder = "/template/tmpl/" + templateFolder; secondaryStorage = _storagePoolMgr.getStoragePoolByURI( - secondaryStorageURL); + secondaryStorageURL); KVMStoragePool primary = _storagePoolMgr.getStoragePool( - cmd.getPool().getType(), - cmd.getPrimaryStoragePoolNameLabel()); + cmd.getPool().getType(), + cmd.getPrimaryStoragePoolNameLabel()); KVMPhysicalDisk disk = primary.getPhysicalDisk(cmd.getVolumePath()); String tmpltPath = secondaryStorage.getLocalPath() + File.separator + templateInstallFolder; @@ -2024,12 +2013,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements } else { s_logger.debug("Converting RBD disk " + disk.getPath() + " into template " + cmd.getUniqueName()); Script.runSimpleBashScript("qemu-img convert" - + " -f raw -O qcow2 " - + KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(), - primary.getSourcePort(), - primary.getAuthUserName(), - primary.getAuthSecret(), - disk.getPath()) + + " -f raw -O qcow2 " + + KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(), + primary.getSourcePort(), + primary.getAuthUserName(), + primary.getAuthSecret(), + disk.getPath()) + " " + tmpltPath + "/" + cmd.getUniqueName() + ".qcow2"); File templateProp = new File(tmpltPath + "/template.properties"); if (!templateProp.exists()) { @@ -2126,8 +2115,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements /* Copy volume to primary storage */ KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool( - cmd.getPool().getType(), - cmd.getPoolUuid()); + cmd.getPool().getType(), + cmd.getPoolUuid()); KVMPhysicalDisk primaryVol = _storagePoolMgr.copyPhysicalDisk( tmplVol, UUID.randomUUID().toString(), primaryPool); @@ -2233,7 +2222,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements final StringBuffer sb = new StringBuffer(); sb.append("http://").append(proxyManagementIp).append(":" + cmdPort) - .append("/cmd/getstatus"); + .append("/cmd/getstatus"); boolean success = true; try { @@ -2291,8 +2280,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements try { Connect conn = LibvirtConnection.getConnection(); KVMStoragePool primary = _storagePoolMgr.getStoragePool( - cmd.getPooltype(), - cmd.getPoolUuid()); + cmd.getPooltype(), + cmd.getPoolUuid()); KVMPhysicalDisk disk = primary.getPhysicalDisk(cmd.getVolumePath()); attachOrDetachDisk(conn, cmd.getAttach(), cmd.getVmName(), disk, cmd.getDeviceId().intValue()); @@ -2364,10 +2353,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements private Answer execute(PingTestCommand cmd) { String result = null; final String computingHostIp = cmd.getComputingHostIp(); // TODO, split - // the - // command - // into 2 - // types + // the + // command + // into 2 + // types if (computingHostIp != null) { result = doPingTest(computingHostIp); @@ -2507,7 +2496,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements final Script cpuScript = new Script("/bin/bash", s_logger); cpuScript.add("-c"); cpuScript - .add("idle=$(top -b -n 1|grep Cpu\\(s\\):|cut -d% -f4|cut -d, -f2);echo $idle"); + .add("idle=$(top -b -n 1|grep Cpu\\(s\\):|cut -d% -f4|cut -d, -f2);echo $idle"); final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); String result = cpuScript.execute(parser); @@ -2521,7 +2510,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements final Script memScript = new Script("/bin/bash", s_logger); memScript.add("-c"); memScript - .add("freeMem=$(free|grep cache:|awk '{print $4}');echo $freeMem"); + .add("freeMem=$(free|grep cache:|awk '{print $4}');echo $freeMem"); final OutputInterpreter.OneLineParser Memparser = new OutputInterpreter.OneLineParser(); result = memScript.execute(Memparser); if (result != null) { @@ -2721,7 +2710,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements script.add("-m","700"); script.add(_SSHKEYSPATH); script.execute(); - + if(!sshKeysDir.exists()) { s_logger.debug("failed to create directory " + _SSHKEYSPATH); } @@ -2903,7 +2892,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements for (NicTO nic : nics) { if (nic.getIsolationUri() != null && nic.getIsolationUri().getScheme() - .equalsIgnoreCase(IsolationType.Ec2.toString())) { + .equalsIgnoreCase(IsolationType.Ec2.toString())) { if (vmSpec.getType() != VirtualMachine.Type.User) { default_network_rules_for_systemvm(conn, vmName); break; @@ -2940,7 +2929,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements String path = isoPath.substring(0, index); String name = isoPath.substring(index + 1); KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI( - path); + path); KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name); return isoVol.getPath(); } else { @@ -2958,7 +2947,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements return arg0.getDeviceId() > arg1.getDeviceId() ? 1 : -1; } }); - + for (VolumeTO volume : disks) { KVMPhysicalDisk physicalDisk = null; KVMStoragePool pool = null; @@ -2968,12 +2957,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements String volDir = volPath.substring(0, index); String volName = volPath.substring(index + 1); KVMStoragePool secondaryStorage = _storagePoolMgr. - getStoragePoolByURI(volDir); + getStoragePoolByURI(volDir); physicalDisk = secondaryStorage.getPhysicalDisk(volName); } else if (volume.getType() != Volume.Type.ISO) { pool = _storagePoolMgr.getStoragePool( - volume.getPoolType(), - volume.getPoolUuid()); + volume.getPoolType(), + volume.getPoolUuid()); physicalDisk = pool.getPhysicalDisk(volume.getPath()); } @@ -2999,23 +2988,23 @@ public class LibvirtComputingResource extends ServerResourceBase implements For RBD pools we use the secret mechanism in libvirt. We store the secret under the UUID of the pool, that's why we pass the pool's UUID as the authSecret - */ + */ disk.defNetworkBasedDisk(physicalDisk.getPath().replace("rbd:", ""), pool.getSourceHost(), pool.getSourcePort(), - pool.getAuthUserName(), pool.getUuid(), - devId, diskBusType, diskProtocol.RBD); + pool.getAuthUserName(), pool.getUuid(), + devId, diskBusType, diskProtocol.RBD); } else if (pool.getType() == StoragePoolType.CLVM) { disk.defBlockBasedDisk(physicalDisk.getPath(), devId, - diskBusType); + diskBusType); } else { if (volume.getType() == Volume.Type.DATADISK) { - disk.defFileBasedDisk(physicalDisk.getPath(), devId, - DiskDef.diskBus.VIRTIO, - DiskDef.diskFmtType.QCOW2); - } else { - disk.defFileBasedDisk(physicalDisk.getPath(), devId, diskBusType, DiskDef.diskFmtType.QCOW2); - } + disk.defFileBasedDisk(physicalDisk.getPath(), devId, + DiskDef.diskBus.VIRTIO, + DiskDef.diskFmtType.QCOW2); + } else { + disk.defFileBasedDisk(physicalDisk.getPath(), devId, diskBusType, DiskDef.diskFmtType.QCOW2); + } - } + } } @@ -3052,8 +3041,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements VolumeTO rootVol = getVolume(vmSpec, Volume.Type.ROOT); String patchName = vmName + "-patchdisk"; KVMStoragePool pool = _storagePoolMgr.getStoragePool( - rootVol.getPoolType(), - rootVol.getPoolUuid()); + rootVol.getPoolType(), + rootVol.getPoolUuid()); String patchDiskPath = pool.getLocalPath() + "/" + patchName; List phyDisks = pool.listPhysicalDisks(); @@ -3069,7 +3058,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements if (!foundDisk) { s_logger.debug("generating new patch disk for " + vmName + " since none was found"); KVMPhysicalDisk disk = pool.createPhysicalDisk(patchName, KVMPhysicalDisk.PhysicalDiskFormat.RAW, - 10L * 1024 * 1024); + 10L * 1024 * 1024); } else { s_logger.debug("found existing patch disk at " + patchDiskPath + " using it for " + vmName); } @@ -3091,9 +3080,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements patchDisk.defBlockBasedDisk(patchDiskPath, 1, rootDisk.getBusType()); } else { patchDisk.defFileBasedDisk(patchDiskPath, 1, rootDisk.getBusType(), - DiskDef.diskFmtType.RAW); + DiskDef.diskFmtType.RAW); } - + disks.add(patchDisk); String bootArgs = vmSpec.getBootArgs(); @@ -3162,14 +3151,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements protected synchronized String attachOrDetachISO(Connect conn, String vmName, String isoPath, boolean isAttach) - throws LibvirtException, URISyntaxException, InternalErrorException { + throws LibvirtException, URISyntaxException, InternalErrorException { String isoXml = null; if (isoPath != null && isAttach) { int index = isoPath.lastIndexOf("/"); String path = isoPath.substring(0, index); String name = isoPath.substring(index + 1); KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI( - path); + path); KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name); isoPath = isoVol.getPath(); @@ -3691,9 +3680,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements info.add(ram); info.add(cap); long dom0ram = Math.min(ram / 10, 768 * 1024 * 1024L);// save a maximum - // of 10% of - // system ram or - // 768M + // of 10% of + // system ram or + // 768M dom0ram = Math.max(dom0ram, _dom0MinMem); info.add(dom0ram); s_logger.debug("cpus=" + cpus + ", speed=" + speed + ", ram=" + ram @@ -4162,7 +4151,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements NodeInfo node = conn.nodeInfo(); utilization = utilization / node.cpus; if(utilization > 0){ - stats.setCPUUtilization(utilization * 100); + stats.setCPUUtilization(utilization * 100); } } diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index 9b1afb27394..10810b70d33 100755 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -84,6 +84,10 @@ public class ApiDispatcher { private static ApiDispatcher s_instance; + public static ApiDispatcher getInstance() { + return s_instance; + } + protected ApiDispatcher() { super(); Map configs = _configDao.getConfiguration(); diff --git a/server/src/com/cloud/api/commands/ListTrafficMonitorsCmd.java b/server/src/com/cloud/api/commands/ListTrafficMonitorsCmd.java index 02f51a8d002..645bf3b7307 100644 --- a/server/src/com/cloud/api/commands/ListTrafficMonitorsCmd.java +++ b/server/src/com/cloud/api/commands/ListTrafficMonitorsCmd.java @@ -19,26 +19,28 @@ package com.cloud.api.commands; import java.util.ArrayList; import java.util.List; +import javax.inject.Inject; + +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.TrafficMonitorResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.log4j.Logger; -import org.apache.cloudstack.api.ApiConstants; -import org.apache.cloudstack.api.BaseListCmd; -import org.apache.cloudstack.api.APICommand; -import org.apache.cloudstack.api.Parameter; -import org.apache.cloudstack.api.response.ListResponse; import com.cloud.host.Host; import com.cloud.network.NetworkUsageManager; -import com.cloud.server.ManagementService; -import org.apache.cloudstack.api.response.TrafficMonitorResponse; @APICommand(name = "listTrafficMonitors", description="List traffic monitor Hosts.", responseObject = TrafficMonitorResponse.class) public class ListTrafficMonitorsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListServiceOfferingsCmd.class.getName()); + public static final Logger s_logger = Logger.getLogger(ListServiceOfferingsCmd.class.getName()); private static final String s_name = "listtrafficmonitorsresponse"; + @Inject NetworkUsageManager networkUsageMgr; ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// @@ -66,17 +68,15 @@ public class ListTrafficMonitorsCmd extends BaseListCmd { @Override public void execute(){ - ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - NetworkUsageManager networkUsageMgr = locator.getManager(NetworkUsageManager.class); - List trafficMonitors = networkUsageMgr.listTrafficMonitors(this); + List trafficMonitors = networkUsageMgr.listTrafficMonitors(this); ListResponse listResponse = new ListResponse(); List responses = new ArrayList(); for (Host trafficMonitor : trafficMonitors) { TrafficMonitorResponse response = networkUsageMgr.getApiResponse(trafficMonitor); - response.setObjectName("trafficmonitor"); - response.setResponseName(getCommandName()); - responses.add(response); + response.setObjectName("trafficmonitor"); + response.setResponseName(getCommandName()); + responses.add(response); } listResponse.setResponses(responses); diff --git a/server/src/com/cloud/storage/s3/S3ManagerImpl.java b/server/src/com/cloud/storage/s3/S3ManagerImpl.java index 8a1354c9282..62db0bb671d 100644 --- a/server/src/com/cloud/storage/s3/S3ManagerImpl.java +++ b/server/src/com/cloud/storage/s3/S3ManagerImpl.java @@ -42,10 +42,13 @@ import java.util.UUID; import java.util.concurrent.Callable; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd; +import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd; import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -53,9 +56,6 @@ import com.cloud.agent.api.DeleteTemplateFromS3Command; import com.cloud.agent.api.DownloadTemplateFromS3ToSecondaryStorageCommand; import com.cloud.agent.api.UploadTemplateToS3FromSecondaryStorageCommand; import com.cloud.agent.api.to.S3TO; -import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd; -import org.springframework.stereotype.Component; - import com.cloud.configuration.Config; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.DataCenterVO; @@ -77,7 +77,6 @@ import com.cloud.storage.dao.VMTemplateS3Dao; import com.cloud.storage.dao.VMTemplateZoneDao; import com.cloud.storage.secondary.SecondaryStorageVmManager; import com.cloud.utils.S3Utils.ClientOptions; - import com.cloud.utils.db.Filter; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.exception.CloudRuntimeException; @@ -90,7 +89,7 @@ public class S3ManagerImpl implements S3Manager { private String name; - @Inject + @Inject private AgentManager agentManager; @Inject @@ -288,32 +287,32 @@ public class S3ManagerImpl implements S3Manager { executeWithNoWaitLock(determineLockId(accountId, templateId), new Callable() { - @Override - public Void call() throws Exception { + @Override + public Void call() throws Exception { - final Answer answer = agentManager.sendToSSVM(null, - new DeleteTemplateFromS3Command(s3, - accountId, templateId)); - if (answer == null || !answer.getResult()) { - final String errorMessage = format( - "Delete Template Failed: Unable to delete template id %1$s from S3 due to following error: %2$s", - templateId, - ((answer == null) ? "answer is null" - : answer.getDetails())); - LOGGER.error(errorMessage); - throw new CloudRuntimeException(errorMessage); - } + final Answer answer = agentManager.sendToSSVM(null, + new DeleteTemplateFromS3Command(s3, + accountId, templateId)); + if (answer == null || !answer.getResult()) { + final String errorMessage = format( + "Delete Template Failed: Unable to delete template id %1$s from S3 due to following error: %2$s", + templateId, + ((answer == null) ? "answer is null" + : answer.getDetails())); + LOGGER.error(errorMessage); + throw new CloudRuntimeException(errorMessage); + } - vmTemplateS3Dao.remove(vmTemplateS3VO.getId()); - LOGGER.debug(format( - "Deleted template %1$s from S3.", - templateId)); + vmTemplateS3Dao.remove(vmTemplateS3VO.getId()); + LOGGER.debug(format( + "Deleted template %1$s from S3.", + templateId)); - return null; + return null; - } + } - }); + }); } catch (Exception e) { @@ -384,38 +383,38 @@ public class S3ManagerImpl implements S3Manager { executeWithNoWaitLock(determineLockId(accountId, templateId), new Callable() { - @Override - public Void call() throws Exception { + @Override + public Void call() throws Exception { - final Answer answer = agentManager.sendToSSVM( - dataCenterId, cmd); + final Answer answer = agentManager.sendToSSVM( + dataCenterId, cmd); - if (answer == null || !answer.getResult()) { - final String errMsg = String - .format("Failed to download template from S3 to secondary storage due to %1$s", - (answer == null ? "answer is null" - : answer.getDetails())); - LOGGER.error(errMsg); - throw new CloudRuntimeException(errMsg); - } + if (answer == null || !answer.getResult()) { + final String errMsg = String + .format("Failed to download template from S3 to secondary storage due to %1$s", + (answer == null ? "answer is null" + : answer.getDetails())); + LOGGER.error(errMsg); + throw new CloudRuntimeException(errMsg); + } - final String installPath = join( - asList("template", "tmpl", accountId, - templateId), File.separator); - final VMTemplateHostVO tmpltHost = new VMTemplateHostVO( - secondaryStorageHost.getId(), templateId, - now(), 100, Status.DOWNLOADED, null, null, - null, installPath, template.getUrl()); - tmpltHost.setSize(templateS3VO.getSize()); - tmpltHost.setPhysicalSize(templateS3VO - .getPhysicalSize()); - vmTemplateHostDao.persist(tmpltHost); + final String installPath = join( + asList("template", "tmpl", accountId, + templateId), File.separator); + final VMTemplateHostVO tmpltHost = new VMTemplateHostVO( + secondaryStorageHost.getId(), templateId, + now(), 100, Status.DOWNLOADED, null, null, + null, installPath, template.getUrl()); + tmpltHost.setSize(templateS3VO.getSize()); + tmpltHost.setPhysicalSize(templateS3VO + .getPhysicalSize()); + vmTemplateHostDao.persist(tmpltHost); - return null; + return null; - } + } - }); + }); } catch (Exception e) { final String errMsg = "Failed to download template from S3 to secondary storage due to " @@ -608,50 +607,50 @@ public class S3ManagerImpl implements S3Manager { executeWithNoWaitLock(determineLockId(accountId, templateId), new Callable() { - @Override - public Void call() throws Exception { + @Override + public Void call() throws Exception { - final UploadTemplateToS3FromSecondaryStorageCommand cmd = new UploadTemplateToS3FromSecondaryStorageCommand( - s3, secondaryHost.getStorageUrl(), - dataCenterId, accountId, templateId); + final UploadTemplateToS3FromSecondaryStorageCommand cmd = new UploadTemplateToS3FromSecondaryStorageCommand( + s3, secondaryHost.getStorageUrl(), + dataCenterId, accountId, templateId); - final Answer answer = agentManager.sendToSSVM( - dataCenterId, cmd); - if (answer == null || !answer.getResult()) { + final Answer answer = agentManager.sendToSSVM( + dataCenterId, cmd); + if (answer == null || !answer.getResult()) { - final String reason = answer != null ? answer - .getDetails() - : "S3 template sync failed due to an unspecified error."; + final String reason = answer != null ? answer + .getDetails() + : "S3 template sync failed due to an unspecified error."; throw new CloudRuntimeException( format("Failed to upload template id %1$s to S3 from secondary storage due to %2$s.", templateId, reason)); - } + } - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(format( - "Creating VMTemplateS3VO instance using template id %1s.", - templateId)); - } + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(format( + "Creating VMTemplateS3VO instance using template id %1s.", + templateId)); + } - final VMTemplateS3VO vmTemplateS3VO = new VMTemplateS3VO( - s3.getId(), templateId, now(), - templateHostRef.getSize(), templateHostRef - .getPhysicalSize()); + final VMTemplateS3VO vmTemplateS3VO = new VMTemplateS3VO( + s3.getId(), templateId, now(), + templateHostRef.getSize(), templateHostRef + .getPhysicalSize()); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(format("Persisting %1$s", - vmTemplateS3VO)); - } + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(format("Persisting %1$s", + vmTemplateS3VO)); + } - vmTemplateS3Dao.persist(vmTemplateS3VO); - propagateTemplateToAllZones(vmTemplateS3VO); + vmTemplateS3Dao.persist(vmTemplateS3VO); + propagateTemplateToAllZones(vmTemplateS3VO); - return null; + return null; - } + } - }); + }); } catch (Exception e) { diff --git a/usage/src/com/cloud/usage/UsageServer.java b/usage/src/com/cloud/usage/UsageServer.java index aedbe768476..5fe46e68d6d 100644 --- a/usage/src/com/cloud/usage/UsageServer.java +++ b/usage/src/com/cloud/usage/UsageServer.java @@ -38,8 +38,7 @@ public class UsageServer { } public void start() { - final ComponentLocator _locator = ComponentLocator.getLocator(UsageServer.Name, "usage-components.xml", "log4j-cloud_usage"); - UsageManager mgr = _locator.getManager(UsageManager.class); + UsageManager mgr = new UsageManager(); if (mgr != null) { if (s_logger.isInfoEnabled()) { s_logger.info("UsageServer ready..."); diff --git a/utils/test/com/cloud/utils/db/TransactionTest.java b/utils/test/com/cloud/utils/db/TransactionTest.java index 5bd1e9aca65..b952be2c28b 100644 --- a/utils/test/com/cloud/utils/db/TransactionTest.java +++ b/utils/test/com/cloud/utils/db/TransactionTest.java @@ -26,7 +26,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; - +import com.cloud.utils.component.ComponentContext; import com.cloud.utils.exception.CloudRuntimeException; /** @@ -34,7 +34,7 @@ import com.cloud.utils.exception.CloudRuntimeException; * all its testcases to set up a test db table, and then tear down these test db artifacts after all testcases are run. * * @author Min Chen - * + * */ public class TransactionTest { @@ -76,7 +76,7 @@ public class TransactionTest { * that the same db connection is reused rather than acquiring a new one each time in typical transaction model. */ public void testUserManagedConnection() { - DbTestDao testDao = ComponentLocator.inject(DbTestDao.class); + DbTestDao testDao = ComponentContext.inject(DbTestDao.class); Transaction txn = Transaction.open("SingleConnectionThread"); Connection conn = null; try { @@ -115,7 +115,7 @@ public class TransactionTest { * This test is simulating ClusterHeartBeat process, where the same transaction and db connection is reused. */ public void testTransactionReuse() { - DbTestDao testDao = ComponentLocator.inject(DbTestDao.class); + DbTestDao testDao = ComponentContext.inject(DbTestDao.class); // acquire a db connection and keep it Connection conn = null; try { diff --git a/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java b/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java index 13e396db06d..bf917dead4f 100644 --- a/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java +++ b/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java @@ -20,7 +20,7 @@ import junit.framework.TestCase; import org.apache.log4j.Logger; - +import com.cloud.utils.component.ComponentContext; import com.cloud.utils.db.DB; import com.cloud.utils.exception.CloudRuntimeException; @@ -48,9 +48,9 @@ public class CglibThrowableRendererTest extends TestCase { } } } - + public void testException() { - Test test = ComponentLocator.inject(Test.class); + Test test = ComponentContext.inject(Test.class); try { test.exception(); } catch (Exception e) {